#include <stdio.h>

#include "DeviceToolKits/GamePort.h"
#ifndef  TESTPROTO
#define  NO_PRAGMAS  1
#endif
#include "DeviceToolKits/proto/GamePort.h"
#include "DeviceToolKits/GamePortBase.h"

DTGamePort_t               Unit0;
BYTE                       type;
struct   GamePortTrigger   trigger;

main(argc,argv)
int   argc;
char  *argv[];
{
   long  status;

#ifdef   TESTSHARED
/*  Open the GamePort library  */

   DTGamePortOpen(DTGAMEPORTREV);
#endif

/*  Try to initialize unit 0 of the GamePort  */

   if ((Unit0 = DTGamePortCreate(0L,&status)) == NULL) {
      fprintf(stderr,"Error initializing unit 1 = %ld.\n",status);
      fflush(stderr);
      goto cleanup;
   }

   fprintf(stderr,"Unit0 = %lX\n",(long) Unit0);
   fflush(stderr);

/*  Find out what kind of controller is on unit 0  */

   if ((status = DTGamePortGetType(Unit0,&type)) != 0) {
      fprintf(stderr,"Error getting unit 0 type = %ld,%ld.\n",
               status,Unit0->gp_error);
      fflush(stderr);
      goto cleanup;
   }

   printf("Unit 0 controller type = %d.\n",type);

/*  Find out what kind of trigger is on unit 0  */

   if ((status = DTGamePortGetTrigger(Unit0,&trigger)) != 0) {
      fprintf(stderr,"Error getting unit 0 trigger = %ld,%ld.\n",
               status,Unit0->gp_error);
      fflush(stderr);
      goto cleanup;
   }

   printf("Keys    = %x\n",trigger.gpt_Keys);
   printf("Timeout = %d\n",trigger.gpt_Timeout);
   printf("XDelta  = %d\n",trigger.gpt_XDelta);
   printf("YDelta  = %d\n",trigger.gpt_YDelta);

/*  Free the stuff  */

cleanup:
   DTGamePortFree(Unit0);
#ifdef   TESTSHARED
   DTGamePortClose();
#endif
}

