Skip to content

Commit 8b032bc

Browse files
committed
Add the ability to add code labels to the template
1 parent eb94ad5 commit 8b032bc

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

z80-disassembler.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,17 @@ 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+
# print("Lookup:",lookup_label(addr))
331+
elif lname[0]!=";":
327332
extern_labels[addr].append(lname)
328333
extern_labels[addr].append(0)
334+
# print(hex(addr),is_in_code(addr))
329335
except OSError:
330336
print("Error: Could not open labels file:", filename)
331337
sys.exit(1)
@@ -625,8 +631,8 @@ def validate_arguments(argslist):
625631
explainlevel=to_number(args.explainlevel)
626632
stay_in_code=args.stay_in_code
627633

628-
if args.labelsfile:
629-
load_labels(args.labelsfile)
634+
# if args.labelsfile:
635+
# load_labels(args.labelsfile)
630636

631637
if args.assembler=="z80asm":
632638
args.labeltype=2
@@ -801,6 +807,8 @@ def lookup_label(addr, prettyprint=""):
801807
Returns:
802808
Formatted String
803809
"""
810+
# if addr==0xccd1:
811+
# print(code[addr])
804812
if not is_in_code(addr):
805813
debug("-->Not in code")
806814
if addr in extern_labels:
@@ -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')
@@ -1713,6 +1725,7 @@ def findstring(memstart, memend):
17131725
this_opcode = b.op.name
17141726
if len(z80.disasm(b).split(",")) > 1: # conditional jumps and calls
17151727
this_opcode = z80.disasm(b).split(",")[0] + ","
1728+
# print("jp:",hex(jump_addr),lookup_label(jump_addr))
17161729
tmp = f"{this_opcode} " + lookup_label(jump_addr)
17171730
code_output(
17181731
program_counter,

0 commit comments

Comments
 (0)