Added a bunch of branching instructions, some stack instructions, and added stack example to the demo

This commit is contained in:
MatCat 2021-04-04 03:26:28 -07:00
parent f67b5c3e64
commit 3d050b8b55
4 changed files with 177 additions and 5 deletions

View File

@ -46,6 +46,9 @@
<div>
<span>RAM: </span><br /><span id="RAM"></brspan>
</div>
<div>
<span>RAM (STACK): </span><br /><span id="STACK-RAM"></brspan>
</div>
<script src="js/cpu.js"></script>
<script src="js/microcode_compiler.js"></script>

View File

@ -39,6 +39,19 @@ function printRAM(ram) {
ramtext += "<br />";
}
sp_ram.innerHTML = ramtext;
let sp_stackram = document.getElementById("STACK-RAM");
ramtext = "ADDR&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;5&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;&nbsp;7&nbsp;&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;B&nbsp;&nbsp;&nbsp;&nbsp;C&nbsp;&nbsp;&nbsp;&nbsp;D&nbsp;&nbsp;&nbsp;&nbsp;E&nbsp;&nbsp;&nbsp;&nbsp;F<br />";
for (let a = 0xffa0; a < 0x10000; a+=16) {
ramtext += "0x" + formatHex(a,4) + ": ";
for (let b = 0; b < 16; b++) {
if (cpu.ADDRBUS === (a)+b) ramtext += '<span style="background-color: #ffff55">';
ramtext += formatHex(ram[(a)+b],4) + " ";
if (cpu.ADDRBUS === (a)+b) ramtext += '</span>';
}
ramtext += "<br />";
}
sp_stackram.innerHTML = ramtext;
}
function updateHTML() {

View File

@ -11,6 +11,8 @@ cpu.RAM[7] = is_LDD_i.Bytecode;
cpu.RAM[8] = 69;
cpu.RAM[9] = is_STDL_i.Bytecode;
cpu.RAM[10] = 0x69;
cpu.RAM[11] = is_PHD.Bytecode;
cpu.RAM[12] = is_PLC.Bytecode;
updateHTML();

View File

@ -59,10 +59,6 @@ function GenerateMicrocode(mcarray,cpu) {
if (c === 1) offset = 0b0100000000000000;
if (c === 2) offset = 0b1000000000000000;
if (c === 0) console.log(`Now populating no-conditional instructions...`);
if (c === 1) console.log(`Now populating conditional ZERO instructions...`);
if (c === 2) console.log(`Now populating conditional Carry instructions...`);
for (let b = 0; b < 16; b++) {
let bytecode = mcarray[a].Bytecode;
let mca = mcarray[a].Bytecode << 4;
@ -261,6 +257,107 @@ class IS_ADD extends Microcode_Instruction {
is_ADD = new IS_ADD;
Instructions.push(is_ADD);
class IS_PHA extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x180;
this.Mnemonic = "PHA";
this.Microcode[2] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[3] = CONTROL_OUT_AL | CONTROL_RI | CONTROL_SPD | CONTROL_SPC;
}
}
is_PHA = new IS_PHA;
Instructions.push(is_PHA);
class IS_PHB extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x181;
this.Mnemonic = "PHB";
this.Microcode[2] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[3] = CONTROL_OUT_BL | CONTROL_RI | CONTROL_SPD | CONTROL_SPC;
}
}
is_PHB = new IS_PHB;
Instructions.push(is_PHB);
class IS_PHC extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x182;
this.Mnemonic = "PHC";
this.Microcode[2] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[3] = CONTROL_OUT_CL | CONTROL_RI | CONTROL_SPD | CONTROL_SPC;
}
}
is_PHC = new IS_PHC;
Instructions.push(is_PHC);
class IS_PHD extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x183;
this.Mnemonic = "PHD";
this.Microcode[2] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[3] = CONTROL_OUT_DL | CONTROL_RI | CONTROL_SPD | CONTROL_SPC;
}
}
is_PHD = new IS_PHD;
Instructions.push(is_PHD);
class IS_PLA extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x1A0;
this.Mnemonic = "PLA";
this.Microcode[2] = CONTROL_SPC;
this.Microcode[3] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[4] = CONTROL_OUT_RO | CONTROL_RAIL;
}
}
is_PLA = new IS_PLA;
Instructions.push(is_PLA);
class IS_PLB extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x1A1;
this.Mnemonic = "PLB";
this.Microcode[2] = CONTROL_SPC;
this.Microcode[3] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[4] = CONTROL_OUT_RO | CONTROL_RBIL;
}
}
is_PLB = new IS_PLB;
Instructions.push(is_PLB);
class IS_PLC extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x1A2;
this.Mnemonic = "PLC";
this.Microcode[2] = CONTROL_SPC;
this.Microcode[3] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[4] = CONTROL_OUT_RO | CONTROL_RCIL;
}
}
is_PLC = new IS_PLC;
Instructions.push(is_PLC);
class IS_PLD extends Microcode_Instruction {
constructor(props) {
super(props);
this.Bytecode = 0x1A3;
this.Mnemonic = "PLD";
this.Microcode[2] = CONTROL_SPC;
this.Microcode[3] = CONTROL_OUT_SP | CONTROL_RRI;
this.Microcode[4] = CONTROL_OUT_RO | CONTROL_RDIL;
}
}
is_PLD = new IS_PLD;
Instructions.push(is_PLD);
class IS_JMP_imm extends Microcode_Instruction {
constructor(props) {
super(props);
@ -288,10 +385,67 @@ class IS_BCC_imm extends Microcode_Instruction {
this.MicrocodeCarry[2] = CONTROL_PCC; // Step over the immediate value
}
}
is_BCC_i = new IS_BCC_imm;
Instructions.push(is_BCC_i);
class IS_BCS_imm extends Microcode_Instruction {
constructor(props) {
super(props);
this.UsesCarry = true;
this.Bytecode = 0x202;
this.Mnemonic = "BCS";
this.MicrocodeCarry = new Array(16);
for (let a = 0; a < 16; a++) {
this.MicrocodeCarry[a] = this.Microcode[a];
}
this.Microcode[2] = CONTROL_PCC; // Step over the immediate value
this.MicrocodeCarry[2] = CONTROL_OUT_PC | CONTROL_RRI;
this.MicrocodeCarry[3] = CONTROL_OUT_RO | CONTROL_PCI;
}
}
is_BCS_i = new IS_BCS_imm;
Instructions.push(is_BCS_i);
class IS_BEQ_imm extends Microcode_Instruction {
constructor(props) {
super(props);
this.UsesZero = true;
this.Bytecode = 0x203;
this.Mnemonic = "BEQ";
this.MicrocodeZero = new Array(16);
for (let a = 0; a < 16; a++) {
this.MicrocodeZero[a] = this.Microcode[a];
}
this.Microcode[2] = CONTROL_PCC; // Step over the immediate value
this.MicrocodeZero[2] = CONTROL_OUT_PC | CONTROL_RRI;
this.MicrocodeZero[3] = CONTROL_OUT_RO | CONTROL_PCI;
}
}
is_BEQ_i = new IS_BEQ_imm;
Instructions.push(is_BEQ_i);
class IS_BNE_imm extends Microcode_Instruction {
constructor(props) {
super(props);
this.UsesZero = true;
this.Bytecode = 0x204;
this.Mnemonic = "BNE";
this.MicrocodeZero = new Array(16);
for (let a = 0; a < 16; a++) {
this.MicrocodeZero[a] = this.Microcode[a];
}
this.MicrocodeZero[2] = CONTROL_PCC; // Step over the immediate value
this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI;
this.Microcode[3] = CONTROL_OUT_RO | CONTROL_PCI;
}
}
is_BNE_i = new IS_BNE_imm;
Instructions.push(is_BNE_i);
class IS_NOP extends Microcode_Instruction {
constructor(props) {
super(props);