Skip to content

Commit

Permalink
Merge pull request #52 from suzukiplan/1.9.0
Browse files Browse the repository at this point in the history
Modify the timing of decrementing the B register with the repeat I/O operands
  • Loading branch information
suzukiplan authored Jan 7, 2023
2 parents c092cd9 + 3c17391 commit 253627b
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change log

## Version 1.9.0 (Jan 7, 2023 JST)

- Modify the timing of decrementing the B register with the repeat I/O operands (`INI`, `INIR`, `IND`, `INDR`, `OUTI`, `OTIR`, `OUTD` and `OTDR`). _(NOTE: **Destructive** change)_
- before
- execute IN/OUT
- B = B - 1
- after
- B = B - 1
- execute IN/OUT

## Version 1.8.0 (Oct 23, 2022 JST)

- Make strict the registers conditions at callback time (NOTE: **Destructive** change specification)
Expand Down
6 changes: 6 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ all:
make test-out
make test-remove-break
make test-unknown
make test-repio

test-execute:
clang $(CFLAGS) test-execute.cpp -lstdc++
Expand Down Expand Up @@ -55,6 +56,11 @@ test-out:
./a.out > test-out.txt
cat test-out.txt

test-repio:
clang $(CFLAGS) test-repio.cpp -lstdc++
./a.out > test-repio.txt
cat test-repio.txt

test-remove-break:
clang $(CFLAGS) test-remove-break.cpp -lstdc++
./a.out > test-remove-break.txt
Expand Down
12 changes: 6 additions & 6 deletions test/test-clock.txt
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ TEST#238: 12Hz [0000] IN E<$00>, (C<$00>) = $00
TEST#238: 12Hz [0000] IN H<$00>, (C<$00>) = $00
TEST#238: 12Hz [0000] IN L<$00>, (C<$00>) = $00
TEST#238: 12Hz [0000] IN A<$00>, (C<$00>) = $00
TEST#239: 16Hz [0000] INI ... (HL<$0000>) <- p(C<$00>) = $00 [B<$00>]
TEST#240: 21Hz [0000] INIR ... (HL<$0001>) <- p(C<$00>) = $00 [B<$02>]
TEST#240: 16Hz [0000] INIR ... (HL<$0002>) <- p(C<$00>) = $00 [B<$01>]
TEST#241: 16Hz [0000] IND ... (HL<$0003>) <- p(C<$00>) = $00 [B<$00>]
TEST#242: 21Hz [0000] INDR ... (HL<$0002>) <- p(C<$00>) = $00 [B<$02>]
TEST#242: 16Hz [0000] INDR ... (HL<$0001>) <- p(C<$00>) = $00 [B<$01>]
TEST#239: 16Hz [0000] INI ... (HL<$0000>) <- p(C<$00>) = $00 [B<$FF>]
TEST#240: 21Hz [0000] INIR ... (HL<$0001>) <- p(C<$00>) = $00 [B<$01>]
TEST#240: 16Hz [0000] INIR ... (HL<$0002>) <- p(C<$00>) = $00 [B<$00>]
TEST#241: 16Hz [0000] IND ... (HL<$0003>) <- p(C<$00>) = $00 [B<$FF>]
TEST#242: 21Hz [0000] INDR ... (HL<$0002>) <- p(C<$00>) = $00 [B<$01>]
TEST#242: 16Hz [0000] INDR ... (HL<$0001>) <- p(C<$00>) = $00 [B<$00>]
TEST#243: 11Hz [0000] OUT ($00), A<$00>
TEST#244: 12Hz [0000] OUT (C<$00>), B<$00>
TEST#244: 12Hz [0000] OUT (C<$00>), C<$00>
Expand Down
63 changes: 63 additions & 0 deletions test/test-repio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "z80.hpp"

