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