/*******************************************************************
** Simple example of using "f1gp.library"
*/
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/f1gp.h>
#include <libraries/f1gp.h>

#include <stdlib.h>
#include <stdio.h>

struct F1GPBase *F1GPBase = NULL;

ULONG Sig_f1gpquit = 0;
 BYTE f1gpquit_SigBit;

int main(int argc, char **argv)
{
   APTR quithandle;
   int i;

   if (F1GPBase = (struct F1GPBase *)OpenLibrary("f1gp.library",0)) {
      /**** INIT ****/
      f1gpquit_SigBit = AllocSignal(-1);
      Sig_f1gpquit = 1L << f1gpquit_SigBit;
      quithandle = f1gpAllocQuitNotify(FindTask(NULL),Sig_f1gpquit);
      /**************/

      if (f1gpDetect()) {	// IMPORTANT: A f1gpDetect() call will
                        	// patch the F1GP quit routines if needed.

         for (i=0;i<4;i++) printf("Hunk %d: 0x%08x\n",i,F1GPBase->HunkStart[i]);

         printf("F1GP version: %d (see libraries/f1gp.h)\n",F1GPBase->F1GPType);
         printf("Waiting until F1GP quits...\n");
         Wait(Sig_f1gpquit);	// Wait until F1GP quits
         printf("F1GP has quitted - bye\n");
      }
      else {
         printf("F1GP not in memory - won't bother to wait, bye...\n");
      }

      /**** SHUTDOWN ****/
      f1gpFreeQuitNotify(quithandle);
      if (f1gpquit_SigBit != -1) FreeSignal(f1gpquit_SigBit);
      CloseLibrary((struct Library *)F1GPBase);
      /******************/
   }
   else {
      printf("Unable to open f1gp.library\n");
   }
   return(0);
}