int main()
{
unsigned char rom[256] = {
0x01, 0x10, 0x03, // LD BC, $0310
0xED, 0xA2, // INI
0x01, 0x20, 0x02, // LD BC, $0220
0xED, 0xB2, // INIR
0x01, 0x30, 0x03, // LD BC, $0330
0xED, 0xAA, // IND
0x01, 0x40, 0x02, // LD BC, $0240
0xED, 0xBA, // INDR
0x01, 0x50, 0x03, // LD BC, $0350
0xED, 0xA3, // OUTI
0x01, 0x60, 0x02, // LD BC, $0260
0xED, 0xB3, // OTIR
0x01, 0x70, 0x03, // LD BC, $0370
0xED, 0xAB, // OUTD
0x01, 0x80, 0x02, // LD BC, $0280
0xED, 0xBB, // OTDR
};
unsigned short expectPorts[] = {
0x0210,
0x0120,
0x0020,
0x0230,
0x0140,
0x0040,
0x0250,
0x0160,
0x0060,
0x0270,
0x0180,
0x0080,
};
int expectPortIndex = 0;
Z80 z80([&rom](void* arg, unsigned short addr) {
return rom[addr & 0xFF];
}, [](void* arg, unsigned char addr, unsigned char value) {
// nothing to do
}, [&](void* arg, unsigned short port) {
printf("IN port A <- $%04X\n",
port // the full (A0 through A15) of the address bus to select the I/O device at one of 65536 possible ports
);
if (port != expectPorts[expectPortIndex++]) {
puts("UNEXPECTED!");
exit(-1);
}
return 0;
}, [](void* arg, unsigned short port, unsigned char value) {
printf("OUT port $%04X <- $%02X\n",
port, // the full (A0 through A15) of the address bus to select the I/O device at one of 65536 possible ports
value
);
}, &z80, true);
z80.setDebugMessage([](void* arg, const char* msg) { puts(msg); });
z80.addBreakOperand(0x00, [](void* arg, unsigned char* operands, int size) {
exit(0);
});
z80.execute(INT_MAX);
return 0;
}
32 changes: 32 additions & 0 deletions test/test-repio.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[0000] LD BC<$0000>, $0310
IN port A <- $0210
[0003] INI ... (HL<$0000>) <- p(C<$10>) = $00 [B<$02>]
[0005] LD BC<$0210>, $0220
IN port A <- $0120
[0008] INIR ... (HL<$0001>) <- p(C<$20>) = $00 [B<$01>]
IN port A <- $0020
[0008] INIR ... (HL<$0002>) <- p(C<$20>) = $00 [B<$00>]
[000A] LD BC<$0020>, $0330
IN port A <- $0230
[000D] IND ... (HL<$0003>) <- p(C<$30>) = $00 [B<$02>]
[000F] LD BC<$0230>, $0240
IN port A <- $0140
[0012] INDR ... (HL<$0002>) <- p(C<$40>) = $00 [B<$01>]
IN port A <- $0040
[0012] INDR ... (HL<$0001>) <- p(C<$40>) = $00 [B<$00>]
[0014] LD BC<$0040>, $0350
[0017] OUTI ... p(C<$50>) <- (HL<$0000>) <$01> [B<$03>]
OUT port $0250 <- $01
[0019] LD BC<$0250>, $0260
[001C] OUTIR ... p(C<$60>) <- (HL<$0001>) <$10> [B<$02>]
OUT port $0160 <- $10
[001C] OUTIR ... p(C<$60>) <- (HL<$0002>) <$03> [B<$01>]
OUT port $0060 <- $03
[001E] LD BC<$0060>, $0370
[0021] OUTD ... p(C<$70>) <- (HL<$0003>) <$ed> [B<$03>]
OUT port $0270 <- $ED
[0023] LD BC<$0270>, $0280
[0026] OUTDR ... p(C<$80>) <- (HL<$0002>) <$03> [B<$02>]
OUT port $0180 <- $03
[0026] OUTDR ... p(C<$80>) <- (HL<$0001>) <$10> [B<$01>]
OUT port $0080 <- $10
6 changes: 3 additions & 3 deletions test/test-status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const char* statusText(unsigned char f, char* buf)
bit[2] = (f & 0b00000100) ? 1 : 0;
bit[1] = (f & 0b00000010) ? 1 : 0;
bit[0] = (f & 0b00000001) ? 1 : 0;
sprintf(buf, "%d%d%d%d%d%d%d%d", bit[7], bit[6], bit[5], bit[4], bit[3], bit[2], bit[1], bit[0]);
snprintf(buf, 9, "%d%d%d%d%d%d%d%d", bit[7], bit[6], bit[5], bit[4], bit[3], bit[2], bit[1], bit[0]);
return buf;
}

Expand Down Expand Up @@ -112,9 +112,9 @@ void stockOpcode(void* arg, unsigned char* opcode, int opcodeLength)
for (int i = 0; i < opcodeLength; i++) {
char buf[80];
if (i) {
sprintf(buf, ",%02X", opcode[i]);
snprintf(buf, sizeof(buf), ",%02X", opcode[i]);
} else {
sprintf(buf, "%02X", opcode[i]);
snprintf(buf, sizeof(buf), "%02X", opcode[i]);
}
strcat(g_opBuf, buf);
}
Expand Down
4 changes: 2 additions & 2 deletions z80.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4875,6 +4875,7 @@ class Z80
inline void repeatIN(bool isIncHL, bool isRepeat)
{
reg.WZ = (unsigned short)(getBC() + (isIncHL ? 1 : -1));
decrementB_forRepeatIO();
unsigned char i = inPort(reg.pair.C);
unsigned short hl = getHL();
if (isDebug()) {
Expand All @@ -4885,7 +4886,6 @@ class Z80
}
}
writeByte(hl, i);
decrementB_forRepeatIO();
hl += isIncHL ? 1 : -1;
setHL(hl);
setFlagZ(reg.pair.B == 0);
Expand Down Expand Up @@ -4942,8 +4942,8 @@ class Z80
log("[%04X] %s ... p(%s) <- (%s) <$%02x> [%s]", reg.PC - 2, isRepeat ? "OUTDR" : "OUTD", registerDump(0b001), registerPairDump(0b10), o, registerDump(0b000));
}
}
outPort(reg.pair.C, o);
decrementB_forRepeatIO();
outPort(reg.pair.C, o);
reg.WZ = (unsigned short)(getBC() + (isIncHL ? 1 : -1));
setHL((unsigned short)(getHL() + (isIncHL ? 1 : -1)));
setFlagZ(reg.pair.B == 0);
Expand Down

0 comments on commit 253627b

Please sign in to comment.