/*
****************************************************************************

      Input Device ToolKit Subroutines.
      Standard Include File.

      Input.h.
      Version 1.1.

      Paris E. Bingham Jr.
      Copyright © 1986 - 1990  All Rights Reserved.


      History:

    Version      Date      Comments
    -------    --------    -----------------------------------------------
      1.0      12/01/89    PEB - Created.
      1.1      09/04/90    PEB - Add support for Manx C V5.0.
               09/22/90    PEB - Add support for SAS C V5.10.

****************************************************************************
*/

#ifndef  DT_INPUT_H
#define  DT_INPUT_H

/*
      Compiler Definitions
*/

#ifdef   SAS
#define  ANSI_PROTO        1
#endif

#ifdef   MANXV3
#undef   ANSI_PROTO
#undef   NO_PRAGMAS
#define  NO_PRAGMAS        1
#define  MANX              1
#endif

#ifdef   MANXV5
#define  ANSI_PROTO        1
#define  MANX              1
#endif

/*
      Include Files
*/

#include <exec/types.h>
#include <exec/exec.h>
#include <exec/execbase.h>
#include <exec/interrupts.h>
#include <devices/input.h>
#include <devices/gameport.h>
#include <devices/timer.h>
#include <devices/inputevent.h>

#ifdef   SAS
#include <proto/exec.h>
#endif

#ifdef   MANX
#ifndef  NOPRAGMAS
#include <pragmas.h>
#else
#include <functions.h>
#endif
#endif

/*
      Definitions
*/

/*
****************************************************************************
      DTInput - Input Control Structure
****************************************************************************
*/

struct   DTInput  {
   ULONG                in_flags;            /* Control flags */
   struct   MsgPort     *in_wport;           /* Write reply port */
   struct   IOStdReq    *in_wreq;            /* Write request block */
   struct   MsgPort     *in_tport;           /* Timer reply port */
   struct   timerequest *in_treq;            /* Timer request block */
   LONG                 in_error;            /* Error on request */
};

/*  Flag bits  */
#define  DTINB_GOTWPORT    0                 /* Got write reply port */
#define  DTINF_GOTWPORT    (1 << DTINB_GOTWPORT)

#define  DTINB_GOTWREQB    1                 /* Got write request block */
#define  DTINF_GOTWREQB    (1 << DTINB_GOTWREQB)

#define  DTINB_GOTTPORT    2                 /* Got timer reply port */
#define  DTINF_GOTTPORT    (1 << DTINB_GOTWPORT)

#define  DTINB_GOTTREQB    3                 /* Got timer request block */
#define  DTINF_GOTTREQB    (1 << DTINB_GOTTREQB)

#define  DTINB_GOTDEVICE   4                 /* Got device */
#define  DTINF_GOTDEVICE   (1 << DTINB_GOTDEVICE)

#define  DTINB_INIT        5                 /* All done */
#define  DTINF_INIT        (1 << DTINB_INIT)

#define  DTINB_COPY        6                 /* Is copy */
#define  DTINF_COPY        (1 << DTINB_COPY)

/*  Typedef for User */
typedef  struct   DTInput  *DTInput_t;


/*
****************************************************************************
      Error Codes
****************************************************************************
*/

#define  DTINE_NO_ERROR       0L             /* No error */
#define  DTINE_NO_STRUCTURE   1L             /* No control structure */
#define  DTINE_NO_WPORT       2L             /* Write reply port not alloc. */
#define  DTINE_NO_WREQB       3L             /* Write req. not alloc. */
#define  DTINE_NO_TPORT       4L             /* Timer reply port not alloc. */
#define  DTINE_NO_TREQB       5L             /* Timer req. not alloc. */
#define  DTINE_NO_DEVICE      6L             /* Device not opened */
#define  DTINE_NO_INIT        7L             /* Control not initialized */
#define  DTINE_NO_DATA        8L             /* No pointer to data */
#define  DTINE_NO_LENGTH      9L             /* No data length */


/*
****************************************************************************
      Useful Macros
****************************************************************************
*/

#define  DTInputFree(i)          { DTInputDestroy(i); i = NULL; }
#define  DTInputWriteLength(c)   ((i)->in_wreq->io_Actual)

#ifndef  DTBuildStdRequest
#define  DTBuildStdRequest(r,c,f,o,d,l) \
   { (r)->io_Command = (UWORD) c; \
     (r)->io_Flags = (UBYTE) f; \
     (r)->io_Offset = (ULONG) o; \
     (r)->io_Data = (APTR) d; \
     (r)->io_Length = (ULONG) l; }
#endif

#ifndef  DTBuildTimerRequest
#define  DTBuildTimerRequest(t,c,f,s,m) \
   { (t)->tr_node.io_Command = (UWORD) c; \
     (t)->tr_node.io_Flags = (UBYTE) f; \
     (t)->tr_time.tv_secs = (ULONG) s; \
     (t)->tr_time.tv_micro = (ULONG) m; }
#endif

/*
****************************************************************************
      End of Input.h
****************************************************************************
*/

#endif

