-
Notifications
You must be signed in to change notification settings - Fork 2
/
FloppyXferIO.py
161 lines (161 loc) · 4.84 KB
/
FloppyXferIO.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import struct
class FloppyXferIO(object):
FX_NOP = 0x00
FX_EXIT = 0xff
FX_SETBUFFER = 0x01
FX_SETLENGTH = 0x02
FX_SETIOREQ = 0x03
FX_SETTRACK = 0x04
FX_SETUSR = 0x05
FX_SENDBUFFER = 0x20
FX_RECVBUFFER = 0x21
FX_CALLUSR = 0x25
FX_TRACKREAD = 0x30
FX_TRACKFORMAT = 0x31
FX_TRACKSEEK = 0x32
FX_MOTOROFF = 0x40
TDERR_NotSpecified = 20
TDERR_NoSecHdr = 21
TDERR_BadSecPreamble = 22
TDERR_BadSecID = 23
TDERR_BadHdrSum = 24
TDERR_BadSecSum = 25
TDERR_TooFewSecs = 26
TDERR_BadSecHdr = 27
TDERR_WriteProt = 28
TDERR_DiskChanged = 29
TDERR_SeekError = 30
TDERR_NoMem = 31
TDERR_BadUnitNum = 32
TDERR_BadDriveType = 33
TDERR_DriveInUse = 34
TDERR_PostReset = 35
def __init__(self, snip):
self.snip = snip
self.floppyxfer = self.snip.getaddrfile("asm/floppyxfer.o")
if not self.floppyxfer:
raise BufferError()
self.serial = self.snip.serial
ser = self.serial
serper = self.snip.serper | (self.snip.amiga.serper << 16)
self.snip.amiga.callargs(addr=self.floppyxfer, d0=serper)
#ser.stopbits = 1
ser.baudrate = self.snip.baudrate
ser.write(b"\0")
ser.flush()
self.sync()
return
def sync(self):
while self.serial.read(1) != b'?':
print("SYNC?!")
pass
return
def exit(self):
self.serial.write(struct.pack(">B", self.FX_EXIT))
self.serial.flush()
self.serial.baudrate = self.snip.amiga.baudrate
self.serial.write(b"F")
self.serial.flush()
self.snip.amiga.sync()
return
def nop(self):
self.serial.write(struct.pack(">B", self.FX_NOP))
self.serial.flush()
self.sync()
return
def sendlong(self, value):
ser = self.serial
value = struct.pack(">I", value)
while ser.read(1) != b'H':
pass
ser.write(struct.pack(">B", value[0]))
ser.flush()
while ser.read(1) != b'h':
pass
ser.write(struct.pack(">B", value[1]))
ser.flush()
while ser.read(1) != b'L':
pass
ser.write(struct.pack(">B", value[2]))
ser.flush()
while ser.read(1) != b'l':
pass
ser.write(struct.pack(">B", value[3]))
ser.flush()
return
def setbuffer(self, bufaddr):
self.serial.write(struct.pack(">B", self.FX_SETBUFFER))
self.serial.flush()
self.sendlong(bufaddr)
self.sync()
return
def setlength(self, length):
self.serial.write(struct.pack(">B", self.FX_SETLENGTH))
self.serial.flush()
self.sendlong(length)
self.sync()
self.length = length
return
def setioreq(self, ioreq):
self.serial.write(struct.pack(">B", self.FX_SETIOREQ))
self.serial.flush()
self.sendlong(ioreq)
self.sync()
return
def setusr(self, usr):
self.serial.write(struct.pack(">B", self.FX_SETUSR))
self.serial.flush()
self.sendlong(usr)
self.sync()
return
def settrack(self, track):
self.serial.write(struct.pack(">B", self.FX_SETTRACK))
self.serial.flush()
self.sendlong(track)
self.sync()
return
def callusr(self):
self.serial.write(struct.pack(">B", self.FX_CALLUSR))
self.serial.flush()
result = struct.unpack(">I",self.serial.read(4))[0]
self.sync()
return result
def sendbuffer(self, buf):
self.serial.write(struct.pack(">B", self.FX_RECVBUFFER))
self.serial.flush()
while self.serial.read(1) != b'S':
pass
self.serial.write(buf)
self.serial.flush()
self.sync()
return
def recvbuffer(self):
self.serial.write(struct.pack(">B", self.FX_SENDBUFFER))
self.serial.flush()
data = self.serial.read(self.length)
self.sync()
return data
def trackread(self):
self.serial.write(struct.pack(">B", self.FX_TRACKREAD))
self.serial.flush()
ioerr = struct.unpack(">B", self.serial.read(1))[0]
self.sync()
return ioerr
def trackformat(self):
self.serial.write(struct.pack(">B", self.FX_TRACKFORMAT))
self.serial.flush()
ioerr = struct.unpack(">B", self.serial.read(1))[0]
self.sync()
return ioerr
def motoroff(self):
self.serial.write(struct.pack(">B", self.FX_MOTOROFF))
self.serial.flush()
ioerr = struct.unpack(">B", self.serial.read(1))[0]
self.sync()
return ioerr
def seek(self):
self.serial.write(struct.pack(">B", self.FX_TRACKSEEK))
self.serial.flush()
ioerr = struct.unpack(">B", self.serial.read(1))[0]
self.sync()
return ioerr