1 |
|
/* |
2 |
|
* cdrom.cpp - CD-ROM driver |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2000 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
151 |
|
// Icon address (Mac address space, set by PatchROM()) |
152 |
|
uint32 CDROMIconAddr; |
153 |
|
|
154 |
+ |
// Flag: Control(accRun) has been called, interrupt routine is now active |
155 |
+ |
static bool acc_run_called = false; |
156 |
+ |
|
157 |
|
|
158 |
|
/* |
159 |
|
* Get pointer to drive info, NULL = invalid drive number |
185 |
|
if (Sys_read(info->fh, map, i * 512, 512) != 512) |
186 |
|
break; |
187 |
|
|
188 |
< |
// Skip driver descriptor |
189 |
< |
uint16 sig = ntohs(((uint16 *)map)[0]); |
190 |
< |
if (sig == 'ER') |
188 |
< |
continue; |
189 |
< |
|
190 |
< |
// No partition map? Then look at next block |
191 |
< |
if (sig != 'PM') |
188 |
> |
// Not a partition map block? Then look at next block |
189 |
> |
uint16 sig = (map[0] << 8) | map[1]; |
190 |
> |
if (sig != 0x504d) |
191 |
|
continue; |
192 |
|
|
193 |
< |
// Partition map found, Apple HFS partition? |
193 |
> |
// Partition map block found, Apple HFS partition? |
194 |
|
if (strcmp((char *)(map + 48), "Apple_HFS") == 0) { |
195 |
|
info->start_byte = ntohl(((uint32 *)map)[2]) << 9; |
196 |
< |
D(bug(" HFS partition found at %ld, %ld blocks\n", info->start_byte, ntohl(((uint32 *)map)[3]))); |
196 |
> |
D(bug(" HFS partition found at %d, %d blocks\n", info->start_byte, ntohl(((uint32 *)map)[3]))); |
197 |
|
break; |
198 |
|
} |
199 |
|
} |
303 |
|
{ |
304 |
|
DriveInfo *info = first_drive_info, *next; |
305 |
|
while (info != NULL) { |
306 |
+ |
SysAllowRemoval(info->fh); |
307 |
|
Sys_close(info->fh); |
308 |
|
next = info->next; |
309 |
|
delete info; |
336 |
|
|
337 |
|
|
338 |
|
/* |
339 |
+ |
* Mount volumes for which the to_be_mounted flag is set |
340 |
+ |
* (called during interrupt time) |
341 |
+ |
*/ |
342 |
+ |
|
343 |
+ |
static void mount_mountable_volumes(void) |
344 |
+ |
{ |
345 |
+ |
DriveInfo *info = first_drive_info; |
346 |
+ |
while (info != NULL) { |
347 |
+ |
|
348 |
+ |
// Disk in drive? |
349 |
+ |
if (ReadMacInt8(info->status + dsDiskInPlace) == 0) { |
350 |
+ |
|
351 |
+ |
// No, check if disk was inserted |
352 |
+ |
if (SysIsDiskInserted(info->fh)) |
353 |
+ |
CDROMMountVolume(info->fh); |
354 |
+ |
} |
355 |
+ |
|
356 |
+ |
// Mount disk if flagged |
357 |
+ |
if (info->to_be_mounted) { |
358 |
+ |
D(bug(" mounting drive %d\n", info->num)); |
359 |
+ |
M68kRegisters r; |
360 |
+ |
r.d[0] = info->num; |
361 |
+ |
r.a[0] = 7; // diskEvent |
362 |
+ |
Execute68kTrap(0xa02f, &r); // PostEvent() |
363 |
+ |
info->to_be_mounted = false; |
364 |
+ |
} |
365 |
+ |
|
366 |
+ |
info = info->next; |
367 |
+ |
} |
368 |
+ |
} |
369 |
+ |
|
370 |
+ |
|
371 |
+ |
/* |
372 |
|
* Driver Open() routine |
373 |
|
*/ |
374 |
|
|
378 |
|
|
379 |
|
// Set up DCE |
380 |
|
WriteMacInt32(dce + dCtlPosition, 0); |
381 |
+ |
acc_run_called = false; |
382 |
|
|
383 |
|
// Install drives |
384 |
|
for (DriveInfo *info = first_drive_info; info; info = info->next) { |
490 |
|
case 1: // KillIO |
491 |
|
return noErr; |
492 |
|
|
493 |
< |
case 65: { // Periodic action ("insert" disks on startup and check for disk changes) |
494 |
< |
DriveInfo *info = first_drive_info; |
495 |
< |
while (info != NULL) { |
496 |
< |
|
463 |
< |
// Disk in drive? |
464 |
< |
if (ReadMacInt8(info->status + dsDiskInPlace) == 0) { |
465 |
< |
|
466 |
< |
// No, check if disk was inserted |
467 |
< |
if (SysIsDiskInserted(info->fh)) |
468 |
< |
CDROMMountVolume(info->fh); |
469 |
< |
} |
470 |
< |
|
471 |
< |
// Mount disk if flagged |
472 |
< |
if (info->to_be_mounted) { |
473 |
< |
D(bug(" mounting drive %d\n", info->num)); |
474 |
< |
M68kRegisters r; |
475 |
< |
r.d[0] = info->num; |
476 |
< |
r.a[0] = 7; // diskEvent |
477 |
< |
Execute68kTrap(0xa02f, &r); // PostEvent() |
478 |
< |
info->to_be_mounted = false; |
479 |
< |
} |
480 |
< |
|
481 |
< |
info = info->next; |
482 |
< |
} |
493 |
> |
case 65: { // Periodic action (accRun, "insert" disks on startup) |
494 |
> |
mount_mountable_volumes(); |
495 |
> |
WriteMacInt16(dce + dCtlFlags, ReadMacInt16(dce + dCtlFlags) & ~0x2000); // Disable periodic action |
496 |
> |
acc_run_called = true; |
497 |
|
return noErr; |
498 |
|
} |
499 |
|
|
595 |
|
break; |
596 |
|
|
597 |
|
case 3: { // Get track starting address |
598 |
< |
uint8 *buf = Mac2HostAddr(ReadMacInt32(pb + csParam + 2)); |
598 |
> |
uint32 buf = ReadMacInt32(pb + csParam + 2); |
599 |
|
uint16 buf_size = ReadMacInt16(pb + csParam + 6); |
600 |
|
int track = bcd2bin[ReadMacInt8(pb + csParam + 8)]; |
601 |
|
|
609 |
|
// Fill buffer |
610 |
|
if (i != 804) |
611 |
|
while (buf_size > 0) { |
612 |
< |
*buf++ = info->toc[i+1] & 0x0f; // Control |
613 |
< |
*buf++ = bin2bcd[info->toc[i+5]]; // M |
614 |
< |
*buf++ = bin2bcd[info->toc[i+6]]; // S |
615 |
< |
*buf++ = bin2bcd[info->toc[i+7]]; // F |
612 |
> |
WriteMacInt8(buf, info->toc[i+1] & 0x0f); buf++; // Control |
613 |
> |
WriteMacInt8(buf, bin2bcd[info->toc[i+5]]); buf++; // M |
614 |
> |
WriteMacInt8(buf, bin2bcd[info->toc[i+6]]); buf++; // S |
615 |
> |
WriteMacInt8(buf, bin2bcd[info->toc[i+7]]); buf++; // F |
616 |
|
|
617 |
|
// Lead-Out? Then stop |
618 |
|
if (info->toc[i+2] == 0xaa) |
643 |
|
|
644 |
|
case 101: { // ReadTheQSubcode |
645 |
|
if (ReadMacInt8(info->status + dsDiskInPlace) == 0) { |
646 |
< |
memset(Mac2HostAddr(pb + csParam), 0, 10); |
646 |
> |
Mac_memset(pb + csParam, 0, 10); |
647 |
|
return offLinErr; |
648 |
|
} |
649 |
|
|
650 |
|
uint8 pos[16]; |
651 |
|
if (SysCDGetPosition(info->fh, pos)) { |
652 |
< |
uint8 *p = Mac2HostAddr(pb + csParam); |
653 |
< |
*p++ = pos[5] & 0x0f; // Control |
654 |
< |
*p++ = bin2bcd[pos[6]]; // Track number |
655 |
< |
*p++ = bin2bcd[pos[7]]; // Index number |
656 |
< |
*p++ = bin2bcd[pos[13]]; // M (rel) |
657 |
< |
*p++ = bin2bcd[pos[14]]; // S (rel) |
658 |
< |
*p++ = bin2bcd[pos[15]]; // F (rel) |
659 |
< |
*p++ = bin2bcd[pos[9]]; // M (abs) |
660 |
< |
*p++ = bin2bcd[pos[10]]; // S (abs) |
661 |
< |
*p++ = bin2bcd[pos[11]]; // F (abs) |
662 |
< |
*p++ = 0; |
652 |
> |
uint32 p = pb + csParam; |
653 |
> |
WriteMacInt8(p, pos[5] & 0x0f); p++; // Control |
654 |
> |
WriteMacInt8(p, bin2bcd[pos[6]]); p++; // Track number |
655 |
> |
WriteMacInt8(p, bin2bcd[pos[7]]); p++; // Index number |
656 |
> |
WriteMacInt8(p, bin2bcd[pos[13]]); p++; // M (rel) |
657 |
> |
WriteMacInt8(p, bin2bcd[pos[14]]); p++; // S (rel) |
658 |
> |
WriteMacInt8(p, bin2bcd[pos[15]]); p++; // F (rel) |
659 |
> |
WriteMacInt8(p, bin2bcd[pos[9]]); p++; // M (abs) |
660 |
> |
WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs) |
661 |
> |
WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs) |
662 |
> |
WriteMacInt8(p, 0); |
663 |
|
return noErr; |
664 |
|
} else |
665 |
|
return ioErr; |
670 |
|
return controlErr; |
671 |
|
|
672 |
|
case 103: { // AudioTrackSearch |
673 |
< |
D(bug(" AudioTrackSearch postype %d, pos %08lx, hold %d\n", ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), ReadMacInt16(pb + csParam + 6))); |
673 |
> |
D(bug(" AudioTrackSearch postype %d, pos %08x, hold %d\n", ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), ReadMacInt16(pb + csParam + 6))); |
674 |
|
if (ReadMacInt8(info->status + dsDiskInPlace) == 0) |
675 |
|
return offLinErr; |
676 |
|
|
747 |
|
if (!SysCDGetPosition(info->fh, pos)) |
748 |
|
return paramErr; |
749 |
|
|
750 |
< |
uint8 *p = Mac2HostAddr(pb + csParam); |
750 |
> |
uint32 p = pb + csParam; |
751 |
|
switch (pos[1]) { |
752 |
|
case 0x11: |
753 |
< |
*p++ = 0; // Audio play in progress |
753 |
> |
WriteMacInt8(p, 0); // Audio play in progress |
754 |
|
break; |
755 |
|
case 0x12: |
756 |
< |
*p++ = 1; // Audio play paused |
756 |
> |
WriteMacInt8(p, 1); // Audio play paused |
757 |
|
break; |
758 |
|
case 0x13: |
759 |
< |
*p++ = 3; // Audio play completed |
759 |
> |
WriteMacInt8(p, 3); // Audio play completed |
760 |
|
break; |
761 |
|
case 0x14: |
762 |
< |
*p++ = 4; // Error occurred |
762 |
> |
WriteMacInt8(p, 4); // Error occurred |
763 |
|
break; |
764 |
|
default: |
765 |
< |
*p++ = 5; // No audio play operation requested |
765 |
> |
WriteMacInt8(p, 5); // No audio play operation requested |
766 |
|
break; |
767 |
|
} |
768 |
< |
*p++ = info->play_mode; |
769 |
< |
*p++ = pos[5] & 0x0f; // Control |
770 |
< |
*p++ = bin2bcd[pos[9]]; // M (abs) |
771 |
< |
*p++ = bin2bcd[pos[10]]; // S (abs) |
772 |
< |
*p++ = bin2bcd[pos[11]]; // F (abs) |
768 |
> |
p++; |
769 |
> |
WriteMacInt8(p, info->play_mode); p++; |
770 |
> |
WriteMacInt8(p, pos[5] & 0x0f); p++; // Control |
771 |
> |
WriteMacInt8(p, bin2bcd[pos[9]]); p++; // M (abs) |
772 |
> |
WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs) |
773 |
> |
WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs) |
774 |
|
return noErr; |
775 |
|
} |
776 |
|
|
867 |
|
uint32 sel = ReadMacInt32(pb + csParam); |
868 |
|
D(bug(" driver gestalt %c%c%c%c\n", sel >> 24, sel >> 16, sel >> 8, sel)); |
869 |
|
switch (sel) { |
870 |
< |
case 'vers': // Version |
870 |
> |
case FOURCC('v','e','r','s'): // Version |
871 |
|
WriteMacInt32(pb + csParam + 4, 0x05208000); |
872 |
|
break; |
873 |
< |
case 'devt': // Device type |
874 |
< |
WriteMacInt32(pb + csParam + 4, 'cdrm'); |
873 |
> |
case FOURCC('d','e','v','t'): // Device type |
874 |
> |
WriteMacInt32(pb + csParam + 4, FOURCC('c','d','r','m')); |
875 |
|
break; |
876 |
< |
case 'intf': // Interface type |
877 |
< |
WriteMacInt32(pb + csParam + 4, 'basi'); |
876 |
> |
case FOURCC('i','n','t','f'): // Interface type |
877 |
> |
WriteMacInt32(pb + csParam + 4, EMULATOR_ID_4); |
878 |
|
break; |
879 |
< |
case 'sync': // Only synchronous operation? |
879 |
> |
case FOURCC('s','y','n','c'): // Only synchronous operation? |
880 |
|
WriteMacInt32(pb + csParam + 4, 0x01000000); |
881 |
|
break; |
882 |
< |
case 'boot': // Boot ID |
882 |
> |
case FOURCC('b','o','o','t'): // Boot ID |
883 |
|
if (info != NULL) |
884 |
|
WriteMacInt16(pb + csParam + 4, info->num); |
885 |
|
else |
886 |
|
WriteMacInt16(pb + csParam + 4, 0); |
887 |
|
WriteMacInt16(pb + csParam + 6, (uint16)CDROMRefNum); |
888 |
|
break; |
889 |
< |
case 'wide': // 64-bit access supported? |
889 |
> |
case FOURCC('w','i','d','e'): // 64-bit access supported? |
890 |
|
WriteMacInt16(pb + csParam + 4, 0); |
891 |
|
break; |
892 |
< |
case 'purg': // Purge flags |
892 |
> |
case FOURCC('p','u','r','g'): // Purge flags |
893 |
|
WriteMacInt32(pb + csParam + 4, 0); |
894 |
|
break; |
895 |
< |
case 'ejec': // Eject flags |
895 |
> |
case FOURCC('e','j','e','c'): // Eject flags |
896 |
|
WriteMacInt32(pb + csParam + 4, 0x00030003); // Don't eject on shutdown/restart |
897 |
|
break; |
898 |
< |
case 'flus': // Flush flags |
898 |
> |
case FOURCC('f','l','u','s'): // Flush flags |
899 |
|
WriteMacInt16(pb + csParam + 4, 0); |
900 |
|
break; |
901 |
< |
case 'vmop': // Virtual memory attributes |
901 |
> |
case FOURCC('v','m','o','p'): // Virtual memory attributes |
902 |
|
WriteMacInt32(pb + csParam + 4, 0); // Drive not available for VM |
903 |
|
break; |
904 |
|
default: |
917 |
|
|
918 |
|
// Drive-specific codes |
919 |
|
switch (code) { |
920 |
+ |
case 6: // Return format list |
921 |
+ |
if (ReadMacInt16(pb + csParam) > 0) { |
922 |
+ |
uint32 adr = ReadMacInt32(pb + csParam + 2); |
923 |
+ |
WriteMacInt16(pb + csParam, 1); // 1 format |
924 |
+ |
WriteMacInt32(adr, SysGetFileSize(info->fh) / 512); // Number of blocks |
925 |
+ |
WriteMacInt32(adr + 4, 0); // heads/track/sectors |
926 |
+ |
return noErr; |
927 |
+ |
} else |
928 |
+ |
return paramErr; |
929 |
+ |
|
930 |
|
case 8: // DriveStatus |
931 |
< |
memcpy(Mac2HostAddr(pb + csParam), Mac2HostAddr(info->status), 22); |
931 |
> |
Mac2Mac_memcpy(pb + csParam, info->status, 22); |
932 |
|
return noErr; |
933 |
|
|
934 |
|
case 70: // GetPowerMode |
964 |
|
return statusErr; |
965 |
|
} |
966 |
|
} |
967 |
+ |
|
968 |
+ |
|
969 |
+ |
/* |
970 |
+ |
* Driver interrupt routine (1Hz) - check for volumes to be mounted |
971 |
+ |
*/ |
972 |
+ |
|
973 |
+ |
void CDROMInterrupt(void) |
974 |
+ |
{ |
975 |
+ |
if (!acc_run_called) |
976 |
+ |
return; |
977 |
+ |
|
978 |
+ |
mount_mountable_volumes(); |
979 |
+ |
} |