[comp.sys.ibm.pc] IBM Game Control Adapter

matthew@sunpix.UUCP ( Sun NCAA) (11/04/88)

I keep seeing requests on info concerning the IBM PC joystick port, and since I
posses a copy of the IBM Personal Computer Hardware Reference Library, I might
as well get this info out on the net.

Heres a copy of a letter I've sent to someone wanting to know how to read a
joystick from 'C'. It should prove usefull to all:

*******************************************************************************
*******************************************************************************

All I've got on hand is the IBM Personal Computer Hardware Reference Library.
It has 6 pages (3 sheets) on the "Game Control Adapter".

To read a joystick position I would use the below data to write a function that
would read the data as follows:

xcoord = joystick(0)    /* 0 = joystick A  x-coordinate */
buttona = button(0)	/* 0 = joystick A  lsb (least significant button) */

Where joystick()  equals

joystick(number)
{
	/*          C or inline assembly code to:
	** 1) zero out a counter
	** 2) write to OUT x'201'
	** might need a wait here for 24.2 usec to let circuit settle **
	** 3) read IN x'201'
	** 4) mask off unwanted bits 
	** 5) if desired bit is zero, return(count)
	** 6) else add 1 to count 
	** 7) if (count < max_count) goto step 3;
	** 8) return(max);
	*/
}

Where button()  equals

button(number)
{
	/*          C or inline assembly code to:
	** 1) read IN x'201'
	** 2) inverse value read ( to change button pressed to a 1 ) 
	** 3) mask off unwanted bits 
	** 4) if value is non-zero return(1) 
	** 5) else return(0)
	*/
}

Here is the Interface Description, if that helps.


Interface Description

The Game Control Adapter has 8 input lines, 4 of which are digital inputs 
and 4 of which are resistive inputs.  The inputs are read with one IN from 
address x'201'.

The 4 digital inputs each have a 1K ohm pullup resistor to +5V. With no 
drive on these inputs, a '1' is read.  For a '0' reading, the inputs must
be pulled to ground.

The 4 resistive inputs, measured to +5V, will converted to a digital pulse
with the duration proportional to the resistive load, according to the
following equation:

	TIME = 24.2 usec + 0.011(r) usec

The user must first begin the conversion by an OUT to address x'201'. An
IN from address address x'201' will show the digital pulse go high and 
remain high for the duration according to the resistance value. All four
go high simultaneously and will reset independently, according to the 
input resistance value.

Input from address x'201'
-----------------------------------------------------------------
! bit 7 ! bit 6 ! bit 5 ! bit 4 ! bit 3 ! bit 2 ! bit 1 ! bit 0 !
-----------------------------------------------------------------
\_______________  _____________/ \______________  ______________/
                \/                              \/
             Digital inputs               Resistive inputs

The typical input to the Game Control Adapter is a set of joysticks or
game paddles.

The joysticks will typically have a set of two joysticks (A&B). These 
will have one or two buttons each with two variable resistances each, 
with a range from 0 to 100K ohms.  One variable resistance will indicate
the X coordinate and the other varable resistance will indicate the Y
coordinate.  This should be attached to give the following input data:

-------------------------------------------------------------------------
! bit 7  ! bit 6  ! bit 5  ! bit 4  ! bit 3  ! bit 2  ! bit 1  ! bit 0  !
! B-2    ! B-2    ! A-2    ! A-1    ! B-Y    ! B-X    ! A-Y    ! A-X    !
! Button ! Button ! Button ! Button ! Coord  ! Coord  ! Coord  ! Coord  !
-------------------------------------------------------------------------

The Game paddles will have a set of two (A&B) or four (A,B,C,&D) paddles.
These will have one button each and one variable resistance each, with a
range from 0 to 100K ohms.  This should be attached to give the following 
data:

-------------------------------------------------------------------------
! bit 7  ! bit 6  ! bit 5  ! bit 4  ! bit 3  ! bit 2  ! bit 1  ! bit 0  !
! D      ! C      ! B      ! A      ! D      ! C      ! B      ! A      !
! Button ! Button ! Button ! Button ! Coord  ! Coord  ! Coord  ! Coord  !
-------------------------------------------------------------------------

The pinout for the game controller is: 
(number indicates bit position at x'201')

1	+5vdc
2	button 4
3	position 0
4	ground
5	ground
6	position 1
7	button 5
8	+5vdc
9	+5vdc
10	button 6
11	position 2
12	ground
13	position 3
14	button 7
15	+5vdc


****************************************************************************
That's all folk's
-- 
Matthew Lee Stier     (919) 469-8300|
Sun Microsystems ---  RTP, NC  27560|          "Wisconsin   Escapee"
uucp: {sun, rti}!sunpix!matthew     |