diff --git a/src/devices/disk.py b/src/devices/disk.py index f24adc7..fa0db18 100644 --- a/src/devices/disk.py +++ b/src/devices/disk.py @@ -1,4 +1,5 @@ import sys +import utils.misc as misc # System can have multple Disks (Floppy, Harddisks) # Disks can have multiple Drives (0, 1, ...) @@ -10,6 +11,7 @@ def __init__(self, type, drives): self.selected_drive = -1 self.numdrives = len(drives) self.drives = [] + self.write_ena = False for i, fs in enumerate(drives): self.drives.append(Drive(i, fs)) @@ -43,13 +45,13 @@ def select_drive(self, i): assert self.selected_drive in [1, 2, 3, 4, 5, 6, 7] + # bad name, also used in Drive def readbyte(self): return self.drive.readbyte() - - def write(self, byte): - print('write not supported') - sys.exit() + # bad name, also used in Drive + def writebyte(self, byte): + self.drive.writebyte(byte) def step(self, stepdir): @@ -93,6 +95,10 @@ def __init__(self, driveno, fs): # self.current_byte = 0 + def dump(self, track): + misc.hexdump(self.data[track], 32, 511) + + def istrack0(self): return self.current_track == 0 @@ -126,6 +132,17 @@ def readbyte(self): return self.data[track][byte] + def writebyte(self, value): + track = self.current_track + byte = self.current_byte - 3 # TODO don't understand this offset + d = self.data[track][byte] + + assert 0 <= track < self.tracks + assert 0 <= byte < self.bytes_per_track, byte + self.data[track][byte] = value + self.current_byte = (self.current_byte + 1) % self.bytes_per_track + + def gettrackno(self): return self.current_track @@ -166,6 +183,10 @@ def data_in(self) -> int: return val + def data_out(self, value): + self.disk.writebyte(value) + + def control1(self, val): drive = val & 0x7f side = val >> 7 @@ -189,7 +210,9 @@ def control2(self, val): if val & 0x20: # Step self.disk.step(stepdir) if val & 0x80: - self.disk.write() + self.disk.write_ena = True + else: + self.disk.write_ena = False def status(self): diff --git a/src/devices/z80io.py b/src/devices/z80io.py index f265388..d5f0219 100644 --- a/src/devices/z80io.py +++ b/src/devices/z80io.py @@ -222,6 +222,7 @@ def handle_disk_out_0b(self, val): def handle_disk_out_09(self, val): self.print(f'IO out - floppy (data) - (0x{val:02x})') + self.floppy.data_out(val) def handle_disk_in_0a(self): diff --git a/src/emulator.py b/src/emulator.py index a572b80..181bfb1 100644 --- a/src/emulator.py +++ b/src/emulator.py @@ -74,7 +74,7 @@ def kbd_input(self): kc = self.kc if self.key.kbhit(): ch = ord(self.key.getch()) - # if 32 <= ch < 127: + # if misc.isprintable(ch): # print(f'{chr(ch)}') # else: # print(f'{ch}') @@ -87,10 +87,11 @@ def kbd_input(self): self.int38(kc.okey(k)) elif ch == 8224: # opt-t args.decode = not args.decode - elif ch == 170: # opt-a FDs - self.ros.index() - self.ros.file() - self.ros.disk() + elif ch == 170: # opt-a misc debug FDs, floppy dump + self.io.floppy.disk.drives[1].dump(0) + # self.ros.index() + # self.ros.file() + # self.ros.disk() # Q1 Keyboard input below elif ch == kc.ikey("HEX"): self.int38(kc.okey("HEX")) diff --git a/src/filesys.py b/src/filesys.py index 0007d0f..0427f75 100644 --- a/src/filesys.py +++ b/src/filesys.py @@ -107,7 +107,9 @@ def rawrecord(self, track, offset, data): i = len(data) d[offset + i + 0] = cksum d[offset + i + 1] = 0x10 - return offset + i + 2 + d[offset + i + 2] = 0x00 # needed by write + d[offset + i + 3] = 0x00 # needed by write + return offset + i + 4 # diff --git a/src/utils/misc.py b/src/utils/misc.py new file mode 100644 index 0000000..e5ee164 --- /dev/null +++ b/src/utils/misc.py @@ -0,0 +1,30 @@ + + + +def isprintable(value : int): + return 32 <= value < 127 + + +def ascii(value : int): + if isprintable(value): + return chr(value) + return '.' + + +def hexdump(lst, width, maxbytes): + hexdp = '0000: ' + ascii = '' + l = 0 + for i, d in enumerate(lst): + if i > maxbytes: + break + hexdp += f'{d:02x} ' + ascii += chr(d) if 32 <= d < 127 else '.' + l += 1 + if l == width: + print(hexdp, ascii) + hexdp = f'{i+1:04x}: ' + ascii = '' + l = 0 + if len(ascii) != width: + print(hexdp, ascii)