 COMPUTE! ISSUE 50 / JULY 1984 / PAGE 6

 Joystick To Keyboard Control On The TI Many of your TI-99/4A games require a joystick. Unfortunately, I don't own one. Could you provide a routine that would enable me to convert these programs to keyboard control? Mike Burgin Several approaches can be taken to convert a program from joystick to keyboard control on the TI. Probably the simplest approach, in console BASIC, is to GOSUB to a keyboard subroutine whenever the JOYST subprogram is CALLed. You should locate this keyboard subroutine at the beginning of the program, to speed execution. Let's put such a subroutine at line 10. The entire routine will occupy four lines beginning at line 10, so RESequence your program to begin at line 50. Next, find where the subprogram JOYST is CALLed within the program. The general form for this statement is CALL JOYST (n,X,Y). Here, n refers to the joystick number (either 1 or 2) while X and Y are values returned based on the joystick position. X and Y may be represented by any legitimate numerical variable name. Note the variable names used for X and Y in the CALL JOYST statement and then replace this statement with GOSUB 10. Then, type in the following lines: 5 GOTO 50 10 CALL KEY(0, K, SS) 20 X = ((K = 67) + (K = 68) + (K = 82)) * -4 + ((K = 83) + (K = 87) + (K = 90)) * 4 30 Y = ((K = 69) + (K = 82) + (K=87)) * - 4 + ((K = 67) + (K = 88) + (K = 90)) * 4 40 RETURN Now, substitute the variable names from the CALL JOYST statement into the above subroutine for X and Y. Also, if K and SS are used in the main program, you may need to name them differently here. Just as with the CALL JOYST statement, X and Y will be returned as -4, 0, or +4 in lines 20 and 30. The standard arrow keys (E, S, D, and X) are tested for in this routine along with W, R, Z, and C for diagonal movement. Providing a routine for keyboard control in Extended BASIC is even easier. Since we can write our own subprogram (using SUB), we no longer need worry about the variable names for X and Y in the main program. Variables used in a subprogram are local to that subprogram. Our subprogram, which we'll call JOY, must be placed at the end of the program. Assuming there's room above line 999, type in the following: 1000 SUB JOY (Z, X, Y) 1102 X = ((K = 67) + (K = 68) + (K = 82)) * - 4 + ((K = 83) + (K = 87) + (K = 90) ) * 4 1030 Y = ((K + 69) + (K = 82) + (K = 87)) * -4 + ((K = 67) + (K = 88) + (K = 90) * 4 1040 SUBEND Next, in the main program, change CALL JOYST(n,X,Y) to CALL JOY(n,X,Y) so that our keyboard subprogram will be CALLed rather than the system joystick subprogram (n is 1 or 2). Last, for either console or Extended BASIC, check to see if the fire button is used. You should find a statement of the form CALL KEY(n,K,S) in the program (n is 1 or 2). Shortly thereafter in the program, a check for the value of K will be made. If K is equal to 18, then the fire button has been pressed. With keyboard control, we can use the space bar rather than the fire button. Change n (which is 1 or 2) to 0 in the appropriate CALL KEY(n,K,S) statement. Also, change 18 to 32 in the subsequent check for the value of K.