/*---------------------------------------------------------------------------
 *                       Konami's Guns functions
---------------------------------------------------------------------------*/

#include <sys/types.h>

#define PADBUFFLEN  86
#define PADID_GUN   0x31
#define PADID_CON   0x41
#define PADID_MOUSE 0x12

static char  Pad_buf[2][PADBUFFLEN];
static unsigned char *padd;

typedef struct
{
   unsigned short  v_count;
   unsigned short  h_count;
} HV_CNT;

typedef struct
{
   char result;
   char id;
   char data[2];
   char mask;
   char count;
   HV_CNT hv[20];
} GUN;

static HV_CNT   *hv[2];
GUN             *gun[2];
static u_short  pre_v_count, pre_h_count;
static char     *GunCount;

/*-------------------------------------
 * Set buffers for the gun's data
 * reading
-------------------------------------*/
void SetGun (char *buff, char *buff1)
{
/*   padd = (unsigned char *)&buff[0];
   GunCount = &buff[5];
   hv[0] = (HV_CNT *)&buff[6];
*/
   gun[0] = (GUN *)&buff[0];
   gun[1] = (GUN *)&buff1[0];
}

/*-------------------------------------
 * Return the gun's X coordinate in the
 * screen
-------------------------------------*/
u_short Read_Gun_x (void)
{
   if ((gun[0]->id == PADID_GUN) && (gun[0]->result == 0) &&
       (gun[0]->count > 0))
      return (gun[0]->hv[0].h_count);

   if ((gun[1]->id == PADID_GUN) && (gun[1]->result == 0) &&
       (gun[1]->count > 0))
      return (gun[1]->hv[0].h_count);

   return 0;
}

/*-------------------------------------
 * Return the gun's Y coordinate in the
 * screen
-------------------------------------*/
u_short Read_Gun_y (void)
{
   if ((gun[0]->id == PADID_GUN) && (gun[0]->result == 0) &&
       (gun[0]->count > 0))
   {
      gun[0]->count = 0;
      return (gun[0]->hv[0].v_count);
   }

   if ((gun[1]->id == PADID_GUN) && (gun[1]->result == 0) &&
       (gun[1]->count > 0))
   {
       gun[1]->count = 0;
       return (gun[1]->hv[0].v_count);
   }

   return 0;
}
