Section 21.2. Gameport Interface

   

21.2 Gameport Interface

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.

Figure 21-1. The gameport connector (on the computer)
figs/pcn2_2101.gif

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.

Table 21-1. Gameport interface signals and pinouts

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

There are two types of gameport, single- and dual-port. Table 21-1 describes the dual-port type. The single-port type uses the same connector, but does not support the Joystick 2 functions. In short, rather than supporting four switched inputs and four variable inputs, a single-port gameport supports only two of each, and can therefore support only one two-button, two-axis game controller. All current sound cards and most older sound cards provide dual-port gameports. Only a few very old models are single-port devices.

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 kfigs/u03a9.gif 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.

Table 21-2. Gameport 201h bytes

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.

       


    PC Hardware in a Nutshell
    PC Hardware in a Nutshell, 3rd Edition
    ISBN: 059600513X
    EAN: 2147483647
    Year: 2002
    Pages: 246

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net