home *** CD-ROM | disk | FTP | other *** search
- /* Test Joystick object.
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include "kernel.h"
-
- /* change the line below to include your copy of the Adhesive
- header file supplied with Adhesive
- */
- #include "C:h.Adhesive"
-
-
- #include "Objects:joystick.149.100.Joystick"
- #include "Objects:joystick.149.100.Keys"
-
- /* external request table */
- extern Adhesive_Request cahg_need_ObjectsNeeded;
-
- /* our user handle */
- Adhesive_User userHandle=NULL;
-
- static void checkErr(_kernel_oserror *err)
- { /* does nothing if passed a zero pointer
- else displays error and does not return
- */
- if (err) {
- fprintf(stderr,"Error: %x %s\n",err->errnum,err->errmess);
- exit(EXIT_FAILURE);
- }
- }
-
-
- static void deRegister(void)
- {
- checkErr(adhesive_Deregister(&userHandle));
- }
-
-
-
- int main()
- {
- Adhesive_UserInfo info;
- Joystick j;
- void *workspace;
- int x,y,buttons;
-
- info.flags=0;
- info.name="Test Joystick object";
-
- /* setup atexit handler to ensure we always deregister */
- atexit(deRegister);
-
- /* register with Adhesive */
- checkErr(adhesive_Register(&userHandle,&info));
-
- /* request objects */
- checkErr(adhesive_Request(&userHandle,&cahg_need_ObjectsNeeded));
-
- /* test the joystick */
-
- /* find out size of workspace required for a Joystick
- and allocate it
- */
- workspace = malloc(joystick_PreNew());
-
- /* create a new Joystick which uses this workspace,
- NB do not use the same workspace more than once!
- We shall use physical joystick 1 if it exists.
- */
- j = joystick_New(1,workspace);
-
- /* I (the author) don't have a joystick so we set up
- the cursor keys and space bar to simulate the joystick.
- Comment out the lines below if you have a real joystick,
- you may also need to change the joystick number above.
- */
-
- joystick_AssignKeyX(j,IKEY_LEFT,IKEY_RIGHT);
- joystick_AssignKeyY(j,IKEY_UP,IKEY_DOWN);
- joystick_AssignButtonKey(j,IKEY_SPACE,0);
-
- /* We will now keep printing out the x,y and button
- values until the program is termianted
- */
- while(1) {
- buttons = joystick_Read(j,&x,&y);
- printf("%i \t%i \t%i\n",x,y,buttons);
- }
-
-
- /* We did ever terminate the while loop we would dispose
- of j and associated workspace as follows
- */
- joystick_Dispose(j);
- free(workspace);
-
- return EXIT_SUCCESS;
- }
-
-