Amos Professional Manual  Contents  Index

the Joystick and Mouse


This Chapter clarifies all aspects of controlling and exploiting the joystick and mouse in your programs.

Joysticks
A joystick can be used to control movement around the screen by pushing its handle in the desired direction, and to trigger all sorts of actions by pressing one or more buttons built in to its mechanism. Either of the two joystick sockets at the back or side of your Amiga will happily accept a joystick plug. If two users want to control one joystick each for specially written programs, both ports can be used. To make a joystick interact with your programs, the computer !Weds to be able to read its movements and actions. AMOS Professional offers a number of useful functions to do just that.

JOY
function: read status of joystick
status=Joy(port number)

This inspects what is happening with the joystick and makes a report. If the joystick you are interested in is plugged into the joystick port, the computer must be told to look at port number (1). If you are using the mouse port call that port number (0). For example:

E> Do
    J=Joy(1)
    Print Bin$(J,5),J
Loop

When you run that routine, reports are given about the movements of the joystick and the status of the fire-button in the form of binary numbers. The pattern of ones and zeros in the report can then be inspected. Binary bits shown as zero indicate that nothing is happening, whereas if any of the bits in the report is shown as a one, it means that the joystick has been moved in the direction that relates to that bit. Here is a list of those bits along with their meanings.

Bit number  Meaning
0           Joystick has been moved Up
1           Joystick has been moved Down
2           Joystick has been moved Left
3           Joystick has been moved Right
4           Fire-button has been pressed

Each of those aspects of the joystick status can be accessed individually, using the following functions:

JLEFT
function: test for joystick movement towards the left
x=Jleft(port number)

This returns a value of -1 (meaning True) if the joystick connected to the given port number has been pushed to the left, otherwise a value of 0 is returned (meaning False).

Back    Next
05.08.01