home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / graphics / graphics_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  4.3 KB  |  212 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: graphics_init.c,v 1.9 1997/01/27 00:36:10 ldp Exp $
  4.  
  5.     Desc: Graphics library
  6.     Lang: english
  7. */
  8. #include <exec/resident.h>
  9. #include <proto/exec.h>
  10. #include <aros/libcall.h>
  11. #include <dos/dos.h>
  12. #include <exec/execbase.h>
  13. #include <graphics/gfxbase.h>
  14. #include <graphics/text.h>
  15. #include <proto/graphics.h>
  16. #include <utility/utility.h>
  17. #include "graphics_intern.h"
  18.  
  19. static const char name[];
  20. static const char version[];
  21. static const APTR inittabl[4];
  22. static void *const Graphics_functable[];
  23. struct GfxBase * AROS_SLIB_ENTRY(init,Graphics)();
  24. extern const char Graphics_end;
  25.  
  26. extern int  driver_init (struct GfxBase *);
  27. extern int  driver_open (struct GfxBase *);
  28. extern void driver_close (struct GfxBase *);
  29. extern void driver_expunge (struct GfxBase *);
  30.  
  31. int Graphics_entry(void)
  32. {
  33.     /* If the library was executed by accident return error code. */
  34.     return -1;
  35. }
  36.  
  37. const struct Resident Graphics_resident=
  38. {
  39.     RTC_MATCHWORD,
  40.     (struct Resident *)&Graphics_resident,
  41.     (APTR)&Graphics_end,
  42.     RTF_AUTOINIT,
  43.     39,
  44.     NT_LIBRARY,
  45.     0,
  46.     (char *)name,
  47.     (char *)&version[6],
  48.     (ULONG *)inittabl
  49. };
  50.  
  51. static const char name[]=GRAPHICSNAME;
  52.  
  53. static const char version[]="$VER: graphics.library 39.0 (12.8.96)\n\015";
  54.  
  55. static const APTR inittabl[4]=
  56. {
  57.     (APTR)sizeof(struct GfxBase),
  58.     (APTR)Graphics_functable,
  59.     NULL,
  60.     &AROS_SLIB_ENTRY(init,Graphics)
  61. };
  62.  
  63. #ifndef SYSFONTNAME
  64. #   define SYSFONTNAME    "topaz.font"
  65. #endif
  66.  
  67. static struct TextAttr sysTA;
  68.  
  69. AROS_LH2(struct GfxBase *, init,
  70.  AROS_LHA(struct GfxBase *, GfxBase, D0),
  71.  AROS_LHA(BPTR,               segList,   A0),
  72.        struct ExecBase *, sysBase, 0, Graphics)
  73. {
  74.     AROS_LIBFUNC_INIT
  75.  
  76.     SysBase = sysBase;
  77.  
  78.     Disable();
  79.     if (!driver_init (GfxBase))
  80.     {
  81.     Enable();
  82.     return NULL;
  83.     }
  84.     Enable();
  85.  
  86.     /* You would return NULL if the init failed */
  87.     return GfxBase;
  88.     AROS_LIBFUNC_EXIT
  89. }
  90.  
  91. AROS_LH1(struct GfxBase *, open,
  92.  AROS_LHA(ULONG, version, D0),
  93.        struct GfxBase *, GfxBase, 1, Graphics)
  94. {
  95.     AROS_LIBFUNC_INIT
  96.     struct TextFont * def;
  97.  
  98.     /* Keep compiler happy */
  99.     version=0;
  100.  
  101.     if (!GfxBase->DefaultFont)
  102.     {
  103.     sysTA.ta_Name  = (STRPTR)SYSFONTNAME;
  104.     sysTA.ta_YSize = 8;
  105.     sysTA.ta_Style = FS_NORMAL;
  106.     sysTA.ta_Flags = 0;
  107.  
  108.     def = OpenFont (&sysTA);
  109.  
  110.     if (!def)
  111.         return NULL;
  112.  
  113.     GfxBase->DefaultFont = def;
  114.     sysTA.ta_YSize = def->tf_YSize;
  115.     }
  116.  
  117.     UtilityBase = OpenLibrary (UTILITYNAME,0L);
  118.  
  119.     if (!UtilityBase)
  120.     return NULL;
  121.  
  122.     Disable();
  123.     if (!driver_open (GfxBase))
  124.     {
  125.     Enable();
  126.     return NULL;
  127.     }
  128.     Enable();
  129.  
  130.     /* I have one more opener. */
  131.     GfxBase->LibNode.lib_OpenCnt++;
  132.     GfxBase->LibNode.lib_Flags&=~LIBF_DELEXP;
  133.  
  134.     /* You would return NULL if the open failed. */
  135.     return GfxBase;
  136.     AROS_LIBFUNC_EXIT
  137. }
  138.  
  139. AROS_LH0(BPTR, close,
  140.        struct GfxBase *, GfxBase, 2, Graphics)
  141. {
  142.     AROS_LIBFUNC_INIT
  143.  
  144.     /* I have one fewer opener. */
  145.     if(!--GfxBase->LibNode.lib_OpenCnt)
  146.     {
  147.     driver_close (GfxBase);
  148.  
  149.     /* Delayed expunge pending? */
  150.     if(GfxBase->LibNode.lib_Flags&LIBF_DELEXP)
  151.         /* Then expunge the library */
  152.         return expunge();
  153.     }
  154.     return 0;
  155.     AROS_LIBFUNC_EXIT
  156. }
  157.  
  158. AROS_LH0(BPTR, expunge,
  159.        struct GfxBase *, GfxBase, 3, Graphics)
  160. {
  161.     AROS_LIBFUNC_INIT
  162. #ifndef DISK_BASED
  163.     if (!(GfxBase->LibNode.lib_OpenCnt) )
  164.     {
  165.     if (GfxBase->DefaultFont)
  166.     {
  167.         CloseFont (GfxBase->DefaultFont);
  168.  
  169.         GfxBase->DefaultFont = NULL;
  170.     }
  171.  
  172.     /* Allow the driver to release uneccessary memory */
  173.     driver_expunge (GfxBase);
  174.     }
  175.  
  176.     /* Don't delete this library. It's in ROM and therefore cannot be
  177.        deleted */
  178.     return 0L;
  179. #else
  180.     BPTR ret;
  181.  
  182.     /* Test for openers. */
  183.     if (GfxBase->LibNode.lib_OpenCnt)
  184.     {
  185.     /* Set the delayed expunge flag and return. */
  186.     GfxBase->LibNode.lib_Flags|=LIBF_DELEXP;
  187.     return 0;
  188.     }
  189.  
  190.     /* Get rid of the library. Remove it from the list. */
  191.     Remove(&GfxBase->LibNode.lib_Node);
  192.  
  193.     /* Get returncode here - FreeMem() will destroy the field. */
  194.     ret=0L;
  195.  
  196.     /* Free the memory. */
  197.     FreeMem((char *)GfxBase-GfxBase->LibNode.lib_NegSize,
  198.         GfxBase->LibNode.lib_NegSize+GfxBase->LibNode.lib_PosSize);
  199.  
  200.     return ret;
  201. #endif
  202.     AROS_LIBFUNC_EXIT
  203. }
  204.  
  205. AROS_LH0I(int, null,
  206.         struct GfxBase *, GfxBase, 4, Graphics)
  207. {
  208.     AROS_LIBFUNC_INIT
  209.     return 0;
  210.     AROS_LIBFUNC_EXIT
  211. }
  212.