Squashed commit of 'sdl-hidd' branch
[cake.git] / rom / graphics / graphics_init.c
blob42f840ef77683266802a3f9e4618bb81f4cb6d3e
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics library
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <aros/debug.h>
13 #include <exec/resident.h>
14 #include <proto/exec.h>
15 #include <aros/libcall.h>
16 #include <aros/symbolsets.h>
17 #include <hardware/intbits.h>
18 #include <dos/dos.h>
19 #include <exec/execbase.h>
20 #include <exec/memory.h>
21 #include <exec/lists.h>
22 #include <graphics/gfxbase.h>
23 #include <graphics/text.h>
24 #include <graphics/regions.h>
25 #include <proto/graphics.h>
26 #include <utility/utility.h>
27 #include "graphics_intern.h"
28 #include "default_font.h"
29 #include LC_LIBDEFS_FILE
31 #include <stdio.h>
33 extern int driver_init (struct GfxBase *);
34 extern int driver_open (struct GfxBase *);
35 extern void driver_close (struct GfxBase *);
36 extern void driver_expunge (struct GfxBase *);
38 AROS_UFP4(ULONG, TOF_VBlank,
39 AROS_UFHA(ULONG, dummy, A0),
40 AROS_UFHA(void *, data, A1),
41 AROS_UFHA(ULONG, dummy2, A5),
42 AROS_UFHA(struct ExecBase *, SysBase, A6));
44 #ifndef SYSFONTNAME
45 # define SYSFONTNAME "topaz.font"
46 #endif
48 static struct TextAttr sysTA;
49 BOOL InitROMFont(struct GfxBase *);
51 static int GfxInit(struct GfxBase *LIBBASE)
53 WORD i;
55 NEWLIST(&LIBBASE->TextFonts);
56 InitSemaphore( &PrivGBase(GfxBase)->tfe_hashtab_sema );
57 InitSemaphore( &PrivGBase(GfxBase)->fontsem );
59 #if REGIONS_USE_MEMPOOL
60 InitSemaphore( &PrivGBase(GfxBase)->regionsem );
61 if (!(PrivGBase(GfxBase)->regionpool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR,
62 sizeof(struct Region) * 20,
63 sizeof(struct Region) * 20)))
65 return FALSE;
68 NEWLIST(&PrivGBase(GfxBase)->ChunkPoolList);
69 #endif
71 InitSemaphore( &PrivGBase(GfxBase)->driverdatasem );
72 if (!(PrivGBase(GfxBase)->driverdatapool = CreatePool(MEMF_PUBLIC | MEMF_SEM_PROTECTED,
73 1024,
74 1024)))
76 return FALSE;
79 for(i = 0; i < DRIVERDATALIST_HASHSIZE; i++)
81 NEWLIST((struct List *)&PrivGBase(GfxBase)->driverdatalist[i]);
84 if (!InitROMFont(LIBBASE)) return FALSE;
86 Disable();
87 if (!driver_init (LIBBASE))
89 Enable();
90 return FALSE;
92 Enable();
94 return TRUE;
97 static int GfxOpen(struct GfxBase *LIBBASE)
99 struct TextFont * def;
101 if (!LIBBASE->DefaultFont)
103 sysTA.ta_Name = (STRPTR)SYSFONTNAME;
104 sysTA.ta_YSize = 8;
105 sysTA.ta_Style = FS_NORMAL;
106 sysTA.ta_Flags = 0;
108 def = OpenFont (&sysTA);
110 if (!def)
111 return NULL;
113 LIBBASE->DefaultFont = def;
114 sysTA.ta_YSize = def->tf_YSize;
117 Disable();
118 if (!driver_open (LIBBASE))
120 Enable();
121 return NULL;
123 Enable();
125 /* Allocate 8 IPTR's for a hash list needed by
126 GfxAssociate(), GfxLookUp() */
128 if (!LIBBASE->hash_table)
129 LIBBASE->hash_table = (LONG *)AllocMem(8*sizeof(LONG *),
130 MEMF_CLEAR|MEMF_PUBLIC);
131 if (!LIBBASE->hash_table)
132 return NULL;
135 if(LIBBASE->LibNode.lib_OpenCnt == 0)
137 NEWLIST(&LIBBASE->TOF_WaitQ);
138 LIBBASE->vbsrv.is_Code = (APTR)TOF_VBlank;
139 LIBBASE->vbsrv.is_Data = LIBBASE;
140 LIBBASE->vbsrv.is_Node.ln_Name = "Graphics TOF server";
141 LIBBASE->vbsrv.is_Node.ln_Pri = 10;
142 LIBBASE->vbsrv.is_Node.ln_Type = NT_INTERRUPT;
144 /* Add a VBLANK server to take care of TOF waiting tasks. */
145 AddIntServer(INTB_VERTB, &LIBBASE->vbsrv);
148 return TRUE;
151 static int GfxExpunge(struct GfxBase *LIBBASE)
153 driver_expunge(LIBBASE);
154 return TRUE;
157 ADD2INITLIB(GfxInit, 0);
158 ADD2OPENLIB(GfxOpen, 0);
159 ADD2CLOSELIB(driver_close, 0);
160 ADD2EXPUNGELIB(GfxExpunge, 0);
162 #undef SysBase
164 AROS_UFH4(ULONG, TOF_VBlank,
165 AROS_UFHA(ULONG, dummy, A0),
166 AROS_UFHA(void *, data, A1),
167 AROS_UFHA(ULONG, dummy2, A5),
168 AROS_UFHA(struct ExecBase *, SysBase, A6))
170 AROS_USERFUNC_INIT
172 struct Node *tNode;
173 struct GfxBase * GfxBase = (struct GfxBase *)data;
175 if(!IsListEmpty(&GfxBase->TOF_WaitQ))
177 ForeachNode(&GfxBase->TOF_WaitQ, tNode)
179 Signal((struct Task *)tNode->ln_Name, SIGF_SINGLE);
183 return 0;
185 AROS_USERFUNC_EXIT