The beginning of the Poll function retrieves status information for the joystick buttons. Poll retrieves the button status information by reading address 0x201. (For a description of address 0x201, see the table in "IBM Game Control Adapter Interface," earlier in this chapter.) The button state information is in bits 7 through 4. Poll inverts the bits and stores the resulting value in the wButtons global variable.
The following example shows the portion of the Poll routine that retrieves the button status information :
cProc Poll <PUBLIC> <si, di>
parmW id
parmW zOnly
localW wClear
cBegin
mov dx,JOYPORT ; Set joystick port address
in al,dx ; Read the port
mov cl,4 ; Shift at least four bits
cmp id, 0 ; If second joystick, shift six bits
jz @f
add cl,2
@@:
shr al,cl ; Shift flags
and ax,3 ; Clear the other bits just in case
xor ax,3 ; Invert the bits (port gives reverse logic)
mov _wButtons,ax ; Save flags in global variable
.
. ; Sample continued in next section
.