--- BasiliskII/src/cdrom.cpp 1999/10/23 17:57:42 1.3 +++ BasiliskII/src/cdrom.cpp 2000/10/11 17:40:07 1.10 @@ -1,7 +1,7 @@ /* * cdrom.cpp - CD-ROM 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 @@ -151,9 +151,6 @@ static DriveInfo *first_drive_info; // Icon address (Mac address space, set by PatchROM()) uint32 CDROMIconAddr; -// Number of ticks between checks for disk insertion -const int driver_delay = 120; - // Flag: Control(accRun) has been called, interrupt routine is now active static bool acc_run_called = false; @@ -188,19 +185,15 @@ static void find_hfs_partition(DriveInfo if (Sys_read(info->fh, map, i * 512, 512) != 512) break; - // Skip driver descriptor - uint16 sig = ntohs(((uint16 *)map)[0]); - if (sig == 'ER') - continue; - - // No partition map? Then look at next block - if (sig != 'PM') + // Not a partition map block? Then look at next block + uint16 sig = (map[0] << 8) | map[1]; + if (sig != 0x504d) continue; - // Partition map found, Apple HFS partition? + // Partition map block found, Apple HFS partition? if (strcmp((char *)(map + 48), "Apple_HFS") == 0) { info->start_byte = ntohl(((uint32 *)map)[2]) << 9; - D(bug(" HFS partition found at %ld, %ld blocks\n", info->start_byte, ntohl(((uint32 *)map)[3]))); + D(bug(" HFS partition found at %d, %d blocks\n", info->start_byte, ntohl(((uint32 *)map)[3]))); break; } } @@ -602,7 +595,7 @@ int16 CDROMControl(uint32 pb, uint32 dce break; case 3: { // Get track starting address - uint8 *buf = Mac2HostAddr(ReadMacInt32(pb + csParam + 2)); + uint32 buf = ReadMacInt32(pb + csParam + 2); uint16 buf_size = ReadMacInt16(pb + csParam + 6); int track = bcd2bin[ReadMacInt8(pb + csParam + 8)]; @@ -616,10 +609,10 @@ int16 CDROMControl(uint32 pb, uint32 dce // Fill buffer if (i != 804) while (buf_size > 0) { - *buf++ = info->toc[i+1] & 0x0f; // Control - *buf++ = bin2bcd[info->toc[i+5]]; // M - *buf++ = bin2bcd[info->toc[i+6]]; // S - *buf++ = bin2bcd[info->toc[i+7]]; // F + WriteMacInt8(buf, info->toc[i+1] & 0x0f); buf++; // Control + WriteMacInt8(buf, bin2bcd[info->toc[i+5]]); buf++; // M + WriteMacInt8(buf, bin2bcd[info->toc[i+6]]); buf++; // S + WriteMacInt8(buf, bin2bcd[info->toc[i+7]]); buf++; // F // Lead-Out? Then stop if (info->toc[i+2] == 0xaa) @@ -650,23 +643,23 @@ int16 CDROMControl(uint32 pb, uint32 dce case 101: { // ReadTheQSubcode if (ReadMacInt8(info->status + dsDiskInPlace) == 0) { - memset(Mac2HostAddr(pb + csParam), 0, 10); + Mac_memset(pb + csParam, 0, 10); return offLinErr; } uint8 pos[16]; if (SysCDGetPosition(info->fh, pos)) { - uint8 *p = Mac2HostAddr(pb + csParam); - *p++ = pos[5] & 0x0f; // Control - *p++ = bin2bcd[pos[6]]; // Track number - *p++ = bin2bcd[pos[7]]; // Index number - *p++ = bin2bcd[pos[13]]; // M (rel) - *p++ = bin2bcd[pos[14]]; // S (rel) - *p++ = bin2bcd[pos[15]]; // F (rel) - *p++ = bin2bcd[pos[9]]; // M (abs) - *p++ = bin2bcd[pos[10]]; // S (abs) - *p++ = bin2bcd[pos[11]]; // F (abs) - *p++ = 0; + uint32 p = pb + csParam; + WriteMacInt8(p, pos[5] & 0x0f); p++; // Control + WriteMacInt8(p, bin2bcd[pos[6]]); p++; // Track number + WriteMacInt8(p, bin2bcd[pos[7]]); p++; // Index number + WriteMacInt8(p, bin2bcd[pos[13]]); p++; // M (rel) + WriteMacInt8(p, bin2bcd[pos[14]]); p++; // S (rel) + WriteMacInt8(p, bin2bcd[pos[15]]); p++; // F (rel) + WriteMacInt8(p, bin2bcd[pos[9]]); p++; // M (abs) + WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs) + WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs) + WriteMacInt8(p, 0); return noErr; } else return ioErr; @@ -677,7 +670,7 @@ int16 CDROMControl(uint32 pb, uint32 dce return controlErr; case 103: { // AudioTrackSearch - D(bug(" AudioTrackSearch postype %d, pos %08lx, hold %d\n", ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), ReadMacInt16(pb + csParam + 6))); + D(bug(" AudioTrackSearch postype %d, pos %08x, hold %d\n", ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), ReadMacInt16(pb + csParam + 6))); if (ReadMacInt8(info->status + dsDiskInPlace) == 0) return offLinErr; @@ -754,29 +747,30 @@ int16 CDROMControl(uint32 pb, uint32 dce if (!SysCDGetPosition(info->fh, pos)) return paramErr; - uint8 *p = Mac2HostAddr(pb + csParam); + uint32 p = pb + csParam; switch (pos[1]) { case 0x11: - *p++ = 0; // Audio play in progress + WriteMacInt8(p, 0); // Audio play in progress break; case 0x12: - *p++ = 1; // Audio play paused + WriteMacInt8(p, 1); // Audio play paused break; case 0x13: - *p++ = 3; // Audio play completed + WriteMacInt8(p, 3); // Audio play completed break; case 0x14: - *p++ = 4; // Error occurred + WriteMacInt8(p, 4); // Error occurred break; default: - *p++ = 5; // No audio play operation requested + WriteMacInt8(p, 5); // No audio play operation requested break; } - *p++ = info->play_mode; - *p++ = pos[5] & 0x0f; // Control - *p++ = bin2bcd[pos[9]]; // M (abs) - *p++ = bin2bcd[pos[10]]; // S (abs) - *p++ = bin2bcd[pos[11]]; // F (abs) + p++; + WriteMacInt8(p, info->play_mode); p++; + WriteMacInt8(p, pos[5] & 0x0f); p++; // Control + WriteMacInt8(p, bin2bcd[pos[9]]); p++; // M (abs) + WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs) + WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs) return noErr; } @@ -873,38 +867,38 @@ int16 CDROMStatus(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, 0x05208000); break; - case 'devt': // Device type - WriteMacInt32(pb + csParam + 4, 'cdrm'); + case FOURCC('d','e','v','t'): // Device type + WriteMacInt32(pb + csParam + 4, FOURCC('c','d','r','m')); break; - case 'intf': // Interface type - WriteMacInt32(pb + csParam + 4, 'basi'); + case FOURCC('i','n','t','f'): // Interface type + WriteMacInt32(pb + csParam + 4, EMULATOR_ID_4); 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)CDROMRefNum); break; - case 'wide': // 64-bit access supported? + case FOURCC('w','i','d','e'): // 64-bit access supported? WriteMacInt16(pb + csParam + 4, 0); 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: @@ -923,8 +917,18 @@ int16 CDROMStatus(uint32 pb, uint32 dce) // Drive-specific codes switch (code) { + case 6: // Return format list + if (ReadMacInt16(pb + csParam) > 0) { + uint32 adr = ReadMacInt32(pb + csParam + 2); + WriteMacInt16(pb + csParam, 1); // 1 format + WriteMacInt32(adr, SysGetFileSize(info->fh) / 512); // Number of blocks + WriteMacInt32(adr + 4, 0); // heads/track/sectors + return noErr; + } else + return paramErr; + case 8: // DriveStatus - memcpy(Mac2HostAddr(pb + csParam), Mac2HostAddr(info->status), 22); + Mac2Mac_memcpy(pb + csParam, info->status, 22); return noErr; case 70: // GetPowerMode @@ -963,18 +967,13 @@ int16 CDROMStatus(uint32 pb, uint32 dce) /* - * Driver interrupt routine - check for volumes to be mounted + * Driver interrupt routine (1Hz) - check for volumes to be mounted */ void CDROMInterrupt(void) { - static int tick_count = 0; if (!acc_run_called) return; - tick_count++; - if (tick_count > driver_delay) { - tick_count = 0; - mount_mountable_volumes(); - } + mount_mountable_volumes(); }