AcornSearch - Acorn and RISC OS information searching
RISC OS Search
containing
"Nutty quip goes here!"
Home  |  About  |  Filebase Archive  |  StrongHelp Manuals  |  Newsgroups  |  Module Database
=>     R0 =     joystick number and reason code
           bits 0-7     joy stick number (0 = first)
           bits 8-15     reason code
           bits 16-31     reserved (must be zero)
<=     Dependant upon reason code

This SWI reads the current state of the joystick, assuming the Joystick module is loaded and hardware present.

See PRM 4-208PRM 5a-638
Joystick_Read reason codes
Code     /Meaning/

0     Return 8 bit state of digital or analogue joystick
1     Return 16 bit state of analogue joystick
Joystick_Read 8 bit state
=>     R0 =     joystick number and reason code
           bits 0-7     joy stick number
           bits 8-15     0 (reason code)
           bits 16-31     reserved
<=     R0 =     8 bit state of joystick

Applications which are only concerned with state (up, down, left, right) should not merely test bytes for postive, negative or zero. At rest‘ should span a range such as -32 to 32 since analogue joysticks cannot be relied upon to produce 0 at rest.

This reason code is available from RISC OS 3 onwards.

See also:     Note about analogue joysticks
          PRM 5a-640
8 bit joystick state
Represented in the form &RRSSHHVV.

Byte     /Value/

V     Signed Y value in the range -127 to 127 (hence 0 = centre)
     For a single switch joystick, -64 = Down, 0 = Rest and 64 = Up.
H     Signed X value in the range -127 to 127 (hence 0 = centre)
     For a single switch joystick, -64 = Left, 0 = Rest and 64 = Right.
S     Switches (eg fire buttons), unimplemented switches return 0
R     reserved
Joystick_Read 16 bit state
=>     R0 =     joystick number and reason code
           bits 0-7     joy stick number
           bits 8-15     1 (reason code)
           bits 16-31     reserved
<=     R0 =     16 bit joystick position
     R1 =     joystick switch state

Applications which are only concerned with state (up, down, left, right) should not merely test bytes for postive, negative or zero. At rest‘ should span a range such as 24576 (&6000) to 40960 (&A000) since analogue joysticks cannot be relied upon to produce a given value at rest.

This reason code is available from RISC OS 3.60 onwards.

See also:     Note about analogue joysticks
          PRM 5a-641
16 bit joystick position
Bits     /Value/

0-15     unsigned Y value in the range 0 (down) to 65535 (up)
15-31     unsigned X value in the range 0 (left) to 65535 (right)
16 bit switch state
Bits     /Value/

0-7     switches (eg fire buttons) starting in bit 0; unimplemented switches return 0
8-31     reserved
Note about analogue joysticks
For analogue joysticks, Joystick_Read reads the last conversion made, but does not force a conversion itself. Conversions are not started until the first call of Joystick_Read, hence the first call to Joystick_Read results in X = 0, Y = 0 with no closed switches since there is no completed conversion to read.

[sh-index] Back to list of manuals