Move display memory and add a pointer to display memory
This commit is contained in:
parent
c732f4408f
commit
91ff26fdea
|
|
@ -5,7 +5,8 @@ const printMemory = require('./print-memory.js');
|
||||||
// 3 = always print
|
// 3 = always print
|
||||||
// 4 = silent
|
// 4 = silent
|
||||||
const DEBUG = 4;
|
const DEBUG = 4;
|
||||||
const INITIAL_IP_ADDRESS = 32;
|
const INITIAL_IP_ADDRESS = 48;
|
||||||
|
const START_OF_DISPLAY_MEM = 0;
|
||||||
|
|
||||||
const mnemonicsWithOptionalArgs = ['end', 'cfc', 'chp'];
|
const mnemonicsWithOptionalArgs = ['end', 'cfc', 'chp'];
|
||||||
const mnemonics2opcodes = {
|
const mnemonics2opcodes = {
|
||||||
|
|
@ -22,7 +23,10 @@ const mnemonics2opcodes = {
|
||||||
|
|
||||||
function decodeInstructions(str) {
|
function decodeInstructions(str) {
|
||||||
let lines = str.split(/\n/); // returns an array of lines
|
let lines = str.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);
|
||||||
|
machineCode[0] = START_OF_DISPLAY_MEM;
|
||||||
|
|
||||||
let labels = {};
|
let labels = {};
|
||||||
let IP = INITIAL_IP_ADDRESS;
|
let IP = INITIAL_IP_ADDRESS;
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
|
const START_OF_DISPLAY_MEM = 0;
|
||||||
|
|
||||||
exports.printDisplay = (mem) => {
|
exports.printDisplay = (mem) => {
|
||||||
for (let i = 0; i < 16; i += 4) {
|
const disp = START_OF_DISPLAY_MEM;
|
||||||
|
for (let i = disp; i < disp + 16; i += 4) {
|
||||||
console.log(`${pad(mem[i])} ${pad(mem[i+1])} ${pad(mem[i+2])} ${pad(mem[i+3])}`);
|
console.log(`${pad(mem[i])} ${pad(mem[i+1])} ${pad(mem[i+2])} ${pad(mem[i+3])}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
// - instructions are two bytes long:
|
// - instructions are two bytes long:
|
||||||
// one byte for the opcode, one for the argument
|
// one byte for the opcode, one for the argument
|
||||||
|
|
||||||
const INITIAL_IP_ADDRESS = 32;
|
const INITIAL_IP_ADDRESS = 48;
|
||||||
const CYCLE_LIMIT = 128; // max number of times to step the CPU, to stop endless loops
|
const CYCLE_LIMIT = 128; // max number of times to step the CPU, to stop endless loops
|
||||||
|
|
||||||
const display = require('./display.js');
|
const display = require('./display.js');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue