Skip to content

Commit 2034902

Browse files
authored
Merge pull request #29 from cormacj/error-handling
Error handling
2 parents 59c3053 + d7b56b0 commit 2034902

File tree

2 files changed

+18
-63
lines changed

2 files changed

+18
-63
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +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.
4+
2025-06-13: Bump to v0.85 - Add the ability to define user-defined labels to the labels file. Increased error handling, more informational messages.

z80-disassembler.py

Lines changed: 17 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ def to_number(n):
450450
return int('0x' + n, 0)
451451
except Exception:
452452
return float(n)
453+
finally:
454+
print("\n\nError occured. Invalid number: ",n)
455+
exit(1)
453456

454457
def parse_arguments():
455458
"""
@@ -1188,18 +1191,22 @@ def findstring(memstart, memend):
11881191
# dump_code_array()
11891192

11901193
print("\nPass 4: Validate labels")
1194+
"""
1195+
This pass is functionally the same as for pass 5, mostly to build the final labels.
1196+
No code is output.
1197+
"""
11911198
code_snapshot = bytearray(8)
11921199
loc = 0
11931200

11941201
# dump_code_array()
1195-
11961202
if args.templatefile is not None:
1203+
print(f"Loading template file: {args.templatefile}...",end="")
11971204
process_template(args.templatefile)
1205+
print(" Done!",end="")
1206+
if args.quiet:
1207+
print("\n")
11981208

11991209

1200-
# This is nearly the final assembly.
1201-
# In this pass I'm building the final labels but not outputting code
1202-
# dump_code_array()
12031210
program_counter=min(code)
12041211
print_progress_bar(program_counter-code_org, endaddress, prefix=' Progress:', suffix='Complete', length=50)
12051212

@@ -1275,23 +1282,12 @@ def findstring(memstart, memend):
12751282
data_addr = handle_data(b)
12761283
if data_addr is None: # So something like LD A,(BC) or LD A,B
12771284
tmp=process_hextype(z80.disasm(b))
1278-
# code_output(
1279-
# program_counter,
1280-
# tmp,
1281-
# list_address,
1282-
# explain.code(z80.disasm(b),explainlevel),
1283-
# add_extra_info(decode_buffer),
1284-
# )
12851285
program_counter += b.len
12861286
else:
12871287
tmp = z80.disasm(b).replace(f'0x{data_addr:04x}',lookup_label(data_addr,1))
12881288
tmp_data_addr = handle_data(b)
12891289
tmp_addr = hex(handle_data(b))
1290-
# mark_handled(tmp_data_addr, 2, "D")
12911290
if is_in_code(tmp_data_addr):
1292-
# if (tmp_data_addr >= code_org) and (
1293-
# tmp_data_addr <= code_org + len(bin_data)
1294-
# ):
12951291
ld_label = lookup_label(handle_data(b))
12961292
# print("---->",hex(program_counter),ld_label,hex(handle_data(b)),code[handle_data(b)][2])
12971293
labelled = tmp.replace(
@@ -1306,54 +1302,8 @@ def findstring(memstart, memend):
13061302
str_for_comment = (
13071303
" - References: " + str_locations[handle_data(b)]
13081304
)
1309-
# if commentlevel==0:
1310-
# code_output(
1311-
# program_counter,
1312-
# labelled,
1313-
# list_address,
1314-
# "", #explain.code(labelled,explainlevel) + " " + str_for_comment,
1315-
# add_extra_info(decode_buffer),
1316-
# )
1317-
# else:
1318-
# code_output(
1319-
# program_counter,
1320-
# labelled,
1321-
# list_address,
1322-
# explain.code(labelled,explainlevel) + " " + str_for_comment,
1323-
# add_extra_info(decode_buffer),
1324-
# )
13251305
program_counter += b.len
13261306

1327-
# data_addr = handle_data(b)
1328-
# if data_addr is None: # So something like LD A,(BC) or LD A,B
1329-
# program_counter += b.len
1330-
# else:
1331-
# tmp = z80.disasm(b)
1332-
# tmp_data_addr = handle_data(b)
1333-
# tmp_addr = hex(handle_data(b))
1334-
# if is_in_code(tmp_data_addr):
1335-
# #We only want to mess with strings, ignore all previous instructions
1336-
# if code[tmp_data_addr][1]=="S" and is_terminator(code[tmp_data_addr][0]):
1337-
# mark_handled(tmp_data_addr, 0, "D")
1338-
# #End of fix
1339-
# if is_in_code(tmp_data_addr):
1340-
# # if (tmp_data_addr >= code_org) and (
1341-
# # tmp_data_addr <= code_org + len(bin_data)
1342-
# # ):
1343-
# # ld_label=f'{identified(handle_data(b))}_{handle_data(b):X}'
1344-
# ld_label = lookup_label(handle_data(b))
1345-
# labelled = tmp.replace(
1346-
# tmp_addr, ld_label
1347-
# ) # Convert inline hex to L_xxxx label
1348-
# else:
1349-
# labelled = tmp
1350-
# str_for_comment = ""
1351-
# if data_addr in labels:
1352-
# if handle_data(b) in str_locations:
1353-
# str_for_comment = (
1354-
# " - References: " + str_locations[handle_data(b)]
1355-
# )
1356-
# program_counter += b.len
13571307
else:
13581308
program_counter += b.len
13591309
else:
@@ -1381,8 +1331,13 @@ def findstring(memstart, memend):
13811331
code[loop][1]="D"
13821332
# Print the used external EQUs (with nice formatting)
13831333
# First find the longest label
1334+
13841335
if args.labelsfile:
1336+
print(f"Loading labels file: {args.labelsfile}... ",end="")
13851337
load_labels(args.labelsfile)
1338+
print("Done!",end="")
1339+
if args.quiet:
1340+
print("\n")
13861341

13871342
maxlen=0
13881343
for loop in extern_labels:
@@ -1814,7 +1769,7 @@ def findstring(memstart, memend):
18141769
print_progress_bar(max(code), max(code),prefix=' Progress:', suffix='Complete', length=50)
18151770
print()
18161771
if args.outfile:
1817-
print(args.outfile," created!")
1772+
print(f"\n{args.outfile} created!")
18181773

18191774
print()
18201775
print("Lines of code:",stats_loc)

0 commit comments

Comments
 (0)