home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / msdos / programm / 10710 < prev    next >
Encoding:
Text File  |  1992-11-17  |  3.6 KB  |  121 lines

  1. Xref: sparky comp.os.msdos.programmer:10710 rec.games.programmer:4720
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!sdd.hp.com!elroy.jpl.nasa.gov!usc!news.service.uci.edu!balboa.eng.uci.edu!cnc
  3. From: cnc@balboa.eng.uci.edu (Christopher Christensen)
  4. Subject: Re: Joystick Routines Needed
  5. Nntp-Posting-Host: balboa.eng.uci.edu
  6. Message-ID: <2B093C3C.10748@news.service.uci.edu>
  7. Newsgroups: comp.os.msdos.programmer,rec.games.programmer
  8. Organization: University of California, Irvine
  9. Lines: 108
  10. Date: 17 Nov 92 18:38:52 GMT
  11. References: <1992Nov16.211134.29296@jarvis.csri.toronto.edu>
  12.  
  13.  
  14. Here's a joystick routine I wrote.  Hope it helps.
  15.  
  16. ----------------------------- cut -------------------------------
  17. /*
  18. "jstk.c" -- Joystick demo code
  19.  
  20. read_jstk() is an assembly language routine which does the actual
  21. reading.  It puts the values in jstk*_*.  The values will range
  22. between 0 and jrange.  The jsense value controls the joystick
  23. sensitivity (the lower the value, the more sensitive the reading).
  24. The jsense value will have to be adjusted to suit the cpu speed.
  25. Oh, the status of the 4 buttons is returned in the 4 LSBs of the
  26. return value of read_jstk().
  27.  
  28. make recipe (Borland C):
  29. bcc jstk.c jstka.asm
  30.  
  31. */
  32.  
  33. extern int jstk1_x;
  34. extern int jstk1_y;
  35. extern int jstk2_x;
  36. extern int jstk2_y;
  37. extern int jsense;
  38. extern int jrange;
  39. extern read_jstk();
  40.  
  41. int main()
  42. {
  43. int button, button2;
  44. int new_button;
  45.  
  46. button=0;
  47. jsense=20;
  48. jrange=500;   /* arbitrary */
  49. while(!kbhit())
  50.   {
  51.   button2=button;
  52.   button=read_jstk();
  53.   new_button=(button^button2)&button;
  54.   if (new_button&1) jsense--;
  55.   if (new_button&2) jsense++;
  56.   if (jsense<1) jsense=1;
  57.   printf("%04x  %04x  %04x  %04x    s=%d\n",
  58.          jstk1_x, jstk1_y, jstk2_x, jstk2_y, jsense);
  59.   }
  60. return(0);
  61. }
  62. ----------------------------- cut -------------------------------
  63.  
  64. ----------------------------- cut -------------------------------
  65. ; "jstka.asm"
  66. GAMEPORT       =      201h
  67.  
  68.                IDEAL
  69.                MODEL  small
  70.  
  71.                DATASEG
  72.                PUBLIC _jstk1_x, _jstk1_y, _jstk2_x, _jstk2_y
  73.                PUBLIC _jsense, _jrange
  74.  
  75. _jstk1_x       dw     0          ; joystick 1 x-axis
  76. _jstk1_y       dw     0          ; joystick 1 y-axis
  77. _jstk2_x       dw     0          ; joystick 2 x-axis
  78. _jstk2_y       dw     0          ; joystick 2 y-axis
  79. _jsense        dw     1          ; joystick sensitivity
  80. _jrange        dw     300        ; joystick range
  81.                CODESEG
  82.  
  83.                PUBLIC _read_jstk
  84. PROC           _read_jstk
  85.                mov    dx,GAMEPORT
  86.                out    dx,al          ;start timer
  87.                xor    ax,ax
  88.                mov    [_jstk1_x],ax  ;initialize to zero
  89.                mov    [_jstk1_y],ax  ;
  90.                mov    [_jstk2_x],ax  ;
  91.                mov    [_jstk2_y],ax  ;
  92.                mov    cx,[_jrange]   ;# times to iterate rangeloop
  93. rangeloop:
  94.                mov    bx,[_jsense]
  95. delay:
  96.                in     al,dx
  97.                dec    bx
  98.                jnz    delay
  99.  
  100.                shr    al,1
  101.                adc    [_jstk1_x],bx
  102.                shr    al,1
  103.                adc    [_jstk1_y],bx
  104.                shr    al,1
  105.                adc    [_jstk2_x],bx
  106.                shr    al,1
  107.                adc    [_jstk2_y],bx
  108.                loop   rangeloop
  109.                not    al
  110.                and    ax,0fh          ;return the button status in ax
  111.                ret
  112. ENDP           _read_jstk
  113.  
  114.                END
  115. ----------------------------- cut -------------------------------
  116.  
  117.  
  118. --
  119. |  Christopher  |  Computer Engineering graduate student, UC Irvine  |
  120. |  Christensen  |  cnc@balboa.eng.uci.edu                            |
  121.