home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- * A simple program to show the use of function J_check(). *
- * Exit the program by pressing both joystick buttons together. *
- ***************************************************************************/
-
- #include "dos.h" /* for gotoxy() and printf() */
- #include "conio.h" /* for kbhit() */
-
- typedef struct {
- int xpos, ypos;
- int sw1, sw2;
- } JOY;
-
- JOY js;
-
-
- main()
- {
- char contin=1;
- clrscr();
-
- while(contin)
- {
- J_check();
- gotoxy(10, 10);
- printf(" ");
- gotoxy(10, 10);
- printf("XPOS=%d YPOS=%d SW1=%d SW2=%d\n", js.xpos, js.ypos, js.sw1, js.sw2);
- if (js.sw1 && js.sw2)
- contin=0;
- if ( kbhit() )
- contin=0;
- }
-
- }
-
- J_check()
- {
-
- union REGS regs;
-
- regs.x.dx = 0; /* DX=0 - Check buttons */
- regs.h.ah = 0x84;
- int86(0x15, ®s, ®s);
-
- if (regs.h.al & 16)
- js.sw1 = 0;
- else
- js.sw1 = 1;
-
- if (regs.h.al & 32)
- js.sw2 = 0;
- else
- js.sw2 = 1;
-
- regs.x.dx = 1; /* DX=1 - Check stick position */
- regs.h.ah = 0x84;
- int86(0x15, ®s, ®s);
-
- js.xpos = regs.x.ax;
- js.ypos = regs.x.bx;
-
- return(0);
- }