home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 499.lha / GamePortDeviceToolKit / gameport.lzh / src / DeviceToolKits / GamePort / test_shared / test4.c < prev    next >
C/C++ Source or Header  |  1991-01-03  |  3KB  |  120 lines

  1. #include <stdio.h>
  2.  
  3. #include "DeviceToolKits/GamePort.h"
  4. #ifndef  TESTPROTO
  5. #define  NO_PRAGMAS  1
  6. #endif
  7. #include "DeviceToolKits/proto/GamePort.h"
  8. #include "DeviceToolKits/GamePortBase.h"
  9.  
  10. DTGamePort_t               Unit1;
  11. BYTE                       type;
  12. struct   GamePortTrigger   trigger;
  13.  
  14. main(argc,argv)
  15. int   argc;
  16. char  *argv[];
  17. {
  18.    long  status;
  19.  
  20. #ifdef   TESTSHARED
  21. /*  Open the GamePort library  */
  22.  
  23.    DTGamePortOpen(DTGAMEPORTREV);
  24. #endif
  25.  
  26. /*  Try to initialize unit 1 of the GamePort  */
  27.  
  28.    if ((Unit1 = DTGamePortCreate(1L,&status)) == NULL) {
  29.       fprintf(stderr,"Error initializing unit 1 = %ld.\n",status);
  30.       fflush(stderr);
  31.       goto cleanup;
  32.    }
  33.  
  34.    fprintf(stderr,"Unit1 = %lX\n",(long) Unit1);
  35.    fflush(stderr);
  36.  
  37. /*  Find out what kind of controller is on unit 1  */
  38.  
  39.    if ((status = DTGamePortGetType(Unit1,&type)) != 0) {
  40.       fprintf(stderr,"Error getting unit 1 type = %ld,%ld.\n",
  41.                status,Unit1->gp_error);
  42.       fflush(stderr);
  43.       goto cleanup;
  44.    }
  45.  
  46.    printf("Unit 1 controller type = %d.\n",type);
  47.  
  48. /*  Set the controller for an absolute joystick  */
  49.  
  50.    type = GPCT_ABSJOYSTICK;
  51.    if ((status = DTGamePortSetType(Unit1,&type)) != 0) {
  52.       fprintf(stderr,"Error setting unit 1 type = %ld,%ld.\n",
  53.                status,Unit1->gp_error);
  54.       fflush(stderr);
  55.       goto cleanup;
  56.    }
  57.  
  58. /*  Find out what kind of controller is on unit 1  */
  59.  
  60.    if ((status = DTGamePortGetType(Unit1,&type)) != 0) {
  61.       fprintf(stderr,"Error getting unit 1 type = %ld,%ld.\n",
  62.                status,Unit1->gp_error);
  63.       fflush(stderr);
  64.       goto cleanup;
  65.    }
  66.  
  67.    printf("Unit 1 controller type = %d.\n",type);
  68.  
  69. /*  Find out what kind of trigger is on unit 1  */
  70.  
  71.    if ((status = DTGamePortGetTrigger(Unit1,&trigger)) != 0) {
  72.       fprintf(stderr,"Error getting unit 1 trigger = %ld,%ld.\n",
  73.                status,Unit1->gp_error);
  74.       fflush(stderr);
  75.       goto cleanup;
  76.    }
  77.  
  78.    printf("Keys    = %x\n",trigger.gpt_Keys);
  79.    printf("Timeout = %d\n",trigger.gpt_Timeout);
  80.    printf("XDelta  = %d\n",trigger.gpt_XDelta);
  81.    printf("YDelta  = %d\n",trigger.gpt_YDelta);
  82.  
  83. /*  Set the trigger for an absolute joystick  */
  84.  
  85.    trigger.gpt_Keys = GPTF_UPKEYS | GPTF_DOWNKEYS;
  86.    trigger.gpt_Timeout = 0;
  87.    trigger.gpt_XDelta = 1;
  88.    trigger.gpt_YDelta = 1;
  89.  
  90.    if ((status = DTGamePortSetTrigger(Unit1,&trigger)) != 0) {
  91.       fprintf(stderr,"Error setting unit 1 trigger = %ld,%ld.\n",
  92.                status,Unit1->gp_error);
  93.       fflush(stderr);
  94.       goto cleanup;
  95.    }
  96.  
  97. /*  Find out what kind of trigger is on unit 1  */
  98.  
  99.    if ((status = DTGamePortGetTrigger(Unit1,&trigger)) != 0) {
  100.       fprintf(stderr,"Error getting unit 1 trigger = %ld,%ld.\n",
  101.                status,Unit1->gp_error);
  102.       fflush(stderr);
  103.       goto cleanup;
  104.    }
  105.  
  106.    printf("Keys    = %x\n",trigger.gpt_Keys);
  107.    printf("Timeout = %d\n",trigger.gpt_Timeout);
  108.    printf("XDelta  = %d\n",trigger.gpt_XDelta);
  109.    printf("YDelta  = %d\n",trigger.gpt_YDelta);
  110.  
  111. /*  Free the stuff  */
  112.  
  113. cleanup:
  114.    DTGamePortFree(Unit1);
  115. #ifdef   TESTSHARED
  116.    DTGamePortClose();
  117. #endif
  118. }
  119.  
  120.