` COMPUTE! ISSUE 56 / JANUARY 1985 / PAGE 10`

 Reading TI Joysticks I built the joystick adapter presented in "Readers' Feedback" of the August 1983 issue for my TI-99/4A and revised it as suggested in a later is­sue. I have several questions about the use of joysticks with the TI. First, how do you detect when the fire buttons are being pressed? And second, how do you achieve simultaneous joy­stick movement? Matt Phillips The fire buttons are detected with the CALL KEY statement on the TI. The format is: ```CALL KEY(unit, key, status) ``` where unit is 1 or 2 for the joystick number. When a fire button is pressed, KEY takes on a value of 18. Ordinarily the key value is 0. You can also detect firing with the STATUS variable. The STATUS variable can have a value of 0, —1, or +1 STATUS is 0 if the fire button is not pressed, —1 if the fire button is still being pressed since the last CALL KEY, and +1 if the fire button was not pressed at the last CALL KEY, but is presently being pressed. There's no such thing as true simultaneous joystick movement on the TI or any other computer. Instead, you create the illusion of simultaneity by alternately checking the joysticks very quickly. The following sample program demonstrates one method of doing this and also illustrates use of the fire but­ton. This program lets you move two figures around the screen with the joysticks. Joystick 1 moves a stick man figure, while joystick 2 moves a ball-shaped figure. Pressing the fire button changes the color of the respective figures. ```10 REM TWO JOYSTICK DEMO 20 CALL CHAR (47, "1818423C183C4242") 30 CALL CHAR (48, "003C7E7E7E7E7E3C") 40 X (1) = 15 50 Y (1) = 11 60 Y (2) = ll 70 X (2) = 17 80 C (1) = 13 90 C (2) = 14 100 CALL COLOR (2,C (1),1) 110 CALL COLOR (3,C (2),1) 120 CALL CLEAR 130 CALL SCREEN (15) 140 FOR I = 1 TO 2 150 CALL JOYST (I, DX, DY) 160 CALL KEY (I, K, S) 170 IF K< >18 THEN 200 180 C (I) = C (I) + 1 + (C(I) = 16) * 15 190 CALL COLOR (1 + 1, C (I), 1) 200 CALL HCHAR(Y(I)), X (I), 32) 210 X (I) = X (I) + DX/4 220 Y (I) = Y (I) - DY/4 230 X (I) = INT (32 * ((X (I) - l)/32 - INT ((X (I) - 1)/32))) + 1 240 Y (I) = INT (24 * ((Y (I) - l)/24 - INT ((Y (I) - 1)/24))) + 1 250 CALL HCHAR(Y (I), X (I) 46 + 1) 260 NEXT I 270 GOTO 140 ``` In this program, each joystick is checked for movement (line 150) and firing (line 160) within a FOR-NEXT loop. If a fire button is being pressed (K equals 18), the program executes a routine to change the color of the appropriate figure (lines 180–190). The old figures are then erased (line 200), new positions calculated (lines 230–240), and new figures drawn (line 250).