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.
13 ; Contains routines for joystick interface.
23 global _joy_bogus_reading
26 _joy_bogus_reading dd 0
38 xor al, al ; Latch timer 0 command
39 out TCOMMAND, al ; Latch timer
40 in al, TDATA ; Read lo byte
42 in al, TDATA ; Read hi byte
50 global _joy_read_stick_friendly2
51 _joy_read_stick_friendly2:
60 ; edi = pointer to event buffer
62 ; returns in eax the number of events
64 mov dword [RetryCount], 0
65 mov dword [_joy_bogus_reading], 0
67 _joy_read_stick_friendly_retry:
68 inc dword [RetryCount]
69 cmp dword [RetryCount], 3
71 mov dword [_joy_bogus_reading], 1
72 inc dword [_joy_retries]
83 and ebx, 01111b ; Make sure we only check the right values
84 ; number of events we found will be in bh, so this also clears it to zero.
88 cli ; disable interrupts while reading time...
89 call joy_get_timer ; Returns counter in EAX
90 sti ; enable interrupts after reading time...
91 mov dword [LastTick], eax
93 waitforstable_f: in al, dx
95 jz ready_f ; Wait for the port in question to be done reading...
97 cli ; disable interrupts while reading time...
98 call joy_get_timer ; Returns counter in EAX
99 sti ; enable interrupts after reading time...
100 xchg eax, dword [LastTick]
101 cmp eax, dword [LastTick]
103 sub eax, dword [LastTick]
105 add dword [TotalTicks], eax
106 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
113 out dx, al ; Start joystick a readin'
115 call joy_get_timer ; Returns counter in EAX
116 mov dword [LastTick], eax
117 mov dword [TotalTicks], 0
119 mov [edi], eax ; Store initial count
122 again_f: in al, dx ; Read Joystick port
124 and al, bl ; Mask off channels we don't want to read
125 jnz flip_f ; See if any of the channels flipped
127 ; none flipped -- check any interrupts...
130 in al, 20h ; Get interrupts pending
134 ; Need to do an interrupt
136 nop ; let the interrupt go on...
139 ; See if any axis turned
145 ; At this point, an interrupt occured, making one or more
146 ; of the axis values bogus. So, we will restart this process...
152 jmp _joy_read_stick_friendly_retry
155 call joy_get_timer ; Returns counter in EAX
157 xchg eax, dword [LastTick]
158 cmp eax, dword [LastTick]
160 sub eax, dword [LastTick]
162 add dword [TotalTicks], eax
163 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
167 flip_f: and eax, 01111b ; Only care about axis values
168 mov [edi], eax ; Record what channel(s) flipped
170 xor bl, al ; Unmark the channels that just tripped
172 call joy_get_timer ; Returns counter in EAX
173 mov [edi], eax ; Record the time this channel flipped
175 inc bh ; Increment number of events
178 jne again_f ; If there are more channels to read, keep looping
183 movzx eax, bh ; Return number of events
195 global _joy_read_stick_asm2
197 _joy_read_stick_asm2:
206 ; edi = pointer to event buffer
207 ; ecx = timeout value
208 ; returns in eax the number of events
209 mov dword [_joy_bogus_reading], 0
211 and ebx, 01111b ; Make sure we only check the right values
212 ; number of events we found will be in bh, so this also clears it to zero.
216 cli ; disable interrupts while reading time...
217 call joy_get_timer ; Returns counter in EAX
218 sti ; enable interrupts after reading time...
219 mov dword [LastTick], eax
221 waitforstable: in al, dx
223 jz ready ; Wait for the port in question to be done reading...
225 cli ; disable interrupts while reading time...
226 call joy_get_timer ; Returns counter in EAX
227 sti ; enable interrupts after reading time...
228 xchg eax, dword [LastTick]
229 cmp eax, dword [LastTick]
231 sub eax, dword [LastTick]
233 add dword [TotalTicks], eax
234 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
241 out dx, al ; Start joystick a readin'
243 call joy_get_timer ; Returns counter in EAX
244 mov dword [LastTick], eax
245 mov dword [TotalTicks], 0
247 mov [edi], eax ; Store initial count
250 again: in al, dx ; Read Joystick port
252 and al, bl ; Mask off channels we don't want to read
253 jnz flip ; See if any of the channels flipped
255 call joy_get_timer ; Returns counter in EAX
257 xchg eax, dword [LastTick]
258 cmp eax, dword [LastTick]
260 sub eax, dword [LastTick]
262 add dword [TotalTicks], eax
263 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
267 flip: and eax, 01111b ; Only care about axis values
268 mov [edi], eax ; Record what channel(s) flipped
270 xor bl, al ; Unmark the channels that just tripped
272 call joy_get_timer ; Returns counter in EAX
273 mov [edi], eax ; Record the time this channel flipped
275 inc bh ; Increment number of events
278 jne again ; If there are more channels to read, keep looping
281 movzx eax, bh ; Return number of events
289 global _joy_read_stick_polled2
291 _joy_read_stick_polled2:
300 ; edi = pointer to event buffer
301 ; ecx = timeout value
302 ; returns in eax the number of events
303 mov dword [_joy_bogus_reading], 0
305 and ebx, 01111b ; Make sure we only check the right values
306 ; number of events we found will be in bh, so this also clears it to zero.
310 mov dword [TotalTicks], 0
312 waitforstable1: in al, dx
314 jz ready1 ; Wait for the port in question to be done reading...
316 inc dword [TotalTicks]
317 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
323 out dx, al ; Start joystick a readin'
325 mov dword [TotalTicks], 0
327 mov dword [edi], 0 ; Store initial count
330 again1: in al, dx ; Read Joystick port
332 and al, bl ; Mask off channels we don't want to read
333 jnz flip1 ; See if any of the channels flipped
335 inc dword [TotalTicks]
336 cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second
340 flip1: and eax, 01111b ; Only care about axis values
341 mov [edi], eax ; Record what channel(s) flipped
343 xor bl, al ; Unmark the channels that just tripped
345 mov eax, dword [TotalTicks]
346 mov [edi], eax ; Record the time this channel flipped
348 inc bh ; Increment number of events
351 jne again1 ; If there are more channels to read, keep looping
354 movzx eax, bh ; Return number of events
361 global _joy_read_stick_bios2
363 _joy_read_stick_bios2:
371 ; edi = pointer to event buffer
372 ; ecx = timeout value
373 ; returns in eax the number of events
375 mov dword [_joy_bogus_reading], 0
387 mov dword [edi+4], 1 ; Axis 1
389 mov [edi+8], eax ; Axis 1 value
391 mov dword [edi+12], 2 ; Axis 2
393 mov [edi+16], ebx ; Axis 2 value
395 mov dword [edi+20], 4 ; Axis 3
397 mov [edi+24], ecx ; Axis 3 value
399 mov dword [edi+28], 8 ; Axis 3
401 mov [edi+32], edx ; Axis 3 value
404 mov eax, 4 ; 4 events
411 global _joy_read_buttons_bios2
413 _joy_read_buttons_bios2:
414 ; returns in eax the button settings
420 mov edx, 0 ; Read switches
430 global _joy_read_buttons_bios_end2
431 _joy_read_buttons_bios_end2: ; to calculate _joy_read_buttons_bios size