support poweron and power off
This commit is contained in:
parent
83f24f3694
commit
843c478cdd
38
index.html
38
index.html
|
@ -59,20 +59,20 @@
|
||||||
<p>
|
<p>
|
||||||
INTE <span class="led">○</span>
|
INTE <span class="led">○</span>
|
||||||
PROT <span class="led">○</span>
|
PROT <span class="led">○</span>
|
||||||
MEMR <span class="led">●</span>
|
MEMR <span id="memr-led" class="led">○</span>
|
||||||
INP <span class="led">○</span>
|
INP <span class="led">○</span>
|
||||||
MI <span class="led">●</span>
|
MI <span id="mi-led" class="led">○</span>
|
||||||
OUT <span class="led">○</span>
|
OUT <span class="led">○</span>
|
||||||
HLTA <span class="led">○</span>
|
HLTA <span class="led">○</span>
|
||||||
STACK <span class="led">○</span>
|
STACK <span class="led">○</span>
|
||||||
WO <span class="led">●</span>
|
WO <span id="wo-led" class="led">○</span>
|
||||||
INT <span class="led">○</span>
|
INT <span class="led">○</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="wait-leds">
|
<div id="wait-leds">
|
||||||
<p>
|
<p>
|
||||||
WAIT <span id="wait-led" class="led">●</span>
|
WAIT <span id="wait-led" class="led">○</span>
|
||||||
HLDA <span class="led">○</span>
|
HLDA <span class="led">○</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -169,24 +169,30 @@
|
||||||
ledElem.innerHTML = isRunning ? '○' : '●';
|
ledElem.innerHTML = isRunning ? '○' : '●';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setStatusLedsCallback(isPoweredOn) {
|
||||||
|
var ledElems = [
|
||||||
|
document.getElementById('memr-led'),
|
||||||
|
document.getElementById('mi-led'),
|
||||||
|
document.getElementById('wo-led')
|
||||||
|
];
|
||||||
|
for (let i = 0; i < ledElems.length; i++) {
|
||||||
|
ledElems[i].innerHTML = isPoweredOn ? '●' : '○';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var dumpCpuElem = document.getElementById('cpu');
|
var dumpCpuElem = document.getElementById('cpu');
|
||||||
var dumpMemElem = document.getElementById('mem');
|
var dumpMemElem = document.getElementById('mem');
|
||||||
var sim = new Sim8800(256, 1000000,
|
var sim = new Sim8800(256, 1000000,
|
||||||
setAddressLedsCallback, setDataLedsCallback,
|
setAddressLedsCallback, setDataLedsCallback,
|
||||||
setWaitLedCallback,
|
setWaitLedCallback, setStatusLedsCallback,
|
||||||
dumpCpuElem, dumpMemElem);
|
dumpCpuElem, dumpMemElem);
|
||||||
|
|
||||||
function init() {
|
function powerOn() {
|
||||||
sim.loadDataAsHexString(0, '00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f');
|
sim.powerOn();
|
||||||
sim.loadData(16, [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]);
|
|
||||||
sim.dumpCpu();
|
|
||||||
sim.dumpMem()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test() {
|
function powerOff() {
|
||||||
console.log(Sim8800.parseBits(10, 1));
|
sim.powerOff();
|
||||||
console.log(Sim8800.parseBits(0xF8, 1));
|
|
||||||
console.log(Sim8800.parseBits(0xF0, 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
|
@ -195,14 +201,10 @@
|
||||||
// Pattern shift.
|
// Pattern shift.
|
||||||
sim.loadDataAsHexString(0, '3e 8c d3 ff 0f c3 02 00');
|
sim.loadDataAsHexString(0, '3e 8c d3 ff 0f c3 02 00');
|
||||||
sim.start();
|
sim.start();
|
||||||
sim.dumpCpu();
|
|
||||||
sim.dumpMem()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop() {
|
function stop() {
|
||||||
sim.stop();
|
sim.stop();
|
||||||
sim.dumpCpu();
|
|
||||||
sim.dumpMem()
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -30,6 +30,8 @@ class Sim8800 {
|
||||||
* callback to set data LEDs.
|
* callback to set data LEDs.
|
||||||
* @param {function(boolean)?} setWaitLedCallback The callback to
|
* @param {function(boolean)?} setWaitLedCallback The callback to
|
||||||
* set the WAIT LED.
|
* set the WAIT LED.
|
||||||
|
* @param {function(boolean)?} setStatusLedsCallback The callback to
|
||||||
|
* set the STATUS LEDs.
|
||||||
* @param {Element?} dumpCpuElem The DOM element used to render
|
* @param {Element?} dumpCpuElem The DOM element used to render
|
||||||
* dumped CPU status. null to disable the feature.
|
* dumped CPU status. null to disable the feature.
|
||||||
* @param {Element?} dumpMemElem The DOM element used to render
|
* @param {Element?} dumpMemElem The DOM element used to render
|
||||||
|
@ -37,13 +39,14 @@ class Sim8800 {
|
||||||
*/
|
*/
|
||||||
constructor(memSize, clockRate,
|
constructor(memSize, clockRate,
|
||||||
setAddressLedsCallback, setDataLedsCallback,
|
setAddressLedsCallback, setDataLedsCallback,
|
||||||
setWaitLedCallback,
|
setWaitLedCallback, setStatusLedsCallback,
|
||||||
dumpCpuElem, dumpMemElem) {
|
dumpCpuElem, dumpMemElem) {
|
||||||
this.clockRate = clockRate;
|
this.clockRate = clockRate;
|
||||||
this.mem = new Array(memSize);
|
this.mem = new Array(memSize);
|
||||||
this.setAddressLedsCallback = setAddressLedsCallback;
|
this.setAddressLedsCallback = setAddressLedsCallback;
|
||||||
this.setDataLedsCallback = setDataLedsCallback;
|
this.setDataLedsCallback = setDataLedsCallback;
|
||||||
this.setWaitLedCallback = setWaitLedCallback;
|
this.setWaitLedCallback = setWaitLedCallback;
|
||||||
|
this.setStatusLedsCallback = setStatusLedsCallback;
|
||||||
this.dumpCpuElem = dumpCpuElem;
|
this.dumpCpuElem = dumpCpuElem;
|
||||||
this.dumpMemElem = dumpMemElem;
|
this.dumpMemElem = dumpMemElem;
|
||||||
this.running = false;
|
this.running = false;
|
||||||
|
@ -85,12 +88,12 @@ class Sim8800 {
|
||||||
* Fills the memory with dummy bytes.
|
* Fills the memory with dummy bytes.
|
||||||
*/
|
*/
|
||||||
initMem(random = false) {
|
initMem(random = false) {
|
||||||
for (let i = 0; i < this.mem.length; i++) {
|
if (random) {
|
||||||
if (random) {
|
for (let i = 0; i < this.mem.length; i++) {
|
||||||
this.mem[i] = Math.floor(Math.random() * 256);
|
this.mem[i] = Math.floor(Math.random() * 256);
|
||||||
} else {
|
|
||||||
this.mem[i] = 0;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.mem.fill(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,8 +276,16 @@ class Sim8800 {
|
||||||
*/
|
*/
|
||||||
powerOn() {
|
powerOn() {
|
||||||
this.stop();
|
this.stop();
|
||||||
reset();
|
this.reset();
|
||||||
this.initMem();
|
this.initMem();
|
||||||
|
if (this.setStatusLedsCallback) {
|
||||||
|
this.setStatusLedsCallback(true);
|
||||||
|
}
|
||||||
|
if (this.setWaitLedCallback) {
|
||||||
|
this.setWaitLedCallback(false);
|
||||||
|
}
|
||||||
|
this.dumpCpu();
|
||||||
|
this.dumpMem();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -282,8 +293,26 @@ class Sim8800 {
|
||||||
*/
|
*/
|
||||||
powerOff() {
|
powerOff() {
|
||||||
this.stop();
|
this.stop();
|
||||||
reset();
|
this.reset();
|
||||||
this.initMem();
|
this.initMem();
|
||||||
|
if (this.setStatusLedsCallback) {
|
||||||
|
this.setStatusLedsCallback(false);
|
||||||
|
}
|
||||||
|
if (this.setWaitLedCallback) {
|
||||||
|
this.setWaitLedCallback(true);
|
||||||
|
}
|
||||||
|
if (this.setAddressLedsCallback) {
|
||||||
|
this.setAddressLedsCallback(new Array(16).fill(0));
|
||||||
|
}
|
||||||
|
if (this.setDataLedsCallback) {
|
||||||
|
this.setDataLedsCallback(new Array(8).fill(0));
|
||||||
|
}
|
||||||
|
if (this.dumpCpuElem) {
|
||||||
|
this.dumpCpuElem.innerHTML = '';
|
||||||
|
}
|
||||||
|
if (this.dumpMemElem) {
|
||||||
|
this.dumpMemElem.innerHTML = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user