From bc67b65de2ec972f80a365ba35982b54e17e38c3 Mon Sep 17 00:00:00 2001 From: Neil Webber Date: Thu, 7 Sep 2023 19:05:13 -0500 Subject: [PATCH] Add boot_file --- boot.py | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/boot.py b/boot.py index e615aa1..726da58 100644 --- a/boot.py +++ b/boot.py @@ -1,4 +1,7 @@ -def boot_hp(p, addr=0o10000): + +def boot_hp(p, /, *, addr=0o10000): + """Read the first 1KB of drive 0 into location 'addr'.""" + # this is the sort of thing that would be keyed in from # the console switches (if the machine was not equipped # with a boot rom option to hold it instead) @@ -8,7 +11,7 @@ def boot_hp(p, addr=0o10000): # at zero is done elsewhere. # # NOTE WELL: THIS ASSUMES THE MACHINE IS IN RESET CONDITION WHICH - # MEANS MANY OF THE DEVICE REGISTERS ARE KNOWN TO BE ZERO + # MEANS MANY OF THE DEVICE REGISTERS ARE ASSUMED TO BE ZERO # # MOV #176704,R0 -- note how used # MOV #177000,-(R0) -- word count - read 1K though boot really 512 @@ -29,6 +32,42 @@ def boot_hp(p, addr=0o10000): return addr +def boot_file(p, fname, /, *, addr=0, little_endian=True, skipwords=8): + """Read a raw binary image of pdp11 data into location 'addr'.""" + + with open(fname, 'rb') as f: + bb = f.read() + + # Two data format cases: + # 1) little_endian (the default) + # + # The file is truly a binary image of pdp11 format data + # and the words (pairs of bytes) in bb are in little endian + # order. They will be assembled accordingly and the names + # "low" and "hi" make sense. + # + # 2) not little_endian + # + # Presumably the file has been byte-swapped already and + # the words (pairs of bytes) in it are in big endian order. + # They will be assembled accordingly, but the names "low" + # and "hi" are backwards. + # + + xi = iter(bb) + words = [] + for low in xi: + hi = next(xi) + if little_endian: + words.append((hi << 8) | low) + else: + words.append((low << 8) | hi) # see case 2) above + + for a, w in enumerate(words[skipwords:]): + p.physmem[a] = w + return p + + if __name__ == "__main__": import time from machine import PDP1170