home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD1.img
/
d1xx
/
d183
/
mklib
/
text.c
< prev
Wrap
C/C++ Source or Header
|
1989-02-25
|
14KB
|
452 lines
/*
Mklib 1.0 - a source file generator for Amiga shared libraries
Compiled with Manx v3.6a small code model/16 bit int. (see makefile)
copyright 1988 Edwin Hoogerbeets
This software and the files it produces are freely redistributable
as long there is no charge beyond reasonable copy fees and as long
as this notice stays intact.
Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this
program is lifted. Also thanks to Neil Katin for his mylib.asm upon
*/
#include <stdio.h>
#include <ctype.h>
#include <edlib.h>
char *makeheader[] = {
"# This makefile was generated with mklib",
"# copyright 1988 Edwin Hoogerbeets",
"#",
"# This software is freely redistributable as long as there is no charge",
"# beyond resonable copy fees and as long as this notice stays intact.",
"#",
"# Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this",
"# program is lifted. Also thanks to Neil Katin for his mylib.asm upon",
"# which elib is based.",
"",
"CFLAGS=-T",
"",
NULL
};
char *makefooter[] = {
" ln $(OBJS) -lc -o $@",
"",
"#yourprog: yourprog.o link.o",
"# ln yourprog.o link.o -lc -o $@",
NULL
};
char *facemid[] = {
"",
" public _geta4",
"",
"myopen:",
" setup",
" push a6",
" jsr _myOpen",
" restore 4",
"",
"myclose:",
" setup",
" push a6",
" jsr _myClose",
" restore 4",
"",
"myexpunge:",
" setup",
" push a6",
" jsr _myExpunge",
" restore 4",
"",
NULL
};
char *asmheader[] = {
"; This file was generated with mklib",
"; copyright 1988 Edwin Hoogerbeets",
";",
"; This software is freely redistributable as long as there is no charge",
"; beyond resonable copy fees and as long as this notice stays intact.",
";",
"; Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this",
"; program is lifted. Also thanks to Neil Katin for his mylib.asm upon",
"; which elib is based.",
";",
"",
NULL
};
char *cheader[] = {
"/*",
" This file was generated with mklib",
" copyright 1988 Edwin Hoogerbeets",
"",
" This software is freely redistributable as long as there is no charge",
" beyond resonable copy fees and as long as this notice stays intact.",
"",
" Thanks to Jimm Mackraz for Elib on Fish 87, from which much of this",
" program is lifted. Also thanks to Neil Katin for his mylib.asm upon",
" which elib is based.",
"*/",
"",
NULL
};
char *startupcode[] = {
";:ts=8",
"; Copyright (C) 1986 by Manx Software Systems, Inc.",
";",
"",
"; *** But FUNKIFIED by jimm ***",
"; library base in D0",
"; segment list in A0",
"; execbase in A6",
"",
"; Initial startup routine for Aztec C.",
"",
"; NOTE: code down to \"start\" must be placed at beginning of",
"; all programs linked with Aztec Linker using small",
"; code or small data.",
"",
"",
"a4save dc.l 0",
"",
" public .begin ; just to resolve label",
".begin",
" public _funkyInit",
"_funkyInit:",
"",
" near code",
"",
" movem.l d0/d2/d3/d4-d7/a2-a6,-(sp)",
"",
" ; FUNKY use a0, not a1 for segment list",
" move.l a0,a4 ;BPTR to code seg",
" add.l a4,a4",
" add.l a4,a4 ;now real address of code seg",
"",
" move.l (a4),a4 ;indirect to get data segment BPTR",
" add.l a4,a4 ;convert to real pointer",
" add.l a4,a4 ;real address of data seg link field",
"",
" ; same as crt0.a68",
" add.l #32766+4,a4 ;bias appropriately (+4 is for link)",
" lea __H1_end,a1",
" lea __H2_org,a2",
" cmp.l a1,a2 ;check if BSS and DATA together",
" bne start ;no, don't have to clear",
" move.w #((__H2_end-__H2_org)/4)-1,d1",
" bmi start ;skip if no bss",
" move.l #0,d2",
"loop",
" move.l d2,(a1)+ ;clear out memory",
" dbra d1,loop",
"",
"start",
" lea a4save,a1 ;get address of a4save",
" move.l a4,(a1) ;save a4",
"; FUNKY",
"; move.l sp,__savsp ;save stack pointer (can't fexec)",
"; move.l 4,a6 ;get Exec's library base pointer",
" move.l a6,_SysBase ;put where we can get it",
"",
" movem.l d0/a0,-(sp) ; pass base and seglist",
" jsr _funkymain ; FUNKY",
" addq.l #8,sp ;pop args to funkymain()",
" ; can pop better (?)",
"",
" movem.l (sp)+,d0/d2/d3/d4-d7/a2-a6",
" rts ;and return",
"",
" public _geta4",
"_geta4:",
" move.l a4save,a4",
" rts",
"",
" dseg",
"",
"",
"_SysBase dc.l 0",
"",
" public _funkymain",
" public _SysBase",
" public __H1_end,__H2_org,__H2_end",
"",
" end",
NULL
};
char *rtag[] = {
"; rtag.asm -- romtag",
"",
" include 'exec/types.i'",
" include 'exec/resident.i'",
" include 'exec/nodes.i'",
" include 'exec/libraries.i'",
"",
"MYVERSION equ 1",
"MYPRI equ 0",
"",
" cseg ; romtag must be in first hunk",
"",
" public _myname",
" public _myid",
" public _myInitTab",
"",
" ds 0",
" public _myRomTag",
"_myRomTag:",
" dc.w RTC_MATCHWORD",
" dc.l _myRomTag",
" dc.l endtag",
" dc.b RTF_AUTOINIT",
" dc.b MYVERSION",
" dc.b NT_LIBRARY",
" dc.b MYPRI",
" dc.l _myname",
" dc.l _myid",
" dc.l _myInitTab",
"endtag:",
"",
" end",
NULL
};
char *mandatory[] = {
"/* created by jim mackraz using mylib.asm by neil katin",
" * may be used and distributed providing this comment block",
" * is retained in the source code",
" */",
"#include <stdio.h>",
"#include \"lib.h\"",
"",
"extern PFL libfunctab[]; /* my function table (libface.asm) */",
"extern LONG funkyInit(); /* hacked up version of Aztec crt0.a68 */",
"",
"LONG myExpunge();",
"",
"struct InitTable myInitTab = {",
" sizeof (struct MyBase),",
" libfunctab,",
" NULL, /* will initialize my data in funkymain() */",
" funkyInit",
"};",
"",
"#define MYREVISION 0 /* would be nice to auto-increment this */",
"",
"extern char myname[];",
"extern char myid[];",
"",
"extern struct Resident myRomTag;",
"",
"/*",
" * this function is my C-language library initRoutine. It is called",
" * by funkyInit() after register saves and small model initialization is",
" * done.",
" */",
"",
"LONG",
"funkymain(libbase, seglist)",
"struct MyBase *libbase;",
"ULONG seglist;",
"{",
" register struct MyBase *base;",
"",
" /* cookie */",
" base = libbase;",
" base->mb_Cookie = 0xDEAD1234; /* debug kind of stuff */",
" base->mb_SegList = seglist;",
"",
" /* init. library structure (since I don't do automatic data init.) */",
" base->mb_Lib.lib_Node.ln_Type = NT_LIBRARY;",
" base->mb_Lib.lib_Node.ln_Name = (char *) myname;",
" base->mb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;",
" base->mb_Lib.lib_Version = myRomTag.rt_Version;",
" base->mb_Lib.lib_Revision = MYREVISION;",
" base->mb_Lib.lib_IdString = (APTR) myid;",
"",
" /* ----- do your own initialization here ----- */",
"}",
"",
"LONG",
"myOpen(base) /* baseptr in A6, version in D0 */",
"struct MyBase *base;",
"{",
" /* mark us as having another customer */",
" base->mb_Lib.lib_OpenCnt++;",
"",
" /* prevent delayed expunges (standard procedure) */",
" base->mb_Lib.lib_Flags &= ~LIBF_DELEXP;",
"",
" return ((LONG) base);",
"}",
"",
"LONG",
"myClose(base)",
"struct MyBase *base;",
"{",
" LONG retval = 0;",
"",
" if ((--base->mb_Lib.lib_OpenCnt == 0) &&",
" (base->mb_Lib.lib_Flags & LIBF_DELEXP))",
" {",
" /* no more people have me open,",
" * and I have a delayed expunge pending",
" */",
" retval = myExpunge(); /* return segment list */",
" }",
"",
" return (retval);",
"}",
"",
"LONG",
"myExpunge(base)",
"struct MyBase *base;",
"{",
" ULONG seglist = 0;",
" LONG libsize;",
"",
" if (base->mb_Lib.lib_OpenCnt == 0)",
" {",
" /* really expunge: remove libbase and freemem */",
"",
" seglist = base->mb_SegList;",
"",
" Remove(base);",
"",
" libsize = base->mb_Lib.lib_NegSize + base->mb_Lib.lib_PosSize;",
" FreeMem((char *) base - base->mb_Lib.lib_NegSize, (LONG) libsize);",
" }",
" else",
" {",
" base->mb_Lib.lib_Flags &= LIBF_DELEXP;",
" }",
"",
"",
" /* return NULL or real seglist */",
" return ((LONG) seglist);",
"}",
"",
NULL
};
char *faceheader[] = {
" include 'exec/types.i'",
"",
"setup macro",
" movem.l d2/d3/d4-d7/a2-a6,-(sp)",
" jsr _geta4",
" endm",
"",
"push macro",
" move.l \\1,-(sp)",
" endm",
"",
"fix macro",
" ifc '\\1',''",
" mexit",
" endc",
" ifle \\1-8",
" addq.l #\\1,sp",
" endc",
" ifgt \\1-8",
" lea \\1(sp),sp",
" endc",
" endm",
"",
"restore macro",
" fix \\1",
" movem.l (sp)+,d2/d3/d4-d7/a2-a6",
" rts",
" endm",
"",
" dseg",
"",
" public _libfunctab",
"_libfunctab:",
" dc.l myopen",
" dc.l myclose",
" dc.l myexpunge",
" dc.l $0000",
NULL
};
char *incbody[] = {
"#include <exec/types.h>",
"#include <exec/nodes.h>",
"#include <exec/resident.h>",
"#include <exec/libraries.h>",
"",
"#include <functions.h>",
"",
"typedef LONG (*PFL)(); /* pointer to function returning 32-bit int */",
"",
"/* library initialization table, used for AUTOINIT libraries */",
"struct InitTable {",
" ULONG it_DataSize; /* library data space size */",
" PFL *it_FuncTable; /* table of entry points */",
" APTR it_DataInit; /* table of data initializers */",
" PFL it_InitFunc; /* initialization function to run */",
"};",
"",
"struct MyBase {",
" struct Library mb_Lib;",
" ULONG mb_Cookie; /* looks good */",
" ULONG mb_SegList;",
" ULONG mb_Flags;",
" APTR mb_ExecBase; /* pointer to exec base */",
" APTR mb_A4; /* proper value of A4 for aztec small model */",
"};",
NULL
};
char *linkhead[] = {
" include 'exec/types.i'",
" include 'exec/libraries.i'",
"",
" LIBINIT",
NULL
};
char *link2[] = {
"",
"store macro",
" movem.l d2-d7/a2-a5,safekeep",
" endm",
"",
"retrieve macro",
" movem.l safekeep,d2-d7/a2-a5",
" endm",
"",
" dseg",
"",
"safekeep:",
" dcb.l 14 ; reserve some space for temporary register storage",
"",
" cseg",
"",
" ; --- xref from application",
" public _libbase",
"",
" ; --- xdef for application\n",
NULL
};
char *face2[] = {
" dc.l $ffffffff",
"",
" cseg",
"",
" ;--- library functions",
" public _myOpen",
" public _myClose",
" public _myExpunge",
NULL
};