refactor the logic of examine

This commit is contained in:
wixette 2020-03-07 01:37:05 +08:00
parent ae735688e6
commit c4b4e5d06d
2 changed files with 25 additions and 12 deletions

View File

@ -211,7 +211,7 @@ db ff d3 ff c3 00 00 // Switch echo between A2 and A1.
dumpMemElem.innerHTML = dumpHtml; dumpMemElem.innerHTML = dumpHtml;
} }
function getInputWord() { function getInputAddressCallback() {
var word = 0; var word = 0;
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
var switchElem = document.getElementById('s' + i); var switchElem = document.getElementById('s' + i);
@ -225,6 +225,7 @@ db ff d3 ff c3 00 00 // Switch echo between A2 and A1.
var sim = new Sim8800(256, 1000000, var sim = new Sim8800(256, 1000000,
setAddressLedsCallback, setDataLedsCallback, setAddressLedsCallback, setDataLedsCallback,
setWaitLedCallback, setStatusLedsCallback, setWaitLedCallback, setStatusLedsCallback,
getInputAddressCallback,
dumpCpuCallback, dumpMemCallback); dumpCpuCallback, dumpMemCallback);
function powerOn() { function powerOn() {
@ -257,8 +258,7 @@ db ff d3 ff c3 00 00 // Switch echo between A2 and A1.
} }
function examine() { function examine() {
var address = getInputWord(); sim.examine();
sim.examine(address);
} }
function examineNext() { function examineNext() {

View File

@ -32,6 +32,8 @@ class Sim8800 {
* set the WAIT LED. * set the WAIT LED.
* @param {function(boolean)?} setStatusLedsCallback The callback to * @param {function(boolean)?} setStatusLedsCallback The callback to
* set the STATUS LEDs. * set the STATUS LEDs.
* @param {function():number?} getInputAddressCallback The
* callback to get the input word from address/data switches.
* @param {function(string)?} dumpCpuCallback The callback to receive * @param {function(string)?} dumpCpuCallback The callback to receive
* CPU status dump, in HTML string. * CPU status dump, in HTML string.
* @param {function(string)?} dumpMemCallback The callback to receive * @param {function(string)?} dumpMemCallback The callback to receive
@ -40,6 +42,7 @@ class Sim8800 {
constructor(memSize, clockRate, constructor(memSize, clockRate,
setAddressLedsCallback, setDataLedsCallback, setAddressLedsCallback, setDataLedsCallback,
setWaitLedCallback, setStatusLedsCallback, setWaitLedCallback, setStatusLedsCallback,
getInputAddressCallback,
dumpCpuCallback, dumpMemCallback) { dumpCpuCallback, dumpMemCallback) {
this.clockRate = clockRate; this.clockRate = clockRate;
this.mem = new Array(memSize); this.mem = new Array(memSize);
@ -47,6 +50,7 @@ class Sim8800 {
this.setDataLedsCallback = setDataLedsCallback; this.setDataLedsCallback = setDataLedsCallback;
this.setWaitLedCallback = setWaitLedCallback; this.setWaitLedCallback = setWaitLedCallback;
this.setStatusLedsCallback = setStatusLedsCallback; this.setStatusLedsCallback = setStatusLedsCallback;
this.getInputAddressCallback = getInputAddressCallback;
this.dumpCpuCallback = dumpCpuCallback; this.dumpCpuCallback = dumpCpuCallback;
this.dumpMemCallback = dumpMemCallback; this.dumpMemCallback = dumpMemCallback;
this.isPoweredOn = false; this.isPoweredOn = false;
@ -377,23 +381,32 @@ class Sim8800 {
} }
/** /**
* Reads a byte from the given address. * Shows the address and the byte at the address via LEDs.
* @param {number} address The given address.
*/ */
examine(address) { showAddressAndData() {
if (!this.isPoweredOn)
return;
this.lastAddress = address;
if (this.setAddressLedsCallback) { if (this.setAddressLedsCallback) {
let bits = Sim8800.parseBits(address, 16); let bits = Sim8800.parseBits(this.lastAddress, 16);
this.setAddressLedsCallback(bits); this.setAddressLedsCallback(bits);
} }
if (this.setDataLedsCallback) { if (this.setDataLedsCallback) {
let bits = Sim8800.parseBits(this.mem[address], 8); let bits = Sim8800.parseBits(this.mem[this.lastAddress], 8);
this.setDataLedsCallback(bits); this.setDataLedsCallback(bits);
} }
} }
/**
* Reads a byte from the given address.
*/
examine() {
if (!this.isPoweredOn)
return;
if (this.getInputAddressCallback) {
var address = this.getInputAddressCallback();
this.lastAddress = address;
this.showAddressAndData();
}
}
/** /**
* Reads a byte from the next address. * Reads a byte from the next address.
*/ */
@ -401,6 +414,6 @@ class Sim8800 {
if (!this.isPoweredOn) if (!this.isPoweredOn)
return; return;
this.lastAddress++; this.lastAddress++;
this.examine(this.lastAddress); this.showAddressAndData();
} }
}; };