home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / info / gameport.inf < prev    next >
Text File  |  1994-03-07  |  3KB  |  100 lines

  1.  
  2. From: bill@hpcvlx.cv.hp.com (Bill Frolik)
  3. Newsgroups: comp.sys.ibm.pc
  4. Subject: Re: How to read game port
  5. Date: 6 Apr 90 17:47:16 GMT
  6.  
  7. > 1) Is there anyone that can tell me the specifications for the game port
  8. >    connector?
  9.  
  10.     15-pin D-shell connector:
  11.  
  12.     PIN    SIGNAL        PIN    SIGNAL
  13.     ---    ------        ---    ------
  14.      1    +5V         8    +5V        
  15.      2    button 1     9    +5V
  16.      3    stick 1        10    button 3
  17.      4    GND        11    stick 3
  18.      5    GND        12    GND
  19.      6    stick 2        13    stick 4
  20.      7    button 2    14    button 4
  21.                 15    +5V
  22.  
  23.     Game card has a female connector;
  24.     Joystick cable has male connector.
  25.     Joystick wiring:
  26.  
  27.         +5    ________________
  28.                                 |
  29.         stick1    ________    |
  30.                 | 100K  |
  31.                 _/\/\/\_____|
  32.         stick2    ________    |
  33.                 | 100K  |
  34.                 _/\/\/\_____|
  35.         stick3    ________    |
  36.                 | 100K  |
  37.                 _/\/\/\_____|
  38.         stick4    ________     |
  39.                 | 100K  |
  40.                 _/\/\/\_____|
  41.                   ___
  42.         button1    ______o o_______ 
  43.                   ___       |
  44.         button2    ______o o_______|
  45.                   ___       |
  46.         button3    ______o o_______|
  47.                   ___       |
  48.         button4    ______o o_______|
  49.                     |
  50.         GND    ________________|
  51.  
  52.  
  53. > 2) As near as I can figure, I have to use the inpw() function (I'm using
  54. >    C) to read the ports.  Unfortunately, I don't know the port number to
  55. >    give the function to read the port.  If this isn't the right/best way,
  56. >    please let me know.
  57.  
  58.     You need to do byte I/O to and from port 201h.
  59.     To read the joysticks (or your slide pot positions), you
  60.     must first write a byte to port 201h.  It doesn't matter
  61.     what value you send, as long as you perform an I/O write.
  62.     This triggers the 558 timer on the game adapter.
  63.  
  64.     Game port 201h byte:
  65.      _______________________________________________________
  66.     |   7  |   6  |   5  |   4  |   3  |   2  |   1  |   0  |
  67.     | but4 | but3 | but2 | but1 | stk4 | stk3 | stk2 | stk1 |
  68.     |______|______|______|______|______|______|______|______|
  69.  
  70.     The most machine-independent way to sample the game port
  71.     is to use a timer.  Note the time (e.g., read the countdown
  72.     register in Timer 0, you need pretty fine resolution and this
  73.     timer performs 65535 counts every 55 ms) just before you
  74.     trigger    the 558.  After triggering, sit in a loop reading
  75.     port 201h and examining bits 0-3.  For those bits that have
  76.     a joystick pot attached, you'll see them sit for a while at 0,
  77.     then become 1.  As each bit flips back to 1, note the time
  78.     again.  When all bit 0-3 have flipped back to 1, you're almost
  79.     done.  Compute elapsed time for each bit, and you end up with
  80.     a value that is proportional to pot position.
  81.     
  82.     If you're lazy and don't care about machine independence,
  83.     you can just trigger the card, then sit in a loop and count
  84.     up from zero.  As each bit flips back to 1, save the count
  85.     for that bit.  I've seen a few games that probably use
  86.     this method.  Problem is that if you then run the same code
  87.     on a faster/slower machine, your calibration can get very
  88.     easily messed up.
  89.  
  90.     Buttons can be read at any time just by reading port 201h
  91.     and looking at bits 4-7.  No triggering is required.
  92.     Button bits are normally 1; while a button is depressed,
  93.     its bit will flip to 0.
  94.  
  95. ___________________________________________
  96.  
  97. Bill Frolik             Hewlett-Packard Co.
  98. hp-pcd!bill             Corvallis, Oregon
  99. bill@hpcvlx.cv.hp.com   (503)750-4082
  100.