Skip to content

Commit 59c3053

Browse files
authored
Merge pull request #28 from cormacj/template-work
Updates for user-defined labels
2 parents 25dc106 + eb85033 commit 59c3053

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
2025-03-07: (0.75)
22
2025-03-05: First official release (0.75)
33
2025-03-21: Bump to v0.80 - Add support for external labels, such as BIOS calls. Improved code detection methods.
4+
2025-06-13: Bump to v0.85 - Add the ability to define user-defined labels to the labels file.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ This is used by adding `--labels LABELSFILE` to the command line.
202202

203203
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.
204204

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-
205+
You can also add custom code labels in this file, such as those for RSX jump points.
207206

208207
This is defined as follows:
209208

z80-disassembler.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Pointer(NamedTuple):
9090
str_sizes = {}
9191
style = "asm"
9292
hexstyle = "0x"
93-
myversion = "0.80"
93+
myversion = "0.85"
9494

9595

9696
#--- Debugging functions ---
@@ -321,11 +321,19 @@ def load_labels(filename):
321321
if len(parsed)==3:
322322
lname=parsed[0]
323323
addr=to_number(parsed[2])
324-
# [0] = labelname
325-
# [1] = number of times it's called
326-
if lname[0]!=";":
324+
# print(lname,hex(addr))
325+
# print("code=",hex(min(code)),hex(max(code)))
326+
if lname[0]!=";" and is_in_code(addr):
327+
# print("in code",hex(addr))
328+
# update_label_name(addr,"C")
329+
code[addr][2]=lname
330+
code[addr][3]=lname #Overwrite string defs
331+
template_labels[addr]=lname #and template label
332+
# print("Lookup:",lookup_label(addr))
333+
elif lname[0]!=";":
327334
extern_labels[addr].append(lname)
328335
extern_labels[addr].append(0)
336+
# print(hex(addr),is_in_code(addr))
329337
except OSError:
330338
print("Error: Could not open labels file:", filename)
331339
sys.exit(1)
@@ -625,8 +633,8 @@ def validate_arguments(argslist):
625633
explainlevel=to_number(args.explainlevel)
626634
stay_in_code=args.stay_in_code
627635

628-
if args.labelsfile:
629-
load_labels(args.labelsfile)
636+
# if args.labelsfile:
637+
# load_labels(args.labelsfile)
630638

631639
if args.assembler=="z80asm":
632640
args.labeltype=2
@@ -1146,6 +1154,7 @@ def findstring(memstart, memend):
11461154
end = endaddress
11471155
findstring(start, end)
11481156

1157+
11491158
# dump_code_array("Post pass 2",0xd8dc)
11501159
# for data_area in id_sort:
11511160
# print(hex(data_area))
@@ -1372,6 +1381,9 @@ def findstring(memstart, memend):
13721381
code[loop][1]="D"
13731382
# Print the used external EQUs (with nice formatting)
13741383
# First find the longest label
1384+
if args.labelsfile:
1385+
load_labels(args.labelsfile)
1386+
13751387
maxlen=0
13761388
for loop in extern_labels:
13771389
debug(f'{extern_labels[loop][0]} called {extern_labels[loop][1]} times')
@@ -1409,11 +1421,11 @@ def findstring(memstart, memend):
14091421
if (program_counter in template_labels):
14101422
labelname=template_labels[program_counter]
14111423
# if labelname[0]=="0":
1412-
# print("1 used")
1424+
# print("1 used")
14131425
else:
14141426
labelname=lookup_label(program_counter,1)
14151427
# if labelname[0]=="0":
1416-
# print("2 used")
1428+
# print("2 used")
14171429

14181430
if code[program_counter][1]=="C":
14191431
stats_c_labels=stats_c_labels+1
@@ -1435,6 +1447,7 @@ def findstring(memstart, memend):
14351447
for tmp in labels[program_counter]:
14361448
tmp_str=tmp_str+f'{hexstyle}{tmp:X} '
14371449
do_write(tmp_str)
1450+
14381451
else:
14391452
do_write(
14401453
";----------------------------------------------------------------------------"
@@ -1713,6 +1726,7 @@ def findstring(memstart, memend):
17131726
this_opcode = b.op.name
17141727
if len(z80.disasm(b).split(",")) > 1: # conditional jumps and calls
17151728
this_opcode = z80.disasm(b).split(",")[0] + ","
1729+
# print("jp:",hex(jump_addr),lookup_label(jump_addr))
17161730
tmp = f"{this_opcode} " + lookup_label(jump_addr)
17171731
code_output(
17181732
program_counter,

0 commit comments

Comments
 (0)