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:
parent
6e897b7f74
commit
b8265409cf
|
|
@ -38,9 +38,7 @@ const mnemonics2opcodes = {
|
||||||
function decodeInstructions(line) {
|
function decodeInstructions(line) {
|
||||||
let lines = line.split(/\n/); // returns an array of lines
|
let lines = line.split(/\n/); // returns an array of lines
|
||||||
|
|
||||||
//let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0);
|
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_DISPLAY] = DISPLAY_ADDR;
|
||||||
machineCode[POINTER_TO_KEYPAD] = KEYPAD_ADDR;
|
machineCode[POINTER_TO_KEYPAD] = KEYPAD_ADDR;
|
||||||
|
|
||||||
|
|
@ -177,9 +175,8 @@ function decodeInstructions(line) {
|
||||||
// DECODE!
|
// DECODE!
|
||||||
const op = mnemonics2opcodes[opName][addressingMode];
|
const op = mnemonics2opcodes[opName][addressingMode];
|
||||||
|
|
||||||
machineCode[IP] = op;
|
machineCode.push(op);
|
||||||
machineCode[IP+1] = arg_num;
|
machineCode.push(arg_num);
|
||||||
|
|
||||||
dbg(3, `IP: $${num2hex(IP)}, new code: $${num2hex(op)} $${num2hex(arg_num)}`);
|
dbg(3, `IP: $${num2hex(IP)}, new code: $${num2hex(op)} $${num2hex(arg_num)}`);
|
||||||
IP += 2;
|
IP += 2;
|
||||||
dbgGroupEnd(1, 'Input line');
|
dbgGroupEnd(1, 'Input line');
|
||||||
|
|
|
||||||
4
cpu.js
4
cpu.js
|
|
@ -16,8 +16,8 @@ const CPU = {
|
||||||
// Functions that update core state
|
// Functions that update core state
|
||||||
/** @param {Uint8Array} data */
|
/** @param {Uint8Array} data */
|
||||||
loadMemory: (data) => {
|
loadMemory: (data) => {
|
||||||
if (data.length > 256) { throw new Error("Out of memory error (program too long)"); }
|
CPU.memory = new Uint8Array(256);
|
||||||
CPU.memory = data;
|
CPU.memory.set(data, 0);
|
||||||
},
|
},
|
||||||
setFlagNegative: () => { CPU.FLAGS |= 8 },
|
setFlagNegative: () => { CPU.FLAGS |= 8 },
|
||||||
setFlagZero: () => { CPU.FLAGS |= 4 },
|
setFlagZero: () => { CPU.FLAGS |= 4 },
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue