From f8df4908fe6986e691ea96b4b07ffbff349ccce0 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Thu, 7 Dec 2023 17:34:18 +1100 Subject: changed shift ins.s and now log CPU state --- src/cpu/instructions.c | 114 +++++++++++++++++++++---------------------------- 1 file changed, 49 insertions(+), 65 deletions(-) (limited to 'src/cpu/instructions.c') 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 -- cgit v1.2.3