1 ;****************************************************************************
3 ;* SciTech OS Portability Manager Library
5 ;* ========================================================================
7 ;* The contents of this file are subject to the SciTech MGL Public
8 ;* License Version 1.0 (the "License"); you may not use this file
9 ;* except in compliance with the License. You may obtain a copy of
10 ;* the License at http://www.scitechsoft.com/mgl-license.txt
12 ;* Software distributed under the License is distributed on an
13 ;* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 ;* implied. See the License for the specific language governing
15 ;* rights and limitations under the License.
17 ;* The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 ;* The Initial Developer of the Original Code is SciTech Software, Inc.
20 ;* All Rights Reserved.
22 ;* ========================================================================
24 ;* Language: 80386 Assembler
25 ;* Environment: Intel x86, any OS
27 ;* Description: Assembly language support routines for reading analogue
30 ;****************************************************************************
34 include "scitech.mac" ; Memory model macros
38 header _joy ; Set up memory model
40 begcodeseg _joy ; Start of code segment
42 ;----------------------------------------------------------------------------
44 ;----------------------------------------------------------------------------
45 ; Sets up 8253 timer 2 (PC speaker) to start timing, but not produce output.
46 ;----------------------------------------------------------------------------
49 ; Start timer 2 counting
52 and al,0FDh ; Disable speaker output (just in case)
56 ; Set the timer 2 count to 0 again to start the timing interval.
58 mov al,10110100b ; set up to load initial (timer 2)
59 out 43h,al ; timer count
61 out 42h,al ; load count lsb
62 out 42h,al ; load count msb
67 ;----------------------------------------------------------------------------
69 ;----------------------------------------------------------------------------
70 ; Reads the number of ticks from the 8253 timer chip using channel 2 (PC
71 ; speaker). This is non-destructive and does not screw up other libraries.
72 ;----------------------------------------------------------------------------
75 xor al,al ; Latch timer 0 command
76 out 43h,al ; Latch timer
77 in al,42h ; least significant byte
79 in al,42h ; most significant byte
86 ;----------------------------------------------------------------------------
88 ;----------------------------------------------------------------------------
89 ; Stops the 8253 timer 2 (PC speaker) counting
90 ;----------------------------------------------------------------------------
93 ; Stop timer 2 from counting
100 ; Some programs have a problem if we change the control port; better change it
101 ; to something they expect (mode 3 - square wave generator)...
110 ;----------------------------------------------------------------------------
111 ; int _EVT_readJoyAxis(int jmask,int *axis);
112 ;----------------------------------------------------------------------------
113 ; Function to poll the joystick to read the current axis positions.
114 ;----------------------------------------------------------------------------
115 cprocstart _EVT_readJoyAxis
117 ARG jmask:UINT, axis:DPTR
119 LOCAL firstTick:UINT, lastTick:UINT, totalTicks:UINT = LocalSize
125 mov ecx,(1193180/100)
126 and ebx,01111b ; Mask out supported axes
127 mov dx,201h ; DX := joystick I/O port
128 call initTimer ; Start timer 2 counting
129 call readTimer ; Returns counter in EAX
134 and al,bl ; Wait for the axes in question to be
135 jz @@Stable ; done reading...
136 call readTimer ; Returns counter in EAX
141 @@1: add [totalTicks],eax
142 cmp [totalTicks],ecx ; Check for timeout
148 out dx,al ; Start joystick reading
149 call initTimer ; Start timer 2 counting
150 call readTimer ; Returns counter in EAX
151 mov [firstTick],eax ; Store initial count
153 mov [DWORD totalTicks],0
157 in al,dx ; Read Joystick port
159 and al,bl ; Mask off channels we don't want to read
160 jnz @@AxisFlipped ; See if any of the channels flipped
161 call readTimer ; Returns counter in EAX
166 @@2: add [totalTicks],eax
167 cmp [totalTicks],ecx ; Check for timeout
175 jnz @@StoreCount ; Joystick 1, X axis flipped
179 jnz @@StoreCount ; Joystick 1, Y axis flipped
183 jnz @@StoreCount ; Joystick 2, X axis flipped
184 add esi,4 ; Joystick 2, Y axis flipped
188 or bh,ah ; Indicate this axis is active
189 xor bl,ah ; Unmark the channels that just tripped
190 call readTimer ; Returns counter in EAX
195 @@3: add [totalTicks],eax
197 mov [edi+esi],eax ; Record the time this channel flipped
198 cmp bl,0 ; If there are more channels to read,
199 jne @@PollLoop ; keep looping
203 call exitTimer ; Stop timer 2 counting
204 movzx eax,bh ; Return the mask of working axes
210 ;----------------------------------------------------------------------------
211 ; int _EVT_readJoyButtons(void);
212 ;----------------------------------------------------------------------------
213 ; Function to poll the current joystick buttons
214 ;----------------------------------------------------------------------------
215 cprocstart _EVT_readJoyButtons