/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* |_o_o|\\ Copyright (c) 1990 The Software Distillery.  All Rights Reserved.*/
/* |. o.| || This program may not be distributed without the permission of   */
/* | .  | || the authors.                                                    */
/* | o  | ||                                                                 */
/* |  . |// Written by Doug Walker                                           */
/* ======          BBS:(919)-471-6436      VOICE:(919)-467-4764              */ 
/*                 BIX: djwalker           USENET: ...!mcnc!rti!sas!walker   */
/*                 405 B3 Gooseneck Dr, Cary, NC 27513, USA                  */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <exec/interrupts.h>
#include <exec/ports.h>
#include <exec/libraries.h>
#include <exec/io.h>
#include <exec/tasks.h>
#include <exec/execbase.h>
#include <exec/devices.h>
#include <devices/timer.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <intuition/intuitionbase.h>
#include <libraries/dos.h>
/*#include <graphics/gfxmacros.h>*/
#include <hardware/custom.h>
#include <hardware/dmabits.h>
#include <hardware/cia.h>
#include <resources/misc.h>
#include <proto/dos.h>
#include <proto/exec.h>
/*#include <proto/intuition.h>*/
#include <graphics/copper.h>
#include <graphics/gfxbase.h>
#include <proto/graphics.h>
#include <string.h>

#include "dnet.h"

#define PORT_NETKEYS 9494



#define NKMPNAME "NetKeys 2.0"
#define BANNER "\x9B" "1m" NKMPNAME "\x9b" "0m by Doug Walker\n"\
               "Copyright \xA9 1990 The Software Distillery\n"\
               "235 Trillingham Ln, Cary NC 27513 USA\nBBS:(919)382-8265\n"

#define INSTR  "Use 'NetKeys QUIT' to remove\n"\
               "Installing, please wait...\n"

#define DEFDOKEY     0x13
#define MAXMSGS      100

#define MSG(fh,st)  if(fh) Write(fh, st, strlen(st))

#define IESZ  (sizeof(struct InputEvent))
#define NKMSZ (sizeof(struct NETKEYMSG))

/* Magic class to tell other side information */
#define IECLASS_NKCONTROL    IECLASS_POINTERPOS

/* Values for the 'Code' field of a IECLASS_NKCONTROL message                  */
#define IECODE_NKHOTKEY  0x01  /* Hotkey transferred control to server         */
#define IECODE_NKHOTQUIT 0x02  /* Hotkey ending control by server              */
#define IECODE_NKLEFT    0x04  /* Mouse is exiting from left of handler screen */
#define IECODE_NKRIGHT   0x08  /* Mouse is exiting from right of handler scrn  */

struct NETKEYMSG
{
   struct Message m;
   short msgtype;
   struct InputEvent ie;   
};

/* Defines for the msgtype field */
#define NKM_NONE    -1
#define NKM_IEVENT   0
#define NKM_QUIT     1
#define NKM_CONTROL  2
#define NKM_ACK      3
#define NKM_HEREWEGO 4
#define NKM_WEBEDONE 5

typedef struct
{
   struct Task *buddy;
   short dokey;
   short state;
   short nmsgs;
   struct MsgPort *nkmp;
   struct MsgPort *rtnp;
   struct IntuitionBase *ibase;
   short  swidth;
   short exit;
   int active;
   struct DChannel *chan;
   
} GLOBAL_DATA;

/* Defines for the global.state field */
#define EM_SANITY -3  /* Failed sanity check - prolly too many msgs outstanding */
#define EM_NOMEM  -2  /* Out of memory                                          */
#define EM_QUIT   -1  /* Normal quit                                            */
#define EM_DOIT    0  /* Keep on truckin'                                       */
#define EM_LURK    1  /* Pass events through                                    */
#define EM_RELURK  2  /* Start lurking immediately                              */

#define NKM_HANDLER 2 /* Parms to InitDevice */
#define NKM_SERVER  1

struct InputEvent * __regargs myhandler(struct InputEvent *ev, GLOBAL_DATA *gptr);

/* * * * * * * * * * * EXTERNAL ROUTINES * * * * * * * * * */
struct IOStdReq * CreateIOReq(struct MsgPort *, int);
void DeleteIOReq(struct IOStdReq *);

void mshow(struct GfxBase *GfxBase, UWORD *NoSprData, int on);
