Skip to content

Commit cb2d6d5

Browse files
authored
Merge pull request #26 from cormacj/template-work
bump version update the readme, bugfixes and improvements
2 parents 013f5ae + 6319cb3 commit cb2d6d5

File tree

5 files changed

+228
-40
lines changed

5 files changed

+228
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
2025-03-07: (0.75)
12
2025-03-05: First official release (0.75)
3+
2025-03-21: Bump to v0.80 - Add support for external labels, such as BIOS calls. Improved code detection methods.

README.md

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ I wanted something similar for Z80 code and this project aims to do this.
2525
# Usage
2626

2727
```
28-
z80-disassembler.py - v0.75 - A Smart Z80 reverse assembler
28+
29+
z80-disassembler.py - v0.80 - A Smart Z80 reverse assembler
2930
Visit https://github.com/cormacj/z80-smart-disassembler for updates and to report issues
3031
31-
usage: z80-disassembler.py [-h] [-q] [-o OUTFILE] [-t TEMPLATEFILE] [-s STRINGTERMINATOR] [-a {pyradev,z80asm,maxam,z88}] [--style {lst,asm}] [-l LOADADDRESS] [-e ENDADDRESS]
32-
[--xref {off,on}] [--stayincode] [--labeltype {2,1}] [-c {2,1,0}] [--explain {2,1,0}]
32+
usage: z80-disassembler.py [-h] [-q] [-o OUTFILE] [-t TEMPLATEFILE] [--labels LABELS] [-s STRINGTERMINATOR] [-a {maxam,z88,z80asm,pyradev}] [--style {lst,asm}] [-l LOADADDRESS]
33+
[-e ENDADDRESS] [--xref {off,on}] [--stayincode] [--labeltype {1,2}] [-c {0,1,2}] [--explain {0,1,2}]
3334
filename
3435
3536
A Smart Z80 reverse assembler
@@ -50,16 +51,19 @@ Recommended arguments, but optional:
5051
5152
Formatting options:
5253
-t TEMPLATEFILE Use a template file. This helps decode strings and allows for fine tuning disassembly. See README.md for more details
53-
-s STRINGTERMINATOR string terminator value - defaults are [0, 13, 141] and printable characters+0x80. You can supply a number, or a single character. You can repeat this as many times as needed.
54-
-a {pyradev,z80asm,maxam,z88}, --assembler {pyradev,z80asm,maxam,z88}
54+
--labels LABELSFILE Use a label file. This file provides user-defined labels that may be external to the program. See README.md for more details
55+
-s STRINGTERMINATOR string terminator value - defaults are [0, 13, 141] and printable characters+0x80. You can supply a number, or a single character. You can repeat this as many times
56+
as needed.
57+
-a {maxam,z88,z80asm,pyradev}, --assembler {maxam,z88,z80asm,pyradev}
5558
Format the code for particular assemblers. The default is z88.
5659
--style {lst,asm} asm produces a file that can be assembled. lst is a dump style output. The default is asm style.
5760
--xref {off,on} Enable or disable cross references for labels
5861
--stayincode Don't try to decode data after a RET/JP
59-
--labeltype {2,1} 1: Uses short name eg D_A123 or C_A345 2: Uses full names, eg data_A123 or code_A123
60-
-c {2,1,0}, --comments {2,1,0}
62+
--labeltype {1,2} 1: Uses short label names eg D_A123 or C_A345 2: Uses descriptive label names, eg data_A123 or code_A123
63+
-c {0,1,2}, --comments {0,1,2}
6164
0: No comments 1: Address 2: (Default) Address+hex and ascii dump
62-
--explain {2,1,0} 0: (Default) No code explanations 1: Data references only 2: Everything
65+
--explain {0,1,2} 0: (Default) No code explanations 1: Data references only 2: Everything
66+
6367
```
6468

6569
# Decoding options
@@ -109,7 +113,7 @@ Maxam uses hex addresses in the format `&12cd`
109113

110114
z88 and z80asm use number style `0x12cd`
111115

112-
z80asm implies that labeltype is 2 which uses longer labelnames (eg `code_12CD`)
116+
z80asm implies that labeltype is 2 which uses longer labelnames (eg `code_12CD`). This is because z80asm has issues with shorter variable names.
113117

114118
---
115119

