0
|
1 ********************************************************************
|
|
2 * VRN - VIRQ/RAM/Nil device driver
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
|
6 * Copyright (C) 1989, 1990 Bruce Isted
|
|
7 *
|
|
8 * This program may be freely distributed as long as the copyright notice
|
|
9 * remains intact and the source, binary, and documentation files are
|
|
10 * distributed together.
|
|
11 *
|
|
12 * This program may not be sold for profit, individually or as part of a
|
|
13 * package without the prior written permission of the copyright holder.
|
|
14 *
|
1348
|
15 * Edt/Rev YYYY/MM/DD Modified by
|
|
16 * Comment
|
0
|
17 * ------------------------------------------------------------------
|
1348
|
18 * ? 2003/02/08 Bruce Isted
|
|
19 * Created.
|
0
|
20
|
|
21 nam VRN
|
|
22 ttl VIRQ/RAM/Nil device driver
|
|
23
|
|
24 ifp1
|
|
25 use defsfile
|
|
26 endc
|
|
27
|
|
28 VTCount equ 4 number of VIRQ tables
|
|
29 * VIRQ Table Data Layout
|
|
30 org 0
|
|
31 FS2.ID rmb 1 Flight Simulator 2 (and FS2+) VIRQ process ID
|
|
32 FS2.Pth rmb 1 path number
|
|
33 FS2.Sgl rmb 1 signal code
|
|
34 FS2.Tmr rmb 2 countdown timer (send signal on zero)
|
|
35 FS2.Rst rmb 2 reset count (no reset if zero)
|
|
36 FS2.STot rmb 1 signal counter
|
|
37 FS2.VTot rmb 4 total VIRQ counter
|
|
38 KQ3.ID rmb 1 King's Quest III VIRQ process ID
|
|
39 KQ3.Pth rmb 1 path number
|
|
40 VTSize equ . VIRQ table size
|
|
41 * RAM Table Data Layout
|
|
42 org 0
|
|
43 RAM.ID rmb 1 RAM process ID
|
|
44 RAM.Pth rmb 1 path number
|
|
45 RAM.Bks rmb 1 number of RAM blocks
|
|
46 RAM.StB rmb 2 starting RAM block number
|
|
47 RTSize equ . RAM table size
|
|
48 * Shared VIRQ/RAM Table Data Layout
|
|
49 org 0
|
|
50 All.ID rmb 1 all tables' process ID
|
|
51 All.Pth rmb 1 all tables' path number
|
|
52 org V.SCF
|
|
53 VIRQPckt rmb 5 VIRQ packet Counter(2),Reset(2),Status(1) bytes
|
|
54 PathNmbr rmb 1 current path number
|
|
55 ProcNmbr rmb 1 current process ID
|
|
56 VIRQTbls rmb VTCount*VTSize space for VIRQ tables
|
|
57 RTCount equ ($0100-.)/RTSize number of tables that fit in balance of page
|
|
58 RAMTbls rmb RTCount*RTSize space for RAM tables
|
|
59 VMem equ .
|
|
60
|
1289
|
61 rev set $00
|
0
|
62 edition set 1
|
|
63
|
|
64 mod VEnd,VName,Drivr+Objct,ReEnt+rev,VEntry,VMem
|
|
65
|
|
66 fcb UPDAT. driver access mode(s)
|
|
67
|
|
68 VName fcs "VRN"
|
|
69 fcb edition edition byte
|
|
70
|
|
71 VEntry lbra VInit
|
|
72 lbra VRead
|
|
73 lbra VWrit
|
|
74 lbra VGStt
|
|
75 lbra VSStt
|
|
76 lbra VTerm
|
1485
|
77
|
|
78 IFGT Level-1
|
0
|
79 IRQPckt fcb $00,$01,$0A IRQ packet Flip(1),Mask(1),Priority(1) bytes
|
1485
|
80 ENDC
|
|
81
|
0
|
82 VInit equ *
|
1485
|
83 IFGT Level-1
|
0
|
84 * Note that all device memory except V.PAGE and
|
|
85 * V.PORT has already been cleared (zeroed).
|
|
86 leax VIRQPckt+Vi.Stat,u fake VIRQ status register
|
|
87 lda #$80 VIRQ flag clear, repeated VIRQs
|
|
88 sta ,x set it while we're here...
|
|
89 tfr x,d copy fake VIRQ status register address
|
|
90 leax IRQPckt,pc IRQ polling packet
|
|
91 leay IRQSvc,pc IRQ service entry
|
|
92 os9 F$IRQ
|
|
93 bcs InitExit go report error...
|
|
94 ldd #$0001 initial count
|
|
95 std VIRQPckt+Vi.Rst,u reset count
|
|
96 ldx #$0001 code to install new VIRQ
|
|
97 leay VIRQPckt,u VIRQ software registers
|
|
98 os9 F$VIRQ
|
|
99 bcc InitExit no error, go exit...
|
|
100 pshs cc,b save error info
|
|
101 bsr DumpIRQ go remove from IRQ polling
|
|
102 puls cc,b,pc recover error info & exit...
|
1485
|
103 ELSE
|
|
104 clrb
|
|
105 rts
|
|
106 ENDC
|
|
107
|
0
|
108 VRead equ *
|
|
109 comb
|
|
110 ldb #E$EOF
|
|
111 InitExit rts
|
1485
|
112
|
0
|
113 VTerm equ *
|
1485
|
114 IFGT Level-1
|
0
|
115 ldx #$0000 code to delete VIRQ entry
|
|
116 leay VIRQPckt,u VIRQ software registers
|
|
117 os9 F$VIRQ remove from VIRQ polling
|
|
118 bcs Term.Err go report error...
|
|
119 DumpIRQ leax VIRQPckt+Vi.Stat,u fake VIRQ status register
|
|
120 tfr x,d copy address...
|
|
121 ldx #$0000 code to remove IRQ entry
|
|
122 leay IRQSvc,pc IRQ service routine
|
|
123 os9 F$IRQ
|
1485
|
124 ELSE
|
|
125 clrb
|
|
126 ENDC
|
0
|
127 Term.Err rts
|
1485
|
128
|
0
|
129 VGStt equ *
|
1485
|
130 IFGT Level-1
|
0
|
131 * [A] = call code
|
|
132 * call $01: SS.Ready (device never has data ready)
|
|
133 * call $80: return FS2/FS2+ total VIRQ counter
|
|
134 * call $81: return FS2/FS2+ number of signals sent
|
|
135 * all others return E$UnkSvc error
|
|
136 bsr GetInfo process+path and caller's stack info
|
|
137 cmpa #$01 SS.Ready?
|
|
138 bne Chk.GS80 no, go check next...
|
|
139 comb
|
|
140 ldb #E$NotRdy
|
|
141 rts
|
|
142 UnitErr ldb #E$Unit
|
|
143 rts
|
|
144 * get process+path info, [Y] --> caller's register stack
|
|
145 * do not alter [A] or [U]
|
|
146 GetInfo ldb PD.PD,y path number
|
|
147 stb PathNmbr,u save it...
|
|
148 ldb PD.CPR,y current process ID (can't depend on V.BUSY)
|
|
149 stb ProcNmbr,u save it...
|
|
150 ldy PD.RGS,y caller's register stack address
|
|
151 rts
|
|
152 Chk.GS80 cmpa #$80 return & clear total VIRQs?
|
|
153 bne Chk.GS81 no, go check next...
|
|
154 bsr FPTFS2 find process+path entry
|
|
155 bcs UnitErr not in tables, go return error...
|
|
156 ldd FS2.VTot,x total VIRQ counter MSBs
|
|
157 std R$X,y return them to caller
|
|
158 ldd FS2.VTot+2,x total VIRQ counter LSBs
|
|
159 std R$Y,y return them to caller
|
|
160 ClrVTot clra
|
|
161 clrb no error...
|
|
162 std FS2.VTot,x *clear total
|
|
163 std FS2.VTot+2,x *VIRQ counter
|
|
164 rts
|
|
165 Chk.GS81 cmpa #$81 return & clear signals sent?
|
|
166 lbne USvcErr not supported, go report error...
|
|
167 bsr FPTFS2 find process+path entry
|
|
168 bcs UnitErr not in tables, go return error...
|
|
169 lda FS2.STot,x number of signals sent
|
|
170 sta R$A,y return it to caller
|
|
171 clr FS2.STot,x clear signal counter
|
1485
|
172 ELSE
|
|
173 clrb
|
|
174 ENDC
|
0
|
175 rts
|
1485
|
176
|
0
|
177 VSStt equ *
|
1485
|
178 IFGT Level-1
|
0
|
179 * [A] = call code
|
|
180 * call $2A: SS.Close (clear all process+path entries)
|
|
181 * call $81: set process+path FS2 VIRQ, clear process+path FS2/FS2+ VIRQ
|
|
182 * call $C7: set process+path FS2+ VIRQ
|
|
183 * call $C8: set process+path KQ3 VIRQ
|
|
184 * call $C9: clear process+path KQ3 VIRQ
|
|
185 * call $CA: allocate process+path RAM blocks
|
|
186 * call $CB: de-allocate process+path RAM blocks
|
|
187 * all others return E$UnkSvc error
|
|
188 bsr GetInfo process+path and caller's stack info
|
|
189 cmpa #$2A SS.Close?
|
|
190 bne Chk.SSC9 no, go check next...
|
|
191 bsr FPTFS2 check for existing FS2/FS2+ VIRQ entry...
|
|
192 bcs Chk.KV2A none, go check for KQ3 VIRQ...
|
|
193 clr All.ID,x de-allocate FS2/FS2+ entry
|
|
194 Chk.KV2A bsr SS2A.KQ3 check/de-allocate KQ3 VIRQ...
|
|
195 bra SS2A.RAM go return RAM blocks, return from there...
|
|
196 Chk.SSC9 cmpa #$C9 clear KQ3 VIRQ?
|
|
197 bne Chk.SSCB no, go check next...
|
|
198 SS2A.KQ3 bsr FPTKQ3 existing KQ3 VIRQ is ours?
|
|
199 bcs SS.OK no, go exit clean...
|
|
200 clr All.ID,x de-allocate KQ3 VIRQ
|
|
201 rts
|
|
202 Chk.SSCB cmpa #$CB return process+path RAM blocks?
|
|
203 bne Chk.SSC8 no, go check next...
|
|
204 SS2A.RAM bsr FPTRAM go find RAM table entry
|
|
205 bcs SS.OK no entry, go exit clean...
|
|
206 clr All.ID,x de-allocate table entry
|
|
207 ldb RAM.Bks,x number of RAM blocks
|
|
208 beq SS.OK no RAM to return, go exit clean...
|
|
209 ldx RAM.StB,x first block number
|
|
210 os9 F$DelRAM
|
|
211 rts
|
|
212 * Find Current Process+Path Table Entry
|
|
213 FPTRAM leax RAMTbls,u first RAM table
|
|
214 ldd #RTCount*256+RTSize [A]=loop count, [B]=table size
|
|
215 bra FPT01
|
|
216 FPTKQ3 leax VIRQTbls+KQ3.ID,u first KQ3 VIRQ entry
|
|
217 bra FPT00
|
|
218 FPTFS2 leax VIRQTbls+FS2.ID,u first FS2/FS2+ VIRQ entry
|
|
219 FPT00 ldd #VTCount*256+VTSize [A]=loop count, [B]=table size
|
|
220 FPT01 pshs a save loop count
|
|
221 FPTLoop lda ProcNmbr,u current process ID
|
|
222 cmpa All.ID,x same?
|
|
223 bne FPTNext no, go check next...
|
|
224 lda PathNmbr,u current path number
|
|
225 cmpa All.Pth,x same?
|
|
226 bne FPTNext no, go check next...
|
|
227 clrb table found, clear Carry
|
|
228 puls a,pc clean up stack, return
|
|
229 FPTNext abx next table
|
|
230 dec ,s done yet?
|
|
231 bne FPTLoop no, go check next...
|
|
232 comb table not found, set Carry
|
|
233 puls a,pc clean up stack, return
|
|
234 Chk.SSC8 cmpa #$C8 set KQ3 VIRQ?
|
|
235 bne Chk.SSCA no, go check next...
|
|
236 bsr FPTKQ3 existing KQ3 VIRQ?
|
|
237 bcc SS.OK yes, go exit clean...
|
|
238 bsr FETKQ3 KQ3 VIRQ available?
|
|
239 bcs BusyErr no, go report error...
|
|
240 SS.OK clrb no error...
|
|
241 rts
|
|
242 Chk.SSCA cmpa #$CA allocate process+path RAM blocks?
|
|
243 bne Chk.SS81 no, go check next...
|
|
244 bsr FPTRAM go check for existing process+path RAM table entry
|
|
245 bcc BusyErr found it, go report error...
|
|
246 bsr FETRAM go find empty RAM table entry...
|
|
247 bcs BusyErr tables full, go report error...
|
|
248 ldb R$X+1,y RAM blocks to allocate
|
|
249 stb RAM.Bks,x save it...
|
|
250 os9 F$AllRAM
|
|
251 bcs SSCA.Err go report error...
|
|
252 std RAM.StB,x save first block number
|
|
253 std R$X,y return it to caller, too
|
|
254 SS.Err rts
|
|
255 SSCA.Err pshs cc,b save error info
|
|
256 clr All.ID,x de-allocate table entry
|
|
257 puls cc,b,pc recover error info, return
|
|
258 GetFS2 bsr FPTFS2 check for existing FS2/FS2+ entry...
|
|
259 bcc GotFS2 found it...
|
|
260 bsr FETFS2 check for empty FS2/FS2+ table...
|
|
261 bcs BusyErr none left, go report error...
|
|
262 lbsr ClrVTot go clear VIRQ total counter
|
|
263 GotFS2 ldd R$X,y FS2/FS2+ timer count
|
|
264 std FS2.Tmr,x save it...
|
|
265 std FS2.Rst,x FS2 reset count
|
|
266 clr FS2.STot,x no signals sent yet...
|
|
267 rts
|
|
268 * Find Empty Table Entry
|
|
269 FETRAM leax RAMTbls,u first RAM table
|
|
270 ldd #RTCount*256+RTSize [A]=loop count, [B]=table size
|
|
271 bra FET01
|
|
272 FETKQ3 leax VIRQTbls+KQ3.ID,u first KQ3 VIRQ entry
|
|
273 bra FET00
|
|
274 FETFS2 leax VIRQTbls+FS2.ID,u first FS2/FS2+ VIRQ entry
|
|
275 FET00 ldd #VTCount*256+VTSize [A]=loop count, [B]=table size
|
|
276 FET01 pshs a save loop count
|
|
277 FETLoop lda All.ID,x table allocated?
|
|
278 bne FETNext yes, go check next...
|
|
279 lda ProcNmbr,u current process ID
|
|
280 sta All.ID,x allocate table
|
|
281 lda PathNmbr,u current path number
|
|
282 sta All.Pth,x set path number
|
|
283 clrb table found, clear Carry
|
|
284 puls a,pc clean up stack, return
|
|
285 FETNext abx next table
|
|
286 dec ,s done yet?
|
|
287 bne FETLoop no, go check next...
|
|
288 comb table not found, set Carry
|
|
289 puls a,pc clean up stack, return
|
|
290 BusyErr comb
|
|
291 ldb #E$DevBsy
|
|
292 rts
|
|
293 Chk.SS81 cmpa #$81 set FS2 VIRQ or clear FS2/FS2+ VIRQ?
|
|
294 bne Chk.SSC7 no, go check next...
|
|
295 bsr GetFS2 go get FS2/FS2+ VIRQ entry
|
|
296 bcs SS.Err go report error...
|
|
297 ldb #$80 standard FS2 signal
|
|
298 stb FS2.Sgl,x save it...
|
|
299 ldb R$Y+1,y FS2 VIRQ enable/disable flag
|
|
300 bne SS.OK set VIRQ flag, go exit clean...
|
|
301 ClrID clr All.ID,x de-allocate entry
|
|
302 rts
|
|
303 Chk.SSC7 cmpa #$C7 set FS2+ VIRQ?
|
|
304 bne USvcErr not supported, go report error...
|
|
305 bsr GetFS2 go get FS2/FS2+ VIRQ entry
|
|
306 bcs SS.Err go report error...
|
|
307 ldd R$Y,y FS2+ reset count (one shot VIRQ if zero)
|
|
308 std FS2.Rst,x save it...
|
|
309 ldb R$U+1,y LSB = caller's signal code
|
|
310 stb FS2.Sgl,x save it...
|
|
311 rts
|
|
312 USvcErr comb
|
|
313 ldb #E$UnkSvc
|
|
314 rts
|
|
315 IRQSvc equ *
|
|
316 lda VIRQPckt+Vi.Stat,u VIRQ status register
|
|
317 anda #^Vi.IFlag clear flag in VIRQ status register
|
|
318 sta VIRQPckt+Vi.Stat,u save it...
|
|
319 leau VIRQTbls,u VIRQ tables
|
|
320 ldy #VTCount loop count
|
|
321 IRQLoop lda KQ3.ID,u KQ3 VIRQ process ID
|
|
322 beq NoKQ3Sgl none, skip signal...
|
|
323 ldb #$80 signal code
|
|
324 os9 F$Send send signal, ignore error (if any)
|
|
325 NoKQ3Sgl lda FS2.ID,u process ID
|
|
326 beq NoFS2Sgl unallocated entry, skip everything...
|
|
327 inc FS2.VTot+3,u *increment
|
|
328 bne DoneVTot *total
|
|
329 inc FS2.VTot+2,u *VIRQ
|
|
330 bne DoneVTot *counter
|
|
331 inc FS2.VTot+1,u *
|
|
332 bne DoneVTot *
|
|
333 inc FS2.VTot,u *
|
|
334 DoneVTot ldx FS2.Tmr,u timer count
|
|
335 leax -1,x less one...
|
|
336 stx FS2.Tmr,u done yet?
|
|
337 bne NoFS2Sgl no, skip signal...
|
|
338 inc FS2.STot,u one more signal...
|
|
339 ldx FS2.Rst,u reset timer count (one shot VIRQ?)
|
|
340 stx FS2.Tmr,u set counter
|
|
341 bne KeepID not zero, go on...
|
|
342 clr FS2.ID,u de-allocate entry
|
|
343 KeepID ldb FS2.Sgl,u signal code
|
|
344 os9 F$Send send signal, ignore error (if any)
|
|
345 NoFS2Sgl leau VTSize,u next table
|
|
346 leay -1,y done all tables?
|
|
347 bne IRQLoop no, go check next...
|
1485
|
348 ENDC
|
|
349
|
0
|
350 VWrit equ *
|
|
351 clrb no error...
|
|
352 rts
|
1485
|
353
|
0
|
354 emod
|
|
355 VEnd equ *
|
|
356 end
|