Peripheral Information

What To Do If You Don't Have Joysticks

Steven Schulman

Use of joysticks with the ATARI computer can add excitement to your programs. But what do you do if you don't have joysticks yet and aren't ready to buy them? Are you out of luck? Do you have to type in numbers to select from a menu of answers? Does it mean you can't use games like IRIDIS' ZAP or the latest from your computing magazines? No! There's another way.

We can look in amongst the bits and bytes that make up the memory of your ATARI. Any time you press a key on your keyboard, the value of the 764th word changes. By taking a PEEK at what number is there you can find out which key it was. Listing I shows you how to find out what the value will he when any key is pressed. Try running it and pressing different keys, shifted and unshifted, reverse video, etc. When you finish, use the BREAK key to stop the program.

"How does this help solve my problem of not having joysticks?" you may ask. To see this you have to know what happens when you use the joysticks. If your program has a line I = STICK(1), the value of I will he one of 9 possible values depending on the position of the joystick when that line is reached. The values will be where the value of I = 15 means that the joystick is in the upright position. In addition, J = STRIG(1) will have a value J = 0 if the fire button is pressed and a value of J = 1 if the fire button is not pressed.

Returning to what we know about the value of the last key pressed, we found that the values for the arrows were:

[up-arrow] = 14
[down-arrow] = 15
[right-arrow] = 7
[left-arrow] = 6

and the values for the shifted arrows were

Shift-[up-arrow] = 78
Shift-[down-arrow] = 71
Shift-[right-arrow] = 79
Shift-[left-arrow] = 70

Finally, the value for the space bar is 33.

We can therefore have the same results as we would get from using a joystick by using the arrows, shift arrows and space bar. The space bar will be our firing button, the arrows will be the obvious up, down, left and right, and the shift up will be to the upper left, the shift down will be to the upper right, the shift left will be to the lower left, and the shift right will be to the lower right. Any other key, or no key at all, being pressed is equal to the joysticks being in an upright position.

The routine in listing II will play the part of a joystick. After calling the subroutine the value of I will he the same as would have been returned by I = STICK(1) and the value of J will he the same as what would have been returned by J = STRIG(1). When you do buy your joysticks, simply replace the subroutine call and remove the subroutine from your program. Happy computing!

Listing 1: Print value of key pressed

Listing 2: Use keyboard for joystick control