diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-07 17:34:18 +1100 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-07 17:34:18 +1100 |
commit | f8df4908fe6986e691ea96b4b07ffbff349ccce0 (patch) | |
tree | a868c23e64fb41bd1e25d3e4f34d738ebd0c549a /src/cpu/instructions.c | |
parent | 68cdad3be01539e583627e1c8929f182255541be (diff) |
changed shift ins.s and now log CPU state
Diffstat (limited to 'src/cpu/instructions.c')
-rw-r--r-- | src/cpu/instructions.c | 114 |
1 files changed, 49 insertions, 65 deletions
diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index abe6365..2b034c4 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -65,7 +65,7 @@ void fSBC(Addressing addr){ SetFlagV(buffer, acc); - SetFlag(flag_C, (buffer > acc) ? 1 : 0); + SetFlag(flag_C, (buffer > acc) ? 0 : 1); acc = buffer; @@ -190,81 +190,65 @@ void fCPY(Addressing addr){ } void fBIT(Addressing addr){ - SetFlag(flag_N, ((idata.value & flag_N) != 0) ? 1 : 0); - SetFlag(flag_V, ((idata.value & flag_V) != 0) ? 1 : 0); - SetFlag(flag_Z, ((idata.value & acc) == 0) ? 1 : 0); + SetFlag(flag_N, ((idata.value & flag_N) != 0)); + SetFlag(flag_V, ((idata.value & flag_V) != 0)); + SetFlag(flag_Z, ((idata.value & acc) == 0)); } // Shift and Rotate Instructions void fASL(Addressing addr){ - 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){ - 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); - } + byte m = (addr == eAccumulator) ? acc : idata.value; + + SetFlag(flag_C, (m & 0b10000000)); + m = (m << 1) & 0b11111110; + SetFlagN(m); + SetFlagZ(m); + + (addr == eAccumulator) + ? acc = m + : SetMemory(idata.add, m); +} + +void fLSR(Addressing addr) { + byte m = (addr == eAccumulator) ? acc : idata.value; + + SetFlag(flag_C, (m & 0b00000001)); + m = (m >> 1) & 0b01111111; + SetFlagN(m); + SetFlagZ(m); + + (addr == eAccumulator) + ? acc = m + : SetMemory(idata.add, m); } void fROL(Addressing addr){ - 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); - } + byte m = (addr == eAccumulator) ? acc : idata.value; + + SetFlag(flag_C, (m & 0b10000000)); + m = (m << 1) & 0b11111110; + m |= (getFlag(flag_C)) ? 0b00000001 : 0; + SetFlagN(m); + SetFlagZ(m); + + (addr == eAccumulator) + ? acc = m + : SetMemory(idata.add, m); } void fROR(Addressing addr){ - 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); - } + byte m = (addr == eAccumulator) ? acc : idata.value; + + SetFlag(flag_C, (m & 0b00000001)); + m = (m >> 1) & 0b01111111; + m |= (getFlag(flag_C)) ? 0b10000000 : 0; + SetFlagN(m); + SetFlagZ(m); + + (addr == eAccumulator) + ? acc = m + : SetMemory(idata.add, m); } // Transfer Instructions |