From 6e897b7f7405f496c90551862ea46769665d38ed Mon Sep 17 00:00:00 2001 From: n loewen Date: Wed, 16 Aug 2023 15:38:59 +0100 Subject: [PATCH] Fix (Assembler): Pad machine code output to a full $FF bytes --- assembler.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/assembler.js b/assembler.js index c765f01..874655c 100644 --- a/assembler.js +++ b/assembler.js @@ -38,8 +38,11 @@ const mnemonics2opcodes = { function decodeInstructions(line) { let lines = line.split(/\n/); // returns an array of lines - let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); - machineCode[POINTER_TO_START_OF_DISPLAY_MEM] = START_OF_DISPLAY_MEM; + //let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); + let machineCode = new Array(256).fill(0); + dbgExec(2, () => logMemory(new Uint8Array(machineCode))); + machineCode[POINTER_TO_DISPLAY] = DISPLAY_ADDR; + machineCode[POINTER_TO_KEYPAD] = KEYPAD_ADDR; let labels = {}; let constants = {}; @@ -174,8 +177,9 @@ function decodeInstructions(line) { // DECODE! const op = mnemonics2opcodes[opName][addressingMode]; - machineCode.push(op); - machineCode.push(arg_num); + machineCode[IP] = op; + machineCode[IP+1] = arg_num; + dbg(3, `IP: $${num2hex(IP)}, new code: $${num2hex(op)} $${num2hex(arg_num)}`); IP += 2; dbgGroupEnd(1, 'Input line'); @@ -198,10 +202,6 @@ function decodeInstructions(line) { } } - // Add an END at the end - machineCode.push('0'); - machineCode.push('0'); - return new Uint8Array(machineCode); }