diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-04 15:12:17 +1100 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-04 15:12:17 +1100 |
commit | 5bb10fc4121a8c8434dcd367f2e611599a11e12e (patch) | |
tree | 8fcac1461a50fca6bec6ccd2246f7515ad26099a /src/cpu | |
parent | 78d3f650b2ca507e3d5376d3cad4d93df1901569 (diff) |
removed stuff; various instruction improvements
Diffstat (limited to 'src/cpu')
-rw-r--r-- | src/cpu/addressing.c | 6 | ||||
-rw-r--r-- | src/cpu/instructions.c | 115 |
2 files changed, 81 insertions, 40 deletions
diff --git a/src/cpu/addressing.c b/src/cpu/addressing.c index fd9bf7e..e5625fa 100644 --- a/src/cpu/addressing.c +++ b/src/cpu/addressing.c @@ -18,7 +18,7 @@ address fAddressGetAddress(Addressing mode, short x) { case eAbsolute: return x; case eIndirectAbsolute: - return GetMemory(x) + ((address)GetMemory(x+1) << 8); + return (address)GetMemory(x) + ((address)GetMemory(x+1) << 8); case eAbsoluteIndexedX: return x + X; case eAbsoluteIndexedY: @@ -30,9 +30,9 @@ address fAddressGetAddress(Addressing mode, short x) { case eZeroPageIndexedY: return ((x + Y) & 0x00FF); case eIndexedIndirect: - return ((GetMemory(x+X+1))<<8) + (GetMemory(x+X)); + return ((address)(GetMemory(x+X+1))<<8) + (address)(GetMemory(x+X)); case eIndirectIndexed: - return ((GetMemory(x+1))<<8) + (GetMemory(x)) + Y; + return ((address)(GetMemory(x+1))<<8) + (address)(GetMemory(x)) + Y; } } diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index 5f4000a..b4daf6e 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -75,7 +75,7 @@ void fSBC(Addressing addr, address val){ //Increment and Decrement Instructions void fINC(Addressing addr, address val){ - byte a = GetMemory(idata.add); + byte a = idata.value; SetMemory(idata.add, ++a); SetFlagN(a); SetFlagZ(a); @@ -94,7 +94,7 @@ void fINY(Addressing addr, address val){ } void fDEC(Addressing addr, address val){ - byte a = GetMemory(idata.add); + byte a = idata.value; SetMemory(idata.add, --a); SetFlagN(a); SetFlagZ(a); @@ -139,35 +139,35 @@ void fJMP(Addressing addr, address val){ } void fBCC(Addressing addr, address val){ - if (getFlag(flag_C) == 0) PC += (char)val; + if (getFlag(flag_C) == 0) PC += (char)idata.value; } void fBCS(Addressing addr, address val){ - if (getFlag(flag_C) == 1) PC += (char)val; + if (getFlag(flag_C) == 1) PC += (char)idata.value; } void fBEQ(Addressing addr, address val){ - if (getFlag(flag_Z) == 1) PC += (char)val; + if (getFlag(flag_Z) == 1) PC += (char)idata.value; } void fBNE(Addressing addr, address val){ - if (getFlag(flag_Z) == 0) PC += (char)val; + if (getFlag(flag_Z) == 0) PC += (char)idata.value; } void fBMI(Addressing addr, address val){ - if (getFlag(flag_N) == 1) PC += (char)val; + if (getFlag(flag_N) == 1) PC += (char)idata.value; } void fBPL(Addressing addr, address val){ - if (getFlag(flag_N) == 0) PC += (char)val; + if (getFlag(flag_N) == 0) PC += (char)idata.value; } void fBVS(Addressing addr, address val){ - if (getFlag(flag_V) == 1) PC += (char)val; + if (getFlag(flag_V) == 1) PC += (char)idata.value; } void fBVC(Addressing addr, address val){ - if (getFlag(flag_V) == 0) PC += (char)val; + if (getFlag(flag_V) == 0) PC += (char)idata.value; } void fCMP(Addressing addr, address val){ @@ -197,33 +197,73 @@ void fBIT(Addressing addr, address val){ // Shift and Rotate Instructions void fASL(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x80)); - acc = (idata.value << 1); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (acc & 0x80)); + acc = (idata.value << 1) & 0xFE; + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x80)); + byte m = ((idata.value << 1) & 0xFE); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } void fLSR(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x01)); - acc = (idata.value >> 1); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (acc & 0x01)); + acc = (idata.value >> 1) & 0x7F; + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x01)); + byte m = ((idata.value >> 1) & 0x7F); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } void fROL(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x80)); - acc = (idata.value << 1); - acc |= (getFlag(flag_C)?1:0); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (idata.value & 0x80)); + acc = (idata.value << 1) & 0xFE; + acc |= ((getFlag(flag_C) != 0) ? 0x01 : 0x00); + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x80)); + byte m = + (((idata.value << 1) & 0xFE) + | ((getFlag(flag_C) != 0) ? 0x01 : 0x00)); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } void fROR(Addressing addr, address val){ - SetFlag(flag_C, (idata.value & 0x01)); - acc = (idata.value >> 1); - acc |= (getFlag(flag_C)?0x80:0); - SetFlagN(acc); - SetFlagZ(acc); + if (addr == eAccumulator) { + SetFlag(flag_C, (idata.value & 0x01)); + acc = (idata.value >> 1) & 0x7F; + acc |= ((getFlag(flag_C) != 0) ? 0x80 : 0x00); + SetFlagN(acc); + SetFlagZ(acc); + } + else { + SetFlag(flag_C, (idata.value & 0x01)); + byte m = + (((idata.value >> 1) & 0x7F) + | ((getFlag(flag_C) != 0) ? 0x80 : 0x00)); + SetMemory(idata.add, m); + SetFlagN(m); + SetFlagZ(m); + } } // Transfer Instructions @@ -283,13 +323,14 @@ void fPLP(Addressing addr, address val){ void fJSR(Addressing addr, address val){ SetStack((PC+3) >> 8); SetStack((PC+3) & 0x00FF); - PC = idata.add; PC -= 3; + PC = idata.add; + PC -= idata.length; } void fRTS(Addressing addr, address val){ PC = (address)(GetStack()); PC += ((address)(GetStack())) << 8; - PC -= 1; + PC -= idata.length; } void fRTI(Addressing addr, address val){ @@ -301,31 +342,31 @@ void fRTI(Addressing addr, address val){ // Set/Reset Insutrctions void fCLC(Addressing addr, address val){ - flagClear(flag_C); + SetFlag(flag_C, 0); } void fCLD(Addressing addr, address val){ - flagClear(flag_D); + SetFlag(flag_D, 0); } void fCLI(Addressing addr, address val){ - flagClear(flag_I); + SetFlag(flag_I, 0); } void fCLV(Addressing addr, address val){ - flagClear(flag_V); + SetFlag(flag_V, 0); } void fSEC(Addressing addr, address val){ - flagSet(flag_C); + SetFlag(flag_C, 1); } void fSED(Addressing addr, address val){ - flagSet(flag_D); + SetFlag(flag_D, 1); } void fSEI(Addressing addr, address val){ - flagSet(flag_I); + SetFlag(flag_I, 1); } // NOP/BRK Instructions |