From da0ababc5998264729614ccfd67fad979ec6b730 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 1 Aug 2023 13:30:48 +0100 Subject: [PATCH] Initialize instruction pointer based on a constant, to move it after screen memory --- sketches/assembler.js | 5 +++-- sketches/simulator-sketch-v3.js | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sketches/assembler.js b/sketches/assembler.js index c00932a..af14567 100644 --- a/sketches/assembler.js +++ b/sketches/assembler.js @@ -15,6 +15,7 @@ const printMemory = require('./print-memory.js'); // 2 = what i'm currently focusing on // 3 = always print const DEBUG = 2; +const INITIAL_IP_ADDRESS = 32; const mnemonicsWithOptionalArgs = ['end', 'cfc', 'chp']; const mnemonics2opcodes = { @@ -31,9 +32,9 @@ const mnemonics2opcodes = { function decodeInstructions(str) { let lines = str.split(/\n/); // returns an array of lines - let machineCode = []; + let machineCode = new Array(INITIAL_IP_ADDRESS).fill(0); let labels = {}; - let byteCursor = 0; + let byteCursor = INITIAL_IP_ADDRESS; for (let i = 0; i < lines.length; i++) { console.log(); console.group(`Input line ${i}, cursor ${byteCursor}`); diff --git a/sketches/simulator-sketch-v3.js b/sketches/simulator-sketch-v3.js index bda3fe2..df7edcd 100644 --- a/sketches/simulator-sketch-v3.js +++ b/sketches/simulator-sketch-v3.js @@ -3,13 +3,15 @@ // - instructions are two bytes long: // one byte for the opcode, one for the argument +const INITIAL_IP_ADDRESS = 32; const CYCLE_LIMIT = 64; // max number of times to step the CPU, to stop endless loops -// STATE +const display = require('./display.js'); +// STATE const CPU = { running: false, - IP: 0, + IP: INITIAL_IP_ADDRESS, CF: 0, Acc: 0, memory: null, @@ -188,6 +190,7 @@ exports.runProgram = (code) => { if (!CPU.running) break; if (CPU.IP >= CPU.memory.length) break; stepCPU(); + display.printDisplay(CPU.memory); }; }