/* const CONTROL_PCC = 0b00000000000000000000000000000001; // PC CLK UP const CONTROL_PCI = 0b00000000000000000000000000000010; // PC Input Enable const CONTROL_SPD = 0b00000000000000000000000000000100; // SP Count Down const CONTROL_SPC = 0b00000000000000000000000000001000; // SP CLK (UP / DOWN) const CONTROL_SPI = 0b00000000000000000000000000010000; // SP Input Enable const CONTROL_RAIL = 0b00000000000000000000000000100000; // GPA LOW Input Enable const CONTROL_RAIH = 0b00000000000000000000000001000000; // GPA HIGH Input Enable const CONTROL_RBIL = 0b00000000000000000000000010000000; // GPB LOW Input Enable const CONTROL_RBIH = 0b00000000000000000000000100000000; // GPB HIGH Input Enable const CONTROL_RCIL = 0b00000000000000000000001000000000; // GPC LOW Input Enable const CONTROL_RCIH = 0b00000000000000000000010000000000; // GPC HIGH Input Enable const CONTROL_RDIL = 0b00000000000000000000100000000000; // GPD LOW Input Enable const CONTROL_RDIH = 0b00000000000000000001000000000000; // GPD HIGH Input Enable const CONTROL_RRI = 0b00000000000000000010000000000000; // LOW Ram Register Input Enable const CONTROL_RHI = 0b00000000000000000100000000000000; // HIGH Ram Register Input Enable const CONTROL_ALUM0 = 0b00000000000000001000000000000000; // ALU MUX 0 const CONTROL_ALUM1 = 0b00000000000000010000000000000000; // ALU MUX 1 const CONTROL_ALUI = 0b00000000000000100000000000000000; // ALU Invert (high side) const CONTROL_ALUC = 0b00000000000001000000000000000000; // ALU Carry Input const CONTROL_ALUSL = 0b00000000000010000000000000000000; // ALU Shift Left const CONTROL_ALUSR = 0b00000000000100000000000000000000; // ALU Shift Right const CONTROL_OEM0 = 0b00000000001000000000000000000000; // Output Enable MUX 0 const CONTROL_OEM1 = 0b00000000010000000000000000000000; // Output Enable MUX 1 const CONTROL_OEM2 = 0b00000000100000000000000000000000; // Output Enable MUX 2 const CONTROL_OEM3 = 0b00000001000000000000000000000000; // Output Enable MUX 3 const CONTROL_OEM4 = 0b00000010000000000000000000000000; // Output Enable MUX 4 const CONTROL_OEME = 0b00000100000000000000000000000000; // Output Enable MUX Enable const CONTROL_RI = 0b00010000000000000000000000000000; // RAM Input Enable const CONTROL_IRI = 0b00100000000000000000000000000000; // Instruction Register Input Enable const CONTROL_MCL0 = 0b01000000000000000000000000000000; // Microcode Counter to 0 const CONTROL_MCL8 = 0b10000000000000000000000000000000; // Microcode Counter to 8 */ const CONTROL_OUT_PC = CONTROL_OEME; const CONTROL_OUT_SP = CONTROL_OEME | CONTROL_OEM0; const CONTROL_OUT_AL = CONTROL_OEME | CONTROL_OEM1; const CONTROL_OUT_AH = CONTROL_OEME | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_OUT_BL = CONTROL_OEME | CONTROL_OEM2; const CONTROL_OUT_BH = CONTROL_OEME | CONTROL_OEM2 | CONTROL_OEM0; const CONTROL_OUT_CL = CONTROL_OEME | CONTROL_OEM2 | CONTROL_OEM1; const CONTROL_OUT_CH = CONTROL_OEME | CONTROL_OEM2 | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_OUT_DL = CONTROL_OEME | CONTROL_OEM3; const CONTROL_OUT_DH = CONTROL_OEME | CONTROL_OEM3 | CONTROL_OEM0; const CONTROL_OUT_AB = CONTROL_OEME | CONTROL_OEM3 | CONTROL_OEM1; const CONTROL_OUT_AE = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM2; const CONTROL_OUT_AO = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM0; const CONTROL_OUT_RO = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_ALU_ADD = CONTROL_OUT_AE; let Instructions = new Array(); function GenerateMicrocode(mcarray,cpu) { for (let a = 0; a < mcarray.length; a++) { for (let c = 0; c < 3; c++) { let offset = 0; 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; mca |= b; let mcv = mcarray[a].Microcode[b]; if (mcarray[a].UsesZero && c === 1) mcv = mcarray[a].MicrocodeZero[b]; if (mcarray[a].UsesCarry && c === 2) mcv = mcarray[a].MicrocodeCarry[b]; cpu.MCRAM[offset + mca] = mcv; //console.log(`[${bytecode.toString(16)}] ${mca.toString(16)}: ${mcv.toString(2)}`); } } } } class Microcode_Instruction { constructor() { this.Bytecode = 0x000; // MAX IS 0x3ff this.Mnemonic = "NOP"; this.Microcode = new Array(16); this.UsesCarry = false; this.UsesZero = false; this.Microcode[0] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[1] = CONTROL_OUT_RO | CONTROL_IRI | CONTROL_PCC; for (let a = 2; a < 16; a++) { this.Microcode[a] = CONTROL_MCL0; } } } class IS_LDA_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x000; this.Mnemonic = "LDA"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RAIL | CONTROL_PCC; } } is_LDA_i = new IS_LDA_imm; Instructions.push(is_LDA_i); class IS_LDB_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x001; this.Mnemonic = "LDB"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RBIL | CONTROL_PCC; } } is_LDB_i = new IS_LDB_imm; Instructions.push(is_LDB_i); class IS_LDC_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x002; this.Mnemonic = "LDC"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RCIL | CONTROL_PCC; } } is_LDC_i = new IS_LDC_imm; Instructions.push(is_LDC_i); class IS_LDD_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x003; this.Mnemonic = "LDD"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RDIL | CONTROL_PCC; } } is_LDD_i = new IS_LDD_imm; Instructions.push(is_LDD_i); class IS_STAL_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x004; this.Mnemonic = "STAL"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_AL | CONTROL_RI; } } is_STAL_i = new IS_STAL_imm; Instructions.push(is_STAL_i); class IS_STAH_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x005; this.Mnemonic = "STAH"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_AH | CONTROL_RI; } } is_STAH_i = new IS_STAH_imm; Instructions.push(is_STAH_i); class IS_STBL_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x006; this.Mnemonic = "STBL"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_BL | CONTROL_RI; } } is_STBL_i = new IS_STBL_imm; Instructions.push(is_STBL_i); class IS_STBH_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x007; this.Mnemonic = "STBH"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_BH | CONTROL_RI; } } is_STBH_i = new IS_STBH_imm; Instructions.push(is_STBH_i); class IS_STCL_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x008; this.Mnemonic = "STCL"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_CL | CONTROL_RI; } } is_STCL_i = new IS_STCL_imm; Instructions.push(is_STCL_i); class IS_STCH_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x009; this.Mnemonic = "STCH"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_CH | CONTROL_RI; } } is_STCH_i = new IS_STCH_imm; Instructions.push(is_STCH_i); class IS_STDL_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x00A; this.Mnemonic = "STDL"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_DL | CONTROL_RI; } } is_STDL_i = new IS_STDL_imm; Instructions.push(is_STDL_i); class IS_STDH_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x00B; this.Mnemonic = "STDH"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_RRI | CONTROL_PCC; this.Microcode[4] = CONTROL_OUT_DH | CONTROL_RI; } } is_STDH_i = new IS_STDH_imm; Instructions.push(is_STDH_i); // This is a simple ADD command which will ADD GPA and GPB putting the sum in GPA class IS_ADD extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x100; this.Mnemonic = "ADD"; this.Microcode[2] = CONTROL_ALU_ADD; this.Microcode[3] = CONTROL_RAIL | CONTROL_OUT_AO; } } is_ADD = new IS_ADD; Instructions.push(is_ADD); class IS_JMP_imm extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x200; this.Mnemonic = "JMP"; this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_PCI; } } is_JMP_i = new IS_JMP_imm; Instructions.push(is_JMP_i); class IS_BCC_imm extends Microcode_Instruction { constructor(props) { super(props); this.UsesCarry = true; this.Bytecode = 0x201; this.Mnemonic = "BCC"; this.MicrocodeCarry = new Array(16); for (let a = 0; a < 16; a++) { this.MicrocodeCarry[a] = this.Microcode[a]; } this.Microcode[2] = CONTROL_OUT_PC | CONTROL_RRI; this.Microcode[3] = CONTROL_OUT_RO | CONTROL_PCI; this.MicrocodeCarry[2] = CONTROL_PCC; // Step over the immediate value } } is_BCC_i = new IS_BCC_imm; Instructions.push(is_BCC_i); class IS_NOP extends Microcode_Instruction { constructor(props) { super(props); this.Bytecode = 0x3ff; this.Mnemonic = "NOP"; } } is_NOP = new IS_NOP; Instructions.push(is_NOP);