[comp.sys.amiga] Joystick Port 2 in C in PD games?

smsst5@unix.cis.pittsburgh.edu (Steve M Suhy) (06/09/89)

     Does anyone know of any cucug, amicus, or fish disks that contain
any games or routines that contain C source for reading Port 2 of
a joystick? Thanks for any response.

-Steve

s110018@pollux.ucdavis.edu (0000;0000001007;4000;250;216;s110) (06/13/89)

In article <18380@unix.cis.pittsburgh.edu> smsst5@unix.cis.pittsburgh.edu (Steve M Suhy) writes:
>
>     Does anyone know of any cucug, amicus, or fish disks that contain
>any games or routines that contain C source for reading Port 2 of
>a joystick? Thanks for any response.
>
>-Steve

Here's a nice short way to do it. (Just a tad bit shorter than
the example by Rob Peck in the RKM.)

#include	<exec/types.h>
#define DMA_REGS	0xdff000
#define	JOY1DAT		0x00C+DMA_REGS

void	CheckJoystick()
{
USHORT	*joyPort2,joyData;
short	dirX,dirY,a,b,c,d;

	joyPort2=JOY1DAT;
	joyData=*joyPort2;
	dirX=dirY=0;
	a= ((joyData & 0x0002) >> 1);
	b= ((joyData & 0x0200) >> 9);
	c= ((joyData & 0x0001)	   );
	d= ((joyData & 0x0100) >> 8);
	c^=a;
	d^=b;
	if (a) dirX= 1;
	if (b) dirX=-1;
	if (c) dirY= 1;
	if (d) dirY=-1;

	/* Just check for dirX or dirY here */
}

	-Bruce Rogers
	-u586182058ea@deneb.ucdavis.edu


_______________________________________________________________________________
Just a man whose circumstances went beyond his control....