A standard PC gameport is actually a simple general-purpose analog data-acquisition port that supports four simple switched inputs and four variable-voltage inputs. A game controller connected to this interface uses one or more of the switched inputs to support buttons and one or more of the variable inputs to support a joystick, steering wheel, or similar device.
A paddle (originally used for Pong) is the simplest game controller. It uses only one switched input for a button and one variable input for a knob that controls movement in one direction. Accordingly, a gameport can support up to four paddles. A joystick uses one or two switched inputs for buttons and two variable inputs for a central stick that controls movement in both the horizontal (x-axis) and vertical (y-axis) directions. Accordingly, a gameport can support one or two joysticks. More complex game controllers use more of the switched inputs for additional buttons, and more of the variable inputs to control a third (z-axis) direction or for other purposes. This means that a gameport can support only one such controller.
Gameports do not require an IRQ, a DMA channel, or mapped memory, and occupy only one I/O base address. The downside of this small resource footprint is that gameports are not interrupt-driven, so the CPU must constantly poll the gameport to detect when a button is pressed or a stick is moved. Polling can require as much as 10% of the CPU, which degrades performance when you least want the performance hit?as you're playing a shoot-'em-up or trying to land a crippled fighter. The gameport connector on the PC is a DB-15F, shown in Figure 21-1.
Table 21-1 describes the gameport interface and pinouts. On MIDI-capable gameports (usually those on sound cards), Pin 12 is MIDI data out and Pin 15 is MIDI data in.
Pin |
Name |
Joystick function |
Paddle function |
Direction |
---|---|---|---|---|
1 |
+5VDC |
Joystick 1 power |
Paddle A coordinate high |
Out |
2 |
Button 4 |
Joystick 1 button 1 |
Paddle A button high |
In |
3 |
Position 0 |
Joystick 1 x-coordinate |
Paddle A coordinate wiper |
In |
4 |
Ground |
Joystick 1 button 1 ground |
Paddle A button ground |
- |
5 |
Ground |
Joystick 1 button 2 ground |
Paddle B button ground |
- |
6 |
Position 1 |
Joystick 1 y-coordinate |
Paddle B coordinate wiper |
In |
7 |
Button 5 |
Joystick 1 button 2 |
Paddle B button high |
In |
8 |
+5VDC |
(unused) |
Paddle B coordinate high |
Out |
9 |
+5VDC |
Joystick 2 power |
Paddle C coordinate high |
Out |
10 |
Button 6 |
Joystick 2 button 1 |
Paddle C button high |
In |
11 |
Position 2 |
Joystick 2 x-coordinate |
Paddle C coordinate wiper |
In |
12 |
Ground |
Joystick 2 button 1/2 ground |
Paddle C/D button return |
- |
13 |
Position 3 |
Joystick 2 y-coordinate |
Paddle D coordinate wiper |
In |
14 |
Button 7 |
Joystick 2 button 2 |
Paddle D button high |
In |
15 |
+5VDC |
(unused) |
Paddle D coordinate high |
Out |
|
Joystick coordinate signals are analog inputs. Pins 3 and 6 report the x- and y-coordinates, respectively, for Joystick 1. Pins 11 and 13 do the same for Joystick 2. Moving the joystick alters the position of the slider on a 0 to 100 kW potentiometer, altering resistance, which in turn alters the voltage present on the pin. The gameport periodically samples the voltage on each coordinate pin using a monostable multivibrator. The gameport uses a base address of 201h. Writing to that address resets the monostable multivibrators and begins position measurement. Each byte subsequently read from 201h reports the status of the coordinate and button pins, as shown in Table 21-2.
201h byte bitmask | |||||||||
---|---|---|---|---|---|---|---|---|---|
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
Description |
Pin |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
Joystick 2, button 2 (0=closed, 1=open) |
14 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
Joystick 2, button 1 (0=closed, 1=open) |
10 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
Joystick 1, button 2 (0=closed, 1=open) |
7 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
Joystick 1, button 1 (0=closed, 1=open) |
2 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
Joystick 2, y-coordinate (0=timed-out, 1=timing) |
13 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
Joystick 2, x-coordinate (0=timed-out, 1=timing) |
11 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
Joystick 1, y-coordinate (0=timed-out, 1=timing) |
6 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
Joystick 1, x-coordinate (0=timed-out, 1=timing) |
3 |
Most game controllers introduced since mid-1999 use USB instead of or in addition to the legacy gameport interface. Because USB is a general-purpose digital interface, game controller designers can implement whatever custom functions they wish in the controller hardware and define support for those functions in the driver.