VIC-20 C64 C16 Plus/4 C128 X16 M65
The JOY()
function returns the status of either joysticks.
DECLARE FUNCTION JOY AS BYTE (portnum AS BYTE) SHARED STATIC INLINE
Where portnum is an expression that evaluates to 1 or 2.
Note
On the Commodore VIC-20, portnum is ignored.
The return value is a BYTE where bits corresponding to a direction are set or unset. The direction to bit mapping if different on each target:
Using the following example, you can read the joystick status on all platforms:
' Uncomment if target is VIC-20 'CONST JOYUP = 4 'CONST JOYDN = 8 'CONST JOYLT = 16 'CONST JOYRT = 128 'CONST J1FIRE = 32 ' Uncomment if target is C64 'CONST JOYUP = 1 'CONST JOYDN = 2 'CONST JOYLT = 4 'CONST JOYRT = 8 'CONST J1FIRE = 16 'CONST J2FIRE = 16 ' Uncomment if target is C16 or C Plus/4 'CONST JOYUP = 1 'CONST JOYDN = 2 'CONST JOYLT = 4 'CONST JOYRT = 8 'CONST J1FIRE = 64 'CONST J2FIRE = 128 DIM j AS BYTE lab: j = JOY(1) IF j = 0 THEN GOTO lab IF j AND JOYUP THEN PRINT " up"; IF j AND JOYDN THEN PRINT " down"; IF j AND JOYLT THEN PRINT " left"; IF j AND JOYRT THEN PRINT " right"; IF j AND J1FIRE THEN PRINT " fire"; PRINT "" GOTO lab