From a9b4eac37fa8eacc8c48548ddb37a7f7a03d5c0d Mon Sep 17 00:00:00 2001 From: Richard Dymond Date: Wed, 14 Aug 2024 17:07:10 -0300 Subject: [PATCH] CSimulator: Fix calculation of IX/IY offset addresses --- c/csimulator.c | 11 ++++++----- sphinx/source/changelog.rst | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/c/csimulator.c b/c/csimulator.c index 4d43eb45..4498f69a 100644 --- a/c/csimulator.c +++ b/c/csimulator.c @@ -35,6 +35,7 @@ #endif #define INC_PC(i) LD(PC, (REG(PC) + (i)) % 65536) #define OUT(p, v) if (mem == NULL && (p & 0x8002) == 0 && (self->out7ffd & 0x20) == 0) out7ffd(self, v) +#define ADDR(a) (a) & 0xFFFF #define CHECK_SIGNALS if ((TIME & 0xFFFFFF) < 10) PyErr_CheckSignals() typedef unsigned char byte; @@ -910,7 +911,7 @@ static void af_xy(CSimulatorObject* self, void* lookup, int args[]) { int xy = REG(xyl) + 256 * REG(xyh); int d = PEEK((REG(PC) + 2) % 65536); - int addr = (xy + (d < 128 ? d : d - 256)) % 65536; + int addr = ADDR(xy + (d < 128 ? d : d - 256)); #ifdef CONTENTION CONTEND { unsigned pc = REG(PC); @@ -1007,7 +1008,7 @@ static void afc_xy(CSimulatorObject* self, void* lookup, int args[]) { int xy = REG(xyl) + 256 * REG(xyh); int d = PEEK((REG(PC) + 2) % 65536); - int addr = (xy + (d < 128 ? d : d - 256)) % 65536; + int addr = ADDR(xy + (d < 128 ? d : d - 256)); #ifdef CONTENTION CONTEND { unsigned pc = REG(PC); @@ -1084,7 +1085,7 @@ static void f_xy(CSimulatorObject* self, void* lookup, int args[]) { int xy = REG(xyl) + 256 * REG(xyh); int d = PEEK((REG(PC) + 2) % 65536); - int addr = (xy + (d < 128 ? d : d - 256)) % 65536; + int addr = ADDR(xy + (d < 128 ? d : d - 256)); #ifdef CONTENTION CONTEND { unsigned pc = REG(PC); @@ -1177,7 +1178,7 @@ static void fc_xy(CSimulatorObject* self, void* lookup, int args[]) { int xy = REG(xyl) + 256 * REG(xyh); int d = PEEK((REG(PC) + 2) % 65536); - int addr = (xy + (d < 128 ? d : d - 256)) % 65536; + int addr = ADDR(xy + (d < 128 ? d : d - 256)); #ifdef CONTENTION CONTEND { unsigned pc = REG(PC); @@ -1338,7 +1339,7 @@ static void bit_xy(CSimulatorObject* self, void* lookup, int args[]) { int xy = REG(xyl) + 256 * REG(xyh); int d = PEEK((REG(PC) + 2) % 65536); - int addr = (xy + (d < 128 ? d : d - 256)) % 65536; + int addr = ADDR(xy + (d < 128 ? d : d - 256)); #ifdef CONTENTION CONTEND { unsigned pc = REG(PC); diff --git a/sphinx/source/changelog.rst b/sphinx/source/changelog.rst index 94cd39c7..b264c793 100644 --- a/sphinx/source/changelog.rst +++ b/sphinx/source/changelog.rst @@ -7,6 +7,8 @@ Changelog affect the half-carry flag * Fixed how 'BIT n,(IX/Y+d)' affects bits 3 and 5 of the flags in the C version of the Z80 simulator +* Fixed how IX/IY offset addresses are calculated in the C version of the Z80 + simulator 9.3 (2024-08-10) ----------------