diff --git a/assembler.js b/assembler.js index 874655c..bb7c293 100644 --- a/assembler.js +++ b/assembler.js @@ -38,9 +38,7 @@ const mnemonics2opcodes = { function decodeInstructions(line) { let lines = line.split(/\n/); // returns an array of lines - //let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); - let machineCode = new Array(256).fill(0); - dbgExec(2, () => logMemory(new Uint8Array(machineCode))); + let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); machineCode[POINTER_TO_DISPLAY] = DISPLAY_ADDR; machineCode[POINTER_TO_KEYPAD] = KEYPAD_ADDR; @@ -177,9 +175,8 @@ function decodeInstructions(line) { // DECODE! const op = mnemonics2opcodes[opName][addressingMode]; - machineCode[IP] = op; - machineCode[IP+1] = arg_num; - + machineCode.push(op); + machineCode.push(arg_num); dbg(3, `IP: $${num2hex(IP)}, new code: $${num2hex(op)} $${num2hex(arg_num)}`); IP += 2; dbgGroupEnd(1, 'Input line'); diff --git a/cpu.js b/cpu.js index c70ce3a..fa3ebdb 100644 --- a/cpu.js +++ b/cpu.js @@ -16,8 +16,8 @@ const CPU = { // Functions that update core state /** @param {Uint8Array} data */ loadMemory: (data) => { - if (data.length > 256) { throw new Error("Out of memory error (program too long)"); } - CPU.memory = data; + CPU.memory = new Uint8Array(256); + CPU.memory.set(data, 0); }, setFlagNegative: () => { CPU.FLAGS |= 8 }, setFlagZero: () => { CPU.FLAGS |= 4 },