From 79a679f3a3d443b631ad5437b69e729550522fcb Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Tue, 11 Apr 2023 15:35:09 +1000 Subject: commit prior to segfault debugging --- a.out | Bin 30760 -> 34808 bytes addressing.h | 2 +- instruction-init.h | 306 ++++++++++++++++++++++++++--------------------------- test.c | 11 ++ 4 files changed, 165 insertions(+), 154 deletions(-) create mode 100644 test.c diff --git a/a.out b/a.out index 2a4c22b..7013c34 100755 Binary files a/a.out and b/a.out differ diff --git a/addressing.h b/addressing.h index cf32561..a179645 100644 --- a/addressing.h +++ b/addressing.h @@ -34,7 +34,7 @@ typedef struct AddData AddData; //Holds address of current instruction. -void (*current_instruction)(address); +void* current_instruction; diff --git a/instruction-init.h b/instruction-init.h index ccfbc85..2e0e29c 100644 --- a/instruction-init.h +++ b/instruction-init.h @@ -15,8 +15,8 @@ void setIT(int i, uintptr_t p, Addressing r){ *r1 = r; } -uintptr_t getITFunction(int i){ - Addressing* r = (IT + (sizeof(uintptr_t)*i)); +uintptr_t getITFunction(int i){ //Segmentation fault is occurring here, likely in next one too + uintptr_t* r = (IT + (sizeof(uintptr_t)*i)); return *r; } @@ -109,230 +109,230 @@ void initIT(){ // 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); + setIT(0xA9, (uintptr_t)&fLDA, eImmediate); + setIT(0xA5, (uintptr_t)&fLDA, eZeroPage); + setIT(0xB5, (uintptr_t)&fLDA, eZeroPageIndexedX); + setIT(0xAD, (uintptr_t)&fLDA, eAbsolute); + setIT(0xBD, (uintptr_t)&fLDA, eAbsoluteIndexedX); + setIT(0xB9, (uintptr_t)&fLDA, eAbsoluteIndexedY); + setIT(0xA1, (uintptr_t)&fLDA, eIndexedIndirect); + setIT(0xB1, (uintptr_t)&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); + setIT(0xA2, (uintptr_t)&fLDX, eImmediate); + setIT(0xA6, (uintptr_t)&fLDX, eZeroPage); + setIT(0xB6, (uintptr_t)&fLDX, eZeroPageIndexedY); + setIT(0xAE, (uintptr_t)&fLDX, eAbsolute); + setIT(0xBE, (uintptr_t)&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); + setIT(0xA0, (uintptr_t)&fLDY, eImmediate); + setIT(0xA4, (uintptr_t)&fLDY, eZeroPage); + setIT(0xB4, (uintptr_t)&fLDY, eZeroPageIndexedX); + setIT(0xAC, (uintptr_t)&fLDY, eAbsolute); + setIT(0xBC, (uintptr_t)&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); + setIT(0x85, (uintptr_t)&fSTA, eZeroPage); + setIT(0x95, (uintptr_t)&fSTA, eZeroPageIndexedX); + setIT(0x8D, (uintptr_t)&fSTA, eAbsolute); + setIT(0x9D, (uintptr_t)&fSTA, eAbsoluteIndexedX); + setIT(0x99, (uintptr_t)&fSTA, eAbsoluteIndexedY); + setIT(0x81, (uintptr_t)&fSTA, eIndexedIndirect); + setIT(0x91, (uintptr_t)&fSTA, eIndirectIndexed); // fSTX(Addressing, address); - setIT(0x86, &fSTX, eZeroPage); - setIT(0x96, &fSTX, eZeroPageIndexedX); - setIT(0x8E, &fSTX, eAbsolute); + setIT(0x86, (uintptr_t)&fSTX, eZeroPage); + setIT(0x96, (uintptr_t)&fSTX, eZeroPageIndexedX); + setIT(0x8E, (uintptr_t)&fSTX, eAbsolute); // fSTY(Addressing, address); - setIT(0x84, &fSTY, eZeroPage); - setIT(0x94, &fSTY, eZeroPageIndexedY); - setIT(0x8C, &fSTY, eAbsolute); + setIT(0x84, (uintptr_t)&fSTY, eZeroPage); + setIT(0x94, (uintptr_t)&fSTY, eZeroPageIndexedY); + setIT(0x8C, (uintptr_t)&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); + setIT(0x69, (uintptr_t)&fADC, eImmediate); + setIT(0x65, (uintptr_t)&fADC, eZeroPage); + setIT(0x75, (uintptr_t)&fADC, eZeroPageIndexedX); + setIT(0x6D, (uintptr_t)&fADC, eAbsolute); + setIT(0x7D, (uintptr_t)&fADC, eAbsoluteIndexedX); + setIT(0x79, (uintptr_t)&fADC, eAbsoluteIndexedY); + setIT(0x61, (uintptr_t)&fADC, eIndexedIndirect); + setIT(0x71, (uintptr_t)&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); + setIT(0xE9, (uintptr_t)&fSBC, eImmediate); + setIT(0xE5, (uintptr_t)&fSBC, eZeroPage); + setIT(0xF5, (uintptr_t)&fSBC, eZeroPageIndexedX); + setIT(0xED, (uintptr_t)&fSBC, eAbsolute); + setIT(0xFD, (uintptr_t)&fSBC, eAbsoluteIndexedX); + setIT(0xF9, (uintptr_t)&fSBC, eAbsoluteIndexedY); + setIT(0xE1, (uintptr_t)&fSBC, eIndexedIndirect); + setIT(0xF1, (uintptr_t)&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); + setIT(0xE6, (uintptr_t)&fINC, eZeroPage); + setIT(0xF6, (uintptr_t)&fINC, eZeroPageIndexedX); + setIT(0xEE, (uintptr_t)&fINC, eAbsolute); + setIT(0xFE, (uintptr_t)&fINC, eAbsoluteIndexedX); //INX(Addressing, address); - setIT(0xE8, &fINX, eImplied); + setIT(0xE8, (uintptr_t)&fINX, eImplied); //INY(Addressing, address); - setIT(0xC8, &fINY, eImplied); + setIT(0xC8, (uintptr_t)&fINY, eImplied); //DEC(Addressing, address); - setIT(0xC6, &fDEC, eZeroPage); - setIT(0xD6, &fDEC, eZeroPageIndexedX); - setIT(0xCE, &fDEC, eAbsolute); - setIT(0xDE, &fDEC, eAbsoluteIndexedX); + setIT(0xC6, (uintptr_t)&fDEC, eZeroPage); + setIT(0xD6, (uintptr_t)&fDEC, eZeroPageIndexedX); + setIT(0xCE, (uintptr_t)&fDEC, eAbsolute); + setIT(0xDE, (uintptr_t)&fDEC, eAbsoluteIndexedX); //DEX(Addressing, address); - setIT(0xCA, &fDEX, eImplied); + setIT(0xCA, (uintptr_t)&fDEX, eImplied); //DEY(Addressing, address); - setIT(0x88, &fDEY, eImplied); + setIT(0x88, (uintptr_t)&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); + setIT(0x29, (uintptr_t)&fAND, eImmediate); + setIT(0x25, (uintptr_t)&fAND, eZeroPage); + setIT(0x35, (uintptr_t)&fAND, eZeroPageIndexedX); + setIT(0x2D, (uintptr_t)&fAND, eAbsolute); + setIT(0x3D, (uintptr_t)&fAND, eAbsoluteIndexedX); + setIT(0x39, (uintptr_t)&fAND, eAbsoluteIndexedY); + setIT(0x21, (uintptr_t)&fAND, eIndexedIndirect); + setIT(0x31, (uintptr_t)&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); + setIT(0x09, (uintptr_t)&fORA, eImmediate); + setIT(0x05, (uintptr_t)&fORA, eZeroPage); + setIT(0x15, (uintptr_t)&fORA, eZeroPageIndexedX); + setIT(0x0D, (uintptr_t)&fORA, eAbsolute); + setIT(0x1D, (uintptr_t)&fORA, eAbsoluteIndexedX); + setIT(0x19, (uintptr_t)&fORA, eAbsoluteIndexedY); + setIT(0x01, (uintptr_t)&fORA, eIndexedIndirect); + setIT(0x11, (uintptr_t)&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); + setIT(0x49, (uintptr_t)&fEOR, eImmediate); + setIT(0x45, (uintptr_t)&fEOR, eZeroPage); + setIT(0x55, (uintptr_t)&fEOR, eZeroPageIndexedX); + setIT(0x4D, (uintptr_t)&fEOR, eAbsolute); + setIT(0x5D, (uintptr_t)&fEOR, eAbsoluteIndexedX); + setIT(0x59, (uintptr_t)&fEOR, eAbsoluteIndexedY); + setIT(0x41, (uintptr_t)&fEOR, eIndexedIndirect); + setIT(0x51, (uintptr_t)&fEOR, eIndirectIndexed); // Jump, Branch, Compare, and Test Bits //JMP(Addressing, address); - setIT(0x4C, &fJMP, eAbsolute); - setIT(0x6C, &fJMP, eIndirectAbsolute); + setIT(0x4C, (uintptr_t)&fJMP, eAbsolute); + setIT(0x6C, (uintptr_t)&fJMP, eIndirectAbsolute); //BCC(Addressing, address); - setIT(0x90, &fBCC, eRelative); + setIT(0x90, (uintptr_t)&fBCC, eRelative); //BCS(Addressing, address); - setIT(0xB0, &fBCS, eRelative); + setIT(0xB0, (uintptr_t)&fBCS, eRelative); //BEQ(Addressing, address); - setIT(0xF0, &fBEQ, eRelative); + setIT(0xF0, (uintptr_t)&fBEQ, eRelative); //BNE(Addressing, address); - setIT(0xD0, &fBNE, eRelative); + setIT(0xD0, (uintptr_t)&fBNE, eRelative); //BMI(Addressing, address); - setIT(0x30, &fBMI, eRelative); + setIT(0x30, (uintptr_t)&fBMI, eRelative); //BPL(Addressing, address); - setIT(0x10, &fBPL, eRelative); + setIT(0x10, (uintptr_t)&fBPL, eRelative); //BVS(Addressing, address); - setIT(0x70, &fBVS, eRelative); + setIT(0x70, (uintptr_t)&fBVS, eRelative); //BVC(Addressing, address); - setIT(0x50, &fBVC, eRelative); + setIT(0x50, (uintptr_t)&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); + setIT(0xC9, (uintptr_t)&fCMP, eImmediate); + setIT(0xC5, (uintptr_t)&fCMP, eZeroPage); + setIT(0xD5, (uintptr_t)&fCMP, eZeroPageIndexedX); + setIT(0xCD, (uintptr_t)&fCMP, eAbsolute); + setIT(0xDD, (uintptr_t)&fCMP, eAbsoluteIndexedX); + setIT(0xD9, (uintptr_t)&fCMP, eAbsoluteIndexedY); + setIT(0xC1, (uintptr_t)&fCMP, eIndexedIndirect); + setIT(0xD1, (uintptr_t)&fCMP, eIndirectIndexed); //CPX(Addressing, address); - setIT(0xE0, &fCPX, eImmediate); - setIT(0xE4, &fCPX, eZeroPage); - setIT(0xEC, &fCPX, eAbsolute); + setIT(0xE0, (uintptr_t)&fCPX, eImmediate); + setIT(0xE4, (uintptr_t)&fCPX, eZeroPage); + setIT(0xEC, (uintptr_t)&fCPX, eAbsolute); //CPY(Addressing, address); - setIT(0xC0, &fCPY, eImmediate); - setIT(0xC4, &fCPY, eZeroPage); - setIT(0xCC, &fCPY, eAbsolute); + setIT(0xC0, (uintptr_t)&fCPY, eImmediate); + setIT(0xC4, (uintptr_t)&fCPY, eZeroPage); + setIT(0xCC, (uintptr_t)&fCPY, eAbsolute); //BIT(Addressing, address); - setIT(0x4C, &fBIT, eZeroPage); - setIT(0x6C, &fBIT, eAbsolute); + setIT(0x4C, (uintptr_t)&fBIT, eZeroPage); + setIT(0x6C, (uintptr_t)&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); + setIT(0x0A, (uintptr_t)&fASL, eAccumulator); + setIT(0x06, (uintptr_t)&fASL, eZeroPage); + setIT(0x16, (uintptr_t)&fASL, eZeroPageIndexedX); + setIT(0x0E, (uintptr_t)&fASL, eAbsolute); + setIT(0x1E, (uintptr_t)&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); + setIT(0x4A, (uintptr_t)&fLSR, eAccumulator); + setIT(0x46, (uintptr_t)&fLSR, eZeroPage); + setIT(0x56, (uintptr_t)&fLSR, eZeroPageIndexedX); + setIT(0x4E, (uintptr_t)&fLSR, eAbsolute); + setIT(0x5E, (uintptr_t)&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); + setIT(0x2A, (uintptr_t)&fROL, eAccumulator); + setIT(0x26, (uintptr_t)&fROL, eZeroPage); + setIT(0x36, (uintptr_t)&fROL, eZeroPageIndexedX); + setIT(0x2E, (uintptr_t)&fROL, eAbsolute); + setIT(0x3E, (uintptr_t)&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); + setIT(0x6A, (uintptr_t)&fROR, eAccumulator); + setIT(0x66, (uintptr_t)&fROR, eZeroPage); + setIT(0x76, (uintptr_t)&fROR, eZeroPageIndexedX); + setIT(0x6E, (uintptr_t)&fROR, eAbsolute); + setIT(0x7E, (uintptr_t)&fROR, eAbsoluteIndexedX); // Transfer Instructions //TAX(Addressing, address); - setIT(0xAA, &fTAX, eImplied); + setIT(0xAA, (uintptr_t)&fTAX, eImplied); //TAY(Addressing, address); - setIT(0xA8, &fTAY, eImplied); + setIT(0xA8, (uintptr_t)&fTAY, eImplied); //TXA(Addressing, address); - setIT(0x8A, &fTXA, eImplied); + setIT(0x8A, (uintptr_t)&fTXA, eImplied); //TYA(Addressing, address); - setIT(0x98, &fTYA, eImplied); + setIT(0x98, (uintptr_t)&fTYA, eImplied); // Stack Instructions //TSX(Addressing, address); - setIT(0xBA, &fTSX, eImplied); + setIT(0xBA, (uintptr_t)&fTSX, eImplied); //TXS(Addressing, address); - setIT(0x9A, &fTXS, eImplied); + setIT(0x9A, (uintptr_t)&fTXS, eImplied); //PHA(Addressing, address); - setIT(0x48, &fPHA, eImplied); + setIT(0x48, (uintptr_t)&fPHA, eImplied); //PHP(Addressing, address); - setIT(0x08, &fPHP, eImplied); + setIT(0x08, (uintptr_t)&fPHP, eImplied); //PLA(Addressing, address); - setIT(0x68, &fPLA, eImplied); + setIT(0x68, (uintptr_t)&fPLA, eImplied); //PLP(Addressing, address); - setIT(0x28, &fPLP, eImplied); + setIT(0x28, (uintptr_t)&fPLP, eImplied); // Subroutine Instructions //JSR(Addressing, address); - setIT(0x20, &fJSR, eAbsolute); + setIT(0x20, (uintptr_t)&fJSR, eAbsolute); //RTS(Addressing, address); - setIT(0x60, &fRTS, eImplied); + setIT(0x60, (uintptr_t)&fRTS, eImplied); //RTI(Addressing, address); - setIT(0x40, &fRTI, eImplied); + setIT(0x40, (uintptr_t)&fRTI, eImplied); // Set/Reset Insutrctions //CLC(Addressing, address); - setIT(0x18, &fCLC, eImplied); + setIT(0x18, (uintptr_t)&fCLC, eImplied); //CLD(Addressing, address); - setIT(0xD8, &fCLD, eImplied); + setIT(0xD8, (uintptr_t)&fCLD, eImplied); //CLI(Addressing, address); - setIT(0x58, &fCLI, eImplied); + setIT(0x58, (uintptr_t)&fCLI, eImplied); //CLV(Addressing, address); - setIT(0xB8, &fCLV, eImplied); + setIT(0xB8, (uintptr_t)&fCLV, eImplied); //SEC(Addressing, address); - setIT(0x38, &fSEC, eImplied); + setIT(0x38, (uintptr_t)&fSEC, eImplied); //SED(Addressing, address); - setIT(0xF8, &fSED, eImplied); + setIT(0xF8, (uintptr_t)&fSED, eImplied); //SEI(Addressing, address); - setIT(0x78, &fSEI, eImplied); + setIT(0x78, (uintptr_t)&fSEI, eImplied); // NOP/BRK Instructions //NOP(Addressing, address); - setIT(0xEA, &fNOP, eImplied); + setIT(0xEA, (uintptr_t)&fNOP, eImplied); //BRK(Addressing, address); - setIT(0x00, &fBRK, eImplied); + setIT(0x00, (uintptr_t)&fBRK, eImplied); } \ No newline at end of file diff --git a/test.c b/test.c new file mode 100644 index 0000000..b8cecd6 --- /dev/null +++ b/test.c @@ -0,0 +1,11 @@ +#include"include.h" +#include"debug.h" + +int main(){ + fAddressGetLength(eAbsolute); + printf("fAddressGetLength Success\n"); + getITFunction(0x00); + printf("getITFunction Success\n"); + getITAddressing(0x00); + printf("getITAddressing Success\n"); +} \ No newline at end of file -- cgit v1.2.3