--- BasiliskII/src/disk.cpp 1999/10/03 14:16:25 1.1 +++ BasiliskII/src/disk.cpp 2000/07/22 16:07:15 1.7 @@ -1,7 +1,7 @@ /* * disk.cpp - Generic disk driver * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2000 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -90,6 +90,9 @@ static DriveInfo *first_drive_info; // Icon address (Mac address space, set by PatchROM()) uint32 DiskIconAddr; +// Flag: Control(accRun) has been called, interrupt routine is now active +static bool acc_run_called = false; + /* * Get pointer to drive info, NULL = invalid drive number @@ -184,6 +187,39 @@ bool DiskMountVolume(void *fh) /* + * Mount volumes for which the to_be_mounted flag is set + * (called during interrupt time) + */ + +static void mount_mountable_volumes(void) +{ + DriveInfo *info = first_drive_info; + while (info != NULL) { + + // Disk in drive? + if (!ReadMacInt8(info->status + dsDiskInPlace)) { + + // No, check if disk was inserted + if (SysIsDiskInserted(info->fh)) + DiskMountVolume(info->fh); + } + + // Mount disk if flagged + if (info->to_be_mounted) { + D(bug(" mounting drive %d\n", info->num)); + M68kRegisters r; + r.d[0] = info->num; + r.a[0] = 7; // diskEvent + Execute68kTrap(0xa02f, &r); // PostEvent() + info->to_be_mounted = false; + } + + info = info->next; + } +} + + +/* * Driver Open() routine */ @@ -193,6 +229,7 @@ int16 DiskOpen(uint32 pb, uint32 dce) // Set up DCE WriteMacInt32(dce + dCtlPosition, 0); + acc_run_called = false; // Install drives for (DriveInfo *info = first_drive_info; info; info = info->next) { @@ -228,7 +265,7 @@ int16 DiskOpen(uint32 pb, uint32 dce) info->num_blocks = SysGetFileSize(info->fh) / 512; info->to_be_mounted = true; } - D(bug(" %ld blocks\n", info->num_blocks)); + D(bug(" %d blocks\n", info->num_blocks)); WriteMacInt16(info->status + dsDriveSize, info->num_blocks & 0xffff); WriteMacInt16(info->status + dsDriveS1, info->num_blocks >> 16); @@ -306,30 +343,10 @@ int16 DiskControl(uint32 pb, uint32 dce) case 1: // KillIO return noErr; - case 65: { // Periodic action ("insert" disks on startup and check for disk changes) - DriveInfo *info = first_drive_info; - while (info != NULL) { - - // Disk in drive? - if (!ReadMacInt8(info->status + dsDiskInPlace)) { - - // No, check if disk was inserted - if (SysIsDiskInserted(info->fh)) - DiskMountVolume(info->fh); - } - - // Mount disk if flagged - if (info->to_be_mounted) { - D(bug(" mounting drive %d\n", info->num)); - M68kRegisters r; - r.d[0] = info->num; - r.a[0] = 7; // diskEvent - Execute68kTrap(0xa02f, &r); // PostEvent() - info->to_be_mounted = false; - } - - info = info->next; - } + case 65: { // Periodic action (accRun, "insert" disks on startup) + mount_mountable_volumes(); + WriteMacInt16(dce + dCtlFlags, ReadMacInt16(dce + dCtlFlags) & ~0x2000); // Disable periodic action + acc_run_called = true; return noErr; } } @@ -410,44 +427,44 @@ int16 DiskStatus(uint32 pb, uint32 dce) uint32 sel = ReadMacInt32(pb + csParam); D(bug(" driver gestalt %c%c%c%c\n", sel >> 24, sel >> 16, sel >> 8, sel)); switch (sel) { - case 'vers': // Version + case FOURCC('v','e','r','s'): // Version WriteMacInt32(pb + csParam + 4, 0x01008000); break; - case 'devt': // Device type + case FOURCC('d','e','v','t'): // Device type if (info != NULL) { if (ReadMacInt8(info->status + dsDiskInPlace) == 8) - WriteMacInt32(pb + csParam + 4, 'disk'); + WriteMacInt32(pb + csParam + 4, FOURCC('d','i','s','k')); else - WriteMacInt32(pb + csParam + 4, 'rdsk'); + WriteMacInt32(pb + csParam + 4, FOURCC('r','d','s','k')); } else - WriteMacInt32(pb + csParam + 4, 'disk'); + WriteMacInt32(pb + csParam + 4, FOURCC('d','i','s','k')); break; - case 'intf': // Interface type - WriteMacInt32(pb + csParam + 4, 'basi'); + case FOURCC('i','n','t','f'): // Interface type + WriteMacInt32(pb + csParam + 4, FOURCC('b','a','s','i')); break; - case 'sync': // Only synchronous operation? + case FOURCC('s','y','n','c'): // Only synchronous operation? WriteMacInt32(pb + csParam + 4, 0x01000000); break; - case 'boot': // Boot ID + case FOURCC('b','o','o','t'): // Boot ID if (info != NULL) WriteMacInt16(pb + csParam + 4, info->num); else WriteMacInt16(pb + csParam + 4, 0); WriteMacInt16(pb + csParam + 6, (uint16)DiskRefNum); break; - case 'wide': // 64-bit access supported? + case FOURCC('w','i','d','e'): // 64-bit access supported? WriteMacInt16(pb + csParam + 4, 0x0100); break; - case 'purg': // Purge flags + case FOURCC('p','u','r','g'): // Purge flags WriteMacInt32(pb + csParam + 4, 0); break; - case 'ejec': // Eject flags + case FOURCC('e','j','e','c'): // Eject flags WriteMacInt32(pb + csParam + 4, 0x00030003); // Don't eject on shutdown/restart break; - case 'flus': // Flush flags + case FOURCC('f','l','u','s'): // Flush flags WriteMacInt16(pb + csParam + 4, 0); break; - case 'vmop': // Virtual memory attributes + case FOURCC('v','m','o','p'): // Virtual memory attributes WriteMacInt32(pb + csParam + 4, 0); // Drive not available for VM break; default: @@ -464,7 +481,7 @@ int16 DiskStatus(uint32 pb, uint32 dce) // Drive-specific codes switch (code) { case 8: // Get drive status - memcpy(Mac2HostAddr(pb + csParam), Mac2HostAddr(info->status), 22); + Mac2Mac_memcpy(pb + csParam, info->status, 22); return noErr; default: @@ -472,3 +489,16 @@ int16 DiskStatus(uint32 pb, uint32 dce) return statusErr; } } + + +/* + * Driver interrupt routine (1Hz) - check for volumes to be mounted + */ + +void DiskInterrupt(void) +{ + if (!acc_run_called) + return; + + mount_mountable_volumes(); +}