NetBoot/romdrv 0.9.6/romdrv.c

1 line
10 KiB
C
Raw Normal View History

#include <Memory.h> #include <Devices.h> #include <Files.h> #include <Disks.h> #include <Errors.h> #include <Events.h> #include <OSUtils.h> #define NEED_DRVSTAT 1 #define NEED_ACCRUN 1 /* If NEED_ACCRUN is set, the dNeedTime (0x60) flag should be set in the header, and the * delayticks field in the header should be set to something sensible. */ //#define kRomDrvSize ((long)(524288L)) //#define kRomDrvSize ((long)(0x00700000L)) //#define kRomDrvLocation 0x40880000 unsigned long kRomDrvSize = 0x00780000L; Ptr kRomDrvLocation = (Ptr)0x40880000; Ptr* BufPtr = (Ptr*)0x10C; Ptr* MemTop = (Ptr*)0x108; #pragma parameter __D0 ReadXPRam(__D0, __D1, __A0) short ReadXPRam(short size, short offset, char *where) = {0x4840, 0x3001, _ReadXPRam}; typedef void (*RomDrvCopyFunc)(unsigned char *, unsigned char *, unsigned long); struct RomDrvContext { DrvSts2 drvsts; Ptr origcopyfunc; Ptr origdisk; /* keep unstripped pointers for Dispose*/ RomDrvCopyFunc copyfunc; unsigned char * disk; char initialized; char useram; char ram24; char alreadyalloced; }; typedef struct RomDrvContext RomDrvContext; const unsigned char DiskIcon[258] = { 0xf, 0xff, 0xff, 0xe0, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x11, 0xff, 0xff, 0x10, 0x12, 0x1, 0x00, 0x90, 0x12, 0x00, 0x81, 0x90, 0x12, 0x00, 0x7e, 0x90, 0x12, 0x11, 0x3c, 0x90, 0x12, 0x11, 0x3c, 0x90, 0x12, 0x1, 0x18, 0x90, 0x12, 0x1, 0x00, 0x90, 0x12, 0x3, 0x00, 0x90, 0x12, 0x00, 0x00, 0x90, 0x12, 0x8, 0x40, 0x90, 0x12, 0x7, 0x80, 0x90, 0x12, 0x00, 0x00, 0x90, 0x12, 0x00, 0x00, 0x90, 0x11, 0xff, 0xff, 0x10, 0x10, 0x00, 0x00, 0x10, 0x8, 0x00, 0x00, 0x20, 0x3f, 0xff, 0xff, 0xf8, 0x20, 0x00, 0x00, 0x8, 0x2f, 0xff, 0xff, 0xe8, 0x20, 0x00, 0x00, 0x8, 0x2f, 0xff, 0xff, 0xe8, 0x20, 0x00, 0x00, 0x8, 0x20, 0x00, 0x00, 0x8, 0x20, 0x00, 0xf, 0xe8, 0x2c, 0x00, 0x00, 0x8, 0x20, 0x00, 0x00, 0x68, 0x20, 0x00, 0x00, 0x8, 0x3f, 0xff, 0xff, 0xf8, // mask 0xf, 0xff, 0xff, 0xe0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xff, 0xf0, 0xf, 0xff, 0xff, 0xe0, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0, 0}; /* AddDrive is declared in Files.h, but it's defined in MacOS.lib, which we don't want, * so just shortcut the whole thing here. */ asm void RomDrvAddDrive(short drvrRefNum, short drvNum, DrvQElPtr dq) { fralloc + CLR.L D0 MOVE.W drvNum, D0 SWAP D0 MOVE.W drvrRefNum, D0 MOVEA.L dq, A0 0xA04E frfree RTS } #pragma parameter __D0 RomDrvStripAddress(__D0) pascal Ptr RomDrvStripAddress(void *addr) = 0xA055; void RomDrvCopy(unsigned char *source, unsigned char *dest, unsigned long count) { signed char mode = true32b; SwapMMUMode(&mode); BlockMove(source, dest, count); SwapMMUMode(&mode); } short RomDrvOpen(IOParamPtr p, DCtlPtr d) { DrvSts2 *dsptr; DrvQElPtr dq; int drvnum = 1; RomDrvContext *ctx; for(dq = (DrvQElPtr)(GetDrvQHdr())->qHead; dq; dq = (DrvQElPtr)dq->qLink) { if(dq->dQDrive >= drvnum) drvnum = dq->dQDrive+1; } d->dCtlStorage = NewHandleSysClear(sizeof(RomDrvContext)); HLock(d->dCtlStorage); ctx = *(RomDrvContext**)d->dCtlStorage; ctx->origcopyfunc = NewPtrSys(64); if(!ctx->origcopyfunc) { SysBeep(8); return openErr; } BlockMove(&RomDrvCopy, ctx->origcopyfunc, 64); ctx->copyfunc = (RomDrvCopyFunc)RomDrvStripAddress(ctx->origcopyfunc); dsptr = &ctx->drvsts; dsptr->writeProt = 0xF0; dsptr->diskInPlace = 8; dsptr->dQDrive = drvnum; dsptr->dQRefNum = d->dCtlRefNum; dsptr->drive