Skip to content

Commit

Permalink
Merge pull request #47 from suzukiplan/add/test/remove
Browse files Browse the repository at this point in the history
Version 1.7.1
  • Loading branch information
suzukiplan authored Oct 18, 2022
2 parents c83809a + a62a5ec commit 4ea5859
Show file tree
Hide file tree
Showing 6 changed files with 524 additions and 115 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## Version 1.7.1 (Oct 18, 2022, JST)

- A bug that prevented `addBreakOperand` from working as expected has been addressed.

## Version 1.7.0 (Oct 17, 2022 JST)

- **Destructive** change specification of in/out callback:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ void outPort(void* arg, unsigned short port, unsigned char value)
Z80 z80(readByte, writeByte, inPort, outPort, &mmu);
```

#### 3-1. Cases when want to use 16bit port

Note that by default, only the lower 8 bits of the port number can be obtained in the callback argument, and the upper 8 bits must be referenced from register B.

If you want to get it in 16 bits from the beginning, please initialize with 6th argument to `true` as follows:
Expand All @@ -114,6 +116,8 @@ If you want to get it in 16 bits from the beginning, please initialize with 6th
Z80 z80(&mmu, readByte, writeByte, inPort, outPort, true);
```
#### 3-2. Cases when performance-sensitive
Normally, `std::function` is used for callbacks, but in more performance-sensitive cases, a function pointer can be used.
```c++
Expand Down
6 changes: 6 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ all:
make test-im2
make test-branch
make test-out
make test-remove-break

test-clock:
clang $(CFLAGS) test-clock.cpp -lstdc++
Expand All @@ -38,3 +39,8 @@ test-out:
clang $(CFLAGS) test-out.cpp -lstdc++
./a.out > test-out.txt
cat test-out.txt

test-remove-break:
clang $(CFLAGS) test-remove-break.cpp -lstdc++
./a.out > test-remove-break.txt
cat test-remove-break.txt
80 changes: 80 additions & 0 deletions test/test-remove-break.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "z80.hpp"

int main()
{
unsigned char rom[256] = {
0x01, 0x34, 0x12, // LD BC, $1234
0x3E, 0x01, // LD A, $01
0xED, 0x79, // OUT (C), A
0xED, 0x78, // IN A, (C)
0xc3, 0x00, 0x00, // JMP $0000
};
Z80 z80([&rom](void* arg, unsigned short addr) {
return rom[addr & 0xFF];
}, [](void* arg, unsigned char addr, unsigned char value) {
((Z80*)arg)->requestBreak();
}, [](void* arg, unsigned short port) {
return 0x00;
}, [](void* arg, unsigned short port, unsigned char value) {
putc(value, stdout);
}, &z80);
z80.setDebugMessage([](void* arg, const char* msg) { puts(msg); });
for (unsigned short addr = 0; addr < 0x8000; addr++) {
for (int i = 0; i < 10; i++) {
z80.addBreakPoint(addr, [=](void* arg) {
printf("break 0x%04X (%d)\n", addr, i);
});
}
}
long totalClocks = 0;
z80.setConsumeClockCallback([&totalClocks](void* arg, int clocks) {
totalClocks = clocks + totalClocks;
});
for (int operand = 0; operand < 65536; operand++) {
unsigned char op1 = (unsigned char)((operand & 0xFF00) >> 8);
unsigned char op2 = (unsigned char)(operand & 0xFF);
for (int i = 0; i < 10; i++) {
z80.addBreakOperand(op1, op2, [=](void* arg, const unsigned char* opcode, int opcodeLength) {
char buf[1024];
buf[0] = '\0';
for (int j = 0; j < opcodeLength; j++) {
char hex[8];
if (j) {
snprintf(hex, sizeof(hex), ",%02X", opcode[j]);
} else {
snprintf(hex, sizeof(hex), "%02X", opcode[j]);
}
strcat(buf, hex);
}
printf("break#%d op1=%02X, op2=%02X (len=%d) ... opcode=%s\n", i, op1, op2, opcodeLength, buf);
});
}
}
z80.execute(50);
puts("\n===== remove break point 3 and 7 =====\n");
z80.removeBreakPoint(3);
z80.removeBreakPoint(7);
printf("executed: %dHz\n", z80.execute(50));
printf("total clocks = %ldHz\n", totalClocks);
puts("\n===== remove all break points =====\n");
z80.removeAllBreakPoints();
printf("executed: %dHz\n", z80.execute(50));
printf("total clocks = %ldHz\n", totalClocks);
puts("\n===== remove break operand ED =====\n");
z80.removeBreakOperand(0xED);
printf("executed: %dHz\n", z80.execute(50));
printf("total clocks = %ldHz\n", totalClocks);
puts("\n===== remove all break operands =====\n");
z80.removeAllBreakOperands();
printf("executed: %dHz\n", z80.execute(50));
printf("total clocks = %ldHz\n", totalClocks);
puts("\n===== reset debug message =====\n");
z80.resetDebugMessage();
printf("executed: %dHz\n", z80.execute(50));
printf("total clocks = %ldHz\n", totalClocks);
puts("\n===== reset consume clock callback =====\n");
z80.resetConsumeClockCallback();
printf("executed: %dHz\n", z80.execute(50));
printf("total clocks = %ldHz\n", totalClocks);
return 0;
}
Loading

0 comments on commit 4ea5859

Please sign in to comment.