This requires a knowledge of bits so if you are not to sure check out the BIT tutor.
Now the purpose of this tutorial basicaly is to allow you to write joystick routines without having to resort to QB's crappy STRIG routines which are anoyingly bad and can be sometimes confusing!
So without further delay lets get started.
The Joystick basicaly has a value in which all the status is stored.
This value is read from PORT &H201
(Joy% = INP(&H201)).
The data uses BITS to show which part of the joystick is in use and
where the joystick is currently at.
Here is a little diagram of the BIT usage in the Value:-
BIT 7 BIT 6 BIT 5 BIT 4 BIT 3 BIT 2 BIT 1 BIT 0 Button 2 Joystick B
Button 1 Joystick A
Button 2 Joystick A
Button 1 Joystick B
Y Axis Joystick B
X axis Joystick A
Y axis Joystick A
X axis Joystick B
Now reading the status of the buttons is straight forward, Just read the bit(be it 7, 6, 5 or 4) and if it = 0 then the button is being pressed! Wasn't that simple?
As for the reading of the sticks position, well that is not as simple as the buttons. First you must send out a dummy byte to the Joystick port. Just out any old value to port &H201, eg:- OUT &H201, anyvalue%. This in effect will set the axis bits to 1. Then you must time how long it takes for the bit to return to 0. This is roughly proprtionl to the position of the stick.
This sounds complex but it can be done! I assure you. The values should be around as follows:
So, I hope this has give you enough insight to write your joystick routine! All you must do is wait for the bit to return and record the duration. Easy!
This article was written by Greg McAusland (Maz)