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/input/dos_joy2.asm,v $
13 ; $Revision: 1.1.1.1 $
15 ; $Date: 2001-01-19 03:33:43 $
17 ; Contains routines for joystick interface.
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.1.1.1 1999/06/14 21:57:53 donut
21 ; Import of d1x 1.37 source.
23 ; Revision 1.17 1995/10/07 13:22:11 john
24 ; Added new method of reading joystick that allows higher-priority
25 ; interrupts to go off.
27 ; Revision 1.16 1995/03/30 11:03:30 john
28 ; Made -JoyBios read buttons using BIOS.
30 ; Revision 1.15 1995/02/14 11:39:36 john
31 ; Added polled/bios joystick readers..
33 ; Revision 1.14 1995/01/29 18:36:00 john
34 ; Made timer count in mode 2 instead of mode 3.
36 ; Revision 1.13 1994/12/28 15:32:21 john
37 ; Added code to read joystick axis not all at one time.
39 ; Revision 1.12 1994/12/27 15:44:59 john
40 ; Made the joystick timeout be at 1/100th of a second,
41 ; regardless of CPU speed.
43 ; Revision 1.11 1994/11/15 12:04:40 john
44 ; Cleaned up timer code a bit... took out unused functions
45 ; like timer_get_milliseconds, etc.
47 ; Revision 1.10 1994/07/01 10:55:54 john
48 ; Fixed some bugs... added support for 4 axis.
50 ; Revision 1.9 1994/06/30 20:36:54 john
51 ; Revamped joystick code.
53 ; Revision 1.8 1994/04/22 12:52:06 john
62 global _joy_bogus_reading
65 _joy_bogus_reading dd 0
77 xor al, al ; Latch timer 0 command
78 out TCOMMAND, al ; Latch timer
79 in al, TDATA ; Read lo byte
81 in al, TDATA ; Read hi byte
89 global _joy_read_stick_friendly2
90 _joy_read_stick_friendly2:
99 ; edi = pointer to event buffer
100 ; ecx = timeout value
101 ; returns in eax the number of events
103 mov dword [RetryCount], 0
104 mov dword [_joy_bogus_reading], 0
106 _joy_read_stick_friendly_retry:
107 inc dword [RetryCount]
108 cmp dword [RetryCount], 3
110 mov dword [_joy_bogus_reading], 1
111 inc dword [_joy_retries]
122 and ebx, 01111b ; Make sure we only check the right values
123 ; number of events we found will be in bh, so this also clears it to zero.
127 cli ; disable interrupts while reading time...
128 call joy_get_timer ; Returns counter in EAX
129 sti ; enable interrupts after reading time...
130 mov dword [LastTick], eax
132 waitforstable_f: in al, dx
134 jz ready_f ; Wait for the port in question to be done reading...
136 cli ; disable interrupts while reading time...
137 call joy_get_timer ; Returns counter in EAX
138 sti ; enable interrupts after reading time...
139 xchg eax, dword [LastTick]
140 cmp eax, dword [LastTick]
142 sub eax, dword [LastTick]
144 add dword [TotalTicks], eax
145 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
152 out dx, al ; Start joystick a readin'
154 call joy_get_timer ; Returns counter in EAX
155 mov dword [LastTick], eax
156 mov dword [TotalTicks], 0
158 mov [edi], eax ; Store initial count
161 again_f: in al, dx ; Read Joystick port
163 and al, bl ; Mask off channels we don't want to read
164 jnz flip_f ; See if any of the channels flipped
166 ; none flipped -- check any interrupts...
169 in al, 20h ; Get interrupts pending
173 ; Need to do an interrupt
175 nop ; let the interrupt go on...
178 ; See if any axis turned
184 ; At this point, an interrupt occured, making one or more
185 ; of the axis values bogus. So, we will restart this process...
191 jmp _joy_read_stick_friendly_retry
194 call joy_get_timer ; Returns counter in EAX
196 xchg eax, dword [LastTick]
197 cmp eax, dword [LastTick]
199 sub eax, dword [LastTick]
201 add dword [TotalTicks], eax
202 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
206 flip_f: and eax, 01111b ; Only care about axis values
207 mov [edi], eax ; Record what channel(s) flipped
209 xor bl, al ; Unmark the channels that just tripped
211 call joy_get_timer ; Returns counter in EAX
212 mov [edi], eax ; Record the time this channel flipped
214 inc bh ; Increment number of events
217 jne again_f ; If there are more channels to read, keep looping
222 movzx eax, bh ; Return number of events
234 global _joy_read_stick_asm2
236 _joy_read_stick_asm2:
245 ; edi = pointer to event buffer
246 ; ecx = timeout value
247 ; returns in eax the number of events
248 mov dword [_joy_bogus_reading], 0
250 and ebx, 01111b ; Make sure we only check the right values
251 ; number of events we found will be in bh, so this also clears it to zero.
255 cli ; disable interrupts while reading time...
256 call joy_get_timer ; Returns counter in EAX
257 sti ; enable interrupts after reading time...
258 mov dword [LastTick], eax
260 waitforstable: in al, dx
262 jz ready ; Wait for the port in question to be done reading...
264 cli ; disable interrupts while reading time...
265 call joy_get_timer ; Returns counter in EAX
266 sti ; enable interrupts after reading time...
267 xchg eax, dword [LastTick]
268 cmp eax, dword [LastTick]
270 sub eax, dword [LastTick]
272 add dword [TotalTicks], eax
273 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
280 out dx, al ; Start joystick a readin'
282 call joy_get_timer ; Returns counter in EAX
283 mov dword [LastTick], eax
284 mov dword [TotalTicks], 0
286 mov [edi], eax ; Store initial count
289 again: in al, dx ; Read Joystick port
291 and al, bl ; Mask off channels we don't want to read
292 jnz flip ; See if any of the channels flipped
294 call joy_get_timer ; Returns counter in EAX
296 xchg eax, dword [LastTick]
297 cmp eax, dword [LastTick]
299 sub eax, dword [LastTick]
301 add dword [TotalTicks], eax
302 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
306 flip: and eax, 01111b ; Only care about axis values
307 mov [edi], eax ; Record what channel(s) flipped
309 xor bl, al ; Unmark the channels that just tripped
311 call joy_get_timer ; Returns counter in EAX
312 mov [edi], eax ; Record the time this channel flipped
314 inc bh ; Increment number of events
317 jne again ; If there are more channels to read, keep looping
320 movzx eax, bh ; Return number of events
328 global _joy_read_stick_polled2
330 _joy_read_stick_polled2:
339 ; edi = pointer to event buffer
340 ; ecx = timeout value
341 ; returns in eax the number of events
342 mov dword [_joy_bogus_reading], 0
344 and ebx, 01111b ; Make sure we only check the right values
345 ; number of events we found will be in bh, so this also clears it to zero.
349 mov dword [TotalTicks], 0
351 waitforstable1: in al, dx
353 jz ready1 ; Wait for the port in question to be done reading...
355 inc dword [TotalTicks]
356 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
362 out dx, al ; Start joystick a readin'
364 mov dword [TotalTicks], 0
366 mov dword [edi], 0 ; Store initial count
369 again1: in al, dx ; Read Joystick port
371 and al, bl ; Mask off channels we don't want to read
372 jnz flip1 ; See if any of the channels flipped
374 inc dword [TotalTicks]
375 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
379 flip1: and eax, 01111b ; Only care about axis values
380 mov [edi], eax ; Record what channel(s) flipped
382 xor bl, al ; Unmark the channels that just tripped
384 mov eax, dword [TotalTicks]
385 mov [edi], eax ; Record the time this channel flipped
387 inc bh ; Increment number of events
390 jne again1 ; If there are more channels to read, keep looping
393 movzx eax, bh ; Return number of events
400 global _joy_read_stick_bios2
402 _joy_read_stick_bios2:
410 ; edi = pointer to event buffer
411 ; ecx = timeout value
412 ; returns in eax the number of events
414 mov dword [_joy_bogus_reading], 0
426 mov dword [edi+4], 1 ; Axis 1
428 mov [edi+8], eax ; Axis 1 value
430 mov dword [edi+12], 2 ; Axis 2
432 mov [edi+16], ebx ; Axis 2 value
434 mov dword [edi+20], 4 ; Axis 3
436 mov [edi+24], ecx ; Axis 3 value
438 mov dword [edi+28], 8 ; Axis 3
440 mov [edi+32], edx ; Axis 3 value
443 mov eax, 4 ; 4 events
450 global _joy_read_buttons_bios2
452 _joy_read_buttons_bios2:
453 ; returns in eax the button settings
459 mov edx, 0 ; Read switches
469 global _joy_read_buttons_bios_end2
470 _joy_read_buttons_bios_end2: ; to calculate _joy_read_buttons_bios size