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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
13 _DATA SEGMENT BYTE PUBLIC USE32 'DATA'
15 rcsid db "$Id: joy.asm,v 1.1.1.2 2001-01-19 03:33:50 bradleyb Exp $"
25 _TEXT SEGMENT BYTE PUBLIC USE32 'CODE'
35 xor al, al ; Latch timer 0 command
36 out TCOMMAND, al ; Latch timer
37 in al, TDATA ; Read lo byte
39 in al, TDATA ; Read hi byte
44 PUBLIC joy_read_stick_asm_
48 ; edi = pointer to event buffer
50 ; returns in eax the number of events
51 and ebx, 01111b ; Make sure we only check the right values
52 ; number of events we found will be in bh, so this also clears it to zero.
56 cli ; disable interrupts while reading time...
57 call joy_get_timer ; Returns counter in EAX
58 sti ; enable interrupts after reading time...
61 waitforstable: in al, dx
63 jz ready ; Wait for the port in question to be done reading...
65 cli ; disable interrupts while reading time...
66 call joy_get_timer ; Returns counter in EAX
67 sti ; enable interrupts after reading time...
74 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
81 out dx, al ; Start joystick a readin'
83 call joy_get_timer ; Returns counter in EAX
87 mov [edi], eax ; Store initial count
90 again: in al, dx ; Read Joystick port
92 and al, bl ; Mask off channels we don't want to read
93 jnz flip ; See if any of the channels flipped
95 call joy_get_timer ; Returns counter in EAX
103 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
107 flip: and eax, 01111b ; Only care about axis values
108 mov [edi], eax ; Record what channel(s) flipped
110 xor bl, al ; Unmark the channels that just tripped
112 call joy_get_timer ; Returns counter in EAX
113 mov [edi], eax ; Record the time this channel flipped
115 inc bh ; Increment number of events
118 jne again ; If there are more channels to read, keep looping
121 movzx eax, bh ; Return number of events
127 PUBLIC joy_read_stick_polled_
129 joy_read_stick_polled_:
131 ; edi = pointer to event buffer
132 ; ecx = timeout value
133 ; returns in eax the number of events
134 and ebx, 01111b ; Make sure we only check the right values
135 ; number of events we found will be in bh, so this also clears it to zero.
141 waitforstable1: in al, dx
143 jz ready1 ; Wait for the port in question to be done reading...
146 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
152 out dx, al ; Start joystick a readin'
156 mov dword ptr [edi], 0 ; Store initial count
159 again1: in al, dx ; Read Joystick port
161 and al, bl ; Mask off channels we don't want to read
162 jnz flip1 ; See if any of the channels flipped
165 cmp TotalTicks, ecx ; Timeout at 1/200'th of a second
169 flip1: and eax, 01111b ; Only care about axis values
170 mov [edi], eax ; Record what channel(s) flipped
172 xor bl, al ; Unmark the channels that just tripped
175 mov [edi], eax ; Record the time this channel flipped
177 inc bh ; Increment number of events
180 jne again1 ; If there are more channels to read, keep looping
183 movzx eax, bh ; Return number of events
188 PUBLIC joy_read_stick_bios_
190 joy_read_stick_bios_:
192 ; edi = pointer to event buffer
193 ; ecx = timeout value
194 ; returns in eax the number of events
198 mov dword ptr [edi], 0
206 mov dword ptr [edi+4], 1 ; Axis 1
208 mov [edi+8], eax ; Axis 1 value
210 mov dword ptr [edi+12], 2 ; Axis 2
212 mov [edi+16], ebx ; Axis 2 value
214 mov dword ptr [edi+20], 4 ; Axis 3
216 mov [edi+24], ecx ; Axis 3 value
218 mov dword ptr [edi+28], 8 ; Axis 3
220 mov [edi+32], edx ; Axis 3 value
223 mov eax, 4 ; 4 events
228 PUBLIC joy_read_buttons_bios_
230 joy_read_buttons_bios_:
231 ; returns in eax the button settings
237 mov edx, 0 ; Read switches