[comp.os.msdos.programmer] Joysticks

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (01/28/91)

I am trying to write a game that uses the joystick and was wondering if there
is a standard interface to the joystick in C that I can access?  Is their
a standard BIOS call I could do using int86()?  Is polling the BIOS too
slow for a highspeed game?

Any info would be appreciated,

Brian

6600dt@ucsbuxa.ucsb.edu (Dave Goggin) (01/29/91)

In article <26542@uflorida.cis.ufl.EDU> jdb@reef.cis.ufl.edu (Brian K. W. Hook) writes:

>I am trying to write a game that uses the joystick and was wondering if there

>Any info would be appreciated,

What kind of computer are you uing?  If it's anything like mine,
you ought to be able to peek into a memorty location to get the information about the current status

>Brian

gordon@osiris.cso.uiuc.edu (John Gordon) (01/30/91)

	Check out the Autumn 1990 issue of _The C Gazette_.

bill@hpcvlx.cv.hp.com (Bill Frolik) (01/31/91)

Reading the joystick is pretty straightforward in assembly.
You just do an arbitrary write to port 201h to trigger the card, 
then you monitor the bits read back from port 201h.  The low 4 bits
go low, I believe, and individually flip back to 1 at some later
time dependent on the stick positions.  In Microsoft C you can 
do the same thing by using the "inp(port)" and "outp(port,data)" 
functions.  The only tricky part is keeping track of elapsed time
in a way that isn't related to CPU speed (i.e., you shouldn't
just count the number of iterations you sit in a loop polling 
the stick position bits).  The best way to do this is probably
to note the value of Timer 0's countdown register when you first
trigger the card, then read it again each time you see one of
the position bits change back.  The timer counts down from 65535
to 0 every 55ms or so, and is used to generate the Timer Tick
interrupt (int 08h and subsequently int 1Ch).  The bits you get 
back from port 201h look something like this:

   7    6    5    4    3    2    1    0
  ---  ---  ---  ---  ---  ---  ---  ---
   BUTTN2    BUTTN1    STICK2    STICK1
   B    A    B    A    Y    X    Y    X

___________________________________________

Bill Frolik             Hewlett-Packard Co.
hp-pcd!bill             Corvallis, Oregon
bill@hpcvlx.cv.hp.com   (503)750-4082