MacIIROMDiskDriver/rdisk.c

456 lines
16 KiB
C
Raw Normal View History

2020-06-22 04:10:31 +00:00
#include <Memory.h>
#include <Devices.h>
#include <Files.h>
#include <Disks.h>
#include <Errors.h>
#include <Events.h>
#include <OSUtils.h>
2020-06-26 07:12:08 +00:00
#include "rdisk.h"
2020-07-12 02:41:51 +00:00
#ifdef RDISK_COMPRESS_ICON
#include <Quickdraw.h>
const char const RDiskIconCompressed[92] = {
2020-07-15 06:12:22 +00:00
-1 * (76 - 1), 0b00000000, /*
2020-07-12 02:41:51 +00:00
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000, */
-1 * (4 - 1), 0b11111111, /*
0b11111111, 0b11111111, 0b11111111, 0b11111111, */
(40 - 1),
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b10000000, 0b00000000, 0b00000000, 0b00000001,
0b10001111, 0b00011110, 0b00111100, 0b01111001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001111, 0b00011110, 0b00111100, 0b01111001,
0b11000000, 0b00000000, 0b00000000, 0b00000001,
0b01010101, 0b01010101, 0b11010101, 0b01010101,
0b01111111, 0b11111111, 0b01111111, 0b11111111,
2020-07-15 06:12:22 +00:00
-1 * (12 - 1), 0b00000000, /*
0b00000000, 0b00000000, 0b00000000, 0b00000000,
2020-07-12 02:41:51 +00:00
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000, */
2020-07-15 06:12:22 +00:00
-1 * (76 - 1), 0b00000000, /*
2020-07-12 02:41:51 +00:00
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000, */
-1 * (32 - 1), 0b11111111, /*
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111, */
(8 - 1),
0b01111111, 0b11111111, 0b11111111, 0b11111111,
0b01111111, 0b11111111, 0b11111111, 0b11111111,
2020-07-15 06:12:22 +00:00
-1 * (12 - 1), 0b00000000, /*
0b00000000, 0b00000000, 0b00000000, 0b00000000,
2020-07-12 02:41:51 +00:00
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000, */
(29 - 1),
27, 'G', 'a', 'r', 'r', 'e', 't', 't', '\'', 's', ' ',
'W', 'o', 'r', 'k', 's', 'h', 'o', 'p', ' ',
'R', 'O', 'M', ' ', 'D', 'i', 's', 'k', 0
};
#else
const char const RDiskIcon[285] = {
2020-06-27 02:13:22 +00:00
// Icon
2020-07-02 07:06:35 +00:00
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b10000000, 0b00000000, 0b00000000, 0b00000001,
0b10001111, 0b00011110, 0b00111100, 0b01111001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001111, 0b00011110, 0b00111100, 0b01111001,
0b11000000, 0b00000000, 0b00000000, 0b00000001,
0b01010101, 0b01010101, 0b11010101, 0b01010101,
0b01111111, 0b11111111, 0b01111111, 0b11111111,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
2020-07-15 06:12:22 +00:00
// Mask
2020-07-02 07:06:35 +00:00
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b01111111, 0b11111111, 0b11111111, 0b11111111,
0b01111111, 0b11111111, 0b11111111, 0b11111111,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
2020-07-15 06:12:22 +00:00
0b00000000, 0b00000000, 0b00000000, 0b00000000,
2020-07-02 07:06:35 +00:00
27, 'G', 'a', 'r', 'r', 'e', 't', 't', '\'', 's', ' ',
'W', 'o', 'r', 'k', 's', 'h', 'o', 'p', ' ',
'R', 'O', 'M', ' ', 'D', 'i', 's', 'k', 0
2020-06-27 02:13:22 +00:00
};
2020-07-12 02:41:51 +00:00
#endif
2020-06-27 02:13:22 +00:00
2020-07-12 02:41:51 +00:00
static void RDiskDecodeSettings(RDiskStorage_t *c, Ptr unmount, Ptr mount, Ptr ram) {
2020-07-02 07:06:35 +00:00
// Decode settings
if (c->postBoot) {
2020-07-12 02:41:51 +00:00
*unmount = 0;
2020-07-02 07:06:35 +00:00
*mount = 1;
*ram = 0;
2020-07-12 02:41:51 +00:00
} else if (RDiskIsRPressed()) { // R boots from ROM disk
*unmount = 0;
2020-07-02 07:06:35 +00:00
*mount = 0;
2020-07-12 02:41:51 +00:00
*ram = RDiskIsAPressed(); // A enables RAM disk
2020-07-02 07:06:35 +00:00
} else {
2020-07-12 02:41:51 +00:00
// Read PRAM
char legacy_startup, legacy_ram;
RDiskReadXPRAM(1, 4, &legacy_startup);
RDiskReadXPRAM(1, 5, &legacy_ram);
if (legacy_startup == 1) {
*unmount = 0;
*mount = 0;
*ram = legacy_ram;
} else if (legacy_startup == 2 || legacy_startup == 3 ||
legacy_startup == 4 || legacy_startup == 5 ||
legacy_startup == 6 || legacy_startup == 7) {
*unmount = 1;
*mount = 1;
*ram = legacy_ram & 1;
} else {
*unmount = 1;
*mount = 0;
*ram = 0;
}
2020-07-02 07:06:35 +00:00
}
2020-06-30 01:08:50 +00:00
}
// Switch to 24-bit mode and copy
void RDiskCopy24(Ptr sourcePtr, Ptr destPtr, unsigned long byteCount) {
2020-06-22 04:10:31 +00:00
char mode = true32b;
SwapMMUMode(&mode);
BlockMove(sourcePtr, destPtr, byteCount);
2020-06-22 04:10:31 +00:00
SwapMMUMode(&mode);
}
2020-07-12 02:41:51 +00:00
// Figure out the first available drive number >= 5
static int RDiskFindDrvNum() {
DrvQElPtr dq;
int drvNum = 5;
for (dq = (DrvQElPtr)(GetDrvQHdr())->qHead; dq; dq = (DrvQElPtr)dq->qLink) {
if (dq->dQDrive >= drvNum) { drvNum = dq->dQDrive + 1; }
}
return drvNum;
}
#pragma parameter __D0 RDiskOpen(__A0, __A1)
2020-06-22 04:10:31 +00:00
OSErr RDiskOpen(IOParamPtr p, DCtlPtr d) {
2020-06-24 17:18:47 +00:00
int drvNum;
2020-06-22 04:10:31 +00:00
RDiskStorage_t *c;
2020-07-12 02:41:51 +00:00
char legacy_startup, legacy_ram;
2020-06-22 04:10:31 +00:00
// Do nothing if already opened
if (d->dCtlStorage) { return noErr; }
2020-06-24 17:11:59 +00:00
2020-06-22 04:10:31 +00:00
// Allocate storage struct
d->dCtlStorage = NewHandleSysClear(sizeof(RDiskStorage_t));
if (!d->dCtlStorage) { return openErr; }
// Lock our storage struct and get master pointer
HLock(d->dCtlStorage);
c = *(RDiskStorage_t**)d->dCtlStorage;
2020-07-12 02:41:51 +00:00
// Find first available drive number
drvNum = RDiskFindDrvNum();
2020-06-24 17:18:47 +00:00
2020-06-22 04:10:31 +00:00
// Set drive status
2020-07-12 02:41:51 +00:00
c->status.track = 0;
c->status.writeProt = -1; // nonzero is write protected
c->status.diskInPlace = 8; // 8 is nonejectable disk
c->status.installed = 1; // drive installed
c->status.sides = 0; // drive installed
c->status.qType = 1;
c->status.dQDrive = drvNum;
2020-07-12 02:41:51 +00:00
c->status.dQFSID = 0;
c->status.dQRefNum = d->dCtlRefNum;
c->status.driveSize = RDiskSize / 512;
c->status.driveS1 = (RDiskSize / 512) >> 16;
2020-06-24 17:18:47 +00:00
2020-07-12 02:41:51 +00:00
#ifdef RDISK_COMPRESS_ICON
// Decompress icon
char *src = &RDiskIconCompressed[0];
char *dst = &c->icon[0];
UnpackBits(&src, &dst, 285);
#endif
2020-06-22 04:10:31 +00:00
// Add drive to drive queue and return
RDiskAddDrive(c->status.dQRefNum, drvNum, (DrvQElPtr)&c->status.qLink);
2020-06-22 04:10:31 +00:00
return noErr;
}
2020-07-12 02:41:51 +00:00
static void RDiskInit(IOParamPtr p, DCtlPtr d, RDiskStorage_t *c) {
char unmountEN, mountEN, ramEN;
2020-06-22 04:10:31 +00:00
2020-06-24 17:18:47 +00:00
// Mark init done
2020-06-30 01:08:50 +00:00
c->initialized = 1;
2020-06-22 04:10:31 +00:00
2020-07-02 07:06:35 +00:00
// Decode settings
2020-07-12 02:41:51 +00:00
RDiskDecodeSettings(c, &unmountEN, &mountEN, &ramEN);
2020-06-22 04:10:31 +00:00
2020-07-12 02:41:51 +00:00
// If RAM disk enabled, try to allocate RAM disk buffer if not already
if (ramEN & !c->ramdisk) {
2020-07-02 07:06:35 +00:00
if (*MMU32bit) { // 32-bit mode
unsigned long minBufPtr, newBufPtr;
// Compute if there is enough high memory
minBufPtr = ((unsigned long)*MemTop / 2) + 1024;
newBufPtr = (unsigned long)*BufPtr - RDiskSize;
if (newBufPtr > minBufPtr && (unsigned long)*BufPtr > newBufPtr) {
// Allocate RAM disk buffer by lowering BufPtr
*BufPtr = (Ptr)newBufPtr;
// Set RAM disk buffer pointer.
c->ramdisk = *BufPtr;
// Copy ROM disk image to RAM disk
BlockMove(RDiskBuf, c->ramdisk, RDiskSize);
// Clearing write protect marks RAM disk enabled
c->status.writeProt = 0;
2020-07-02 07:58:25 +00:00
}
2020-07-02 07:06:35 +00:00
} else { // 24-bit mode
2020-07-12 02:41:51 +00:00
// Get address of copy24 routine
RDiskCopy_t copy24 = (RDiskCopy_t)RDiskCopy24;
2020-07-02 07:06:35 +00:00
// Put RAM disk just past 8MB
2020-07-12 02:41:51 +00:00
c->ramdisk = (Ptr)(8 * 1024 * 1024);
2020-07-02 07:06:35 +00:00
// Copy ROM disk image to RAM disk
2020-07-12 02:41:51 +00:00
copy24(RDiskBuf, c->ramdisk, RDiskSize);
2020-07-02 07:06:35 +00:00
// Clearing write protect marks RAM disk enabled
c->status.writeProt = 0;
//FIXME: what if we don't have enough RAM?
// Will this wrap around and overwrite low memory?
// That's not the worst, since the system would just crash,
// but it would be better to switch to read-only status
}
2020-07-02 07:58:25 +00:00
}
2020-07-02 07:06:35 +00:00
2020-07-12 02:41:51 +00:00
// Unmount if not booting from ROM disk
if (unmountEN) {
c->status.diskInPlace = 0; // 0 == no disk in drive
2020-07-02 07:06:35 +00:00
}
2020-07-12 02:41:51 +00:00
// If mount enabled, enable accRun to post disk inserted event later
if (mountEN) {
d->dCtlFlags |= dNeedTimeMask; // Enable accRun
d->dCtlDelay = 150; // Set accRun delay (150 ticks is 2.5 sec.)
}
2020-06-22 04:10:31 +00:00
}
#pragma parameter __D0 RDiskPrime(__A0, __A1)
2020-06-22 04:10:31 +00:00
OSErr RDiskPrime(IOParamPtr p, DCtlPtr d) {
RDiskStorage_t *c;
char cmd;
2020-07-12 02:41:51 +00:00
Ptr disk;
2020-06-22 04:10:31 +00:00
// Return disk offline error if dCtlStorage null
2020-07-12 02:41:51 +00:00
if (!d->dCtlStorage) { return notOpenErr; }
2020-06-22 04:10:31 +00:00
// Dereference dCtlStorage to get pointer to our context
c = *(RDiskStorage_t**)d->dCtlStorage;
// Initialize if this is the first prime call
2020-07-12 02:41:51 +00:00
if (!c->initialized) { RDiskInit(p, d, c); }
// Return disk offline error if virtual disk not inserted
if (!c->status.diskInPlace) { return offLinErr; }
2020-06-22 04:10:31 +00:00
// Get pointer to RAM or ROM disk buffer
2020-07-12 02:41:51 +00:00
disk = (c->ramdisk ? c->ramdisk : RDiskBuf) + d->dCtlPosition;
// Bounds checking
if (d->dCtlPosition >= RDiskSize || p->ioReqCount >= RDiskSize ||
d->dCtlPosition + p->ioReqCount >= RDiskSize) { return paramErr; }
2020-06-22 04:10:31 +00:00
// Service read or write request
cmd = p->ioTrap & 0x00FF;
if (cmd == aRdCmd) { // Read
// Read from disk into buffer.
2020-06-26 07:12:08 +00:00
if (*MMU32bit) { BlockMove(disk, p->ioBuffer, p->ioReqCount); }
else {
2020-07-12 02:41:51 +00:00
// Get address of copy24 routine and then copy
RDiskCopy_t copy24 = (RDiskCopy_t)RDiskCopy24;
copy24(disk, StripAddress(p->ioBuffer), p->ioReqCount);
2020-06-22 04:10:31 +00:00
}
} else if (cmd == aWrCmd) { // Write
2020-06-26 07:12:08 +00:00
// Fail if write protected or RAM disk buffer not set up
if (c->status.writeProt || !c->ramdisk) { return wPrErr; }
2020-06-22 04:10:31 +00:00
// Write from buffer into disk.
if (*MMU32bit) { BlockMove(p->ioBuffer, disk, p->ioReqCount); }
else {
2020-07-12 02:41:51 +00:00
// Get address of copy24 routine and then copy
RDiskCopy_t copy24 = (RDiskCopy_t)RDiskCopy24;
copy24(StripAddress(p->ioBuffer), disk, p->ioReqCount);
2020-06-22 04:10:31 +00:00
}
2020-07-12 02:41:51 +00:00
} else { return noErr; } //FIXME: Fail if cmd isn't read or write?
// Update count and position/offset, then return
d->dCtlPosition += p->ioReqCount;
p->ioActCount = p->ioReqCount;
return noErr;
2020-06-22 04:10:31 +00:00
}
#pragma parameter __D0 RDiskControl(__A0, __A1)
2020-06-26 07:12:08 +00:00
OSErr RDiskControl(CntrlParamPtr p, DCtlPtr d) {
2020-06-22 04:10:31 +00:00
RDiskStorage_t *c;
2020-06-26 07:12:08 +00:00
// Fail if dCtlStorage null
2020-07-12 02:41:51 +00:00
if (!d->dCtlStorage) { return notOpenErr; }
2020-06-22 04:10:31 +00:00
// Dereference dCtlStorage to get pointer to our context
c = *(RDiskStorage_t**)d->dCtlStorage;
// Handle control request based on csCode
2020-06-26 07:12:08 +00:00
switch (p->csCode) {
2020-07-12 02:41:51 +00:00
case kFormat:
if (!c->status.diskInPlace || c->status.writeProt || !c->ramdisk) {
2020-07-02 07:58:25 +00:00
return controlErr;
2020-07-12 02:41:51 +00:00
}
long zero[16];
zero[0] = 0;
for (int i = 0; i < 256; i++) {
if (*MMU32bit) { BlockMove(zero, c->ramdisk, sizeof(zero)); }
else {
// Get address of copy24 routine and then copy
RDiskCopy_t copy24 = (RDiskCopy_t)RDiskCopy24;
copy24((Ptr)zero, c->ramdisk, sizeof(zero));
2020-07-02 07:58:25 +00:00
}
}
return noErr;
2020-07-12 02:41:51 +00:00
case kVerify:
if (!c->status.diskInPlace) { return controlErr; }
return noErr;
case killCode:
return noErr;
case kEject:
// "Reinsert" disk if ejected illegally
if (c->installed) { PostEvent(diskEvt, c->status.dQDrive); }
return controlErr; // Eject not allowed so return error
2020-07-02 07:06:35 +00:00
case accRun:
2020-07-12 02:41:51 +00:00
d->dCtlFlags &= ~dNeedTimeMask; // Disable accRun
c->status.diskInPlace = 8; // 8 is nonejectable disk
PostEvent(diskEvt, c->status.dQDrive); // Post disk inserted event
2020-07-02 07:06:35 +00:00
return noErr;
2020-07-12 02:41:51 +00:00
case kDriveIcon: case kMediaIcon: // Get icon
#ifdef RDISK_COMPRESS_ICON
*(Ptr*)p->csParam = (Ptr)c->icon;
#else
*(Ptr*)p->csParam = (Ptr)RDiskIcon;
#endif
2020-06-27 02:13:22 +00:00
return noErr;
2020-07-12 02:41:51 +00:00
case kDriveInfo:
// high word (bytes 2 & 3) clear
// byte 1 = primary + fixed media + internal
// byte 0 = drive type (0x10 is RAM disk) / (0x11 is ROM disk)
if (c->status.writeProt) { *(long*)p->csParam = 0x00000410; }
else { *(long*)p->csParam = 0x00000411; }
return noErr;
case 24: // Return SCSI partition size
*(long*)p->csParam = RDiskSize / 512;
return noErr;
case 2351: // Enable post-boot mode
2020-07-02 07:06:35 +00:00
c->postBoot = 1;
return noErr;
2020-06-22 04:10:31 +00:00
default: return controlErr;
}
}
#pragma parameter __D0 RDiskStatus(__A0, __A1)
2020-06-26 07:12:08 +00:00
OSErr RDiskStatus(CntrlParamPtr p, DCtlPtr d) {
2020-06-27 02:13:22 +00:00
RDiskStorage_t *c;
2020-06-26 07:12:08 +00:00
// Fail if dCtlStorage null
2020-07-12 02:41:51 +00:00
if (!d->dCtlStorage) { return notOpenErr; }
2020-06-27 02:13:22 +00:00
// Dereference dCtlStorage to get pointer to our context
c = *(RDiskStorage_t**)d->dCtlStorage;
2020-06-22 04:10:31 +00:00
// Handle status request based on csCode
2020-06-26 07:12:08 +00:00
switch (p->csCode) {
2020-07-12 02:41:51 +00:00
case kDriveStatus:
2020-06-26 07:12:08 +00:00
BlockMove(*d->dCtlStorage, &p->csParam, sizeof(DrvSts2));
2020-06-22 04:10:31 +00:00
return noErr;
default: return statusErr;
}
}
#pragma parameter __D0 RDiskClose(__A0, __A1)
2020-06-22 04:10:31 +00:00
OSErr RDiskClose(IOParamPtr p, DCtlPtr d) {
// If dCtlStorage not null, dispose of it and its contents
2020-06-26 07:12:08 +00:00
if (!d->dCtlStorage) { return noErr; }
RDiskStorage_t *c = *(RDiskStorage_t**)d->dCtlStorage;
HUnlock(d->dCtlStorage);
DisposeHandle(d->dCtlStorage);
2020-06-22 04:10:31 +00:00
d->dCtlStorage = NULL;
return noErr;
}