@@ -192,6 +196,33 @@ CALL 0xbb5a ;0x121: cd 5a bb ".Z."
192196
LD A,0x2e ;0x11f: 3e 2e ">." Load A with 0x2e
193197
CALL 0xbb5a ;0x121: cd 5a bb ".Z." The current PC value plus three is pushed onto the stack, then PC is loaded with 0xbb5a.
194198
```
199+
# Label file
200+
201+
This is used by adding `--labels LABELSFILE` to the command line.
202+
203+
A label file allows external calls, such as BIOS entry points, to be defined and used in disassembled code. I've included `amstrad-labels.txt` in this repository as an example and for convenience.
204+
205+
The disassembler tracks what labels have been used during disassembly and will only add the labels that were used to the final disassembly.
206+
207+
208+
This is defined as follows:
209+
210+
```
211+
;A list of Amstrad CPC BIOS calls.
212+
;Recorded here for use with the disassembler
213+
214+
KL_ROM_SELECT equ 0xb90f
215+
KL_CURR_SELECTION equ 0xb912
216+
KL_PROBE_ROM equ 0xb915
217+
KL_ROM_DESELECT equ 0xb918
218+
```
219+
220+
Comments start with ';'
221+
222+
Blank lines are ignored.
223+
224+
Labels should be structed as `Labelname equ 0x0000`
225+
195226

196227
# Templates
197228

@@ -254,12 +285,17 @@ The disassembler will try to automatically identify strings in the code, but it
254285

255286
# Example usage
256287

288+
This command disassembles the RODOS219.ROM file and stores the output in rodos.asm
289+
257290
```
258-
$ ./z80-disassembler.py RODOS219.ROM -l 0xc000 --style lst --xref on -o rodos-listing.lst
291+
$ ./z80-disassembler.py RODOS219.ROM -t amstrad_rom_template.txt -o rodos.asm -l 0xc000 -a z80asm --labels amstrad-labels.txt
292+
293+
z80-disassembler.py - v0.80 - A Smart Z80 reverse assembler
294+
Visit https://github.com/cormacj/z80-smart-disassembler for updates and to report issues
259295
260-
./z80-disassembler.py v0.75 - A Smart Z80 reverse assembler
296+
Writing code to rodos.asm
261297
262-
Writing code to rodos-listing.lst
298+
Disassembling RODOS219.ROM: 16384 bytes
263299
264300
Loading code: |██████████████████████████████████████████████████| 100.0% Complete
265301
@@ -273,13 +309,13 @@ Pass 4: Validate labels
273309
Progress: |██████████████████████████████████████████████████| 100.0% Complete
274310
Pass 5: Produce final listing
275311
Progress: |██████████████████████████████████████████████████| 100.0% Complete
312+
rodos.asm created!
276313
277-
rodos-listing.lst created!
278-
279-
Lines of code: 10181
280-
Code Labels: 735
281-
Data Labels: 54
314+
Lines of code: 9238
315+
Code Labels: 734
316+
Data Labels: 57
282317
```
318+
283319
# Example Results
284320

285321
I wrote a simple "hello world" file and compiled it on an Amstrad.

amstrad-labels.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
;A list of Amstrad CPC BIOS calls.
2+
;Recorded here for use with the disassembler
3+
4+
KL_ROM_SELECT equ 0xb90f
5+
KL_CURR_SELECTION equ 0xb912
6+
KL_PROBE_ROM equ 0xb915
7+
KL_ROM_DESELECT equ 0xb918
8+
KL_LDIR equ 0xb91b
9+
KM_WAIT_CHAR equ 0xbb06
10+
KM_READ_CHAR equ 0xbb09
11+
KM_SET_EXPAND equ 0xbb0f
12+
KM_WAIT_KEY equ 0xbb18
13+
KM_TEST_KEY equ 0xbb1e
14+
KM_SET_SHIFT equ 0xbb2d
15+
KM_BREAK_EVENT equ 0xbb4b
16+
TXT_OUTPUT equ 0xbb5a
17+
TXT_RD_CHAR equ 0xbb60
18+
TXT_GET_WINDOW equ 0xbb69
19+
TXT_SET_CURSOR equ 0xbb75
20+
TXT_GET_CURSOR equ 0xbb78
21+
SCR_GET_MODE equ 0xbc11
22+
CAS_NOISY equ 0xbc6b
23+
CAS_START_MOTOR equ 0xbc6e
24+
CAS_STOP_MOTOR equ 0xbc71
25+
CAS_IN_OPEN equ 0xbc77
26+
CAS_IN_CLOSE equ 0xbc7a
27+
CAS_IN_ABANDON equ 0xbc7d
28+
CAS_IN_CHAR equ 0xbc80
29+
CAS_IN_DIRECT equ 0xbc83
30+
CAS_OUT_OPEN equ 0xbc8c
31+
CAS_OUT_CLOSE equ 0xbc8f
32+
CAS_OUT_ABANDON equ 0xbc92
33+
CAS_OUT_CHAR equ 0xbc95
34+
CAS_OUT_DIRECT equ 0xbc98
35+
CAS_CATALOG equ 0xbc9b
36+
KL_CHOKE_OFF equ 0xbcc8
37+
KL_ROM_WALK equ 0xbccb
38+
KL_INIT_BACK equ 0xbcce
39+
KL_LOG_EXT equ 0xbcd1
40+
KL_FIND_COMMAND equ 0xbcd4
41+
KL_ADD_FRAME_FLY equ 0xbcda
42+
KL_DEL_TICKER equ 0xbcec
43+
KL_INIT_EVENT equ 0xbcef
44+
MC_START_PROGRAM equ 0xbd16
45+
MC_PRINT_CHAR equ 0xbd2b
46+
MC_BUSY_PRINTER equ 0xbd2e
47+
MC_SEND_PRINTER equ 0xbd31
48+
JUMP_RESTORE equ 0xbd37

amstrad_rom_template.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
;
1414
; This is an example template for an Amstrad RODOS rom.
1515
;
16+
1617
; Standard start of rom things
1718
0xc000,0xc000,b,ROM_TYPE
1819
0xc001,0xc001,b,ROM_MAJOR
1920
0xc002,0xc002,b,ROM_MARK
2021
0xc003,0xc003,b,ROM_MOD
21-
0xc3e6,0xc3e6,w,EXEC_RSX_CMD
2222

2323
;Now tag the pointer to the command names table
2424
0xc004,0xc004,p,CMD_TABLE_PTR

0 commit comments

Comments
 (0)