home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.ibm.pc.hardware
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsc!cbfsb!cbnewsg.cb.att.com!rnichols
- From: rnichols@cbnewsg.cb.att.com (robert.k.nichols)
- Subject: Re: [Q] How do Game Ports Work?
- Message-ID: <1993Jan2.221922.2341@cbfsb.cb.att.com>
- Sender: news@cbfsb.cb.att.com
- Organization: AT&T
- References: <1i2lnqINNso8@faatcrl.Faa.Gov> <1993Jan1.231920.1@vms.ucc.okstate.edu>
- Date: Sat, 2 Jan 1993 22:19:22 GMT
- Lines: 67
-
- In article <1993Jan1.231920.1@vms.ucc.okstate.edu> v923137@vms.ucc.okstate.edu writes:
- >In article <1i2lnqINNso8@faatcrl.Faa.Gov>, warb@tgf.tc.faa.gov (Dan Warburton) writes:
- >> Q1. Can you have more than one Game port enabled?
- >> I have one on the Seril/Par Board and one on a PAS16 board.
- >
- >A1. Yes. The IBM can support up to two joysticks on ONE 15-pin port.
- > I am not sure about using two joysticks on two ports, as you are
- > suggesting, however, I'm sure it is quite possible.
-
- Oops! I think we have a slight misunderstanding here. As you said,
- ONE game port supports TWO joysticks -- but that's still ONE game port.
- You can't run two game ports on the same machine unless you find a
- game port controller that can be switched to a non-standard I/O address
- (unlikely), a driver which can access this address (the BIOS routines
- are hard-coded to a single address), and game software that can
- utilize this driver (even more unlikely). So, the answer is
- essentially: "No."
-
- >> Q2. How do the games know when a button is pushed? Interrupt, polling
- >> something else.
- >
- >A2. I have done some programming on 286/386 machines using assembly
- > language to read joystick ports. I was not interested in whether
- > the button(s) were pushed, but only about the values of the pot. lines.
- > The standard game port works by the program issuing an interrupt, at
- > which time the port is scanned, and the values of all potentiometers
- > and buttons are loaded into a buffer. Then you read that buffer at your
- > (the program's) leisure to find the position of the stick/buttons.
- > This way you do not have to immediately process the joystick data and
- > run the risk of the joystick moving while you are reading one axis, and
- > the other axis changing before you get to it. ...
-
- If you examine the BIOS code that read the game port, you'll find that
- each of the 4 potentiometers are read separately. Essentially, the
- sequence is:
-
- 1. Record the value of a timer.
-
- 2. Inhibit interrupts.
-
- 3. Trigger the monopulsers in the game controller.
-
- 4. Poll the game controller until the pulse you are now
- measuring has ended.
-
- 5. Read the timer again.
-
- 6. Re-enable interrupts.
-
- 7. Compute the elapsed time from the 2 timer readings.
-
- 8. Repeat steps 1-7 for the remaining 3 analog inputs.
-
- 9. Return the 4 measurements to the caller.
-
- So, there is still the possibility that one channel has changed while
- another was being measured, but at least this is all within the scope
- of one BIOS call.
-
- As for the button presses, the BIOS will tell you the current state of
- the buttons any time you ask (i.e., poll). It's the same BIOS call:
- DX=0 returns the current switch positions in AL bits 4-7; DX=1 reads
- the resistance inputs and returns the results in AX, BX, CX and DX.
-
- Bob Nichols
- AT&T Bell Laboratories
- rnichols@ihlpm.ih.att.com
-