MacIIROMDiskDriver/RDiskCP/RDiskCP.c
2020-07-16 02:29:09 -04:00

1 line
3.0 KiB
C
Executable File

#include "RDiskCP.h"
static long RDiskCPMacDev() {
int i;
// Check signature and return 0 if doesn't match
for (i = 0; i < sizeof(RDiskSig)-1; i++) {
if (RDiskSigAddr[i] != RDiskSig[i]) {
// If signature doesn't match,
// fail if not holding R key
if (!((*((char*)0x175)) & 0x80)) { return 0; }
}
}
return 1; // Otherwise return 1 if signature matches
}
static void RDiskCPUpdate(DialogPtr cpDialog, short numItems) {
GrafPtr savePort;
Handle h;
Rect r;
short type;
char startup, ram;
// Get startup and ram from PRAM
RDiskCPReadXPRam(1, 4, &startup);
RDiskCPReadXPRam(1, 5, &ram);
// Save GrafPort and set port to dialog before updating items
GetPort(&savePort);
SetPort(cpDialog);
GetDItem(cpDialog, BootCheckbox+numItems, &type, &h, &r);
SetCtlValue((ControlHandle)h, startup & 0x01 ? 1 : 0);
GetDItem(cpDialog, MountCheckbox+numItems, &type, &h, &r);
SetCtlValue((ControlHandle)h, startup & 0x02 && !(startup & 0x01) ? 1 : 0);
HiliteControl((ControlHandle)h, startup & 0x01 ? 255 : 0);
GetDItem(cpDialog, RAMCheckbox+numItems, &type, &h, &r);
SetCtlValue((ControlHandle)h, startup & 0x03 && ram & 0x01 ? 1 : 0);
HiliteControl((ControlHandle)h, startup & 0x03 ? 0 : 255);
// Restore old GrafPort
SetPort(savePort);
}
static void RDiskCPHitDev(short message, short item, short numItems,
short cpPrivateVal, EventRecord *theEvent,
void *cdevStorageValue, DialogPtr cpDialog) {
char startup, ram;
RDiskCPReadXPRam(1, 4, &startup);
RDiskCPReadXPRam(1, 5, &ram);
switch (item - numItems) {
case BootCheckbox:
if (startup & 0x01) { startup &= 0x0F & ~0x01; }
else { startup = startup & 0x0F | 0x01; }
break;
case MountCheckbox:
if (!(startup & 0x01)) {
if (startup & 0x02) { startup &= 0x0F & ~0x02; }
else { startup = startup & 0x0F | 0x02; }
}
break;
case RAMCheckbox:
if (startup & 0x03) {
if (ram & 0x01) { ram = 0x00; }
else { ram = 0x01; }
}
break;
};
RDiskCPWriteXPRam(1, 4, &startup);
RDiskCPWriteXPRam(1, 5, &ram);
RDiskCPUpdate(cpDialog, numItems);
}
pascal long main(short message, short item, short numItems,
short cpPrivateVal, EventRecord *theEvent,
void *cdevStorageValue, DialogPtr cpDialog)
{
long ret = (long)cdevStorageValue;
// Switch to our A4 world
EnterCodeResource();
// Handle message
switch (message) {
case initDev:
if (RDiskSigAddr[sizeof(RDiskSig) + 4] == 0x57) {
Str15 ramSize;
ramSize[0] = 2;
ramSize[1] = RDiskSigAddr[sizeof(RDiskSig) + 5];
ramSize[2] = RDiskSigAddr[sizeof(RDiskSig) + 6];
ParamText(ramSize, 0, 0, 0);
} else { ParamText("\p16", 0, 0, 0); }
case closeDev:
ret = cdevUnset; break;
case macDev:
ret = RDiskCPMacDev(); break;
case updateDev:
case activDev:
case deactivDev:
RDiskCPUpdate(cpDialog, numItems);
break;
case hitDev:
RDiskCPHitDev(message, item, numItems,
cpPrivateVal, theEvent,
cdevStorageValue, cpDialog);
break;
};
// Restore old A4 world and return result
ExitCodeResource();
return ret;
}