Repository navigation
Expand file tree
/
Copy pathmydriver.a
More file actions
325 lines (266 loc) · 7.98 KB
/
Copy pathmydriver.a
File metadata and controls
325 lines (266 loc) · 7.98 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
; mydriver.a
;
; Copyright (C) 2020 Paul C. Pratt, Jesus A. Alvarez
;
; You can redistribute this file and/or modify it under the terms
; of version 2 of the GNU General Public License as published by
; the Free Software Foundation. You should have received a copy
; of the license along with this file; see the file COPYING.
;
; This file is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; license for more details.
; most of this is adapted from sample source code from Apple.
FakeSonyDriver MAIN EXPORT
BLANKS ON
STRING ASIS
kqLink EQU 0
kqType EQU 4
kioTrap EQU 6
kioCmdAddr EQU 8
kioCompletion EQU 12
kioResult EQU 16
kioNamePtr EQU 18
kioVRefNum EQU 22
kioRefNum EQU 24
kcsCode EQU 26
kcsParam EQU 28
kioBuffer EQU 32 ; Buffer to store data into
kioReqCount EQU 36 ; Requested Number of Bytes
kioActCount EQU 40 ; Actual Number of Bytes obtained
kioPosMode EQU 44 ; Positioning Mode
kioPosOffset EQU 46 ; Position Offset
killCode EQU 1 ; KillIO requested
noQueueBit EQU 9 ; trap word modifier
JIODone EQU $08FC
kCmndSonyPrime EQU $0001
kCmndSonyControl EQU $0002
kCmndSonyStatus EQU $0003
kCmndSonyClose EQU $0004
kCmndSonyOpenA EQU $0005
kCmndSonyOpenB EQU $0006
kCmndSonyOpenC EQU $0007
kCmndSonyMount EQU $0008
DHeader
DFlags DC.W $4F00 ; need lock, responds to all requests
DDelay DC.W 0 ; none
DEMask DC.W 0 ; DA event mask
DMenu DC.W 0 ; no menu
DC.W DOpen - DHeader ; offset to Open
DC.W DPrime - DHeader ; offset to Prime
DC.W DControl - DHeader ; offset to Control
DC.W DStatus - DHeader ; offset to Status
DC.W DClose - DHeader ; offset to Close
Name DC.B 5 ; length of name
DC.B '.Sony'
ALIGN 2 ; word alignment
DPrime
MOVEM.L A0-A1, -(SP) ; push ParmBlkPtr, DCtlPtr for C
SUBQ #2, A7 ; result code
MOVE.W #kCmndSonyPrime, -(A7)
BRA.B DPrimeStatusCommon
DControl
MOVEM.L A0-A1, -(SP) ; push ParmBlkPtr, DCtlPtr for C
SUBQ #2, A7 ; result code
MOVE.W #kCmndSonyControl, -(A7)
LEA TailData, A0
MOVE.L (A0)+, -(A7)
MOVEA.L (A0), A0
MOVE.L A7, (A0)
ADDA.W #6, A7
MOVE.W (A7)+, D0 ; save result code
MOVEM.L (SP)+, A0-A1 ; restore ParmBlkPtr, DCtlPtr
CMPI.W #killCode,kcsCode(A0) ; test for KillIO call (special case)
BNE.B IOReturn
RTS ; KillIO must always return via RTS
DStatus
MOVEM.L A0-A1, -(SP) ; push ParmBlkPtr, DCtlPtr for C
SUBQ #2, A7 ; result code
MOVE.W #kCmndSonyStatus, -(A7)
DPrimeStatusCommon
LEA TailData, A0
MOVE.L (A0)+, -(A7)
MOVEA.L (A0), A0
MOVE.L A7, (A0)
ADDA.W #6, A7
MOVE.W (A7)+, D0 ; save result code
MOVEM.L (SP)+, A0-A1 ; restore ParmBlkPtr, DCtlPtr
IOReturn
MOVE.W kioTrap(A0),D1
BTST #noQueueBit,D1 ; immediate calls are not queued, and must RTS
BEQ.B @Queued ; branch if queued
@NotQueued
TST.W D0 ; test asynchronous return result
BLE.B @ImmedRTS ; result must be <= 0
CLR.W D0 ; "in progress" result (> 0) not passed back
@ImmedRTS
MOVE.W D0,kioResult(A0) ; for immediate calls you must explicitly
; place the result in the ioResult field
RTS
@Queued
TST.W D0 ; test asynchronous return result
BLE.B @MyIODone ; I/O is complete if result <= 0
CLR.W D0 ; "in progress" result (> 0) not passed back
RTS
@MyIODone
MOVE.L JIODone,-(SP) ; push IODone jump vector onto stack
RTS
DClose
MOVEM.L A0-A1, -(SP) ; push ParmBlkPtr, DCtlPtr for C
SUBQ #2, A7 ; result code
MOVE.W #kCmndSonyClose, -(A7)
LEA TailData, A0
MOVE.L (A0)+, -(A7)
MOVEA.L (A0), A0
MOVE.L A7, (A0)
ADDA.W #6, A7
MOVE.W (A7)+, D0 ; save result code
MOVEM.L (SP)+, A0-A1 ; restore ParmBlkPtr, DCtlPtr
RTS
DUpdate
MOVEM.L D0-D2/A0-A1,-(SP)
MOVE.L 20(A7),D0 ; data = what was on top of stack before 5 registers pushed
SUBQ #4, A7 ; room for eventMsg
MOVE.L D0,-(A7) ; data
SUBQ #2, A7 ; room for result code
MOVE.W #kCmndSonyMount, -(A7)
LEA TailData, A0
MOVE.L (A0)+, -(A7)
MOVEA.L (A0), A0
MOVE.L A7, (A0)
ADDA.W #6, A7
MOVE.W (A7)+, D1 ; result code
ADDQ #4, A7 ; skip over data
MOVE.L (A7)+, D0 ; eventMsg
TST.W D1 ; result code
BNE.S @1
MOVEA.W #$0007,A0
DC.W $A02F ; _PostEvent
@1
MOVEM.L (SP)+,D0-D2/A0-A1
ADDA.W #4,A7 ; remove arguments from stack
RTE
MyAddDrive64k
; This is only needed for the 64k ROM.
DrvQHdr EQU 776
RomBase EQU $00400000
Move.L D0,6(A0)
Lea.L (DrvQHdr),A1
Jmp (RomBase + 2848)
VBLTaskFreq EQU $0E19
; about once a minute, often enough that
; a problem with VBLTaskProc noticable.
VBLTaskProc
MOVE.W VBLTaskFreq, $000A(A0)
; fall through to return
NullTaskProc
RTS
DOpen
MOVEM.L D3-D7/A3-A4,-(A7)
MOVEM.L A0-A1, -(SP) ; push ParmBlkPtr, DCtlPtr for C
SUBQ #6, A7 ; room for result code, L
MOVE.W #kCmndSonyOpenA, -(A7)
LEA TailData, A0
MOVE.L (A0)+, -(A7)
MOVEA.L (A0), A0
MOVE.L A7, (A0)
ADDA.W #6, A7
MOVE.W (A7)+, D0 ; result code
MOVE.L (A7)+, D7 ; L
CMPI.W #$FFCF,D0
BNE.S @1
; driver already open, change to no error and leave
CLR.W D0
BRA @2
@1
TST.W D0
BNE @2
MOVE.L D7,D0
DC.W $A71E ; _NewPtr ,Sys,Clear
MOVEA.L A0,A4
MOVE.L A4,D0
BEQ @6
SUBA #16, A7 ; room for various results
MOVE.L A4, -(A7)
MOVE.L D7, -(A7)
SUBQ #2, A7 ; room for result code
MOVE.W #kCmndSonyOpenB, -(A7)
LEA TailData, A0
MOVE.L (A0)+, -(A7)
MOVEA.L (A0), A0
MOVE.L A7, (A0)
ADDA.W #6, A7
MOVE.W (A7)+, D0 ; result code
ADDA.W #8, A7
MOVE.L (A7)+, D7 ; dvl
MOVEQ #$00, D3
MOVE.W (A7)+, D3 ; step
MOVE.W (A7)+, D4 ; n
MOVE.W (A7)+, D6 ; i
MOVE.W (A7)+, D5 ; driver
MOVEA.L (A7)+, A3 ; NullTask
TST.W D0
BNE.S @2
; Patch from Jesus A. Alvarez:
; The program Winter Games by Epyx manipulates
; the VBL queue directly, and will break if the
; queue was empty. Add a VBL task to prevent this
; (like the real disk driver does).
; MOVE.L #14, D0
; DC.W $A71E ; _NewPtr ,Sys,Clear
LEA 48(A4), A0
LEA VBLTaskProc,A1
MOVE.W #1,$0004(A0) ; task type
MOVE.L A1,$0006(A0) ; task procedure
MOVE.W VBLTaskFreq,$000A(A0)
DC.W $A033 ; _VInstall
MOVE.L A3,D0
BEQ.S @3
; There is apparently a bug in the time manager
; in System 6.0.8, which will cause a crash
; if there are no installed time
; tasks. So create a time task, since
; real disk driver does.
LEA NullTaskProc,A0 ; id: 102
MOVE.L A0,$0006(A3)
MOVEA.L A3,A0
DC.W $A058 ; _InsTime
BRA.S @4
@3
LEA MyAddDrive64k,A0 ; id: 106
MOVE.W #$A04E,D0
DC.W $A047 ; _SetTrapAddress
BRA.S @4
@5
MOVEA.L D7,A0
MOVE.W D6,D0 ; drive number in high word
SWAP D0
MOVE.W D5,D0 ; driver in low word
DC.W $A04E ; _AddDrive
ADD.L D3,D7
ADDQ.W #$1,D6
@4
DBF D4, @5
PEA DUpdate
SUBQ #2, A7 ; room for result code
MOVE.W #kCmndSonyOpenC, -(A7)
LEA TailData, A0
MOVE.L (A0)+, -(A7)
MOVEA.L (A0), A0
MOVE.L A7, (A0)
ADDA.W #6, A7
MOVE.W (A7)+, D0 ; result code
ADDA.W #4, A7
@2
; result code should be in D0 when reach here
MOVEM.L (A7)+, A0-A1 ; restore ParmBlkPtr, DCtlPtr
MOVEM.L (A7)+, D3-D7/A3-A4
RTS ; open is always immediate, must return via RTS
@6
; _NewPtr failed
MOVE.W #-1, D0
BRA.S @2
TailData
ENDMAIN
END