4 Copyright (C) 2002-2011 Neil Cafferkey
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 #include <exec/types.h>
25 #include <exec/resident.h>
26 #include <utility/utility.h>
27 #include <graphics/gfxbase.h>
28 #include "initializers.h"
30 #include <proto/exec.h>
31 #include <proto/intuition.h>
35 #include "datatype_protos.h"
36 #include "gemimage_protos.h"
38 #define SUPERCLASS_VERSION 0
39 #define INTUITION_VERSION 36
40 #define UTILITY_VERSION 36
41 #define DATATYPES_VERSION 0
42 #define GRAPHICS_VERSION 39
43 #define DOS_VERSION 36
46 /* Private prototypes */
48 static VOID
DeleteDataType(struct GemImgBase
*base
);
51 /* Return an error immediately if someone tries to run the datatype */
60 const TEXT datatype_name
[] = DATATYPE_NAME
;
61 const TEXT version_string
[] =
62 DATATYPE_NAME
" " STR(VERSION
) "." STR(REVISION
) " (" DATE
")\n";
63 static const TEXT superclass_name
[] = "datatypes/picture.datatype";
64 static const TEXT intuition_name
[] = "intuition.library";
65 static const TEXT utility_name
[] = UTILITYNAME
;
66 static const TEXT datatypes_name
[] = "datatypes.library";
67 static const TEXT graphics_name
[] = GRAPHICSNAME
;
68 static const TEXT dos_name
[] = DOSNAME
;
71 static const APTR vectors
[] =
84 SMALLINITBYTEDEF(type
);
85 SMALLINITPINTDEF(name
);
86 SMALLINITBYTEDEF(flags
);
87 SMALLINITWORDDEF(version
);
88 SMALLINITWORDDEF(revision
);
89 SMALLINITPINTDEF(id_string
);
94 SMALLINITBYTE(OFFSET(Node
, ln_Type
), NT_LIBRARY
),
95 SMALLINITPINT(OFFSET(Node
, ln_Name
), datatype_name
),
96 SMALLINITBYTE(OFFSET(Library
, lib_Flags
), LIBF_SUMUSED
| LIBF_CHANGED
),
97 SMALLINITWORD(OFFSET(Library
, lib_Version
), VERSION
),
98 SMALLINITWORD(OFFSET(Library
, lib_Revision
), REVISION
),
99 SMALLINITPINT(OFFSET(Library
, lib_IdString
), version_string
),
104 static const APTR init_table
[] =
106 (APTR
)sizeof(struct GemImgBase
),
113 const struct Resident rom_tag
=
116 (struct Resident
*)&rom_tag
,
117 (APTR
)(&rom_tag
+ 1),
122 (TEXT
*)datatype_name
,
123 (TEXT
*)version_string
,
129 /****i* gemimage.datatype/LibInit ******************************************
135 * lib_base = LibInit(lib_base, seg_list)
137 * struct GemImgBase *LibInit(struct GemImgBase *, APTR);
139 ****************************************************************************
143 struct GemImgBase
*LibInit(struct GemImgBase
*lib_base
REG("d0"),
144 APTR seg_list
REG("a0"), struct GemImgBase
*base
REG(BASE_REG
))
148 lib_base
->sys_base
= (APTR
)base
;
150 base
->seg_list
= seg_list
;
152 base
->superclass_base
= OpenLibrary(superclass_name
, SUPERCLASS_VERSION
);
153 base
->intuition_base
= (APTR
)OpenLibrary(intuition_name
,
155 base
->utility_base
= (APTR
)OpenLibrary(utility_name
, UTILITY_VERSION
);
156 base
->datatypes_base
= (APTR
)OpenLibrary(datatypes_name
,
158 base
->graphics_base
= (APTR
)OpenLibrary(graphics_name
, GRAPHICS_VERSION
);
159 base
->dos_base
= (APTR
)OpenLibrary(dos_name
, DOS_VERSION
);
160 if(base
->superclass_base
== NULL
|| base
->intuition_base
== NULL
161 || base
->utility_base
== NULL
|| base
->datatypes_base
== NULL
162 || base
->graphics_base
== NULL
|| base
->dos_base
== NULL
)
167 base
->class = MakeGemImgClass(base
);
168 if(base
->class == NULL
)
174 DeleteDataType(base
);
183 /****i* gemimage.datatype/LibOpen ******************************************
189 * datatype = LibOpen(version)
191 * struct GemImgBase *LibOpen(ULONG);
193 ****************************************************************************
197 struct GemImgBase
*LibOpen(ULONG version
REG("d0"),
198 struct GemImgBase
*base
REG(BASE_REG
))
200 ((struct Library
*)base
)->lib_OpenCnt
++;
201 ((struct Library
*)base
)->lib_Flags
&= ~LIBF_DELEXP
;
208 /****i* gemimage.datatype/LibClose *****************************************
214 * seg_list = LibClose()
216 * APTR LibClose(VOID);
218 ****************************************************************************
222 APTR
LibClose(struct GemImgBase
*base
REG(BASE_REG
))
224 APTR seg_list
= NULL
;
226 /* Expunge the datatype if a delayed expunge is pending */
228 if((--((struct Library
*)base
)->lib_OpenCnt
) == 0)
230 if((((struct Library
*)base
)->lib_Flags
& LIBF_DELEXP
) != 0)
231 seg_list
= LibExpunge(base
);
239 /****i* gemimage.datatype/LibExpunge ***************************************
245 * seg_list = LibExpunge()
247 * APTR LibExpunge(VOID);
249 ****************************************************************************
253 APTR
LibExpunge(struct GemImgBase
*base
REG(BASE_REG
))
257 if(((struct Library
*)base
)->lib_OpenCnt
== 0)
259 seg_list
= base
->seg_list
;
261 DeleteDataType(base
);
265 ((struct Library
*)base
)->lib_Flags
|= LIBF_DELEXP
;
273 /****i* gemimage.datatype/LibReserved **************************************
279 * result = LibReserved()
281 * APTR LibReserved(VOID);
283 ****************************************************************************
287 APTR
LibReserved(VOID
)
294 /****i* gemimage.datatype/ObtainClass **************************************
300 * class = ObtainClass()
302 * struct IClass *ObtainClass(VOID);
304 ****************************************************************************
308 struct IClass
*ObtainClass(struct GemImgBase
*base
REG(BASE_REG
))
315 /****i* gemimage.datatype/DeleteDataType ***********************************
323 * VOID DeleteDataType(VOID);
325 ****************************************************************************
329 static VOID
DeleteDataType(struct GemImgBase
*base
)
331 UWORD neg_size
, pos_size
;
333 if(base
->class != NULL
)
334 FreeClass(base
->class);
336 /* Close libraries */
338 if(base
->dos_base
!= NULL
)
339 CloseLibrary((APTR
)base
->dos_base
);
340 if(base
->graphics_base
!= NULL
)
341 CloseLibrary((APTR
)base
->graphics_base
);
342 if(base
->datatypes_base
!= NULL
)
343 CloseLibrary(base
->datatypes_base
);
344 if(base
->utility_base
!= NULL
)
345 CloseLibrary((APTR
)base
->utility_base
);
346 if(base
->intuition_base
!= NULL
)
347 CloseLibrary((APTR
)base
->intuition_base
);
348 if(base
->superclass_base
!= NULL
)
349 CloseLibrary(base
->superclass_base
);
351 /* Free datatype's memory */
353 neg_size
= ((struct Library
*)base
)->lib_NegSize
;
354 pos_size
= ((struct Library
*)base
)->lib_PosSize
;
355 FreeMem((UBYTE
*)base
- neg_size
, pos_size
+ neg_size
);