home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: StartUp.c 37.5 (24.1.97)
- **
- ** Library startup-code and function table definition
- **
- ** (C) Copyright 1996-97 Andreas R. Kleinert
- ** All Rights Reserved.
- */
-
-
- #define __USE_SYSBASE // ignored by MAXON
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <exec/libraries.h>
- #include <exec/execbase.h>
- #include <exec/resident.h>
- #include <exec/initializers.h>
-
-
- #ifdef __MAXON__
- #include <pragma/exec_lib.h>
- #include <linkerfunc.h>
- #else
- #include <proto/exec.h> // all other compilers
- #endif
- #include "compiler.h"
-
- #include "/include/example/examplebase.h"
- #include "samplefuncs.h"
-
- extern ULONG __saveds __stdargs L_OpenLibs(void);
- extern void __saveds __stdargs L_CloseLibs(void);
-
- struct ExampleBase * __saveds __asm InitLib( register __a6 struct ExecBase *sysbase,
- register __a0 struct SegList *seglist,
- register __d0 struct ExampleBase *exb);
- struct ExampleBase * __saveds __asm OpenLib( register __a6 struct ExampleBase *ExampleBase);
- struct SegList * __saveds __asm CloseLib( register __a6 struct ExampleBase *ExampleBase);
- struct SegList * __saveds __asm ExpungeLib( register __a6 struct ExampleBase *exb);
- ULONG __saveds __asm ExtFuncLib(void);
-
- LONG __saveds __asm LibStart(void)
- {
- return(-1);
- }
-
- extern APTR FuncTab [];
- extern struct MyDataInit DataTab;
-
- struct InitTable /* do not change */
- {
- ULONG LibBaseSize;
- APTR *FunctionTable;
- struct MyDataInit *DataTable;
- APTR InitLibTable;
- } InitTab =
- {
- sizeof(struct ExampleBase),
- &FuncTab[0],
- &DataTab,
- InitLib
- };
-
- APTR FuncTab [] =
- {
- OpenLib,
- CloseLib,
- ExpungeLib,
- ExtFuncLib,
-
- EXF_TestRequest, /* add your own functions here */
-
- (APTR) ((LONG)-1)
- };
-
-
- extern struct ExampleBase *ExampleBase;
-
- struct ExampleBase * __saveds __asm InitLib( register __a6 struct ExecBase *sysbase,
- register __a0 struct SegList *seglist,
- register __d0 struct ExampleBase *exb)
- {
- ExampleBase = exb;
-
- ExampleBase->exb_SysBase = sysbase;
- ExampleBase->exb_SegList = seglist;
-
- if(L_OpenLibs()) return(ExampleBase);
-
- L_CloseLibs();
-
- return(NULL);
- }
-
- struct ExampleBase * __saveds __asm OpenLib( register __a6 struct ExampleBase *ExampleBase)
- {
- #ifdef __MAXON__
- GetBaseReg();
- InitModules();
- #endif
-
- ExampleBase->exb_LibNode.lib_OpenCnt++;
-
- ExampleBase->exb_LibNode.lib_Flags &= ~LIBF_DELEXP;
-
- return(ExampleBase);
- }
-
- struct SegList * __saveds __asm CloseLib( register __a6 struct ExampleBase *ExampleBase)
- {
- ExampleBase->exb_LibNode.lib_OpenCnt--;
-
- if(!ExampleBase->exb_LibNode.lib_OpenCnt)
- {
- if(ExampleBase->exb_LibNode.lib_Flags & LIBF_DELEXP)
- {
- return( ExpungeLib(ExampleBase) );
- }
- }
-
- return(NULL);
- }
-
- struct SegList * __saveds __asm ExpungeLib( register __a6 struct ExampleBase *exb)
- {
- struct ExampleBase *ExampleBase = exb;
- struct SegList *seglist;
-
- if(!ExampleBase->exb_LibNode.lib_OpenCnt)
- {
- ULONG negsize, possize, fullsize;
- UBYTE *negptr = (UBYTE *) ExampleBase;
-
- seglist = ExampleBase->exb_SegList;
-
- Remove((struct Node *)ExampleBase);
-
- L_CloseLibs();
-
- negsize = ExampleBase->exb_LibNode.lib_NegSize;
- possize = ExampleBase->exb_LibNode.lib_PosSize;
- fullsize = negsize + possize;
- negptr -= negsize;
-
- FreeMem(negptr, fullsize);
-
- #ifdef __MAXON__
- CleanupModules();
- #endif
-
- return(seglist);
- }
-
- ExampleBase->exb_LibNode.lib_Flags |= LIBF_DELEXP;
-
- return(NULL);
- }
-
- ULONG __saveds __asm ExtFuncLib(void)
- {
- return(NULL);
- }
-
- struct ExampleBase *ExampleBase = NULL;
-
-
- #ifdef __SASC
-
- ULONG XCEXIT = NULL; /* these symbols may be referenced by */
- ULONG _XCEXIT = NULL; /* some functions of sc.lib, but should */
- ULONG ONBREAK = NULL; /* never be used inside a shared library */
- ULONG _ONBREAK = NULL;
- ULONG base = NULL;
- ULONG _base = NULL;
- ULONG ProgramName = NULL;
- ULONG _ProgramName = NULL;
- ULONG StackPtr = NULL;
- ULONG _StackPtr = NULL;
- ULONG oserr = NULL;
- ULONG _oserr = NULL;
- ULONG OSERR = NULL;
- ULONG _OSERR = NULL;
-
- void __regargs __chkabort(void) { } /* a shared library cannot be */
- void __regargs _CXBRK(void) { } /* CTRL-C aborted when doing I/O */
-
- #endif /* __SASC */
-