// instruction-init.h // Initializes every instruction function prior to addressing.h so that function addresses are accessible // also defines the array used to refer to functions //InstructionTable void* IT; void setIT(int i, uintptr_t p, Addressing r){ uintptr_t* p1 = (IT + (i * sizeof(uintptr_t))); *p1 = p; Addressing* r1 = (IT + ((sizeof(uintptr_t)*256)) + (i * sizeof(Addressing))); *r1 = r; } Addressing getITAddressing(int i){ Addressing* r = IT + (sizeof(uintptr_t)*256)) + (sizeof(Addressing)*i) return *r; } void callIT(int i, address val){ void (*func)(Addressing, address); func = (IT + (sizeof(uintptr_t) * i)); Addressing r = (IT + ((i * sizeof(Addressing)) + (sizeof(uintptr_t)*256))); func(r, val); } // Load and Store Instructions void fLDA(Addressing, address); void fLDX(Addressing, address); void fLDY(Addressing, address); void fSTA(Addressing, address); void fSTX(Addressing, address); void fSTY(Addressing, address); // Arithmetic Instructions void fADC(Addressing, address); void fSBC(Addressing, address); //Increment and Decrement Instructions void fINC(Addressing, address); void fINX(Addressing, address); void fINY(Addressing, address); void fDEC(Addressing, address); void fDEX(Addressing, address); void fDEY(Addressing, address); // Logical Instructions void fAND(Addressing, address); void fORA(Addressing, address); void fEOR(Addressing, address); // Jump, Branch, Compare, and Test Bits void fJMP(Addressing, address); void fBCC(Addressing, address); void fBCS(Addressing, address); void fBEQ(Addressing, address); void fBNE(Addressing, address); void fBMI(Addressing, address); void fBPL(Addressing, address); void fBVS(Addressing, address); void fBVC(Addressing, address); void fCMP(Addressing, address); void fCPX(Addressing, address); void fCPY(Addressing, address); void fBIT(Addressing, address); // Shift and Rotate Instructions void fASL(Addressing, address); void fLSR(Addressing, address); void fROL(Addressing, address); void fROR(Addressing, address); // Transfer Instructions void fTAX(Addressing, address); void fTAY(Addressing, address); void fTXA(Addressing, address); void fTYA(Addressing, address); // Stack Instructions void fTSX(Addressing, address); void fTXS(Addressing, address); void fPHA(Addressing, address); void fPHP(Addressing, address); void fPLA(Addressing, address); void fPLP(Addressing, address); // Subroutine Instructions void fJSR(Addressing, address); void fRTS(Addressing, address); void fRTI(Addressing, address); // Set/Reset Insutrctions void fCLC(Addressing, address); void fCLD(Addressing, address); void fCLI(Addressing, address); void fCLV(Addressing, address); void fSEC(Addressing, address); void fSED(Addressing, address); void fSEI(Addressing, address); // NOP/BRK Instructions void fNOP(Addressing, address); void fBRK(Addressing, address); void initIT(){ IT = malloc(256 * (sizeof(uintptr_t) + sizeof(Addressing))); // Load and Store Instructions // fLDA(Addressing, address); setIT(0xA9, &fLDA, eImmediate); setIT(0xA5, &fLDA, eZeroPage); setIT(0xB5, &fLDA, eZeroPageIndexedX); setIT(0xAD, &fLDA, eAbsolute); setIT(0xBD, &fLDA, eAbsoluteIndexedX); setIT(0xB9, &fLDA, eAbsoluteIndexedY); setIT(0xA1, &fLDA, eIndexedIndirect); setIT(0xB1, &fLDA, eIndirectIndexed); // fLDX(Addressing, address); setIT(0xA2, &fLDX, eImmediate); setIT(0xA6, &fLDX, eZeroPage); setIT(0xB6, &fLDX, eZeroPageIndexedY); setIT(0xAE, &fLDX, eAbsolute); setIT(0xBE, &fLDX, eAbsoluteIndexedY); // fLDY(Addressing, address); setIT(0xA0, &fLDY, eImmediate); setIT(0xA4, &fLDY, eZeroPage); setIT(0xB4, &fLDY, eZeroPageIndexedX); setIT(0xAC, &fLDY, eAbsolute); setIT(0xBC, &fLDY, eAbsoluteIndexedX); // fSTA(Addressing, address); setIT(0x85, &fSTA, eZeroPage); setIT(0x95, &fSTA, eZeroPageIndexedX); setIT(0x8D, &fSTA, eAbsolute); setIT(0x9D, &fSTA, eAbsoluteIndexedX); setIT(0x99, &fSTA, eAbsoluteIndexedY); setIT(0x81, &fSTA, eIndexedIndirect); setIT(0x91, &fSTA, eIndirectIndexed); // fSTX(Addressing, address); setIT(0x86, &fSTX, eZeroPage); setIT(0x96, &fSTX, eZeroPageIndexedX); setIT(0x8E, &fSTX, eAbsolute); // fSTY(Addressing, address); setIT(0x84, &fSTY, eZeroPage); setIT(0x94, &fSTY, eZeroPageIndexedY); setIT(0x8C, &fSTY, eAbsolute); // Arithmetic Instructions // fADC(Addressing, address); setIT(0x69, &fADC, eImmediate); setIT(0x65, &fADC, eZeroPage); setIT(0x75, &fADC, eZeroPageIndexedX); setIT(0x6D, &fADC, eAbsolute); setIT(0x7D, &fADC, eAbsoluteIndexedX); setIT(0x79, &fADC, eAbsoluteIndexedY); setIT(0x61, &fADC, eIndexedIndirect); setIT(0x71, &fADC, eIndirectIndexed); // fSBC(Addressing, address); setIT(0xE9, &fSBC, eImmediate); setIT(0xE5, &fSBC, eZeroPage); setIT(0xF5, &fSBC, eZeroPageIndexedX); setIT(0xED, &fSBC, eAbsolute); setIT(0xFD, &fSBC, eAbsoluteIndexedX); setIT(0xF9, &fSBC, eAbsoluteIndexedY); setIT(0xE1, &fSBC, eIndexedIndirect); setIT(0xF1, &fSBC, eIndirectIndexed); //Increment and Decrement Instructions //INC(Addressing, address); setIT(0xE6, &fINC, eZeroPage); setIT(0xF6, &fINC, eZeroPageIndexedX); setIT(0xEE, &fINC, eAbsolute); setIT(0xFE, &fINC, eAbsoluteIndexedX); //INX(Addressing, address); setIT(0xE8, &fINX, eImplied); //INY(Addressing, address); setIT(0xC8, &fINY, eImplied); //DEC(Addressing, address); setIT(0xC6, &fDEC, eZeroPage); setIT(0xD6, &fDEC, eZeroPageIndexedX); setIT(0xCE, &fDEC, eAbsolute); setIT(0xDE, &fDEC, eAbsoluteIndexedX); //DEX(Addressing, address); setIT(0xCA, &fDEX, eImplied); //DEY(Addressing, address); setIT(0x88, &fDEY, eImplied); // Logical Instructions //AND(Addressing, address); setIT(0x29, &fAND, eImmediate); setIT(0x25, &fAND, eZeroPage); setIT(0x35, &fAND, eZeroPageIndexedX); setIT(0x2D, &fAND, eAbsolute); setIT(0x3D, &fAND, eAbsoluteIndexedX); setIT(0x39, &fAND, eAbsoluteIndexedY); setIT(0x21, &fAND, eIndexedIndirect); setIT(0x31, &fAND, eIndirectIndexed); //ORA(Addressing, address); setIT(0x09, &fORA, eImmediate); setIT(0x05, &fORA, eZeroPage); setIT(0x15, &fORA, eZeroPageIndexedX); setIT(0x0D, &fORA, eAbsolute); setIT(0x1D, &fORA, eAbsoluteIndexedX); setIT(0x19, &fORA, eAbsoluteIndexedY); setIT(0x01, &fORA, eIndexedIndirect); setIT(0x11, &fORA, eIndirectIndexed); //EOR(Addressing, address); setIT(0x49, &fEOR, eImmediate); setIT(0x45, &fEOR, eZeroPage); setIT(0x55, &fEOR, eZeroPageIndexedX); setIT(0x4D, &fEOR, eAbsolute); setIT(0x5D, &fEOR, eAbsoluteIndexedX); setIT(0x59, &fEOR, eAbsoluteIndexedY); setIT(0x41, &fEOR, eIndexedIndirect); setIT(0x51, &fEOR, eIndirectIndexed); // Jump, Branch, Compare, and Test Bits //JMP(Addressing, address); setIT(0x4C, &fJMP, eAbsolute); setIT(0x6C, &fJMP, eIndirectAbsolute); //BCC(Addressing, address); setIT(0x90, &fBCC, eRelative); //BCS(Addressing, address); setIT(0xB0, &fBCS, eRelative); //BEQ(Addressing, address); setIT(0xF0, &fBEQ, eRelative); //BNE(Addressing, address); setIT(0xD0, &fBNE, eRelative); //BMI(Addressing, address); setIT(0x30, &fBMI, eRelative); //BPL(Addressing, address); setIT(0x10, &fBPL, eRelative); //BVS(Addressing, address); setIT(0x70, &fBVS, eRelative); //BVC(Addressing, address); setIT(0x50, &fBVC, eRelative); //CMP(Addressing, address); setIT(0xC9, &fCMP, eImmediate); setIT(0xC5, &fCMP, eZeroPage); setIT(0xD5, &fCMP, eZeroPageIndexedX); setIT(0xCD, &fCMP, eAbsolute); setIT(0xDD, &fCMP, eAbsoluteIndexedX); setIT(0xD9, &fCMP, eAbsoluteIndexedY); setIT(0xC1, &fCMP, eIndexedIndirect); setIT(0xD1, &fCMP, eIndirectIndexed); //CPX(Addressing, address); setIT(0xE0, &fCPX, eImmediate); setIT(0xE4, &fCPX, eZeroPage); setIT(0xEC, &fCPX, eAbsolute); //CPY(Addressing, address); setIT(0xC0, &fCPY, eImmediate); setIT(0xC4, &fCPY, eZeroPage); setIT(0xCC, &fCPY, eAbsolute); //BIT(Addressing, address); setIT(0x4C, &fBIT, eZeroPage); setIT(0x6C, &fBIT, eAbsolute); // Shift and Rotate Instructions //ASL(Addressing, address); setIT(0x0A, &fASL, eAccumulator); setIT(0x06, &fASL, eZeroPage); setIT(0x16, &fASL, eZeroPageIndexedX); setIT(0x0E, &fASL, eAbsolute); setIT(0x1E, &fASL, eAbsoluteIndexedX); //LSR(Addressing, address); setIT(0x4A, &fLSR, eAccumulator); setIT(0x46, &fLSR, eZeroPage); setIT(0x56, &fLSR, eZeroPageIndexedX); setIT(0x4E, &fLSR, eAbsolute); setIT(0x5E, &fLSR, eAbsoluteIndexedX); //ROL(Addressing, address); setIT(0x2A, &fROL, eAccumulator); setIT(0x26, &fROL, eZeroPage); setIT(0x36, &fROL, eZeroPageIndexedX); setIT(0x2E, &fROL, eAbsolute); setIT(0x3E, &fROL, eAbsoluteIndexedX); //ROR(Addressing, address); setIT(0x6A, &fROR, eAccumulator); setIT(0x66, &fROR, eZeroPage); setIT(0x76, &fROR, eZeroPageIndexedX); setIT(0x6E, &fROR, eAbsolute); setIT(0x7E, &fROR, eAbsoluteIndexedX); // Transfer Instructions //TAX(Addressing, address); setIT(0xAA, &fTAX, eImplied); //TAY(Addressing, address); setIT(0xA8, &fTAY, eImplied); //TXA(Addressing, address); setIT(0x8A, &fTXA, eImplied); //TYA(Addressing, address); setIT(0x98, &fTYA, eImplied); // Stack Instructions //TSX(Addressing, address); setIT(0xBA, &fTSX, eImplied); //TXS(Addressing, address); setIT(0x9A, &fTXS, eImplied); //PHA(Addressing, address); setIT(0x48, &fPHA, eImplied); //PHP(Addressing, address); setIT(0x08, &fPHP, eImplied); //PLA(Addressing, address); setIT(0x68, &fPLA, eImplied); //PLP(Addressing, address); setIT(0x28, &fPLP, eImplied); // Subroutine Instructions //JSR(Addressing, address); setIT(0x20, &fJSR, eAbsolute); //RTS(Addressing, address); setIT(0x60, &fRTS, eImplied); //RTI(Addressing, address); setIT(0x40, &fRTI, eImplied); // Set/Reset Insutrctions //CLC(Addressing, address); setIT(0x18, &fCLC, eImplied); //CLD(Addressing, address); setIT(0xD8, &fCLD, eImplied); //CLI(Addressing, address); setIT(0x58, &fCLI, eImplied); //CLV(Addressing, address); setIT(0xB8, &fCLV, eImplied); //SEC(Addressing, address); setIT(0x38, &fSEC, eImplied); //SED(Addressing, address); setIT(0xF8, &fSED, eImplied); //SEI(Addressing, address); setIT(0x78, &fSEI, eImplied); // NOP/BRK Instructions //NOP(Addressing, address); setIT(0xEA, &fNOP, eImplied); //BRK(Addressing, address); setIT(0x00, &fBRK, eImplied); }