From 09288876a8080b2a643a8c644eb116c021f0c397 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Sun, 3 Dec 2023 21:06:45 +1100 Subject: changed compare instructions --- src/cpu/addressing.c | 4 ++-- src/cpu/instructions.c | 37 +++++++++---------------------------- src/cpu/table.c | 2 +- 3 files changed, 12 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/cpu/addressing.c b/src/cpu/addressing.c index f21e7da..f381e51 100644 --- a/src/cpu/addressing.c +++ b/src/cpu/addressing.c @@ -50,8 +50,8 @@ byte fAddressGetValue(Addressing mode, short x, address addr) { switch(mode){ case eImplied: case eIndirectAbsolute: - case eRelative: return 0; + case eRelative: // TODO: MARKER FOR 3/12/2023 case eImmediate: return x; case eAccumulator: @@ -176,4 +176,4 @@ AddData fAddress(Addressing mode, short x) { ret.length = fAddressGetLength (mode); ret.cycles = fAddressGetCycles (mode, x, ret.add); return ret; -} \ No newline at end of file +} diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index 2d4fc9e..2a2f97f 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -172,42 +172,23 @@ void fBVC(Addressing addr, address val){ } void fCMP(Addressing addr, address val){ - if (acc < idata.value){ - flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); - } - else if (acc == idata.value){ - flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); - } - else if (acc > idata.value){ - flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); - } + SetFlag(flag_C, (acc >= val) ? 1 : 0); + SetFlag(flag_Z, (acc == val) ? 1 : 0); + SetFlag(flag_N, (acc & flag_N ) ? 1 : 0); } void fCPX(Addressing addr, address val){ - if (X < idata.value){ - flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); - } - else if (X == idata.value){ - flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); - } - else if (X > idata.value){ - flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); - } + SetFlag(flag_C, (X >= val) ? 1 : 0); + SetFlag(flag_Z, (X == val) ? 1 : 0); + SetFlag(flag_N, (X & flag_N ) ? 1 : 0); } void fCPY(Addressing addr, address val){ - if (Y < idata.value){ - flagSet(flag_N); flagClear(flag_Z); flagClear(flag_C); - } - else if (Y == idata.value){ - flagClear(flag_N); flagSet(flag_Z); flagClear(flag_C); - } - else if (Y > idata.value){ - flagClear(flag_N); flagClear(flag_Z); flagSet(flag_C); - } + SetFlag(flag_C, (Y >= val) ? 1 : 0); + SetFlag(flag_Z, (Y == val) ? 1 : 0); + SetFlag(flag_N, (Y & flag_N ) ? 1 : 0); } -//NEED TO DOUBLE CHECK THIS INSTRUCTION void fBIT(Addressing addr, address val){ SetFlag(flag_N, (idata.value & flag_N)?1:0); SetFlag(flag_V, (idata.value & flag_V)?1:0); diff --git a/src/cpu/table.c b/src/cpu/table.c index ca14c1c..735ab80 100644 --- a/src/cpu/table.c +++ b/src/cpu/table.c @@ -34,7 +34,7 @@ void CallInstructionTable(int i, address val){ idata = fAddress(*r, val); // Perform function - func(*r, val); + func(*r, val); // TODO: MARKER FOR 3/12/2023 PC += idata.length; } -- cgit v1.2.3