2

The Color BASIC/Extended Color BASIC “Getting Started” manuals say that to find out if a joystick button is pressed, to PEEK in location 65280. The value 255 means neither button is pressed; the values 126 or 254 correspond to the right joystick’s button; and 125 or 253 to the left joystick’s button.

While looking at the button values, I noticed that when both buttons are pressed, I see 252 in 65280. This made me think that perhaps each button press is changing a single bit in the binary value at 65280:

126  01111110 (right button)
254  11111110 (right button)
125  01111101 (left button)
253  11111101 (left button)
252  11111100 (both buttons)
255  11111111 (no button)

It appears that the right button is indicated by a zero in position 1, and the left button by a zero in position 2.

Is this correct? Is it (as) reliable to check those bits as to check for the numbers, so that I might use, say, the following code to know whether the joystick buttons are pressed?

5 CLS
10 BU = PEEK(65280)
20 PRINT@0,"RIGHT BUTTON ";
30 IF (1 AND NOT BU)=1 THEN PRINT "ON" ELSE PRINT "OFF"
40 PRINT@32,"LEFT BUTTON ";
50 IF (2 AND NOT BU)=2 THEN PRINT "ON" ELSE PRINT "OFF"
60 GOTO 10

Obviously, a lot more numbers than just 125, 126, 253, and 254 (and presumably 124 or 252 for both buttons at the same time) will match those conditions. Is it correct to assume that it is the bit that matters and not the full number when checking the joystick buttons?

4
  • Confused. Are you referring to a TRS-80 ( my initial thought) or another system like the TI-99/4A etc ? Could you perhaps edit your question to add system information please. Thanks :)
    – AndyF
    Feb 13, 2020 at 22:02
  • 1
    The TRS-80. I’ve updated the title so that people don’t have to look at the tags. Feb 13, 2020 at 22:04
  • 1
    Thank you. The tags (to me) did not indicate the system specified though hence me asking kindly for clarity.
    – AndyF
    Feb 13, 2020 at 22:07
  • Related but not duplicate: Why did pressing the joystick button spit out keypresses?
    – DrSheldon
    Feb 15, 2020 at 7:18

1 Answer 1

4

Address 65280 (Hex &FF00) is the I/O port on the CoCo for the joystick and the keyboard row input. It is the case that the lower 2 bits are assigned to the left and right joystick buttons. Bit 7 is associated with the joystick direction, which is why it can be either 0 OR 1 while a button is pressed. So, your proposed approach is correct.

3
  • Usually it is the best not assuming things and checking for bits. You never know when a new model or some hw model might use a different bit, or have an extra button and messes up routines using integers. Feb 14, 2020 at 13:00
  • Where can I learn more about bit 7? Or is it appropriate to explain it further in your answer? Feb 14, 2020 at 15:57
  • @JerryStratton If you're Ok with "C" code, you can look at the implementation of a joystick interface for the CoCo in the "BControl" project for CMOC
    – Brian H
    Feb 14, 2020 at 22:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .