1 ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
2 ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
3 ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
4 ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
5 ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
6 ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
7 ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
8 ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
9 ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
10 ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
12 ; $Source: /cvs/cvsroot/d2x/arch/dos/joy2.asm,v $
15 ; $Date: 2001-10-24 09:25:05 $
17 ; Contains routines for joystick interface.
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.1.1.1 2001/01/19 03:33:43 bradleyb
21 ; Import of d2x-0.0.9-pre1
23 ; Revision 1.1.1.1 1999/06/14 21:57:53 donut
24 ; Import of d1x 1.37 source.
26 ; Revision 1.17 1995/10/07 13:22:11 john
27 ; Added new method of reading joystick that allows higher-priority
28 ; interrupts to go off.
30 ; Revision 1.16 1995/03/30 11:03:30 john
31 ; Made -JoyBios read buttons using BIOS.
33 ; Revision 1.15 1995/02/14 11:39:36 john
34 ; Added polled/bios joystick readers..
36 ; Revision 1.14 1995/01/29 18:36:00 john
37 ; Made timer count in mode 2 instead of mode 3.
39 ; Revision 1.13 1994/12/28 15:32:21 john
40 ; Added code to read joystick axis not all at one time.
42 ; Revision 1.12 1994/12/27 15:44:59 john
43 ; Made the joystick timeout be at 1/100th of a second,
44 ; regardless of CPU speed.
46 ; Revision 1.11 1994/11/15 12:04:40 john
47 ; Cleaned up timer code a bit... took out unused functions
48 ; like timer_get_milliseconds, etc.
50 ; Revision 1.10 1994/07/01 10:55:54 john
51 ; Fixed some bugs... added support for 4 axis.
53 ; Revision 1.9 1994/06/30 20:36:54 john
54 ; Revamped joystick code.
56 ; Revision 1.8 1994/04/22 12:52:06 john
65 global _joy_bogus_reading
68 _joy_bogus_reading dd 0
80 xor al, al ; Latch timer 0 command
81 out TCOMMAND, al ; Latch timer
82 in al, TDATA ; Read lo byte
84 in al, TDATA ; Read hi byte
92 global _joy_read_stick_friendly2
93 _joy_read_stick_friendly2:
102 ; edi = pointer to event buffer
103 ; ecx = timeout value
104 ; returns in eax the number of events
106 mov dword [RetryCount], 0
107 mov dword [_joy_bogus_reading], 0
109 _joy_read_stick_friendly_retry:
110 inc dword [RetryCount]
111 cmp dword [RetryCount], 3
113 mov dword [_joy_bogus_reading], 1
114 inc dword [_joy_retries]
125 and ebx, 01111b ; Make sure we only check the right values
126 ; number of events we found will be in bh, so this also clears it to zero.
130 cli ; disable interrupts while reading time...
131 call joy_get_timer ; Returns counter in EAX
132 sti ; enable interrupts after reading time...
133 mov dword [LastTick], eax
135 waitforstable_f: in al, dx
137 jz ready_f ; Wait for the port in question to be done reading...
139 cli ; disable interrupts while reading time...
140 call joy_get_timer ; Returns counter in EAX
141 sti ; enable interrupts after reading time...
142 xchg eax, dword [LastTick]
143 cmp eax, dword [LastTick]
145 sub eax, dword [LastTick]
147 add dword [TotalTicks], eax
148 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
155 out dx, al ; Start joystick a readin'
157 call joy_get_timer ; Returns counter in EAX
158 mov dword [LastTick], eax
159 mov dword [TotalTicks], 0
161 mov [edi], eax ; Store initial count
164 again_f: in al, dx ; Read Joystick port
166 and al, bl ; Mask off channels we don't want to read
167 jnz flip_f ; See if any of the channels flipped
169 ; none flipped -- check any interrupts...
172 in al, 20h ; Get interrupts pending
176 ; Need to do an interrupt
178 nop ; let the interrupt go on...
181 ; See if any axis turned
187 ; At this point, an interrupt occured, making one or more
188 ; of the axis values bogus. So, we will restart this process...
194 jmp _joy_read_stick_friendly_retry
197 call joy_get_timer ; Returns counter in EAX
199 xchg eax, dword [LastTick]
200 cmp eax, dword [LastTick]
202 sub eax, dword [LastTick]
204 add dword [TotalTicks], eax
205 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
209 flip_f: and eax, 01111b ; Only care about axis values
210 mov [edi], eax ; Record what channel(s) flipped
212 xor bl, al ; Unmark the channels that just tripped
214 call joy_get_timer ; Returns counter in EAX
215 mov [edi], eax ; Record the time this channel flipped
217 inc bh ; Increment number of events
220 jne again_f ; If there are more channels to read, keep looping
225 movzx eax, bh ; Return number of events
237 global _joy_read_stick_asm2
239 _joy_read_stick_asm2:
248 ; edi = pointer to event buffer
249 ; ecx = timeout value
250 ; returns in eax the number of events
251 mov dword [_joy_bogus_reading], 0
253 and ebx, 01111b ; Make sure we only check the right values
254 ; number of events we found will be in bh, so this also clears it to zero.
258 cli ; disable interrupts while reading time...
259 call joy_get_timer ; Returns counter in EAX
260 sti ; enable interrupts after reading time...
261 mov dword [LastTick], eax
263 waitforstable: in al, dx
265 jz ready ; Wait for the port in question to be done reading...
267 cli ; disable interrupts while reading time...
268 call joy_get_timer ; Returns counter in EAX
269 sti ; enable interrupts after reading time...
270 xchg eax, dword [LastTick]
271 cmp eax, dword [LastTick]
273 sub eax, dword [LastTick]
275 add dword [TotalTicks], eax
276 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
283 out dx, al ; Start joystick a readin'
285 call joy_get_timer ; Returns counter in EAX
286 mov dword [LastTick], eax
287 mov dword [TotalTicks], 0
289 mov [edi], eax ; Store initial count
292 again: in al, dx ; Read Joystick port
294 and al, bl ; Mask off channels we don't want to read
295 jnz flip ; See if any of the channels flipped
297 call joy_get_timer ; Returns counter in EAX
299 xchg eax, dword [LastTick]
300 cmp eax, dword [LastTick]
302 sub eax, dword [LastTick]
304 add dword [TotalTicks], eax
305 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
309 flip: and eax, 01111b ; Only care about axis values
310 mov [edi], eax ; Record what channel(s) flipped
312 xor bl, al ; Unmark the channels that just tripped
314 call joy_get_timer ; Returns counter in EAX
315 mov [edi], eax ; Record the time this channel flipped
317 inc bh ; Increment number of events
320 jne again ; If there are more channels to read, keep looping
323 movzx eax, bh ; Return number of events
331 global _joy_read_stick_polled2
333 _joy_read_stick_polled2:
342 ; edi = pointer to event buffer
343 ; ecx = timeout value
344 ; returns in eax the number of events
345 mov dword [_joy_bogus_reading], 0
347 and ebx, 01111b ; Make sure we only check the right values
348 ; number of events we found will be in bh, so this also clears it to zero.
352 mov dword [TotalTicks], 0
354 waitforstable1: in al, dx
356 jz ready1 ; Wait for the port in question to be done reading...
358 inc dword [TotalTicks]
359 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
365 out dx, al ; Start joystick a readin'
367 mov dword [TotalTicks], 0
369 mov dword [edi], 0 ; Store initial count
372 again1: in al, dx ; Read Joystick port
374 and al, bl ; Mask off channels we don't want to read
375 jnz flip1 ; See if any of the channels flipped
377 inc dword [TotalTicks]
378 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
382 flip1: and eax, 01111b ; Only care about axis values
383 mov [edi], eax ; Record what channel(s) flipped
385 xor bl, al ; Unmark the channels that just tripped
387 mov eax, dword [TotalTicks]
388 mov [edi], eax ; Record the time this channel flipped
390 inc bh ; Increment number of events
393 jne again1 ; If there are more channels to read, keep looping
396 movzx eax, bh ; Return number of events
403 global _joy_read_stick_bios2
405 _joy_read_stick_bios2:
413 ; edi = pointer to event buffer
414 ; ecx = timeout value
415 ; returns in eax the number of events
417 mov dword [_joy_bogus_reading], 0
429 mov dword [edi+4], 1 ; Axis 1
431 mov [edi+8], eax ; Axis 1 value
433 mov dword [edi+12], 2 ; Axis 2
435 mov [edi+16], ebx ; Axis 2 value
437 mov dword [edi+20], 4 ; Axis 3
439 mov [edi+24], ecx ; Axis 3 value
441 mov dword [edi+28], 8 ; Axis 3
443 mov [edi+32], edx ; Axis 3 value
446 mov eax, 4 ; 4 events
453 global _joy_read_buttons_bios2
455 _joy_read_buttons_bios2:
456 ; returns in eax the button settings
462 mov edx, 0 ; Read switches
472 global _joy_read_buttons_bios_end2
473 _joy_read_buttons_bios_end2: ; to calculate _joy_read_buttons_bios size