Allow for no checksum in END block of an LDA file

This commit is contained in:
Neil Webber 2024-05-08 17:58:38 -05:00
parent 53d7c5d7ab
commit 625c5ce1cc

14
boot.py
View file

@ -172,17 +172,14 @@ def boot_bin(p, fname, /, *, addr=0, deposit_only=False,
def _must_read_n(f, n, zeroskip=False): def _must_read_n(f, n, zeroskip=False):
"""read exactly n bytes from f; raise exception if can't. n==0 allowed. """read exactly n (>0) bytes from f; raise exception if can't.
If zeroskip is True (default: False), zero bytes will be discarded. If zeroskip is True (default: False), zero bytes will be discarded.
It is not legal to zeroskip with n == 0.
""" """
if n == 0:
if zeroskip and n == 0: raise ValueError("n == 0 is not allowed")
raise ValueError("zeroskip and n == 0")
b = bytes() b = bytes()
if n > 0:
while zeroskip and (b := f.read(1)) == b'\00': while zeroskip and (b := f.read(1)) == b'\00':
pass pass
@ -270,9 +267,12 @@ def get_lda_block(f):
if count < 6: if count < 6:
raise ValueError(f"header error, {count=}") raise ValueError(f"header error, {count=}")
elif count == 6:
# an "END" block, which has no checksum.
return addr, bytes()
# count > 6
b = _must_read_n(f, count-6) b = _must_read_n(f, count-6)
chksum = _must_read_n(f, 1) chksum = _must_read_n(f, 1)
if (sum(header) + sum(b) + sum(chksum)) & 0xFF: if (sum(header) + sum(b) + sum(chksum)) & 0xFF:
raise ValueError(f"checksum mismatch, {header=}") raise ValueError(f"checksum mismatch, {header=}")