summaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpu')
-rw-r--r--src/cpu/addressing.c5
-rw-r--r--src/cpu/instructions.c114
2 files changed, 52 insertions, 67 deletions
diff --git a/src/cpu/addressing.c b/src/cpu/addressing.c
index 903e5d0..b8f9330 100644
--- a/src/cpu/addressing.c
+++ b/src/cpu/addressing.c
@@ -18,7 +18,7 @@ address fAddressGetAddress(Addressing mode, address x) {
case eAbsolute:
return x;
case eIndirectAbsolute:
- return (address)GetMemory(x) + ((address)GetMemory(x+1) << 8);
+ return (address)GetMemory(x) + (((address)GetMemory(x+1)) << 8);
case eAbsoluteIndexedX:
return x + X;
case eAbsoluteIndexedY:
@@ -32,7 +32,8 @@ address fAddressGetAddress(Addressing mode, address x) {
case eIndexedIndirect:
return (((address)(GetMemory(x+X+1)))<<8) + (address)(GetMemory(x+X));
case eIndirectIndexed:
- return ((address)(GetMemory(x+1))<<8) + (address)(GetMemory(x)) + Y;
+ return ((address)(GetMemory(x+1))<<8) + ((address)(GetMemory(x))) + ((address)Y);
+ //return ((x >> 8) & 0xFF) (x & 0xFF)
}
}
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