Skip to content

Commit

Permalink
added support for write, not thoroughly tested
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenjc committed Nov 14, 2024
1 parent 1f67281 commit f5e2208
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
33 changes: 28 additions & 5 deletions src/devices/disk.py
Original file line number Diff line number Diff line change
@@ -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, ...)
Expand All @@ -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))

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions src/devices/z80io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 6 additions & 5 deletions src/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand All @@ -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"))
Expand Down
4 changes: 3 additions & 1 deletion src/filesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


#
Expand Down
30 changes: 30 additions & 0 deletions src/utils/misc.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f5e2208

Please sign in to comment.