diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-04-07 02:35:46 +1000 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-04-07 02:35:46 +1000 |
commit | fbca225d25db812fe7823a8528dff17320cf1c53 (patch) | |
tree | f99d672c7245233814cd038fd683ef8bf4270961 /instruction.h | |
parent | 4b2952578ece47358960e29825443f77070a7457 (diff) |
commit so I can access it tomorrow.
Diffstat (limited to 'instruction.h')
-rw-r--r-- | instruction.h | 123 |
1 files changed, 66 insertions, 57 deletions
diff --git a/instruction.h b/instruction.h index c1b4843..e8e9bbc 100644 --- a/instruction.h +++ b/instruction.h @@ -1,16 +1,18 @@ +// instruction.h +// Definition of all instruction functions, handling effect of instruction and flags. + // array/map of pointers which all point // to the functions which the index corresponds to. // use that like a sort of map -AddData idata; //Instruction Data +//Instruction Data +AddData idata; // Load and Store Instructions -// the load and store instructions are currently -// used to express how data structures will work eventually. void fLDA(Addressing addr, address val){ idata = fAddress(addr, val); - acc = idata.val; + acc = idata.value; } void fLDX(Addressing addr, address val){ idata = fAddress(addr, val); @@ -22,44 +24,43 @@ void fLDY(Addressing addr, address val){ idata = fAddress(addr, val); } void fSTA(Addressing addr, address val){ idata = fAddress(addr, val); - Memory[idata.value] = acc; + Memory[idata.add] = acc; } void fSTX(Addressing addr, address val){ idata = fAddress(addr, val); - Memory[idata.value] = X; + Memory[idata.add] = X; } void fSTY(Addressing addr, address val){ idata = fAddress(addr, val); - Memory[idata.value] = Y; + Memory[idata.add] = Y; } // Arithmetic Instructions void fADC(Addressing addr, address val){ idata = fAddress(addr, val); - int buffer = acc + fAddress(addr, val); + int buffer = acc + idata.value; setFlagV(buffer, acc); - if (buffer > 255){ + if (buffer > 255) flagSet(flag_C); - }else{ + else flagClear(flag_C); - } - acc += fAddress(addr, val); + acc += idata.value; setFlagN(acc); setFlagZ(acc); } void fSBC(Addressing addr, address val){ idata = fAddress(addr, val); - int buffer = acc - fAddress(addr, val); + int buffer = acc - idata.value; setFlagV(buffer, acc); - if (buffer < 0){ + if (buffer < 0) flagSet(flag_C); - }else{ + else flagClear(flag_C); - } - acc -= fAddress(addr, val); + + acc -= idata.value; setFlagN(acc); setFlagZ(acc); } @@ -67,14 +68,14 @@ void fSBC(Addressing addr, address val){ idata = fAddress(addr, val); //Increment and Decrement Instructions void fINC(Addressing addr, address val){ idata = fAddress(addr, val); - Memory[x]++; - setFlagD(Memory[x]); - setFlagZ(Memory[x]); + Memory[idata.add]++; + setFlagN(Memory[idata.add]); + setFlagZ(Memory[idata.add]); } void fINX(Addressing addr, address val){ idata = fAddress(addr, val); X++; - setFlagD(X); + setFlagN(X); setFlagZ(X); } @@ -85,9 +86,9 @@ void fINY(Addressing addr, address val){ idata = fAddress(addr, val); } void fDEC(Addressing addr, address val){ idata = fAddress(addr, val); - Memory[x]--; - setFlagD(Memory[x]); - setFlagZ(Memory[x]); + Memory[idata.add]--; + setFlagD(Memory[idata.add]); + setFlagZ(Memory[idata.add]); } void fDEX(Addressing addr, address val){ idata = fAddress(addr, val); @@ -105,19 +106,19 @@ void fDEY(Addressing addr, address val){ idata = fAddress(addr, val); // Logical Instructions void fAND(Addressing addr, address val){ idata = fAddress(addr, val); - acc = acc & fAddress(addr, val); - setFlagN(); + acc &= idata.value; + setFlagN(acc); setFlagZ(acc); } void fORA(Addressing addr, address val){ idata = fAddress(addr, val); - acc = acc | fAddress(addr, val); - setFlagN(); + acc |= idata.value; + setFlagN(acc); setFlagZ(acc); } void fEOR(Addressing addr, address val){ idata = fAddress(addr, val); - acc = acc ^ fAddress(addr, val); + acc ^= idata.value; setFlagN(acc); setFlagZ(acc); } @@ -128,7 +129,7 @@ void fJMP(Addressing addr, address val){ idata = fAddress(addr, val); PC = val; } -void fBCC(Addressing addr, address val){ idata = fAddress(addr, val); +void fBCC(Addressing addr, address val){ idata = fAddress(addr, val); //FINISH ALL BRANCH INSTRUCTIONS //signed char val down to BVC if (getFlag(flag_C) == 0) PC += val; } @@ -162,35 +163,36 @@ void fBVC(Addressing addr, address val){ idata = fAddress(addr, val); } void fCMP(Addressing addr, address val){ idata = fAddress(addr, val); - if (acc < Memory[val]){ + if (acc < idata.value){ flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); - }if (acc == Memory[val]){ + }if (acc == idata.value){ flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); - }if (acc > Memory[val]){ + }if (acc > idata.value){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } } void fCPX(Addressing addr, address val){ idata = fAddress(addr, val); - if (X < Memory[val]){ + if (X < idata.value){ flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); - }if (X == Memory[val]){ + }if (X == idata.value){ flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); - }if (X > Memory[val]){ + }if (X > idata.value){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } } void fCPY(Addressing addr, address val){ idata = fAddress(addr, val); - if (Y < Memory[val]){ + if (Y < idata.value){ flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); - }if (Y == Memory[val]){ + }if (Y == idata.value){ flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); - }if (Y > Memory[val]){ + }if (Y > idata.value){ flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); } } +//Need to double check the function of this instruction void fBIT(Addressing addr, address val){ idata = fAddress(addr, val); setFlag(flag_N, (Memory[val] & flag_N)); setFlag(flag_V, (Memory[val] & flag_V)); @@ -210,7 +212,7 @@ void fASL(Addressing addr, address val){ idata = fAddress(addr, val); setFlagZ(acc); } -void fASL(Addressing addr, address val){ idata = fAddress(addr, val); +void fLSR(Addressing addr, address val){ idata = fAddress(addr, val); setFlag(flag_C, (val & 0x01)); acc = (val >> 1); setFlagN(acc); @@ -237,14 +239,14 @@ void fROR(Addressing addr, address val){ idata = fAddress(addr, val); void fTAX(Addressing addr, address val){ idata = fAddress(addr, val); X = acc; - setFlagN(X); - setFlagZ(X); + //setFlagN(X); + //setFlagZ(X); } void fTAY(Addressing addr, address val){ idata = fAddress(addr, val); Y = acc; - setFlagN(Y); - setFlagZ(Y); + //setFlagN(Y); + //setFlagZ(Y); } void fTXA(Addressing addr, address val){ idata = fAddress(addr, val); @@ -270,69 +272,76 @@ void fTXS(Addressing addr, address val){ idata = fAddress(addr, val); } void fPHA(Addressing addr, address val){ idata = fAddress(addr, val); - + Memory[0x01FF-S] = A; + S++; } void fPHP(Addressing addr, address val){ idata = fAddress(addr, val); - + Memory[0x01FF-S] = P; + S++; } void fPLA(Addressing addr, address val){ idata = fAddress(addr, val); - + S--; + A = Memory[0x01FF-S]; } void fPLP(Addressing addr, address val){ idata = fAddress(addr, val); - + S--; + P = Memory[0x01FF-S]; } // Subroutine Instructions +void fJSR(Addressing addr, address val){ idata = fAddress(addr, val) + Memory[0x01FF-S] = (idata.add-1); + S++; + PC = idata.add +} + +void fRTS(Addressing addr, address val){ idata = fAddress(addr, val) +} + +void fRTI(Addressing addr, address val){ idata = fAddress(addr, val) + +} // Set/Reset Insutrctions void fCLC(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_C); - return {1, 2}; } void fCLD(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_D); - return {1, 2}; } void fCLI(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_I); - return {1, 2}; } void fCLV(Addressing addr, address val){ idata = fAddress(addr, val); flagClear(flag_V); - return {1, 2}; } void fSEC(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_C); - return {1, 2}; } void fSED(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_D); - return {1, 2}; } void fSEI(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_I); - return {1, 2}; } // NOP/BRK Instructions void fNOP(Addressing addr, address val){ idata = fAddress(addr, val); - return {1, 2}; } void fBRK(Addressing addr, address val){ idata = fAddress(addr, val); flagSet(flag_B); - return {1, 7}; }
\ No newline at end of file |