Mercurial > hg > Members > kono > nitros9-code
annotate level2/modules/joydrv_6551L.asm @ 2229:918c7c68ea4d
Made formats quiet
author | boisy |
---|---|
date | Sun, 22 Mar 2009 12:21:59 +0000 |
parents | 8a96f5241556 |
children | 1317b044e8bf |
rev | line source |
---|---|
0 | 1 ******************************************************************** |
2 * JoyDrv - Joystick Driver for 6551/Logitech Mouse | |
3 * | |
4 * $Id$ | |
5 * | |
1846 | 6 * Edt/Rev YYYY/MM/DD Modified by |
7 * Comment | |
0 | 8 * ------------------------------------------------------------------ |
1846 | 9 * 6 1988/??/?? |
10 * L2 Upgrade distribution version. | |
11 * | |
12 * 6r1 2005/04/25 Boisy G. Pitre | |
13 * Fixed error where wrong branch was taken. | |
14 | |
15 nam JoyDrv | |
0 | 16 ttl Joystick Driver for 6551/Logitech Mouse |
1846 | 17 |
0 | 18 * Disassembled 98/09/09 09:22:44 by Disasm v1.6 (C) 1988 by RML |
1846 | 19 |
20 ifp1 | |
21 use defsfile | |
22 use l51.defs | |
23 endc | |
24 | |
0 | 25 tylg set Systm+Objct |
1846 | 26 atrv set ReEnt+rev |
0 | 27 rev set $01 |
1846 | 28 edition set 6 |
29 | |
2194 | 30 MPISlot set $FF |
1846 | 31 |
0 | 32 mod eom,name,tylg,atrv,start,$FF68 |
1846 | 33 |
34 name fcs /JoyDrv/ | |
35 fcb edition | |
36 | |
2173
5daef7cf8a1b
Fixed error where equ should have been fcb for MPI slot select
boisy
parents:
1846
diff
changeset
|
37 SlotSlct fcb MPISlot |
1846 | 38 |
39 start lbra Init | |
40 lbra Term | |
41 lbra SSMsBtn | |
42 lbra SSMsXY | |
43 lbra SSJoyBtn | |
44 | |
45 SSJoyXY pshs x,b,a | |
46 ldx #PIA0Base | |
47 lda <$23,x | |
48 ldb <$20,x | |
49 pshs b,a | |
50 anda #$F7 | |
51 sta <$23,x | |
52 lda $01,x | |
53 ldb $03,x | |
54 pshs b,a | |
55 andb #$F7 | |
56 lsr $04,s | |
57 bcs L0043 | |
58 orb #$08 | |
59 L0043 stb $03,x | |
60 lda ,s | |
61 ora #$08 | |
62 bsr L0065 | |
63 std $06,s | |
64 lda ,s | |
65 anda #$F7 | |
66 bsr L0065 | |
67 std $04,s | |
68 puls b,a | |
69 sta $01,x | |
70 stb $03,x | |
71 puls b,a | |
72 stb <$20,x | |
73 sta <$23,x | |
74 puls pc,y,x | |
75 L0065 sta $01,x | |
76 lda #$7F | |
77 ldb #$40 | |
78 bra L0078 | |
79 L006D lsrb | |
80 cmpb #$01 | |
81 bhi L0078 | |
82 lsra | |
83 lsra | |
84 tfr a,b | |
85 clra | |
86 rts | |
87 L0078 pshs b | |
88 sta <$20,x | |
89 tst ,x | |
90 bpl L0085 | |
91 adda ,s+ | |
92 bra L006D | |
93 L0085 suba ,s+ | |
94 bra L006D | |
95 | |
96 IRQPckt equ * | |
0 | 97 Pkt.Flip fcb Stat.Flp D.Poll flip byte |
98 Pkt.Mask fcb Stat.Msk D.Poll mask byte | |
99 fcb $01 priority | |
1846 | 100 |
101 *** | |
102 * JoyDrv Initialization. | |
103 * | |
104 * INPUT: U = JoyDrv data area address (8 bytes) | |
105 * | |
106 * OUTPUT: IRQ service entry installed | |
107 * D, X, and U registers may be altered | |
108 * | |
109 * ERROR OUTPUT: CC = Carry set | |
110 * B = error code | |
111 Init clra | |
112 clrb | |
0 | 113 sta Btn.Cntr,u set up Rx data sync, no button(s) pressed |
114 std CrntXPos,u set up X position at left screen edge | |
115 ldd #HResMaxY*2 | |
116 std CrntYPos,u set up Y position at top screen edge | |
1846 | 117 ldd M$Mem,pcr get base hardware address |
0 | 118 addd #StatReg status register address |
119 leax IRQPckt,pcr | |
120 leay IRQSvc,pcr | |
1846 | 121 os9 F$IRQ |
122 bcs TermExit go report error... | |
123 ldx M$Mem,pcr get base hardware address again | |
0 | 124 ldd #(TIC.RTS!Cmd.DTR)*256+(DB.8!Ctl.RClk!BR.01200) [D]=command:control |
1846 | 125 pshs cc |
0 | 126 orcc #IntMasks disable IRQs while setting up hardware |
127 sta PRstReg,x reset 6551 | |
128 std CmdReg,x set command and control registers | |
129 lda >PIA1Base+3 get PIA CART* input control register | |
130 anda #$FC clear PIA CART* control bits | |
131 sta >PIA1Base+3 disable PIA CART* FIRQs | |
132 lda >PIA1Base+2 clear possible pending PIA CART* FIRQ | |
133 lda #$01 GIME CART* IRQ enable | |
134 ora <D.IRQER mask in current GIME IRQ enables | |
135 sta <D.IRQER save GIME CART* IRQ enable shadow register | |
136 sta >IrqEnR enable GIME CART* IRQs | |
137 ldb DataReg,x *ensure old error, | |
138 ldb StatReg,x *Rx data, and | |
139 ldb DataReg,x *IRQ flags | |
140 ldb StatReg,x *are clear | |
141 andb Pkt.Mask,pcr IRQ bits still set? | |
142 bne InitErr yes, go disable ACIA and return... | |
143 lda SlotSlct,pcr get MPI slot select value | |
144 bmi InitExit no MPI slot select, go exit... | |
145 sta >MPI.Slct set MPI slot select register | |
1846 | 146 * BUG FIX: InitExit is now here... was TermExit... |
147 InitExit puls pc,cc recover original regs, return... | |
148 | |
149 *** | |
150 * JoyDrv Termination. | |
151 * | |
152 * INPUT: U = JoyDrv data area address (8 bytes) | |
153 * | |
154 * OUTPUT: IRQ service entry removed | |
155 * D, X, and U registers may be altered | |
156 * | |
157 * ERROR OUTPUT: CC = Carry set | |
158 * B = error code | |
0 | 159 Term pshs cc save regs we alter |
160 orcc #IntMasks mask IRQs while disabling ACIA | |
161 InitErr ldx M$Mem,pcr get base address | |
162 lda #TIC.RTS!Cmd.RxIE!Cmd.DTR *disable all | |
163 sta CmdReg,x *ACIA IRQs | |
1846 | 164 puls cc |
0 | 165 leax StatReg,x point to status register |
166 tfr x,d copy status register address | |
167 ldx #$0000 remove IRQ table entry | |
168 leay IRQSvc,pcr | |
1846 | 169 os9 F$IRQ |
170 TermExit rts | |
171 | |
172 *** | |
173 * Joystick button(s) status check. | |
174 * | |
175 * INPUT: U = JoyDrv data area address (8 bytes) | |
176 * | |
177 * OUTPUT: B = button or "clear" status | |
178 * button(s) = xxxxLRLR | |
179 * A, X, and U registers may be altered | |
180 * | |
181 * ERROR OUTPUT: none | |
182 SSJoyBtn ldb #$FF | |
183 ldx #PIA0Base check for standard joystick/mouse fire buttons | |
0 | 184 stb $02,x |
1846 | 185 ldb ,x |
186 comb set == button pressed | |
187 andb #$0F | |
188 rts | |
189 | |
190 *** | |
191 * Mouse button(s) status check. | |
192 * | |
193 * INPUT: U = JoyDrv data area address (8 bytes) | |
194 * | |
195 * OUTPUT: B = button or "clear" status | |
196 * button(s) = xxxxLRLR | |
197 * clear = 10000000 | |
198 * shift-clear = 11000000 | |
199 * A, X, and U registers may be altered | |
200 * | |
201 * ERROR OUTPUT: none | |
202 SSMsBtn pshs cc | |
203 orcc #IntMasks mask interrupts | |
0 | 204 lda ,u |
1846 | 205 tfr a,b |
206 andb #%11000000 mask SHIFT-CLEAR | |
207 bne L0120 | |
208 bita #%00100000 ???? | |
209 beq L011A | |
210 orb #%00000011 | |
211 L011A bita #%00010000 | |
212 beq L0120 | |
213 orb #%00001100 | |
214 L0120 anda #%00111111 turn off SHIFT-CLEAR flag | |
215 sta ,u | |
216 puls pc,cc | |
217 | |
218 *** | |
219 * Joystick/Mouse XY coordinate read. | |
220 * | |
221 * INPUT: A = side flag (1 = right, 2 = left) | |
222 * Y = resolution (0 = low, 1 = high) | |
223 * U = JoyDrv data area address (8 bytes) | |
224 * | |
225 * OUTPUT: X = horizontal coordinate (left edge = 0) | |
226 * low resolution = 0 to 63 | |
227 * high resolution = 0 to HResMaxX | |
228 * Y = vertical coordinate (top edge = 0) | |
229 * low resolution = 0 to 63 | |
230 * high resolution = 0 to HResMaxY | |
231 * D and U registers may be altered | |
232 * | |
233 * ERROR OUTPUT: none | |
234 SSMsXY ldd #$017E | |
235 pshs cc | |
236 orcc #IntMasks | |
0 | 237 ldx CrntXPos,u |
238 subd CrntYPos,u | |
1846 | 239 lsra |
240 rorb | |
241 tfr d,y | |
242 puls pc,cc | |
243 | |
0 | 244 *** |
245 * Mouse IRQ service routine. | |
246 * | |
247 * INPUT: A = flipped and masked device status byte | |
248 * U = mouse data area address | |
249 * | |
250 * OUTPUT: updated serial mouse data | |
251 * CC Carry clear | |
252 * D, X, Y, and U registers may be altered | |
253 * | |
254 * ERROR OUTPUT: none | |
1846 | 255 IRQSvc ldx M$Mem,pcr |
0 | 256 bita #Stat.Err any error(s)? |
257 beq ChkRDRF no, go check Rx data | |
258 ldb DataReg,x read Rx data register to clear error flags | |
259 ClrRxCnt lda Btn.Cntr,u get current button status and Rx data counter | |
260 anda #^BC.RxCnt clear Rx data counter | |
261 ButnExit sta Btn.Cntr,u reset Rx mouse data counter to wait for sync... | |
262 IRQExit clrb clear Carry to mark IRQ serviced | |
1846 | 263 rts |
264 | |
0 | 265 ChkRDRF bita #Stat.RxF Rx data? |
266 beq IRQExit no, but this branch should never be taken... | |
267 ldb DataReg,x get Rx data | |
268 lda Btn.Cntr,u get button status and Rx counter | |
269 anda #BC.RxCnt waiting for sync with mouse data? | |
270 bne ChkOfst no, go check Rx offset... | |
271 tfr b,a copy Rx data | |
272 anda #SyncMask clear button status bits | |
273 cmpa #SyncData is it *PROBABLY* the initial (sync) byte? | |
274 bne IRQExit no, just ignore it... | |
275 comb invert button bits to match SS.Mouse format | |
276 lslb *move button | |
277 lslb *status into | |
278 lslb *bits 5-3 | |
279 andb #BC.Butns clear everything but the button bits | |
280 incb set Rx counter to first XY position byte | |
1846 | 281 pshs b |
282 lda ,u | |
283 bita #$08 | |
284 beq L017A | |
285 bitb #$08 | |
286 bne L017A | |
287 lda #$C0 | |
0 | 288 ldx CrntXPos,u |
1846 | 289 cmpx #$0140 |
290 bcs L017A | |
291 lsla | |
292 L017A anda #$C0 | |
293 ora ,s+ | |
0 | 294 bra ButnExit go save new button status and Rx counter, exit... |
295 ChkOfst cmpa #PcktSize-1 last byte in mouse packet? | |
296 bcs SaveData no, go save mouse data to Rx buffer... | |
297 ldx #HResMaxY*2 get maximum Y position | |
298 pshs x save it for CalcPos subroutine | |
299 leax CrntYPos,u point to current Y position | |
300 leay Buffer+1,u point to primary Y offset | |
301 bsr CalcPos go calculate & save mouse's new Y position | |
302 ldb Buffer+2,u get mouse packet's secondary X offset | |
303 ldx #HResMaxX get maximum X position | |
304 stx ,s save it for CalcPos subroutine | |
305 leax CrntXPos,u point to current X position | |
306 leay Buffer+0,u point to primary X offset | |
307 bsr CalcPos go calculate & save mouse's new X position | |
308 leas 2,s clean up stack | |
309 bra ClrRxCnt go save button status and clear Rx counter, exit... | |
310 SaveData stb a,u save XY position byte to mouse data Rx buffer | |
311 inc Btn.Cntr,u point to next byte in Rx buffer | |
312 clrb clear Carry to mark IRQ serviced | |
1846 | 313 rts |
314 | |
0 | 315 CalcPos sex sign extend mouse packet's 2nd XY offset ([D] = -128 to +127) |
316 pshs d save it temporarily... | |
317 ldb ,y get mouse packet's 1st XY offset | |
318 sex sign extend it ([D] = -128 to +127) | |
319 addd ,s add mouse's 2nd XY offset | |
320 std ,s save XY offset total temporarily... | |
321 bpl PosAdjst go de-sensitize positive "ballistic" XY offset... | |
322 orb #%00000111 if -8<XYoffset<0, no "ballistic" response | |
323 addd #1 "fix" negative offset "ballistic" response | |
324 bra RShiftD go calculate "ballistic" offset... | |
325 PosAdjst andb #%11111000 if 0<XYoffset<8, no "ballistic" response | |
326 RShiftD asra *calculate 50% of XY offset | |
327 rorb *for "ballistic" response | |
328 addd ,s++ add original XY offset total, clean up stack | |
329 addd ,x add mouse's current XY position | |
330 bpl CheckPos zero or positive XY position, go check it... | |
331 clra *set minimum | |
332 clrb *XY position | |
333 CheckPos cmpd 2,s past maximum XY position? | |
334 bls SavePos no, go save it... | |
335 ldd 2,s get maximum XY position | |
336 SavePos std ,x save new XY position | |
1846 | 337 rts |
338 | |
339 emod | |
340 eom equ * | |
341 end |