Skip to content

Commit

Permalink
CSimulator: Fix calculation of IX/IY offset addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Aug 14, 2024
1 parent cca6324 commit a9b4eac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions c/csimulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
----------------
Expand Down

0 comments on commit a9b4eac

Please sign in to comment.