Skip to content

Commit

Permalink
Fixed IN and OUT instructions to support the upper byte of the address
Browse files Browse the repository at this point in the history
Fixed IN and OUT instructions to support the upper byte of the address
  • Loading branch information
abelykh0 committed Nov 24, 2024
1 parent 1c418fa commit 5e6d78d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions z80emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2220,10 +2220,10 @@ static int emulate (Z80_STATE * state,

case IN_A_N: {

int n;
int n;

READ_N(n);
Z80_INPUT_BYTE(n, A);
Z80_INPUT_BYTE(n, A, A);

elapsed_cycles += 4;

Expand All @@ -2234,7 +2234,7 @@ static int emulate (Z80_STATE * state,
case IN_R_C: {

int x;
Z80_INPUT_BYTE(C, x);
Z80_INPUT_BYTE(C, B, x);
if (Y(opcode) != INDIRECT_HL)

R(Y(opcode)) = x;
Expand All @@ -2258,7 +2258,7 @@ static int emulate (Z80_STATE * state,

int x, f;

Z80_INPUT_BYTE(C, x);
Z80_INPUT_BYTE(C, B, x);
WRITE_BYTE(HL, x);

f = SZYX_FLAGS_TABLE[--B & 0xff]
Expand Down Expand Up @@ -2309,7 +2309,7 @@ static int emulate (Z80_STATE * state,

r += 2;

Z80_INPUT_BYTE(C, x);
Z80_INPUT_BYTE(C, B, x);
Z80_WRITE_BYTE(hl, x);

hl += d;
Expand Down Expand Up @@ -2372,7 +2372,7 @@ static int emulate (Z80_STATE * state,
int n;

READ_N(n);
Z80_OUTPUT_BYTE(n, A);
Z80_OUTPUT_BYTE(n, A, A);

elapsed_cycles += 4;

Expand All @@ -2387,7 +2387,7 @@ static int emulate (Z80_STATE * state,
x = Y(opcode) != INDIRECT_HL
? R(Y(opcode))
: 0;
Z80_OUTPUT_BYTE(C, x);
Z80_OUTPUT_BYTE(C, B, x);

elapsed_cycles += 4;

Expand All @@ -2400,11 +2400,12 @@ static int emulate (Z80_STATE * state,
int x, f;

READ_BYTE(HL, x);
Z80_OUTPUT_BYTE(C, x);
B--;
Z80_OUTPUT_BYTE(C, B, x);

HL += opcode == OPCODE_OUTI ? +1 : -1;

f = SZYX_FLAGS_TABLE[--B & 0xff]
f = SZYX_FLAGS_TABLE[B & 0xff]
| (x >> (7 - Z80_N_FLAG_SHIFT));
x += HL & 0xff;
f |= x & 0x0100 ? HC_FLAGS : 0;
Expand Down Expand Up @@ -2432,10 +2433,11 @@ static int emulate (Z80_STATE * state,
r += 2;

Z80_READ_BYTE(hl, x);
Z80_OUTPUT_BYTE(C, x);
b--;
Z80_OUTPUT_BYTE(C, b, x);

hl += d;
if (--b)
if (b)

elapsed_cycles += 21;

Expand Down
4 changes: 2 additions & 2 deletions z80user.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ extern "C" {

#define Z80_WRITE_WORD_INTERRUPT(address, x) Z80_WRITE_WORD((address), (x))

#define Z80_INPUT_BYTE(port, x) \
#define Z80_INPUT_BYTE(portLow, portHigh, x) \
{ \
SystemCall((ZEXTEST *) context); \
}

#define Z80_OUTPUT_BYTE(port, x) \
#define Z80_OUTPUT_BYTE(portLow, portHigh, x) \
{ \
((ZEXTEST *) context)->is_done = !0; \
number_cycles = 0; \
Expand Down

0 comments on commit 5e6d78d

Please sign in to comment.