Classic Computer Magazine Archive COMPUTE! ISSUE 57 / FEBRUARY 1985 / PAGE 10

Apple Joystick To Keys Conversion
I use an Apple II+ for games and educational programming, and would like to change games which require a paddle to keyboard input. How can I do this?
Michael Weaver

Applesoft BASIC has a very handy statement (PDL) for reading the value of the game controller, and you can also read the keyboard buffer to see which key is being pressed (although it's not as handy). The GET statement can read the keyboard, too, but it halts the program while waiting for input.
    To convert a program from using a game controller to the keyboard, find all the routines which read PDL, then change those routines to read the keyboard buffer instead. Try using this subroutine:

10 A = PEEK ( - 16384)
20 B = PEEK ( - 16368)
40 IF A < 128 THEN 10
50 D = A - 128
60 IF D = 65 THEN PRINT "RIGHT"
70 IF D = 68 THEN PRINT "LEFT"
80 IF D = 87 THEN PRINT "UP"
90 IF D = 88 THEN PRINT "DOWN"
100 IF D = 32 THEN PRINT "FIRE!"
110 GOTO 10

    This checks for the ASCII values of the A, D, W X, and space bar, and ignores all other keys. Line 10 reads the keyboard and line 20 resets the keyboard to await the next keypress. Line 40 evaluates A to see if a key was pressed. I f bit 7 is set (the value of A is greater that 128), then a key was pressed. Line 50 translates the value of A to an ASCII value, and lines 60 through 110 evaluate the key pressed. Of course, these lines could be changed to read any keys, and values could be included to check for diagonal movement (the Q, E, C, and Z keys).
    Be advised, however, that Apple paddles are resistive, so they return numeric variables that do not correspond directly. to directions. The keyboard routine presented above provides for reading directions and is thus not a perfect replacement for an Apple paddle.