1 ; THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
\r
2 ; SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
\r
3 ; END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
\r
4 ; ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
\r
5 ; IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
\r
6 ; SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
\r
7 ; FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
\r
8 ; CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
\r
9 ; AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
\r
10 ; COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
\r
13 _DATA SEGMENT BYTE PUBLIC USE32 'DATA'
\r
15 rcsid db "$Id: joy.asm,v 1.1.1.1 2001-01-19 03:30:14 bradleyb Exp $"
\r
25 _TEXT SEGMENT BYTE PUBLIC USE32 'CODE'
\r
35 xor al, al ; Latch timer 0 command
\r
36 out TCOMMAND, al ; Latch timer
\r
37 in al, TDATA ; Read lo byte
\r
39 in al, TDATA ; Read hi byte
\r
44 PUBLIC joy_read_stick_asm_
\r
46 joy_read_stick_asm_:
\r
48 ; edi = pointer to event buffer
\r
49 ; ecx = timeout value
\r
50 ; returns in eax the number of events
\r
51 and ebx, 01111b ; Make sure we only check the right values
\r
52 ; number of events we found will be in bh, so this also clears it to zero.
\r
56 cli ; disable interrupts while reading time...
\r
57 call joy_get_timer ; Returns counter in EAX
\r
58 sti ; enable interrupts after reading time...
\r
61 waitforstable: in al, dx
\r
63 jz ready ; Wait for the port in question to be done reading...
\r
65 cli ; disable interrupts while reading time...
\r
66 call joy_get_timer ; Returns counter in EAX
\r
67 sti ; enable interrupts after reading time...
\r
74 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
\r
81 out dx, al ; Start joystick a readin'
\r
83 call joy_get_timer ; Returns counter in EAX
\r
87 mov [edi], eax ; Store initial count
\r
90 again: in al, dx ; Read Joystick port
\r
92 and al, bl ; Mask off channels we don't want to read
\r
93 jnz flip ; See if any of the channels flipped
\r
95 call joy_get_timer ; Returns counter in EAX
\r
102 add TotalTicks, eax
\r
103 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
\r
107 flip: and eax, 01111b ; Only care about axis values
\r
108 mov [edi], eax ; Record what channel(s) flipped
\r
110 xor bl, al ; Unmark the channels that just tripped
\r
112 call joy_get_timer ; Returns counter in EAX
\r
113 mov [edi], eax ; Record the time this channel flipped
\r
115 inc bh ; Increment number of events
\r
118 jne again ; If there are more channels to read, keep looping
\r
121 movzx eax, bh ; Return number of events
\r
127 PUBLIC joy_read_stick_polled_
\r
129 joy_read_stick_polled_:
\r
131 ; edi = pointer to event buffer
\r
132 ; ecx = timeout value
\r
133 ; returns in eax the number of events
\r
134 and ebx, 01111b ; Make sure we only check the right values
\r
135 ; number of events we found will be in bh, so this also clears it to zero.
\r
141 waitforstable1: in al, dx
\r
143 jz ready1 ; Wait for the port in question to be done reading...
\r
146 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
\r
152 out dx, al ; Start joystick a readin'
\r
156 mov dword ptr [edi], 0 ; Store initial count
\r
159 again1: in al, dx ; Read Joystick port
\r
161 and al, bl ; Mask off channels we don't want to read
\r
162 jnz flip1 ; See if any of the channels flipped
\r
165 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
\r
169 flip1: and eax, 01111b ; Only care about axis values
\r
170 mov [edi], eax ; Record what channel(s) flipped
\r
172 xor bl, al ; Unmark the channels that just tripped
\r
174 mov eax, TotalTicks
\r
175 mov [edi], eax ; Record the time this channel flipped
\r
177 inc bh ; Increment number of events
\r
180 jne again1 ; If there are more channels to read, keep looping
\r
183 movzx eax, bh ; Return number of events
\r
188 PUBLIC joy_read_stick_bios_
\r
190 joy_read_stick_bios_:
\r
192 ; edi = pointer to event buffer
\r
193 ; ecx = timeout value
\r
194 ; returns in eax the number of events
\r
198 mov dword ptr [edi], 0
\r
206 mov dword ptr [edi+4], 1 ; Axis 1
\r
208 mov [edi+8], eax ; Axis 1 value
\r
210 mov dword ptr [edi+12], 2 ; Axis 2
\r
212 mov [edi+16], ebx ; Axis 2 value
\r
214 mov dword ptr [edi+20], 4 ; Axis 3
\r
216 mov [edi+24], ecx ; Axis 3 value
\r
218 mov dword ptr [edi+28], 8 ; Axis 3
\r
220 mov [edi+32], edx ; Axis 3 value
\r
223 mov eax, 4 ; 4 events
\r
228 PUBLIC joy_read_buttons_bios_
\r
230 joy_read_buttons_bios_:
\r
231 ; returns in eax the button settings
\r
237 mov edx, 0 ; Read switches
\r