machine config - Change CFG variable names to lowercase; Change to always access them as 'CFG.property'

This commit is contained in:
n loewen 2023-08-29 09:56:21 -04:00
parent ccc032b379
commit 74c6f83fcc
4 changed files with 14 additions and 18 deletions

View File

@ -1,9 +1,5 @@
const { logMemory, num2hex } = require('./logging.js');
const {
INITIAL_IP_ADDRESS,
DISPLAY_ADDR,
POINTER_TO_DISPLAY,
} = require('./machine.config.js');
const CFG = require('./machine.config.js');
// 1 = verbose
// 2 = what i'm currently focusing on
@ -203,7 +199,7 @@ function decodeInstructions(source) {
if (lines[idOfFirstLineWithCode].operation.startsWith(ASM_IP_LABEL)) {
IP = parseInt(lines[idOfFirstLineWithCode].argument);
} else {
IP = INITIAL_IP_ADDRESS;
IP = CFG.initialIP;
}
// Initialize arrays to collect assembled code
@ -214,7 +210,7 @@ function decodeInstructions(source) {
let debugInfo = {};
// Initialize memory-mapped IO -- TODO this should probably be in the CPU, not here
machineCode[POINTER_TO_DISPLAY] = DISPLAY_ADDR;
machineCode[CFG.pointerToDisplay] = CFG.displayAddr;
// Initialize arrays that collect code references that
// have to be revisited after our first pass through the source

View File

@ -13,7 +13,7 @@ const io = require('./io.js');
const inputFile_str = fs.readFileSync(filename, 'utf8');
let assemblerOutput = assembler.assemble(inputFile_str);
let cpu = new CPU(CFG.INITIAL_IP_ADDRESS, CFG.DEFAULT_CYCLE_LIMIT);
let cpu = new CPU(CFG.initialIP, CFG.defaultCycleLimit);
cpu.loadMemory(assemblerOutput.machineCode);
cpu.loadSourceInfo(assemblerOutput.debugInfo);

View File

@ -4,7 +4,7 @@ const CFG = require('./machine.config.js');
const { num2hex } = require('./logging.js');
function readKeyMem(mem) {
return mem[CFG.KEYPAD_ADDR];
return mem[CFG.keypadAddr];
}
function getKeypadInput(cpu) {
@ -16,8 +16,8 @@ function getKeypadInput(cpu) {
// TODO: is it possible to turn this off again?
if (key.sequence === '\x03') process.exit();
let name = key.name.toUpperCase();
if (name in CFG.KEY_MAP) {
cpu.memory[CFG.KEYPAD_ADDR] = CFG.KEY_MAP[name];
if (name in CFG.keyMap) {
cpu.memory[CFG.keypadAddr] = CFG.keyMap[name];
}
});
}
@ -29,7 +29,7 @@ function getKeypadInput(cpu) {
* @param {Boolean} pretty - Display pixels using black and white emoji circles
**/
function showDisplay(mem, pretty=false) {
const disp = mem[CFG.POINTER_TO_DISPLAY];
const disp = mem[CFG.pointerToDisplay];
const num2pic = (n) => n > 0 ? '⚫' : '⚪';
let fmt = (n) => num2hex(n);
if (pretty) fmt = (n) => num2pic(n);

View File

@ -1,13 +1,13 @@
module.exports = {
"INITIAL_IP_ADDRESS": 29,
"initialIP": 29,
// Use these in CPU:
"DISPLAY_ADDR": 0,
"KEYPAD_ADDR": 27,
"displayAddr": 0,
"keypadAddr": 27,
// Store the `DISPLAY_ADDR` at this address when assembling:
"POINTER_TO_DISPLAY": 26,
"pointerToDisplay": 26,
"KEY_MAP": {
"keyMap": {
// Same layout as COSMAC VIP / CHIP-8
// (This object maps qwerty keys to hex keys
// so that they are arranged in the same layout
@ -27,5 +27,5 @@ module.exports = {
// max number of times to step the CPU,
// to stop endless loops
// 0 = infinite
"DEFAULT_CYCLE_LIMIT": 2048,
"defaultCycleLimit": 2048,
}