Fix: Load CPU with 256 bytes of memory, regardless of the length of the data provided

(This mostly reverts the previous commit -- better to have short assembler output, and memory-padding/validation on the CPU side)
This commit is contained in:
n loewen 2023-08-16 15:55:04 +01:00
parent 6e897b7f74
commit b8265409cf
2 changed files with 5 additions and 8 deletions

View File

@ -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');

4
cpu.js
View File

@ -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 },