home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PARADIS1 / JOYSTICK.PAS < prev    next >
Pascal/Delphi Source File  |  1992-04-08  |  3KB  |  105 lines

  1. (4682)  Sat 4 Apr 92 17:32
  2. By: Matt Schuttloffel
  3. To: Gavin Campbell
  4. Re: Joystick
  5. St:
  6. ---------------------------------------------------------------------------
  7. @EID:e493 18848c00
  8. @PID: FasToss .9b
  9. @MSGID: 1:170/806 2f918191
  10. @REPLY: 1:250/801.0 29d97bd6
  11.  >   How would someone read from a joystick.  Anyone have
  12.  > any ideas.  Is it
  13.  > like a mouse ore different.  Does anyone have any
  14.  > units or can anyone
  15.  > help?
  16.  
  17. {$S-,R-,V-,D-}
  18.  
  19. unit JoyStk;                {Joystick routines for Turbo Pascal 4.0}
  20.                             {John Haluska, CIS 74000,1106}
  21. interface
  22.  
  23. const
  24.   BtnA1 = 16;  BtnA2 = 32;   {for joystick buttons }
  25.   BtnB1 = 64;  BtnB2 = 128;
  26. var
  27.   JoyMaxCt : word;           {max count for joystick postion output }
  28.                              {set by procedure InitJoyMaxCt }
  29.  
  30. procedure JoyStkPos (N : byte; var X,Y : integer);
  31.  
  32. function JoyStkBtn (Num:byte) : boolean;
  33.  
  34. function JoyStkPresent : boolean;
  35.  
  36. function GetClkTicks : longint;
  37.  
  38. procedure JoyStkCal (N : byte; var X,Y : integer);
  39.  
  40. implementation
  41.  
  42. {$L JOYSTK.OBJ}
  43. {$F+}
  44. procedure JoyStkPos (N : byte; var X,Y : integer); external;
  45.          {Return X, Y position of joystick 0 or 1}
  46.  
  47. function JoyStkBtn (Num:byte) : boolean; external;
  48.         {Return position (true-button pressed or false-button not pressed)
  49.          for button 16, 32, 64 or 128 corresponding to bit positions 4 - 7.
  50.          No contact debounce is provided.}
  51.  
  52. function JoyStkPresent : boolean; external;
  53.         {Returns true if a game adapter interface is present.}
  54.  
  55. function GetClkTicks : longint; external;
  56.         {Return DOS time in ticks (18.2/sec).  The ticks/second is
  57.          1193180/65535.  The midnight value is 1573040.
  58.          Ref: Programer's Guide To PC, Peter Norton, ISBN 0-914845-46-2, p223}
  59. {$F-}
  60. procedure InitJoyMaxCt;
  61.         {Determine JoyMaxCt as a function of processor speed.}
  62.   var
  63.     I,J,T3   : word;
  64.     T1,T2    : longint;
  65.   begin
  66.     repeat
  67.       I := 0;
  68.       T1 := GetClkTicks;
  69.       for J := 1 to 65535 do I := I + 1;
  70.       T2 := GetClkTicks;
  71.     until T2 > T1;    {prevent error if counter rollover at midnight}
  72.     T3 := T2 - T1;
  73.     JoyMaxCt := 5000 div T3;
  74.   end;
  75.  
  76. procedure JoyStkCal (N : byte; var X,Y : integer);
  77.          {Return X, Y position of joystick N (0 or 1) when any joystick
  78.           button is pressed.  Joystick button is contact debounced by waiting
  79.           55 - 110 milliseconds.}
  80.   var
  81.     Ts, Tl   : longint;
  82.   begin
  83.     repeat
  84.       JoyStkPos(N, X, Y);
  85.     until JoyStkBtn(BtnA1) or JoyStkBtn(BtnA2) or JoyStkBtn(BtnB1)
  86.           or JoyStkBtn(BtnB2);
  87.     Ts := GetClkTicks;
  88.     repeat
  89.       repeat
  90.         Tl := GetClkTicks - Ts;
  91.       until Tl >= 2;            {55 -110 ms delay for switch contact bounce}
  92.     until not(JoyStkBtn(BtnA1) or JoyStkBtn(BtnA2) or JoyStkBtn(BtnB1)
  93.           or JoyStkBtn(BtnB2));
  94.   end;
  95.  
  96. begin
  97.   InitJoyMaxCt;     {Intialize max count}
  98. end.
  99.  
  100. --- FOFasToss 0.90/beta
  101.  * Origin: Total Force BBS = 250-3018 = 213megs, 14.4k (1:170/806@fidonet)
  102.  
  103. @PATH: 170/806 800 400 396/1 13/13 1/217 105/27 42 500/1 9 512/0 
  104. @PATH: 512/1007 
  105.