void setup() { Serial.begin(9600); while (!Serial) { ; } pinMode(1, OUTPUT); pinMode(2, INPUT); // CONSTANT Register Bit 0 pinMode(3, INPUT); pinMode(4, INPUT); pinMode(5, INPUT); pinMode(6, INPUT); pinMode(7, INPUT); pinMode(8, INPUT); pinMode(9, INPUT); pinMode(10, INPUT); pinMode(11, INPUT); pinMode(12, INPUT); pinMode(13, INPUT); pinMode(A2, INPUT); pinMode(A3, INPUT); pinMode(A4, INPUT); pinMode(A5, INPUT); // CONSTANT Register Bit 15 pinMode(A1, INPUT); // CLK input pinMode(A0, INPUT); // ISEL input char c1 = 0xfe; char c2 = 0x01; Serial.print(c1); Serial.print(c2); // clear display } word CMD = 0; byte ALUF = 0; byte ALUOP = 0; bool CONST = false; bool LDSTBR = false; byte RB = 0; byte RC = 0; byte RA = 0; byte t = 0; String OUT1 = String(); String CVAL = String(); void loop() { OUT1 = String(); // String to display on line 1 of display CVAL = String(); // Second word of command, if required // wait for ISEL to go high: new command cycle do {} while (digitalRead(A0) == LOW); // wait for CLK to go low, then high again: command ready do {} while (digitalRead(A1) == HIGH); do {} while (digitalRead(A1) == LOW); delayMicroseconds(50); // wait 50 microseconds for data to stabilize on CONSTANT Register CMD = getWord(); // isolate command components ALUF = (CMD >> 14); // ALU Module ALUOP = (CMD & 0x3800) >> 11; // ALU Operation CONST = (CMD & 0x0400) != 0; // Constant (2nd word) required LDSTBR = (CMD & 0x0200) != 0; // False if ALU Command, true if Load/Store/Branch Command RB = (CMD & 0x01c0) >> 6; // 2nd parameter (Rb) RC = (CMD & 0x0038) >> 3; // 3rd Parameter (Rc) RA = (CMD & 0x0007); // 1st Parameter (Ra) if (CONST) { // if constant is required, wait for clock pulse and get the next word // wait for CLK to go low, then high again - CONST ready do {} while (digitalRead(A1) == HIGH); do {} while (digitalRead(A1) == LOW); delayMicroseconds(50); // wait 50 microseconds for data to stabilize on CONSTANT register word w = getWord(); char h[4]; sprintf(h, "%04X", w); // format: 4 hex digits CVAL = String("0x") + String(h); } if (!LDSTBR) { // ALU Command switch (ALUF) { case 0: // ALU Compare Command switch (ALUOP) { case 1: OUT1 = String(" CMPEQ"); break; case 3: OUT1 = String(" CMPUL"); break; case 5: OUT1 = String(" CMPLT"); break; case 7: OUT1 = String(" CMPLE"); break; default: OUT1 = String(" ?????"); } OUT1.concat(CONST ? "C " : " "); // Add 'C' if it's a command with a constant parameter break; case 1: switch (ALUOP) { // ALU Arithmetic Command case 0: OUT1 = String(" ADD"); break; case 1: OUT1 = String(" SUB"); break; default: OUT1 = String(" ???"); break; } OUT1.concat(CONST ? "C " : " "); // Add 'C' if it's a command with a constant parameter break; case 2: switch (ALUOP) { // ALU Bitwise Math Command case 3: OUT1 = String(" XOR"); break; case 4: OUT1 = String(" AND"); break; case 7: OUT1 = String(" OR"); break; default: OUT1 = String(" ???"); break; } OUT1.concat(CONST ? "C " : " "); // Add 'C' if it's a command with a constant parameter break; case 3: switch (ALUOP) { // ALU Shift Command case 0: OUT1 = String(" SHR"); break; case 1: OUT1 = String(" SHL"); break; case 2: OUT1 = String(" SRA"); break; case 3: OUT1 = String(" SLC"); break; default: OUT1 = String(" ???"); break; } OUT1.concat(CONST ? "C " : " "); // Add 'C' if it's a command with a constant parameter break; default: OUT1 = String(" ???? "); } } else { // LDSTRBR is true // Load/Store/Branch Command if (!CONST && ALUF == 2 && ALUOP == 5) { OUT1 = String(" JMP "); RB = 8; // flag to not print RB } else if (ALUF == 1 && ALUOP == 0) { switch (RB) { case 0: OUT1 = String(" JMPC "); break; case 2: OUT1 = String(" LD "); break; case 3: OUT1 = String(" ST "); t = RA; RA = RC; RC = t; // swap RA and RC for ST statement break; case 4: OUT1 = String(" BEQ "); break; case 5: OUT1 = String(" BNE "); break; case 6: OUT1 = String(" LDR "); RA = 8; // flag to not print RA break; default: OUT1 = String(" ??? "); break; } } else { OUT1 = String(" ??? "); } } // print OUT1, then figure out what to print on second line Serial.print(String(OUT1)); Serial.print( (RA != 8) ? String("R") + String(RA) : String(" ") ); // print Ra or nothing Serial.print(" "); Serial.print( CONST ? CVAL : ((RB != 8) ? String(" R") + String(RB) + String(" ") : String(" ")) ); Serial.print(String(" R") + String(RC)); } word getWord() { word d = PIND >> 2; // first 6 bits word b = PINB << 6; // next 6 bits word c = (PINC & 0x3c) << 10; // last 4 bits (already shifted 2 bits) return c | b | d; // OR them all together and return }