ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/cdrom.cpp
(Generate patch)

Comparing BasiliskII/src/cdrom.cpp (file contents):
Revision 1.1.1.1 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.5 by cebix, 2000-04-10T18:52:19Z

# Line 1 | Line 1
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
# Line 151 | Line 151 | static DriveInfo *first_drive_info;
151   // Icon address (Mac address space, set by PatchROM())
152   uint32 CDROMIconAddr;
153  
154 + // Number of ticks between checks for disk insertion
155 + const int driver_delay = 120;
156 +
157 + // Flag: Control(accRun) has been called, interrupt routine is now active
158 + static bool acc_run_called = false;
159 +
160  
161   /*
162   *  Get pointer to drive info, NULL = invalid drive number
# Line 304 | Line 310 | void CDROMExit(void)
310   {
311          DriveInfo *info = first_drive_info, *next;
312          while (info != NULL) {
313 +                SysAllowRemoval(info->fh);
314                  Sys_close(info->fh);
315                  next = info->next;
316                  delete info;
# Line 336 | Line 343 | bool CDROMMountVolume(void *fh)
343  
344  
345   /*
346 + *  Mount volumes for which the to_be_mounted flag is set
347 + *  (called during interrupt time)
348 + */
349 +
350 + static void mount_mountable_volumes(void)
351 + {
352 +        DriveInfo *info = first_drive_info;
353 +        while (info != NULL) {
354 +
355 +                // Disk in drive?
356 +                if (ReadMacInt8(info->status + dsDiskInPlace) == 0) {
357 +
358 +                        // No, check if disk was inserted
359 +                        if (SysIsDiskInserted(info->fh))
360 +                                CDROMMountVolume(info->fh);
361 +                }
362 +
363 +                // Mount disk if flagged
364 +                if (info->to_be_mounted) {
365 +                        D(bug(" mounting drive %d\n", info->num));
366 +                        M68kRegisters r;
367 +                        r.d[0] = info->num;
368 +                        r.a[0] = 7;     // diskEvent
369 +                        Execute68kTrap(0xa02f, &r);             // PostEvent()
370 +                        info->to_be_mounted = false;
371 +                }
372 +
373 +                info = info->next;
374 +        }
375 + }
376 +
377 +
378 + /*
379   *  Driver Open() routine
380   */
381  
# Line 345 | Line 385 | int16 CDROMOpen(uint32 pb, uint32 dce)
385  
386          // Set up DCE
387          WriteMacInt32(dce + dCtlPosition, 0);
388 +        acc_run_called = false;
389  
390          // Install drives
391          for (DriveInfo *info = first_drive_info; info; info = info->next) {
# Line 456 | Line 497 | int16 CDROMControl(uint32 pb, uint32 dce
497                  case 1:         // KillIO
498                          return noErr;
499  
500 <                case 65: {      // Periodic action ("insert" disks on startup and check for disk changes)
501 <                        DriveInfo *info = first_drive_info;
502 <                        while (info != NULL) {
503 <
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 <                        }
500 >                case 65: {      // Periodic action (accRun, "insert" disks on startup)
501 >                        mount_mountable_volumes();
502 >                        WriteMacInt16(dce + dCtlFlags, ReadMacInt16(dce + dCtlFlags) & ~0x2000);        // Disable periodic action
503 >                        acc_run_called = true;
504                          return noErr;
505                  }
506  
# Line 581 | Line 602 | int16 CDROMControl(uint32 pb, uint32 dce
602                                          break;
603  
604                                  case 3: {               // Get track starting address
605 <                                        uint8 *buf = Mac2HostAddr(ReadMacInt32(pb + csParam + 2));
605 >                                        uint32 buf = ReadMacInt32(pb + csParam + 2);
606                                          uint16 buf_size = ReadMacInt16(pb + csParam + 6);
607                                          int track = bcd2bin[ReadMacInt8(pb + csParam + 8)];
608  
# Line 595 | Line 616 | int16 CDROMControl(uint32 pb, uint32 dce
616                                          // Fill buffer
617                                          if (i != 804)
618                                                  while (buf_size > 0) {
619 <                                                        *buf++ = info->toc[i+1] & 0x0f;         // Control
620 <                                                        *buf++ = bin2bcd[info->toc[i+5]];       // M
621 <                                                        *buf++ = bin2bcd[info->toc[i+6]];       // S
622 <                                                        *buf++ = bin2bcd[info->toc[i+7]];       // F
619 >                                                        WriteMacInt8(buf, info->toc[i+1] & 0x0f); buf++;        // Control
620 >                                                        WriteMacInt8(buf, bin2bcd[info->toc[i+5]]); buf++;      // M
621 >                                                        WriteMacInt8(buf, bin2bcd[info->toc[i+6]]); buf++;      // S
622 >                                                        WriteMacInt8(buf, bin2bcd[info->toc[i+7]]); buf++;      // F
623  
624                                                          // Lead-Out? Then stop
625                                                          if (info->toc[i+2] == 0xaa)
# Line 629 | Line 650 | int16 CDROMControl(uint32 pb, uint32 dce
650  
651                  case 101: {             // ReadTheQSubcode
652                          if (ReadMacInt8(info->status + dsDiskInPlace) == 0) {
653 <                                memset(Mac2HostAddr(pb + csParam), 0, 10);
653 >                                Mac_memset(pb + csParam, 0, 10);
654                                  return offLinErr;
655                          }
656  
657                          uint8 pos[16];
658                          if (SysCDGetPosition(info->fh, pos)) {
659 <                                uint8 *p = Mac2HostAddr(pb + csParam);
660 <                                *p++ = pos[5] & 0x0f;           // Control
661 <                                *p++ = bin2bcd[pos[6]];         // Track number
662 <                                *p++ = bin2bcd[pos[7]];         // Index number
663 <                                *p++ = bin2bcd[pos[13]];        // M (rel)
664 <                                *p++ = bin2bcd[pos[14]];        // S (rel)
665 <                                *p++ = bin2bcd[pos[15]];        // F (rel)
666 <                                *p++ = bin2bcd[pos[9]];         // M (abs)
667 <                                *p++ = bin2bcd[pos[10]];        // S (abs)
668 <                                *p++ = bin2bcd[pos[11]];        // F (abs)
669 <                                *p++ = 0;
659 >                                uint32 p = pb + csParam;
660 >                                WriteMacInt8(p, pos[5] & 0x0f); p++;    // Control
661 >                                WriteMacInt8(p, bin2bcd[pos[6]]); p++;  // Track number
662 >                                WriteMacInt8(p, bin2bcd[pos[7]]); p++;  // Index number
663 >                                WriteMacInt8(p, bin2bcd[pos[13]]); p++; // M (rel)
664 >                                WriteMacInt8(p, bin2bcd[pos[14]]); p++; // S (rel)
665 >                                WriteMacInt8(p, bin2bcd[pos[15]]); p++; // F (rel)
666 >                                WriteMacInt8(p, bin2bcd[pos[9]]); p++;  // M (abs)
667 >                                WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs)
668 >                                WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs)
669 >                                WriteMacInt8(p, 0);
670                                  return noErr;
671                          } else
672                                  return ioErr;
# Line 733 | Line 754 | int16 CDROMControl(uint32 pb, uint32 dce
754                          if (!SysCDGetPosition(info->fh, pos))
755                                  return paramErr;
756  
757 <                        uint8 *p = Mac2HostAddr(pb + csParam);
757 >                        uint32 p = pb + csParam;
758                          switch (pos[1]) {
759                                  case 0x11:
760 <                                        *p++ = 0;       // Audio play in progress
760 >                                        WriteMacInt8(p, 0);     // Audio play in progress
761                                          break;
762                                  case 0x12:
763 <                                        *p++ = 1;       // Audio play paused
763 >                                        WriteMacInt8(p, 1);     // Audio play paused
764                                          break;
765                                  case 0x13:
766 <                                        *p++ = 3;       // Audio play completed
766 >                                        WriteMacInt8(p, 3);     // Audio play completed
767                                          break;
768                                  case 0x14:
769 <                                        *p++ = 4;       // Error occurred
769 >                                        WriteMacInt8(p, 4);     // Error occurred
770                                          break;
771                                  default:
772 <                                        *p++ = 5;       // No audio play operation requested
772 >                                        WriteMacInt8(p, 5);     // No audio play operation requested
773                                          break;
774                          }
775 <                        *p++ = info->play_mode;
776 <                        *p++ = pos[5] & 0x0f;           // Control
777 <                        *p++ = bin2bcd[pos[9]];         // M (abs)
778 <                        *p++ = bin2bcd[pos[10]];        // S (abs)
779 <                        *p++ = bin2bcd[pos[11]];        // F (abs)
775 >                        p++;
776 >                        WriteMacInt8(p, info->play_mode); p++;
777 >                        WriteMacInt8(p, pos[5] & 0x0f); p++;    // Control
778 >                        WriteMacInt8(p, bin2bcd[pos[9]]); p++;  // M (abs)
779 >                        WriteMacInt8(p, bin2bcd[pos[10]]); p++; // S (abs)
780 >                        WriteMacInt8(p, bin2bcd[pos[11]]); p++; // F (abs)
781                          return noErr;
782                  }
783  
# Line 903 | Line 925 | int16 CDROMStatus(uint32 pb, uint32 dce)
925          // Drive-specific codes
926          switch (code) {
927                  case 8:                 // DriveStatus
928 <                        memcpy(Mac2HostAddr(pb + csParam), Mac2HostAddr(info->status), 22);
928 >                        Mac2Mac_memcpy(pb + csParam, info->status, 22);
929                          return noErr;
930  
931                  case 70:                // GetPowerMode
# Line 939 | Line 961 | int16 CDROMStatus(uint32 pb, uint32 dce)
961                          return statusErr;
962          }
963   }
964 +
965 +
966 + /*
967 + *  Driver interrupt routine - check for volumes to be mounted
968 + */
969 +
970 + void CDROMInterrupt(void)
971 + {
972 +        static int tick_count = 0;
973 +        if (!acc_run_called)
974 +                return;
975 +
976 +        tick_count++;
977 +        if (tick_count > driver_delay) {
978 +                tick_count = 0;
979 +                mount_mountable_volumes();
980 +        }
981 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines