[comp.sys.atari.st.tech] Assembly joystick routines WANTED

Bobster@cup.portal.com (Robert Jules Shaughnessy) (06/02/91)

     I am having a terrible time reading the joystick port (1 and 2) from 
assembly language. If you have an assembly routine that will do this, could yo
please post it or send it to me?


Thanks in Advance!

robin@castle.ed.ac.uk (R C Smith) (06/03/91)

In article <42873@cup.portal.com> Bobster@cup.portal.com (Robert Jules Shaughnessy) writes:
>
>     I am having a terrible time reading the joystick port (1 and 2) from 
>assembly language. If you have an assembly routine that will do this, could yo
>please post it or send it to me?
>
 I would also like to see this posted as Atari ST internals doesn't make
this clear enough for me..

warwick@cs.uq.oz.au (Warwick Allison) (06/04/91)

>>     I am having a terrible time reading the joystick port (1 and 2) from 
>>assembly language. If you have an assembly routine that will do this, could yo
>>please post it or send it to me?
>>
> I would also like to see this posted as Atari ST internals doesn't make
>this clear enough for me..

Okay, I'll post my code.  Note that I think this WORKS (on tos 1.0, and 1.4 so far)
but I think it may be wrong (because I am assuming "a0" is the input parameter,
whereas I expect it would be on the stack).

This is my code:

First, the packet handler:

JoyDo:
    movem.l d0/a1,-(sp)
    move.l  #Stick,a1     ; Location of the place you want to
    move.w  1(a0),d0      ; store data (it is "byte Stick[2]")
    cmp.b   #$FF,(a0)     ; (or VAR Stick:ARRAY [0..1] OF CHAR)
    beq     Joy1
    lsr.w   #8,d0
    add.l   #1,a1
Joy1:
    move.b  d0,(a1)
    movem.l (sp)+,d0/a1
    rts

That isn't my actual code - I decode the directions and trigger - but it shows
what you want.

Now the rest (which you can probably work out already)... It's in Modula-2,
so anyone who knows Pascal can work it out.


TYPE KeyVectors=POINTER TO
         RECORD
            midivec,vkbderr,vmierr,statvec,
            mousevec,clockvec,joyvec:ADDRESS
         END;

VAR OldJoy:ADDRESS;

PROCEDURE InitJoysticks;

VAR KV:KeyVectors;
    Cmd:CHAR;

BEGIN
    Cmd:=024C; (* 20 decimal, 14 hex *)
    ikbdws(ADR(Cmd),0)
    KV:=kbdvbase();
    OldJoy:=KV^.joyvec;
    KV^.joyvec:=ADDRESS(JoyDo);
END InitJoysticks;

PROCEDURE TermJoysticks;

VAR KV:KeyVectors;
    Cmd:CHAR;

BEGIN
    Cmd:=010C; (* 8 decimal/hex *)
    ikbdws(ADR(Cmd),0);
    KV:=kbdvbase();
    KV^.joyvec:=OldJoy;
END TermJoysticks;


Finally, I appologise if this is ugly or incorrect, all I have seen of this
module for a while is:


DEFINITION MODULE Joysticks;

(* Supplies access to the two joystick ports *)

TYPE	JoystickDirection=(none,up,down,updown,
				left,upleft,downleft,updownleft,
				right,upright,downright,updownright,
				leftright,upleftright,downleftright,
				updownleftright);

	JoystickRecord=	RECORD
				Up,Down,Left,Right,Trigger:BOOLEAN;
			END;

(* A variety of formats... *)

VAR	Joystick:ARRAY [0..1] OF JoystickRecord;
	Stick:ARRAY [0..1] OF JoystickDirection;
	Trig:ARRAY [0..1] OF BOOLEAN;

	XStick:ARRAY JoystickDirection OF INTEGER;
	YStick:ARRAY JoystickDirection OF INTEGER;

PROCEDURE InitJoysticks;
(* Enables both joysticks, disables mouse movement *)

PROCEDURE TermJoysticks;
(* Restores normal mouse action, disables joysticks *)

(* InitJoysticks is automatically done at initialisation
   TermJoysticks is automatically done upon termination *)

END Joysticks.


Long live M2,
Ciao,
Warwick.
--
  _-_|\       warwick@cs.uq.oz.au
 /     *  <-- Computer Science Department,
 \_.-._/      University of Queensland,
      v       Brisbane, AUSTRALIA.