home *** CD-ROM | disk | FTP | other *** search
- /* JOYST.C - Joystick show positions routine. v. 123086
- by Kyle Cordes.
- Thanks to Dale Randall for the joystick
- packet format:
- $fe or $ff for which joystick changed,
- data of joystick 0
- data of joystick 1
-
- remember: joystick 0 is the front (left on 1040ST) port and
- joystick 1 is the back (right on 1040ST) port
-
- THIS PROGRAM WORKS WITH EITHER LATTICE C OR ALCYON C.
- */
-
- /*************************************************************/
- /* YOUR SOURCE FILE NEEDS THIS: */
-
- #include "osbind.h" /* for GEMDOS and XBIOS calls */
-
- long *vecs; /* pointer to vector table */
- long oldvec; /* old joystick vector */
-
- char joy0,joy1; /* position of joysticks 0 and 1 */
-
- /* THROUGH HERE */
- /*************************************************************/
-
- #define supexec(a) xbios(38,a) /* for Alcyon C */
-
- main() /* all this does is show values on the screen */
- {
- char old0,old1;
-
- joysetup();
-
- Cconout(27); /* clear screen */
- Cconout('E');
-
- Cconws("Joystick show routine.\r\nby Kyle Cordes\r\n");
- Cconws("Press any key to exit.\r\n");
- Cconws("See related article please.\r\n");
-
- old0=255; /* the joystick and mouse never generate these values, */
- old1=255; /* so we will be sure the positions will be shown */
- /* immediately */
- while(!Cconis()) { /* while no key pressed */
- if(joy0!=old0) {
- old0=joy0;
- Cconout(27); /* position cursor */
- Cconout('Y');
- Cconout(32+6);
- Cconout(32);
- Cconout(27);
- Cconout('l'); /* clear line */
- Cconws("Joystick 0: ");
- if(((int)joy0)&128)
- Cconws("fire ");
- if(joy0&1)
- Cconws("up ");
- if(joy0&2)
- Cconws("down ");
- if(joy0&4)
- Cconws("left ");
- if(joy0&8)
- Cconws("right");
- }
- if(joy1!=old1) {
- old1=joy1;
- Cconout(27); /* position cursor */
- Cconout('Y');
- Cconout(32+7);
- Cconout(32);
- Cconout(27);
- Cconout('l'); /* clear line */
- Cconws("Joystick 1: ");
- if(((int)joy1)&128)
- Cconws("fire ");
- if(joy1&1)
- Cconws("up ");
- if(joy1&2)
- Cconws("down ");
- if(joy1&4)
- Cconws("left ");
- if(joy1&8)
- Cconws("right");
- }
- }
-
- Cconin(); /* get the detected key */
-
- joyunset(); /* fix vector, else crash when */
- } /* BIOS calls destroyed routine */
-
- /**********************************************************************/
- /* JOYSTICK ROUTINES */
- /* YOUR SOURCE FILE NEEDS THE CODE FROM HERE TO THE END OF MY PROGRAM */
- /* */
- /* Feel free to use this as long as credit is given. */
- /**********************************************************************/
-
- /* The reason that this works is:
- When your routine called, the address of the packet is on the stack
- and the registers have already been saved and will be restored when your
- program exits.
- The documentation doesn't say this; I learned it from the BIOS listing. */
-
- joyinter(a) /* called by the BIOS when the joystick pos changes */
- char *a;
- {
- /* first byte is 254 for joystick 0 changed,
- 255 for joystick 1 changed */
- joy0=(*(a+1)); /* get second byte: position of joystick 0 */
- joy1=(*(a+2)); /* get third byte: position of joystick 1 */
- } /* format: bits numbered 76543210
- bit 0 - up
- bit 1 - down
- bit 2 - left
- bit 3 - right
- bit 7 - fire button */
-
- joyasetup() /* called in supervsior mode */
- {
- oldvec=(*(vecs+6)); /* save old vector */
- *(vecs+6)=(long)joyinter; /* insert new vector */
- }
-
- joysetup()
- {
- static char onmsg[]={0x12,0x14}; /* send message to IKBD */
- /* message is: mouse off, joystick auto-return mode */
-
- vecs=(long *)Kbdvbase(); /* address of table */
- Ikbdws(1,onmsg); /* send message: length-1,address of message */
- supexec((long)joyasetup); /* call XBIOS to call procedure in */
- } /* supervisor mode */
-
- joyaunset() /* called in supervisor mode */
- {
- *(vecs+6)=oldvec; /* replace old vector */
- }
-
- joyunset()
- {
- static char offmsg[]={0x15,0x8};
- /* message is: joystick auto-return off, mouse on */
- /* you MUST send the mouse off and on commands if you use joystick 0 */
-
- Ikbdws(1,offmsg); /* transmit */
-
- supexec((long)joyaunset); /* fix vector */
- }
-
- /******************************************************/
- /* END OF JOYSTICK ROUTINES */
- /******************************************************/
-