Add simple device and simple library examples.

This commit is contained in:
Krystian Bacławski 2015-09-09 07:41:04 +02:00
parent 96f2ca8451
commit 2deab525fe
4 changed files with 261 additions and 1 deletions

1
examples/.gitignore vendored
View File

@ -1,3 +1,4 @@
*-*
!*.*
*~
*.o

View File

@ -4,8 +4,9 @@ CFLAGS = -Os -Wall -fomit-frame-pointer
CXXFLAGS = -Os -Wall -fomit-frame-pointer
BINS = hello-ks13 hello-ks20 hello-stdio hello-iostream hello-mui test-mmu
OBJS = simple-device.o simple-library.o
all: $(BINS)
all: $(BINS) $(OBJS)
hello-ks13: CC += -fbaserel
hello-ks13: CFLAGS += -m68000 -msmall-code
@ -29,6 +30,24 @@ hello-mui: hello-mui.c
test-mmu: CFLAGS += -m68060 -msmall-code
test-mmu: test-mmu.c
simple-device.o: CC += -fbaserel
simple-device.o: simple-device.c
simple-library.o: CC += -fbaserel
simple-library.o: simple-library.c
# normal library
lib: CC = m68k-amigaos-gcc -nostdlib -fbaserel
lib: libinit.o simple-library.o
# multibase library
libr: CC = m68k-amigaos-gcc -nostdlib -fbaserel
libr: libinitr.o simple-library.o
# device
dev: CC = m68k-amigaos-gcc -nostdlib -fbaserel
dev: devinit.o simple-device.o
clean:
rm -f $(BINS)
rm -f *.o *~

149
examples/simple-device.c Normal file
View File

@ -0,0 +1,149 @@
/******************************************************************************/
/* */
/* includes */
/* */
/******************************************************************************/
#include <exec/errors.h>
#include <proto/exec.h>
#include <stabs.h>
/******************************************************************************/
/* */
/* exports */
/* */
/******************************************************************************/
const char DevName[]="simple.device";
const char DevIdString[]="version 1.0";
const UWORD DevVersion=1;
const UWORD DevRevision=0;
/******************************************************************************/
/* */
/* global declarations */
/* */
/******************************************************************************/
struct Device *myDevPtr;
struct ExecBase *SysBase;
/******************************************************************************/
/* */
/* user device initialization */
/* */
/* !!! CAUTION: This function runs in a forbidden state !!! */
/* */
/******************************************************************************/
int __UserDevInit(struct Device *myDev)
{
/* !!! required !!! */
SysBase = *(struct ExecBase **)4L;
/* setup your device base - to access device functions over *this* basePtr! */
myDevPtr = myDev;
/* now do your initialization */
/* ... */
/* return a bool to indicate success */
return 0;
}
/******************************************************************************/
/* */
/* user device cleanup */
/* */
/* !!! CAUTION: This function runs in a forbidden state !!! */
/* */
/******************************************************************************/
void __UserDevCleanup(void)
{
/* your cleanup comes here */
/* ... */
/* nothing to return */
}
/******************************************************************************/
/* */
/* device dependent open function */
/* */
/* !!! CAUTION: This function runs in a forbidden state !!! */
/* */
/******************************************************************************/
int __UserDevOpen(struct IORequest *iorq,ULONG unit,ULONG flags)
{
int io_err = IOERR_OPENFAIL;
/* return a bool to indicate success */
return io_err;
}
/******************************************************************************/
/* */
/* device dependent close function */
/* */
/* !!! CAUTION: This function runs in a forbidden state !!! */
/* */
/******************************************************************************/
void __UserDevClose(struct IORequest *iorq)
{
/* nothing to return */
}
/******************************************************************************/
/* */
/* device dependent beginio function */
/* */
/******************************************************************************/
ADDTABL_1(__BeginIO,a1);
void __BeginIO(struct IORequest *iorq)
{
};
/******************************************************************************/
/* */
/* device dependent abortio function */
/* */
/******************************************************************************/
ADDTABL_1(__AbortIO,a1);
void __AbortIO(struct IORequest *iorq)
{
};
/******************************************************************************/
/* */
/* additional device dependent functions */
/* */
/******************************************************************************/
/******************************************************************************/
/* */
/* endtable marker (required!) */
/* */
/******************************************************************************/
ADDTABL_END();
/******************************************************************************/
/* */
/* end of simpledev.c */
/* */
/******************************************************************************/

91
examples/simple-library.c Normal file
View File

@ -0,0 +1,91 @@
/******************************************************************************/
/* */
/* includes */
/* */
/******************************************************************************/
#include <dos/dosextens.h>
#include <proto/exec.h>
#include <stabs.h>
/******************************************************************************/
/* */
/* exports */
/* */
/******************************************************************************/
const char LibName[]="simple.library";
const char LibIdString[]="version 1.0";
const UWORD LibVersion=1;
const UWORD LibRevision=0;
/******************************************************************************/
/* */
/* global declarations */
/* */
/******************************************************************************/
struct Library *myLibPtr;
struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
/******************************************************************************/
/* */
/* user library initialization */
/* */
/* !!! CAUTION: This function may run in a forbidden state !!! */
/* */
/******************************************************************************/
int __UserLibInit(struct Library *myLib)
{
/* setup your library base - to access library functions over *this* basePtr! */
myLibPtr = myLib;
/* !!! required !!! */
SysBase = *(struct ExecBase **)4L;
return (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",33L))==NULL;
}
/******************************************************************************/
/* */
/* user library cleanup */
/* */
/* !!! CAUTION: This function runs in a forbidden state !!! */
/* */
/******************************************************************************/
void __UserLibCleanup(void)
{
CloseLibrary(&DOSBase->dl_lib);
}
/******************************************************************************/
/* */
/* library dependent function(s) */
/* */
/******************************************************************************/
ADDTABL_1(__UserFunc,d0); /* One Argument in d0 */
int __UserFunc(long a)
{
return a*2;
}
/******************************************************************************/
/* */
/* endtable marker (required!) */
/* */
/******************************************************************************/
ADDTABL_END();
/******************************************************************************/
/* */
/* end of simplelib.c */
/* */
/******************************************************************************/