SWI Interface for Joystick Devices

The Joystick module provides a SWI interface for reading the state of a joystick. When the module initialises, it tests for the existence of built-in joystick hardware and if it does not find any then it will not initialise. Third parties can replace this module to provide support for different hardware. It is recommended that any such modules have version numbers greater than 2.00 so that Acorn can upgrade its own module without

preventing its replacement.       

SWI Joystick_Read (SWI &43F40)


Returns the state of a joystick.

On entry:               R0 = joystick number
On exit:                R0 = joystick state
Interrupts:             Interrupt status is not altered
Processor mode:         Processor is in SVC mode
Re-entrancy:            Not defined
Use: This SWI is used to obtain the state of the requested
joystick. The state is returned in the following
                        format:
                        Byte 0:    signed Y value (range -127 to 127)
                                   -64, 0 or 64 for single switch joystick
                                   (corresponds to Down, Rest, Up).
                        Byte 1:    signed X value (range -127 to 127)
                                   -64, 0 or 64 for single switch joystick
                                   (corresponds to Left, Rest, Right).
                        Byte 2:    Switches (e.g. fire buttons) starting in
                                   bit 0, unimplemented switches return 0.
                        Byte 3:    Reserved.

Note that this format allows both digital and analogue devices to be supported. Applications which are only interested in state (up, down, left, right) should not simply test the bytes for positive, negative or zero. It is recommended that the 'at rest' state should span a middle range, say from -32 to 32 since analogue joysticks cannot be relied upon to produce 0 when at rest.