21.2 Gameport InterfaceA 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. Figure 21-1. The gameport connector (on the computer)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.
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 k 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 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.
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. |