home *** CD-ROM | disk | FTP | other *** search
/ PC Home MegaDisk 24 / PCHomeMegaDisk_199409_24.img / CFILES.EXE / JOYTEST.C next >
Encoding:
C/C++ Source or Header  |  1994-07-19  |  1.3 KB  |  64 lines

  1. /***************************************************************************
  2.  *  A simple program to show the use of function J_check().                *
  3.  *  Exit the program by pressing both joystick buttons together.           *
  4.  ***************************************************************************/
  5.  
  6. #include "dos.h"           /* for gotoxy() and printf() */
  7. #include "conio.h"         /* for kbhit() */
  8.  
  9. typedef struct {
  10.         int xpos, ypos;
  11.         int sw1, sw2;
  12.         } JOY;
  13.  
  14. JOY js;
  15.  
  16.  
  17. main()
  18. {
  19. char contin=1;
  20. clrscr();
  21.  
  22. while(contin)
  23.       {
  24.       J_check();
  25.       gotoxy(10, 10);
  26.       printf("                               ");
  27.       gotoxy(10, 10);
  28.       printf("XPOS=%d YPOS=%d SW1=%d SW2=%d\n", js.xpos, js.ypos, js.sw1, js.sw2);
  29.       if (js.sw1 && js.sw2)
  30.          contin=0;
  31.       if ( kbhit() )
  32.          contin=0;
  33.       }
  34.  
  35. }
  36.  
  37. J_check()
  38. {
  39.  
  40. union REGS regs;
  41.  
  42. regs.x.dx = 0;                /* DX=0 - Check buttons */
  43. regs.h.ah = 0x84;
  44. int86(0x15, ®s, ®s);
  45.  
  46. if (regs.h.al & 16)
  47.    js.sw1 = 0;
  48. else
  49.    js.sw1 = 1;
  50.  
  51. if (regs.h.al & 32)
  52.    js.sw2 = 0;
  53. else
  54.    js.sw2 = 1;
  55.  
  56. regs.x.dx = 1;                /* DX=1 - Check stick position */
  57. regs.h.ah = 0x84;
  58. int86(0x15, ®s, ®s);
  59.  
  60. js.xpos = regs.x.ax;
  61. js.ypos = regs.x.bx;
  62.  
  63. return(0);
  64. }