[comp.sys.atari.st.tech] "Right way" to read the joystick ports ?

tkld@cs.ed.ac.uk (Kevin Davidson) (01/14/91)

What is the "right way" to read the state of the joysticks, and return
everything to normal after I've finished ?

Do I just hook a routine into joyvec to receive stuff from the keyboard 6301?
Should I tell the 6301 to send joystick messages instead of mouse messages ?
How do I reset it (should I check what it was first with a status message)?

Suppose I want players 3&4 on the centronics port too, do I poll or can I use
interrupts ?

Anyone got code to do it ? I started, but got fed up rebooting if I
screwed the mouse vector.


I'm sure loads of peeps would love to know how it's "supposed" to be done.

	.Kevin.	<tkld@lfcs.ed.ac.uk>

warwick@batserver.cs.uq.oz.au (Warwick Allison) (01/18/91)

In <4454@skye.cs.ed.ac.uk> tkld@cs.ed.ac.uk (Kevin Davidson) writes:

>What is the "right way" to read the state of the joysticks, and return
>everything to normal after I've finished ?

	I've done it, but the method has been tucked away in a code module
for quite a while now... Basically,

	1. Adjust the joyvec to point to your routine
		(I think you use an XBIOS call to do this)
	2. Tell the IKBD to send joystick packets for each joystick
	   position change. (an XBIOS call again)

	3. Before you quit, re-enable the mouse.


	Your routine is a parameterless procedure, and the joystick
values are contained in some registers. I'm a bit vague on this part,
so if nobody has any accurate data, I'll post my code.

	I'd say it is right, I works on a 520 and a Mega 4, so that's enough
for me.

kilian@seas.gwu.edu (Jens Kilian) (01/18/91)

In article <6811@uqcspe.cs.uq.oz.au> warwick@batserver.cs.uq.oz.au writes:
[...]
>
>	Your routine is a parameterless procedure, and the joystick
>values are contained in some registers. I'm a bit vague on this part,
>so if nobody has any accurate data, I'll post my code.
>
[...]

The joystick routine called by the XBIOS gets a pointer to a status block
(in A0, I think). The first byte identifies the joystick that caused the
event, the second and third byte contain the current values of joysticks
0 and 1.
You should be somewhat careful about saving registers in your joystick
routine, and make it short. I usually copy the joystick values to some
global variables which are polled by the program.

	Hope this helps.

		Jens Kilian

--
\/// Internet: kilian@seas.gwu.edu     |Snail: 4715 MacArthur Blvd. \\\/
///  UUCP: ...uunet!seas.gwu.edu!kilian|       Washington, DC 20007  \\\
\\\   [These addresses will change (to kilian@cc.gatech.edu) soon]   ///
/\\\ "Wos deht ich-en so gern haage, awwer er spihrt doch nix ..."  ///\