8SA1Sim/js/main.js

138 lines
3.6 KiB
JavaScript

let cpu = new CPU_8SA1();
GenerateMicrocode(Instructions,cpu);
/*cpu.RAM[0] = is_LDA_i.Bytecode;
cpu.RAM[1] = 0;
cpu.RAM[2] = is_LDB_i.Bytecode;
cpu.RAM[3] = 100;
cpu.RAM[4] = is_ADD.Bytecode;
cpu.RAM[5] = is_BCC_i.Bytecode;
cpu.RAM[6] = 4;
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;
*/
/*cpu.RAM[0] = is_JSR.Bytecode;
cpu.RAM[1] = 0x40;
cpu.RAM[2] = is_LDA_i.Bytecode;
cpu.RAM[3] = 0x20;
cpu.RAM[4] = is_PLB.Bytecode;
cpu.RAM[5] = is_ADD.Bytecode;
cpu.RAM[0x40] = is_PLAB.Bytecode;
cpu.RAM[0x41] = is_LDC_i.Bytecode;
cpu.RAM[0x42] = 0x22;
cpu.RAM[0x43] = is_PHC.Bytecode;
cpu.RAM[0x44] = is_PHAB.Bytecode;
cpu.RAM[0x45] = is_RTS.Bytecode;*/
/*cpu.RAM[0] = is_LDA_i.Bytecode;
cpu.RAM[1] = 0x0;
cpu.RAM[2] = is_LDB_i.Bytecode;
cpu.RAM[3] = 0;
cpu.RAM[4] = is_CMP.Bytecode;
*/
cpu.RAM[0] = is_LDAB_i.Bytecode;
cpu.RAM[1] = 0x0050;
cpu.RAM[2] = is_PHAB.Bytecode;
cpu.RAM[3] = is_JSR.Bytecode;
cpu.RAM[4] = 0x00D0;
cpu.RAM[0xD0] = is_PLAB.Bytecode;
cpu.RAM[0xD1] = is_PLCD.Bytecode;
cpu.RAM[0xD2] = is_PHAB.Bytecode;
cpu.RAM[0xD3] = is_LDAB_i.Bytecode;
cpu.RAM[0xD4] = 0x8000;
cpu.RAM[0xD5] = is_PHAB.Bytecode;
cpu.RAM[0xD6] = is_LDAB_GPCD.Bytecode;
cpu.RAM[0xD7] = is_CMP.Bytecode;
cpu.RAM[0xD8] = is_BEQ_i.Bytecode;
cpu.RAM[0xD9] = 0x00FB;
cpu.RAM[0xDA] = is_STAB_sp.Bytecode;
cpu.RAM[0xDB] = is_TCA.Bytecode;
cpu.RAM[0xDC] = is_LDB_i.Bytecode;
cpu.RAM[0xDD] = 1;
cpu.RAM[0xDE] = is_ADD.Bytecode;
cpu.RAM[0xDF] = is_BCS_i.Bytecode;
cpu.RAM[0xE0] = 0x00EC;
cpu.RAM[0xE1] = is_TAC.Bytecode;
cpu.RAM[0xE2] = is_PLAB.Bytecode;
cpu.RAM[0xE3] = is_PHCD.Bytecode;
cpu.RAM[0xE4] = is_TBC.Bytecode;
cpu.RAM[0xE5] = is_LDB_i.Bytecode;
cpu.RAM[0xE6] = 1;
cpu.RAM[0xE7] = is_ADD.Bytecode;
cpu.RAM[0xE8] = is_TCB.Bytecode;
cpu.RAM[0xE9] = is_PLCD.Bytecode;
cpu.RAM[0xEA] = is_JMP_i.Bytecode;
cpu.RAM[0xEB] = 0x00D5;
cpu.RAM[0xEC] = is_TAC.Bytecode;
cpu.RAM[0xED] = is_TDA.Bytecode;
cpu.RAM[0xEE] = is_LDB_i.Bytecode;
cpu.RAM[0xEF] = 1;
cpu.RAM[0xF0] = is_ADD.Bytecode;
cpu.RAM[0xF1] = is_TAD.Bytecode;
cpu.RAM[0xF2] = is_PLAB.Bytecode;
cpu.RAM[0xF3] = is_LDA_i.Bytecode;
cpu.RAM[0xF4] = 1;
cpu.RAM[0xF5] = is_ADD.Bytecode;
cpu.RAM[0xF6] = is_TAB.Bytecode;
cpu.RAM[0xF7] = is_LDA_i.Bytecode;
cpu.RAM[0xF8] = 0;
cpu.RAM[0xF9] = is_JMP_i.Bytecode;
cpu.RAM[0xFA] = 0x00D5;
cpu.RAM[0xFB] = is_PLAB.Bytecode;
cpu.RAM[0xFC] = is_RTS.Bytecode;
stringToRAM("Blackbeard420 is a Butt Fuckers",cpu.RAM,0x50);
updateHTML();
let btn_clk = document.getElementById("btn_clk");
let btn_runtil = document.getElementById("btn_runtil");
let brkpt = document.getElementById("addrbrk");
let btn_rst = document.getElementById("btn_rst");
let clk_counter = document.getElementById("clk_counter");
let clk_count = 0;
btn_clk.addEventListener('mousedown', function(evt) {
cpu.CLOCK(true);
clk_count++;
clk_counter.innerText = clk_count;
updateHTML();
});
btn_clk.addEventListener('mouseup', function(evt) {
cpu.CLOCK(false);
updateHTML();
});
btn_runtil.addEventListener('click', function(evt) {
let addr = parseInt("0x" + brkpt.value);
RunUntilBreak(addr);
});
btn_rst.addEventListener('click', function(evt) {
cpu.PC = 0;
cpu.MCC = 0xf;
cpu.IR = 0;
cpu.DATABUS = 0;
cpu.ADDRBUS = 0;
cpu.MC_Controls = 0;
cpu.ALUSUM = 0;
cpu.RR = 0;
cpu.GPA = 0;
cpu.GPB = 0;
cpu.GPC = 0;
cpu.GPD = 0;
cpu.SR = 0;
cpu.SP = BITMASK_16;
clk_count = 0;
clk_counter.innerText = clk_count;
updateHTML();
});