// Setup a few bitmasks we can use in the code that are handy to clean inputs to registers const BITMASK_8 = 0x00000000000000ff; const BITMASK_16 = 0x000000000000ffff; const BITMASK_24 = 0x0000000000ffffff; // These are the control lines that are controlled by the microcode RAM output 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_AE = 0b00001000000000000000000000000000; // ALU 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 // These are the output enable control lines, they are muxed since none of them can ever be on together const OECONTROL_PC = 0b00000 // PC Register const OECONTROL_SP = 0b00001 // SP Register const OECONTROL_AL = 0b00010 // GPA to LOW const OECONTROL_AH = 0b00011 // GPA to HIGH const OECONTROL_BL = 0b00100 // GPB to LOW const OECONTROL_BH = 0b00101 // GPB to HIGH const OECONTROL_CL = 0b00110 // GPC to LOW const OECONTROL_CH = 0b00111 // GPC to HIGH const OECONTROL_DL = 0b01000 // GPD to LOW const OECONTROL_DH = 0b01001 // GPD to HIGH const OECONTROL_AB = 0b01010 // GPB to HIGH, GPA to LOW const OECONTROL_AC = 0b01011 // GPC to HIGH, GPA to LOW const OECONTROL_AD = 0b01100 // GPD to HIGH, GPA to LOW const OECONTROL_BA = 0b01101 // GPA to HIGH, GPB to LOW const OECONTROL_BC = 0b01110 // GPC to HIGH, GPB to LOW const OECONTROL_BD = 0b01111 // GPD to HIGH, GPB to LOW const OECONTROL_CA = 0b10000 // GPA to HIGH, GPC to LOW const OECONTROL_CB = 0b10001 // GPB to HIGH, GPC to LOW const OECONTROL_CD = 0b10010 // GPD to HIGH, GPC to LOW const OECONTROL_DA = 0b10011 // GPA to HIGH, GPD to LOW const OECONTROL_DB = 0b10100 // GPB to HIGH, GPD to LOW const OECONTROL_DC = 0b10101 // GPC to HIGH, GPD to LOW // 10110 // 10111 const OECONTROL_I2 = 0b11000 // RAM Out, IR2 In const OECONTROL_2O = 0b11001 // IR2 Out const OECONTROL_HO = 0b11010 // HIGH Ram to DATABUS LOW const OECONTROL_HS = 0b11011 // Stack Page Byte out to ADDRBUS HIGH (disables RH out) const OECONTROL_SS = 0b11100 // GPA to LOW, Status Register IN const OECONTROL_AO = 0b11101 // ALU Output to LOW const OECONTROL_SR = 0b11110 // Status Register to LOW const OECONTROL_RO = 0b11111 // RAM to DATABUS Enable 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_AC = CONTROL_OEME | CONTROL_OEM3 | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_OUT_AD = CONTROL_OEME | CONTROL_OEM3 | CONTROL_OEM2; const CONTROL_OUT_BA = CONTROL_OEME | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM0; const CONTROL_OUT_BC = CONTROL_OEME | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM1; const CONTROL_OUT_BD = CONTROL_OEME | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_OUT_CA = CONTROL_OEME | CONTROL_OEM4; const CONTROL_OUT_CB = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM0; const CONTROL_OUT_CD = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM1; const CONTROL_OUT_DA = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_OUT_DB = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM2; const CONTROL_OUT_DC = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM2 | CONTROL_OEM0; const CONTROL_OUT_I2 = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3; const CONTROL_OUT_2O = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM0; const CONTROL_OUT_HO = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM1; const CONTROL_OUT_HS = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_OUT_SS = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM2; const CONTROL_OUT_AE = CONTROL_AE; const CONTROL_OUT_AO = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM0; const CONTROL_OUT_SR = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM1; const CONTROL_OUT_RO = CONTROL_OEME | CONTROL_OEM4 | CONTROL_OEM3 | CONTROL_OEM2 | CONTROL_OEM1 | CONTROL_OEM0; const CONTROL_ALU_ADD = CONTROL_OUT_AE; const CONTROL_ALU_SUB = CONTROL_OUT_AE | CONTROL_ALUI | CONTROL_ALUC; const CONTROL_ALU_NOT = CONTROL_OUT_AE | CONTROL_ALUI; const CONTROL_ALU_AND = CONTROL_OUT_AE | CONTROL_ALUM0; const CONTROL_ALU_NAND = CONTROL_OUT_AE | CONTROL_ALUM0 | CONTROL_ALUI; const CONTROL_ALU_OR = CONTROL_OUT_AE | CONTROL_ALUM1; const CONTROL_ALU_NOR = CONTROL_OUT_AE | CONTROL_ALUM1 | CONTROL_ALUI; const CONTROL_ALU_XOR = CONTROL_OUT_AE | CONTROL_ALUM1 | CONTROL_ALUM0; const CONTROL_ALU_XNOR = CONTROL_OUT_AE | CONTROL_ALUM1 | CONTROL_ALUM0 | CONTROL_ALUI; function reverseString(str) { return str.split("").reverse().join(""); } function formatHex(value,places,spaces=0) { let hexval = parseInt(value,10).toString(16).toUpperCase(); if (hexval.length < places) { let placecount = (places - hexval.length); for (let a = 0; a < placecount; a++) { hexval = "0" + hexval; } } if (spaces > 0) { hexval = reverseString(hexval); let newhexval = ""; for (let a = 0; a < hexval.length; a++) { newhexval += hexval.substring(a,a+1); if ((a % spaces) === 3 && a !== hexval.length-1) newhexval += " "; } hexval = reverseString(newhexval); } return hexval; } function formatBinary(value,places,spaces=0,labels = false) { let hexval = parseInt(value,10).toString(2); if (hexval.length < places) { let placecount = (places - hexval.length); for (let a = 0; a < placecount; a++) { hexval = "0" + hexval; } } if (spaces > 0) { hexval = reverseString(hexval); let newhexval = ""; for (let a = 0; a < hexval.length; a++) { if (labels) { newhexval += reverseString(``) + hexval.substring(a,a+1) + reverseString(``); } else { newhexval += hexval.substring(a,a+1); } if ((a % spaces) === 3 && a !== hexval.length-1) newhexval += " "; } hexval = reverseString(newhexval); } return hexval; } function GetMnemonic(mcarray,instruction) { for (let a = 0; a < mcarray.length; a++) { if (mcarray[a] === instruction || mcarray[a].Bytecode === instruction) { return mcarray[a].Mnemonic; } } }