Skip to content

Latest commit

 

History

History
135 lines (101 loc) · 3.55 KB

README.md

File metadata and controls

135 lines (101 loc) · 3.55 KB

Z80test

Z80test is a simple test harness / Z80 emulator to help with testing Z80 machine code snippets, especially functions generated by the Syc C compiler.

Z80test is executed as

$ z80test [-q] -s <script.scr>

Where -q means quiet mode.

The script contains a series of commands, each termineted by a semicolon. Thhe script is free form, the type and amount of white space (spaces, tabs, newlines) does not matter. C-style comments are allowed anywhere where whitespace is allowed.

Here is an example script:

ldbin "test.bin", 0x8000; /* Loads binary file at address 0x8000 */
mapfile "test.map"; /* Loads a symbol table */
ld HL, 1; /* Set register HL to 1 */
ld BC, 2;
call @add2; /* This function adds HL, BC, placing the result into BC */
print BC; /* Print the content of BC register pair */
verify BC, 3; /* Generate an error if BC != 3 */

Here is another example, with memory accesses:

ldbin "test.bin", 0x8000;
mapfile "test.map";
ld word ptr (@a), 1;
ld word ptr (@b), 2;
call @add; /* Add values of vars a and b, storing the result to var. c */
print word ptr (@c); /* Print the value of variable a */
verify word ptr (@c), 3; /* Generate an error if c != 3 */

Note that we need not know the exact addresses of symbols, only their identifiers. The identifiers are mapped to addresses using the symbol table loaded from the map file.

Syntax of individual script commands is described in more detail in the following sections.

Expressions

A valid expression is one of

<decimal-number>
0x<hexadecimal-number>
0X<hexadecimal-number>
AF
BC
DE
HL
@<symbol-name>
@<symbol-name>+<decimal-or-hex-number>
AF+<decimal-or-hex-number>
BC+<decimal-or-hex-number>
DE+<decimal-or-hex-number>
HL+<decimal-or-hex-number>

Register/memory operands

A register/memory operand is one of

AF
BC
DE
HL
byte ptr (<expression>)
word ptr (<expression>)
dword ptr (<expression>)
qword ptr (<expression>)

With the memory operands the byte/word/dword/qword ptr denotes 8-bit/ 16-bit/32-bit/64-bit pointer, respectively, while the value of denotes the address in memory.

Load binary file

Load data from a binary file at the specified address

ldbin "<filename>", <expression>;

Load map file

Load symbol table from a Z80asm-compatible map file

mapfile "<filename>";

Load register/memory

Load a value of the specified expression into register or into memory

ld <register/memory>, <expression>;

Or, load value from register/memory (right operand) and store it into register or memory (left operand)

ld <register/memory>, <register/memory>;

Print register/memory

Print the contents of register or memory

print <register/memory>;

Verify register/memory

Verify that the value of register or memory is equal to the specified value. If not, generate an error.

verify <register/memory>, <expression>;

Call function

Call function at the specified address. Stop once SP is >= the point where the return address would be on the stack. If the function takes too long to execute (the preset CPU cycle limit is exceeded), an error is generated and the test is aborted.

call <expression>;

Push to stack

Push result of the specified expression to the stack as a 16-bit number.

push <expression>;

Pop from stack

Pop the topmost 16-bit entry from the stack.

pop;