machine config - Change CFG variable names to lowercase; Change to always access them as 'CFG.property'
This commit is contained in:
parent
ccc032b379
commit
74c6f83fcc
|
|
@ -1,9 +1,5 @@
|
||||||
const { logMemory, num2hex } = require('./logging.js');
|
const { logMemory, num2hex } = require('./logging.js');
|
||||||
const {
|
const CFG = require('./machine.config.js');
|
||||||
INITIAL_IP_ADDRESS,
|
|
||||||
DISPLAY_ADDR,
|
|
||||||
POINTER_TO_DISPLAY,
|
|
||||||
} = require('./machine.config.js');
|
|
||||||
|
|
||||||
// 1 = verbose
|
// 1 = verbose
|
||||||
// 2 = what i'm currently focusing on
|
// 2 = what i'm currently focusing on
|
||||||
|
|
@ -203,7 +199,7 @@ function decodeInstructions(source) {
|
||||||
if (lines[idOfFirstLineWithCode].operation.startsWith(ASM_IP_LABEL)) {
|
if (lines[idOfFirstLineWithCode].operation.startsWith(ASM_IP_LABEL)) {
|
||||||
IP = parseInt(lines[idOfFirstLineWithCode].argument);
|
IP = parseInt(lines[idOfFirstLineWithCode].argument);
|
||||||
} else {
|
} else {
|
||||||
IP = INITIAL_IP_ADDRESS;
|
IP = CFG.initialIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize arrays to collect assembled code
|
// Initialize arrays to collect assembled code
|
||||||
|
|
@ -214,7 +210,7 @@ function decodeInstructions(source) {
|
||||||
let debugInfo = {};
|
let debugInfo = {};
|
||||||
|
|
||||||
// Initialize memory-mapped IO -- TODO this should probably be in the CPU, not here
|
// 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
|
// Initialize arrays that collect code references that
|
||||||
// have to be revisited after our first pass through the source
|
// have to be revisited after our first pass through the source
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ const io = require('./io.js');
|
||||||
const inputFile_str = fs.readFileSync(filename, 'utf8');
|
const inputFile_str = fs.readFileSync(filename, 'utf8');
|
||||||
let assemblerOutput = assembler.assemble(inputFile_str);
|
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.loadMemory(assemblerOutput.machineCode);
|
||||||
cpu.loadSourceInfo(assemblerOutput.debugInfo);
|
cpu.loadSourceInfo(assemblerOutput.debugInfo);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ const CFG = require('./machine.config.js');
|
||||||
const { num2hex } = require('./logging.js');
|
const { num2hex } = require('./logging.js');
|
||||||
|
|
||||||
function readKeyMem(mem) {
|
function readKeyMem(mem) {
|
||||||
return mem[CFG.KEYPAD_ADDR];
|
return mem[CFG.keypadAddr];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getKeypadInput(cpu) {
|
function getKeypadInput(cpu) {
|
||||||
|
|
@ -16,8 +16,8 @@ function getKeypadInput(cpu) {
|
||||||
// TODO: is it possible to turn this off again?
|
// TODO: is it possible to turn this off again?
|
||||||
if (key.sequence === '\x03') process.exit();
|
if (key.sequence === '\x03') process.exit();
|
||||||
let name = key.name.toUpperCase();
|
let name = key.name.toUpperCase();
|
||||||
if (name in CFG.KEY_MAP) {
|
if (name in CFG.keyMap) {
|
||||||
cpu.memory[CFG.KEYPAD_ADDR] = CFG.KEY_MAP[name];
|
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
|
* @param {Boolean} pretty - Display pixels using black and white emoji circles
|
||||||
**/
|
**/
|
||||||
function showDisplay(mem, pretty=false) {
|
function showDisplay(mem, pretty=false) {
|
||||||
const disp = mem[CFG.POINTER_TO_DISPLAY];
|
const disp = mem[CFG.pointerToDisplay];
|
||||||
const num2pic = (n) => n > 0 ? '⚫' : '⚪';
|
const num2pic = (n) => n > 0 ? '⚫' : '⚪';
|
||||||
let fmt = (n) => num2hex(n);
|
let fmt = (n) => num2hex(n);
|
||||||
if (pretty) fmt = (n) => num2pic(n);
|
if (pretty) fmt = (n) => num2pic(n);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"INITIAL_IP_ADDRESS": 29,
|
"initialIP": 29,
|
||||||
|
|
||||||
// Use these in CPU:
|
// Use these in CPU:
|
||||||
"DISPLAY_ADDR": 0,
|
"displayAddr": 0,
|
||||||
"KEYPAD_ADDR": 27,
|
"keypadAddr": 27,
|
||||||
// Store the `DISPLAY_ADDR` at this address when assembling:
|
// 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
|
// Same layout as COSMAC VIP / CHIP-8
|
||||||
// (This object maps qwerty keys to hex keys
|
// (This object maps qwerty keys to hex keys
|
||||||
// so that they are arranged in the same layout
|
// so that they are arranged in the same layout
|
||||||
|
|
@ -27,5 +27,5 @@ module.exports = {
|
||||||
// max number of times to step the CPU,
|
// max number of times to step the CPU,
|
||||||
// to stop endless loops
|
// to stop endless loops
|
||||||
// 0 = infinite
|
// 0 = infinite
|
||||||
"DEFAULT_CYCLE_LIMIT": 2048,
|
"defaultCycleLimit": 2048,
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue