home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / ibm / pc / hardware / 34615 < prev    next >
Encoding:
Text File  |  1993-01-02  |  3.3 KB  |  79 lines

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