--- BasiliskII/src/disk.cpp 1999/10/03 14:16:25 1.1 +++ BasiliskII/src/disk.cpp 2000/07/14 21:29:08 1.6 @@ -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; } } @@ -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(); +}