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 |
187 |
|
|
188 |
|
// Skip driver descriptor |
189 |
|
uint16 sig = ntohs(((uint16 *)map)[0]); |
190 |
< |
if (sig == 'ER') |
190 |
> |
if (sig == 0x4552) |
191 |
|
continue; |
192 |
|
|
193 |
|
// No partition map? Then look at next block |
194 |
< |
if (sig != 'PM') |
194 |
> |
if (sig != 0x504d) |
195 |
|
continue; |
196 |
|
|
197 |
|
// Partition map found, Apple HFS partition? |
198 |
|
if (strcmp((char *)(map + 48), "Apple_HFS") == 0) { |
199 |
|
info->start_byte = ntohl(((uint32 *)map)[2]) << 9; |
200 |
< |
D(bug(" HFS partition found at %ld, %ld blocks\n", info->start_byte, ntohl(((uint32 *)map)[3]))); |
200 |
> |
D(bug(" HFS partition found at %d, %d blocks\n", info->start_byte, ntohl(((uint32 *)map)[3]))); |
201 |
|
break; |
202 |
|
} |
203 |
|
} |
307 |
|
{ |
308 |
|
DriveInfo *info = first_drive_info, *next; |
309 |
|
while (info != NULL) { |
310 |
+ |
SysAllowRemoval(info->fh); |
311 |
|
Sys_close(info->fh); |
312 |
|
next = info->next; |
313 |
|
delete info; |
340 |
|
|
341 |
|
|
342 |
|
/* |
343 |
+ |
* Mount volumes for which the to_be_mounted flag is set |
344 |
+ |
* (called during interrupt time) |
345 |
+ |
*/ |
346 |
+ |
|
347 |
+ |
static void mount_mountable_volumes(void) |
348 |
+ |
{ |
349 |
+ |
DriveInfo *info = first_drive_info; |
350 |
+ |
while (info != NULL) { |
351 |
+ |
|
352 |
+ |
// Disk in drive? |
353 |
+ |
if (ReadMacInt8(info->status + dsDiskInPlace) == 0) { |
354 |
+ |
|
355 |
+ |
// No, check if disk was inserted |
356 |
+ |
if (SysIsDiskInserted(info->fh)) |
357 |
+ |
CDROMMountVolume(info->fh); |
358 |
+ |
} |
359 |
+ |
|
360 |
+ |
// Mount disk if flagged |
361 |
+ |
if (info->to_be_mounted) { |
362 |
+ |
D(bug(" mounting drive %d\n", info->num)); |
363 |
+ |
M68kRegisters r; |
364 |
+ |
r.d[0] = info->num; |
365 |
+ |
r.a[0] = 7; // diskEvent |
366 |
+ |
Execute68kTrap(0xa02f, &r); // PostEvent() |
367 |
+ |
info->to_be_mounted = false; |
368 |
+ |
} |
369 |
+ |
|
370 |
+ |
info = info->next; |
371 |
+ |
} |
372 |
+ |
} |
373 |
+ |
|
374 |
+ |
|
375 |
+ |
/* |
376 |
|
* Driver Open() routine |
377 |
|
*/ |
378 |
|
|
382 |
|
|
383 |
|
// Set up DCE |
384 |
|
WriteMacInt32(dce + dCtlPosition, 0); |
385 |
+ |
acc_run_called = false; |
386 |
|
|
387 |
|
// Install drives |
388 |
|
for (DriveInfo *info = first_drive_info; info; info = info->next) { |
494 |
|
case 1: // KillIO |
495 |
|
return noErr; |
496 |
|
|
497 |
< |
case 65: { // Periodic action ("insert" disks on startup and check for disk changes) |
498 |
< |
DriveInfo *info = first_drive_info; |
499 |
< |
while (info != NULL) { |
500 |
< |
|
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 |
< |
} |
497 |
> |
case 65: { // Periodic action (accRun, "insert" disks on startup) |
498 |
> |
mount_mountable_volumes(); |
499 |
> |
WriteMacInt16(dce + dCtlFlags, ReadMacInt16(dce + dCtlFlags) & ~0x2000); // Disable periodic action |
500 |
> |
acc_run_called = true; |
501 |
|
return noErr; |
502 |
|
} |
503 |
|
|
599 |
|
break; |
600 |
|
|
601 |
|
case 3: { // Get track starting address |
602 |
< |
uint8 *buf = Mac2HostAddr(ReadMacInt32(pb + csParam + 2)); |
602 |
> |
uint32 buf = ReadMacInt32(pb + csParam + 2); |
603 |
|
uint16 buf_size = ReadMacInt16(pb + csParam + 6); |
604 |
|
int track = bcd2bin[ReadMacInt8(pb + csParam + 8)]; |
605 |
|
|
613 |
|
// Fill buffer |
614 |
|
if (i != 804) |
615 |
|
while (buf_size > 0) { |
616 |
< |
*buf++ = info->toc[i+1] & 0x0f; // Control |
617 |
< |
*buf++ = bin2bcd[info->toc[i+5]]; // M |
618 |
< |
*buf++ = bin2bcd[info->toc[i+6]]; // S |
619 |
< |
*buf++ = bin2bcd[info->toc[i+7]]; // F |
616 |
> |
WriteMacInt8(buf, info->toc[i+1] & 0x0f); buf++; // Control |
617 |
> |
WriteMacInt8(buf, bin2bcd[info->toc[i+5]]); buf++; // M |
618 |
> |
WriteMacInt8(buf, bin2bcd[info->toc[i+6]]); buf++; // S |
619 |
> |
WriteMacInt8(buf, bin2bcd[info->toc[i+7]]); buf++; // F |
620 |
|
|
621 |
|
// Lead-Out? Then stop |
622 |
|
if (info->toc[i+2] == 0xaa) |
647 |
|
|
648 |
|
case 101: { // ReadTheQSubcode |
649 |
|
if (ReadMacInt8(info->status + dsDiskInPlace) == 0) { |
650 |
< |
memset(Mac2HostAddr(pb + csParam), 0, 10); |
650 |
> |
Mac_memset(pb + csParam, 0, 10); |
651 |
|
return offLinErr; |
652 |
|
} |
653 |
|
|
654 |
|
uint8 pos[16]; |
655 |
|
if (SysCDGetPosition(info->fh, pos)) { |
656 |
< |
uint8 *p = Mac2HostAddr(pb + csParam); |
657 |
< |
*p++ = pos[5] & 0x0f; // Control |
658 |
< |
*p++ = bin2bcd[pos[6]]; // Track number |
659 |
< |
*p++ = bin2bcd[pos[7]]; // Index number |
660 |
< |
*p++ = bin2bcd[pos[13]]; // M (rel) |
661 |
< |
*p++ = bin2bcd[pos[14]]; // S (rel) |
662 |
< |
*p++ = bin2bcd[pos[15]]; // F (rel) |
663 |
< |
*p++ = bin2bcd[pos[9]]; // M (abs) |
664 |
< |
*p++ = bin2bcd[pos[10]]; // S (abs) |
665 |
< |
*p++ = bin2bcd[pos[11]]; // F (abs) |
666 |
< |
*p++ = 0; |
656 |
> |
uint32 p = pb + csParam; |
657 |
> |
WriteMacInt8(p, pos[5] & 0x0f); p++; // Control |
658 |
> |
WriteMacInt8(p, bin2bcd[pos[6]]); p++; // Track number |
659 |
> |
WriteMacInt8(p, bin2bcd[pos[7]]); p++; // Index number |
660 |
> |
WriteMacInt8(p, bin2bcd[pos[13]]); p++; // M (rel) |
661 |
> |
WriteMacInt8(p, bin2bcd[pos[14]]); p++; // S (rel) |
662 |
> |
WriteMacInt8(p, bin2bcd[pos[15]]); p++; // F (rel) |
663 |
> |
WriteMacInt8(p, bin2bcd[pos[9]]); p++; // M (abs) |
664 |
> |
WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs) |
665 |
> |
WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs) |
666 |
> |
WriteMacInt8(p, 0); |
667 |
|
return noErr; |
668 |
|
} else |
669 |
|
return ioErr; |
674 |
|
return controlErr; |
675 |
|
|
676 |
|
case 103: { // AudioTrackSearch |
677 |
< |
D(bug(" AudioTrackSearch postype %d, pos %08lx, hold %d\n", ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), ReadMacInt16(pb + csParam + 6))); |
677 |
> |
D(bug(" AudioTrackSearch postype %d, pos %08x, hold %d\n", ReadMacInt16(pb + csParam), ReadMacInt32(pb + csParam + 2), ReadMacInt16(pb + csParam + 6))); |
678 |
|
if (ReadMacInt8(info->status + dsDiskInPlace) == 0) |
679 |
|
return offLinErr; |
680 |
|
|
751 |
|
if (!SysCDGetPosition(info->fh, pos)) |
752 |
|
return paramErr; |
753 |
|
|
754 |
< |
uint8 *p = Mac2HostAddr(pb + csParam); |
754 |
> |
uint32 p = pb + csParam; |
755 |
|
switch (pos[1]) { |
756 |
|
case 0x11: |
757 |
< |
*p++ = 0; // Audio play in progress |
757 |
> |
WriteMacInt8(p, 0); // Audio play in progress |
758 |
|
break; |
759 |
|
case 0x12: |
760 |
< |
*p++ = 1; // Audio play paused |
760 |
> |
WriteMacInt8(p, 1); // Audio play paused |
761 |
|
break; |
762 |
|
case 0x13: |
763 |
< |
*p++ = 3; // Audio play completed |
763 |
> |
WriteMacInt8(p, 3); // Audio play completed |
764 |
|
break; |
765 |
|
case 0x14: |
766 |
< |
*p++ = 4; // Error occurred |
766 |
> |
WriteMacInt8(p, 4); // Error occurred |
767 |
|
break; |
768 |
|
default: |
769 |
< |
*p++ = 5; // No audio play operation requested |
769 |
> |
WriteMacInt8(p, 5); // No audio play operation requested |
770 |
|
break; |
771 |
|
} |
772 |
< |
*p++ = info->play_mode; |
773 |
< |
*p++ = pos[5] & 0x0f; // Control |
774 |
< |
*p++ = bin2bcd[pos[9]]; // M (abs) |
775 |
< |
*p++ = bin2bcd[pos[10]]; // S (abs) |
776 |
< |
*p++ = bin2bcd[pos[11]]; // F (abs) |
772 |
> |
p++; |
773 |
> |
WriteMacInt8(p, info->play_mode); p++; |
774 |
> |
WriteMacInt8(p, pos[5] & 0x0f); p++; // Control |
775 |
> |
WriteMacInt8(p, bin2bcd[pos[9]]); p++; // M (abs) |
776 |
> |
WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs) |
777 |
> |
WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs) |
778 |
|
return noErr; |
779 |
|
} |
780 |
|
|
871 |
|
uint32 sel = ReadMacInt32(pb + csParam); |
872 |
|
D(bug(" driver gestalt %c%c%c%c\n", sel >> 24, sel >> 16, sel >> 8, sel)); |
873 |
|
switch (sel) { |
874 |
< |
case 'vers': // Version |
874 |
> |
case FOURCC('v','e','r','s'): // Version |
875 |
|
WriteMacInt32(pb + csParam + 4, 0x05208000); |
876 |
|
break; |
877 |
< |
case 'devt': // Device type |
878 |
< |
WriteMacInt32(pb + csParam + 4, 'cdrm'); |
877 |
> |
case FOURCC('d','e','v','t'): // Device type |
878 |
> |
WriteMacInt32(pb + csParam + 4, FOURCC('c','d','r','m')); |
879 |
|
break; |
880 |
< |
case 'intf': // Interface type |
881 |
< |
WriteMacInt32(pb + csParam + 4, 'basi'); |
880 |
> |
case FOURCC('i','n','t','f'): // Interface type |
881 |
> |
WriteMacInt32(pb + csParam + 4, FOURCC('b','a','s','i')); |
882 |
|
break; |
883 |
< |
case 'sync': // Only synchronous operation? |
883 |
> |
case FOURCC('s','y','n','c'): // Only synchronous operation? |
884 |
|
WriteMacInt32(pb + csParam + 4, 0x01000000); |
885 |
|
break; |
886 |
< |
case 'boot': // Boot ID |
886 |
> |
case FOURCC('b','o','o','t'): // Boot ID |
887 |
|
if (info != NULL) |
888 |
|
WriteMacInt16(pb + csParam + 4, info->num); |
889 |
|
else |
890 |
|
WriteMacInt16(pb + csParam + 4, 0); |
891 |
|
WriteMacInt16(pb + csParam + 6, (uint16)CDROMRefNum); |
892 |
|
break; |
893 |
< |
case 'wide': // 64-bit access supported? |
893 |
> |
case FOURCC('w','i','d','e'): // 64-bit access supported? |
894 |
|
WriteMacInt16(pb + csParam + 4, 0); |
895 |
|
break; |
896 |
< |
case 'purg': // Purge flags |
896 |
> |
case FOURCC('p','u','r','g'): // Purge flags |
897 |
|
WriteMacInt32(pb + csParam + 4, 0); |
898 |
|
break; |
899 |
< |
case 'ejec': // Eject flags |
899 |
> |
case FOURCC('e','j','e','c'): // Eject flags |
900 |
|
WriteMacInt32(pb + csParam + 4, 0x00030003); // Don't eject on shutdown/restart |
901 |
|
break; |
902 |
< |
case 'flus': // Flush flags |
902 |
> |
case FOURCC('f','l','u','s'): // Flush flags |
903 |
|
WriteMacInt16(pb + csParam + 4, 0); |
904 |
|
break; |
905 |
< |
case 'vmop': // Virtual memory attributes |
905 |
> |
case FOURCC('v','m','o','p'): // Virtual memory attributes |
906 |
|
WriteMacInt32(pb + csParam + 4, 0); // Drive not available for VM |
907 |
|
break; |
908 |
|
default: |
922 |
|
// Drive-specific codes |
923 |
|
switch (code) { |
924 |
|
case 8: // DriveStatus |
925 |
< |
memcpy(Mac2HostAddr(pb + csParam), Mac2HostAddr(info->status), 22); |
925 |
> |
Mac2Mac_memcpy(pb + csParam, info->status, 22); |
926 |
|
return noErr; |
927 |
|
|
928 |
|
case 70: // GetPowerMode |
958 |
|
return statusErr; |
959 |
|
} |
960 |
|
} |
961 |
+ |
|
962 |
+ |
|
963 |
+ |
/* |
964 |
+ |
* Driver interrupt routine (1Hz) - check for volumes to be mounted |
965 |
+ |
*/ |
966 |
+ |
|
967 |
+ |
void CDROMInterrupt(void) |
968 |
+ |
{ |
969 |
+ |
if (!acc_run_called) |
970 |
+ |
return; |
971 |
+ |
|
972 |
+ |
mount_mountable_volumes(); |
973 |
+ |
} |