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?