/*
 *  NL-Daemon   A program to force old programs to use NL gadget imagery.
 *
 *              Copyright 1989 by Davide P. Cervone.
 *  You may use this code, provided this copyright notice is kept intact.
 */

#include "NL-Handler.h"


struct IntuitionBase *IntuitionBase = NULL;
struct SysBase *SysBase;


/*
 *  These are the assembly code stubs that replace the Intuition Library
 *  vectors.  Thes stubs in turn call the C-language routines that actually
 *  do the work.
 */

extern void aOpenWindow();
extern void aSetMenuStrip();
extern void aOpenScreen();

/*
 *  These are used by the assembly stubs to call the original routines when
 *  needed.  They also are used to replace the Intution vectors when 
 *  NL-Daemon exits.
 */

long OldOpenWindow;
long OldSetMenuStrip;
long OldOpenScreen;

/*
 *  This routine is used to retro-fit existing windows and screens.
 */
 
extern void cOpenWindow();
extern void cOpenScreen();

/*
 *  These are the structures that need to be passed to the loader
 *  so that it can clean up after NL-Handler is removed
 */

extern struct Image CloseImage;
extern struct Image UpFrontImage;
extern struct Image DownBackImage;
extern struct Image SizeImage;
extern struct Image ZoomImage;

extern struct Image LR_CloseImage;
extern struct Image LR_UpFrontImage;
extern struct Image LR_DownBackImage;
extern struct Image LR_SizeImage;
extern struct Image LR_ZoomImage;

static struct NL_HandlerInfo NL_HandlerData =
{
   {                                            /* the MsgPort is pre-setup */
      {NULL,NULL, NT_MSGPORT, 0, PORTNAME},     /*  to include the name and */
      PA_IGNORE, 0, NULL,                       /*  type so that it can just */
      {NULL,NULL,NULL, 0,0}                     /*  be added to the port list */
   },                                           /*  so it can be found later */
   MAJVERS,MINVERS, MINLOADVER,
   NULL,
   &IntuitionBase,
   &SysBase,
   
   &aOpenWindow,
   &aSetMenuStrip,
   &aOpenScreen,
   &OldOpenWindow,
   &OldSetMenuStrip,
   &OldOpenScreen,
   
   &cOpenWindow,
   &cOpenScreen,

   &CloseImage,
   &UpFrontImage,
   &DownBackImage,
   &SizeImage,
   &ZoomImage,

   &LR_CloseImage,
   &LR_UpFrontImage,
   &LR_DownBackImage,
   &LR_SizeImage,
   &LR_ZoomImage,
   
   0,
};


/*
 *  Setup()
 *
 *  This routine MUST be linked into the NL-Handler executable 
 *  as the first routine, so that the loader can find it.
 *  It should check the version number for compatibility with the loader,
 *  and should return NULL for an error, or the pointer to the shared
 *  data structure if everything is OK.
 */

struct NL_HandlerInfo *Setup(version)
int version;
{
   if (version < MINLOADVER) return(NULL);
   return(&NL_HandlerData);
}
