]> icculus.org git repositories - btb/d2x.git/blob - unused/bios/joy.asm
remove rcs tags
[btb/d2x.git] / unused / bios / joy.asm
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.
11 .386
12
13 _DATA   SEGMENT BYTE PUBLIC USE32 'DATA'
14
15         LastTick        dd      0
16         TotalTicks      dd      0
17         
18 _DATA   ENDS
19
20 DGROUP  GROUP _DATA
21
22
23 _TEXT   SEGMENT BYTE PUBLIC USE32 'CODE'
24
25         ASSUME  ds:_DATA
26         ASSUME  cs:_TEXT
27
28         JOY_PORT        EQU     0201h
29         TDATA           EQU     40h
30         TCOMMAND        EQU     43h
31
32 joy_get_timer:
33         xor     al, al                  ; Latch timer 0 command
34         out     TCOMMAND, al            ; Latch timer
35         in      al, TDATA               ; Read lo byte
36         mov     ah, al
37         in      al, TDATA               ; Read hi byte
38         xchg    ah, al
39         and     eax, 0ffffh
40         ret     
41
42 PUBLIC joy_read_stick_asm_
43
44 joy_read_stick_asm_:    
45                 ; ebx = read mask
46                 ; edi = pointer to event buffer
47                 ; ecx = timeout value
48                 ; returns in eax the number of events
49                 and     ebx, 01111b             ; Make sure we only check the right values                                                                              
50                                                 ; number of events we found will be in bh, so this also clears it to zero.
51
52                 mov     dx, JOY_PORT
53
54                 cli                             ; disable interrupts while reading time...
55                 call    joy_get_timer           ; Returns counter in EAX
56                 sti                             ; enable interrupts after reading time...
57                 mov     LastTick, eax
58
59 waitforstable:  in      al, dx
60                 and     al, bl
61                 jz      ready                   ; Wait for the port in question to be done reading...
62                 
63                 cli                             ; disable interrupts while reading time...
64                 call    joy_get_timer           ; Returns counter in EAX
65                 sti                             ; enable interrupts after reading time...
66                 xchg    eax, LastTick
67                 cmp     eax, LastTick
68                 jb      @f
69                 sub     eax, LastTick
70 @@:             ; Higher...
71                 add     TotalTicks, eax
72                 cmp     TotalTicks, ecx         ; Timeout at 1/200'th of a second
73                 jae     ready
74                 jmp     waitforstable
75                 
76 ready:
77                 cli
78                 mov     al, 0ffh
79                 out     dx, al                  ; Start joystick a readin'
80
81                 call    joy_get_timer           ; Returns counter in EAX
82                 mov     LastTick, eax
83                 mov     TotalTicks, 0
84                 
85                 mov     [edi], eax              ; Store initial count
86                 add     edi, 4          
87
88         again:  in      al, dx                  ; Read Joystick port
89                 not     al
90                 and     al, bl                  ; Mask off channels we don't want to read
91                 jnz     flip                    ; See if any of the channels flipped
92
93                 call    joy_get_timer           ; Returns counter in EAX
94                 
95                 xchg    eax, LastTick
96                 cmp     eax, LastTick
97                 jb      @f
98                 sub     eax, LastTick
99 @@:             ; Higher...
100                 add     TotalTicks, eax
101                 cmp     TotalTicks, ecx         ; Timeout at 1/200'th of a second
102                 jae     timedout
103                 jmp     again
104
105         flip:   and     eax, 01111b             ; Only care about axis values
106                 mov     [edi], eax              ; Record what channel(s) flipped
107                 add     edi, 4  
108                 xor     bl, al                  ; Unmark the channels that just tripped
109
110                 call    joy_get_timer           ; Returns counter in EAX
111                 mov     [edi], eax              ; Record the time this channel flipped
112                 add     edi, 4          
113                 inc     bh                      ; Increment number of events
114
115                 cmp     bl, 0   
116                 jne     again                   ; If there are more channels to read, keep looping
117
118         timedout:
119                 movzx   eax, bh                 ; Return number of events
120
121                 sti
122                 ret
123
124
125 PUBLIC joy_read_stick_polled_
126
127 joy_read_stick_polled_: 
128                 ; ebx = read mask
129                 ; edi = pointer to event buffer
130                 ; ecx = timeout value
131                 ; returns in eax the number of events
132                 and     ebx, 01111b             ; Make sure we only check the right values                                                                              
133                                                 ; number of events we found will be in bh, so this also clears it to zero.
134
135                 mov     dx, JOY_PORT
136
137                 mov     TotalTicks, 0
138
139 waitforstable1: in      al, dx
140                 and     al, bl
141                 jz      ready1                  ; Wait for the port in question to be done reading...
142                 
143                 inc     TotalTicks
144                 cmp     TotalTicks, ecx         ; Timeout at 1/200'th of a second
145                 jae     ready1
146                 jmp     waitforstable1
147 ready1:
148                 cli
149                 mov     al, 0ffh
150                 out     dx, al                  ; Start joystick a readin'
151
152                 mov     TotalTicks, 0
153
154                 mov     dword ptr [edi], 0              ; Store initial count
155                 add     edi, 4          
156
157         again1: in      al, dx                  ; Read Joystick port
158                 not     al
159                 and     al, bl                  ; Mask off channels we don't want to read
160                 jnz     flip1                   ; See if any of the channels flipped
161
162                 inc     TotalTicks
163                 cmp     TotalTicks, ecx         ; Timeout at 1/200'th of a second
164                 jae     timedout1
165                 jmp     again1
166
167         flip1:  and     eax, 01111b             ; Only care about axis values
168                 mov     [edi], eax              ; Record what channel(s) flipped
169                 add     edi, 4  
170                 xor     bl, al                  ; Unmark the channels that just tripped
171
172                 mov     eax, TotalTicks
173                 mov     [edi], eax              ; Record the time this channel flipped
174                 add     edi, 4          
175                 inc     bh                      ; Increment number of events
176
177                 cmp     bl, 0   
178                 jne     again1                  ; If there are more channels to read, keep looping
179
180         timedout1:
181                 movzx   eax, bh                 ; Return number of events
182
183                 sti
184                 ret
185
186 PUBLIC joy_read_stick_bios_
187
188 joy_read_stick_bios_:   
189                 ; ebx = read mask
190                 ; edi = pointer to event buffer
191                 ; ecx = timeout value
192                 ; returns in eax the number of events
193                 
194                 pusha
195
196                 mov     dword ptr [edi], 0
197                         
198                 mov     eax, 08400h
199                 mov     edx, 1
200                 cli
201                 int     15h
202                 sti
203         
204                 mov     dword ptr [edi+4], 1    ;       Axis 1          
205                 and     eax, 0ffffh
206                 mov     [edi+8], eax            ;       Axis 1 value
207
208                 mov     dword ptr [edi+12], 2   ;       Axis 2
209                 and     ebx, 0ffffh
210                 mov     [edi+16], ebx           ;       Axis 2 value
211
212                 mov     dword ptr [edi+20], 4   ;       Axis 3
213                 and     ecx, 0ffffh
214                 mov     [edi+24], ecx           ;       Axis 3 value
215
216                 mov     dword ptr [edi+28], 8   ;       Axis 3
217                 and     edx, 0ffffh
218                 mov     [edi+32], edx           ;       Axis 3 value
219
220                 popa
221                 mov     eax, 4                  ; 4 events
222
223                 ret
224
225
226 PUBLIC joy_read_buttons_bios_
227
228 joy_read_buttons_bios_: 
229                 ; returns in eax the button settings
230                 
231                 push    ebx
232                 push    ecx
233                 push    edx
234                 mov     eax, 08400h
235                 mov     edx, 0  ; Read switches
236                 int     15h
237                 pop     edx
238                 pop     ecx
239                 pop     ebx
240                 
241                 shr     eax, 4
242                 not     eax
243                 and     eax, 01111b
244                 ret
245
246
247 _TEXT   ENDS
248
249
250                 END