Initialize instruction pointer based on a constant, to move it after screen memory

This commit is contained in:
n loewen 2023-08-01 13:30:48 +01:00
parent 36e013b866
commit da0ababc59
2 changed files with 8 additions and 4 deletions

View File

@ -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}`);

View File

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