summaryrefslogtreecommitdiff
path: root/src/cpu/instructions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpu/instructions.c')
-rw-r--r--src/cpu/instructions.c115
1 files changed, 78 insertions, 37 deletions
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