home *** CD-ROM | disk | FTP | other *** search
- /*
- ** tolleuhr.library
- ** Written by Gunther Nikl (gnikl@informatik.uni-rostock.de)
- */
-
- #include <exec/types.h>
-
- #if !defined(__GNUC__)
- #define REG(x)
- #else
- #define REG(x) asm(#x)
- #endif
-
- #include <exec/resident.h>
- #include <exec/execbase.h>
- #include <proto/exec.h>
-
- struct LibBase {
- struct Library LibNode;
- UWORD Pad;
- BPTR SegList;
- struct Library *SysBase;
- };
-
- LONG Start();
-
- /****************************************************************************/
-
- #define VERSION 37
- #define REVISION 1
- #define LIBNAME "tolleuhr.library\0tolleuhr 37.1 (15.11.95) by M.Fleischer and G.Nikl\r\n"
-
- #if !defined(mc68020) && !defined(mc68030) && !defined(mc68040) && !defined(mc68060)
- #define REQUIRES_68020(x) (0)
- #else
- #define REQUIRES_68020(x) ((((struct ExecBase *)x)->AttnFlags & AFF_68020) == 0)
- #endif
-
- /****************************************************************************/
-
- // First executable routine of this library; must return an error
- // to the unsuspecting caller
-
- LONG
- ReturnError(VOID)
- {
- return -1;
- }
-
- /****************************************************************************/
-
- /* LibReserved(VOID):
- *
- * The mandatory reserved library function.
- */
-
- LONG
- LibReserved(VOID)
- {
- return 0;
- }
-
- /* LibExpunge(REG(a6) struct LibBase *lib):
- *
- * Expunge the library, remove it from memory
- */
-
- BPTR
- LibExpunge(struct LibBase *lib REG(a6))
- {
- BPTR Result = 0;
-
- // Expunge it later
-
- lib->LibNode.lib_Flags |= LIBF_DELEXP;
-
- // Can we get away with this?
-
- if (!lib->LibNode.lib_OpenCnt) {
-
- struct Library *SysBase = lib->SysBase;
-
- // Return the seglist, so it can be unloaded
-
- Result = lib->SegList;
-
- // Remove the library from the public list
-
- Remove((struct Node *)lib);
-
- // Free the vector table and the library data
-
- FreeMem((UBYTE *)lib-lib->LibNode.lib_NegSize,lib->LibNode.lib_NegSize+lib->LibNode.lib_PosSize);
- }
-
- // Return the segment pointer, if any
-
- return Result;
- }
-
- /* LibClose(REG(a6) struct LibBase *lib):
- *
- * Close the library, as called by CloseLibrary()
- */
-
- BPTR
- LibClose(struct LibBase *lib REG(a6))
- {
- BPTR Result = 0;
-
- // Decrement usage count and check how
- // many customers we still have
-
- if (!--lib->LibNode.lib_OpenCnt && (lib->LibNode.lib_Flags & LIBF_DELEXP))
- Result = LibExpunge(lib);
-
- return Result;
- }
-
- /* LibOpen(REG(a6) struct LibBase *lib):
- *
- * Open the library, as called via OpenLibrary()
- */
-
- struct LibBase *
- LibOpen(struct LibBase *lib REG(a6))
- {
- // Increment the user count and prevent delayed expunge
-
- lib->LibNode.lib_OpenCnt++;
- lib->LibNode.lib_Flags &= ~LIBF_DELEXP;
-
- return lib;
- }
-
- /* LibInit():
- *
- * Initialize the library.
- */
-
- struct LibBase *
- LibInit(BPTR SegList REG(a0),struct LibBase *lib REG(d0),struct Library *SysBase REG(a6))
- {
- // Set up the header data; everything that doesn't get set
- // up here will have been set up by InitResident().
-
- lib->LibNode.lib_Revision = REVISION;
-
- // Remember the segment pointer
-
- lib->SegList = SegList;
-
- // Remember the exec library base pointer
-
- lib->SysBase = SysBase;
-
- if (37>SysBase->lib_Version || REQUIRES_68020(SysBase)) {
- FreeMem((UBYTE *)lib-lib->LibNode.lib_NegSize,lib->LibNode.lib_NegSize+lib->LibNode.lib_PosSize);
- lib = NULL;
- }
-
- return lib;
- }
-
- /****************************************************************************/
-
- // This is the table of functions that make up the library. The first
- // four are mandatory, everything following it are user callable
- // routines. The table is terminated by the value -1.
-
- const APTR LibVectors[] = {
- LibOpen,
- LibClose,
- LibExpunge,
- LibReserved,
- Start,
- (APTR) -1
- };
-
- // The following data structures and data are responsible for
- // setting up the Library base data structure and the library
- // function vector.
-
- const ULONG LibInitTable[] = {
- (ULONG)sizeof(struct LibBase), // Size of the base data structure
- (ULONG)LibVectors, // Points to the function vector
- (ULONG)NULL, // Library base data structure setup table
- (ULONG)LibInit // The address of the routine to do the setup
- };
-
- /****************************************************************************/
-
- // The library loader looks for this marker in the memory
- // the library code and data will occupy. It is responsible
- // setting up the Library base data structure.
-
- const struct Resident RomTag = {
- RTC_MATCHWORD, // Marker value.
- (struct Resident *)&RomTag, // This points back to itself.
- (struct Resident *)&RomTag+1, // This points behind this marker.
- RTF_AUTOINIT, // The Library should be set up according to the given table.
- VERSION, // The version of this Library.
- NT_LIBRARY, // This defines this module as a Library.
- 0, // Initialization priority of this Library; unused.
- LIBNAME, // Points to the name of the Library.
- LIBNAME+17, // The identification string of this Library.
- (APTR)&LibInitTable // This table is for initializing the Library.
- };
-