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