src/cdrom/mint/SDL_syscdrom.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
    55 } metados_drive_t;
    55 } metados_drive_t;
    56 
    56 
    57 static metados_drive_t metados_drives[MAX_DRIVES];
    57 static metados_drive_t metados_drives[MAX_DRIVES];
    58 
    58 
    59 /* The system-dependent CD control functions */
    59 /* The system-dependent CD control functions */
    60 static const char *SDL_SYS_CDName (int drive);
    60 static const char *SDL_SYS_CDName(int drive);
    61 static int SDL_SYS_CDOpen (int drive);
    61 static int SDL_SYS_CDOpen(int drive);
    62 static void SDL_SYS_CDClose (SDL_CD * cdrom);
    62 static void SDL_SYS_CDClose(SDL_CD * cdrom);
    63 static int SDL_SYS_CDioctl (int id, int command, void *arg);
    63 static int SDL_SYS_CDioctl(int id, int command, void *arg);
    64 static int SDL_SYS_CDGetTOC (SDL_CD * cdrom);
    64 static int SDL_SYS_CDGetTOC(SDL_CD * cdrom);
    65 static CDstatus SDL_SYS_CDStatus (SDL_CD * cdrom, int *position);
    65 static CDstatus SDL_SYS_CDStatus(SDL_CD * cdrom, int *position);
    66 static int SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length);
    66 static int SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length);
    67 static int SDL_SYS_CDPause (SDL_CD * cdrom);
    67 static int SDL_SYS_CDPause(SDL_CD * cdrom);
    68 static int SDL_SYS_CDResume (SDL_CD * cdrom);
    68 static int SDL_SYS_CDResume(SDL_CD * cdrom);
    69 static int SDL_SYS_CDStop (SDL_CD * cdrom);
    69 static int SDL_SYS_CDStop(SDL_CD * cdrom);
    70 static int SDL_SYS_CDEject (SDL_CD * cdrom);
    70 static int SDL_SYS_CDEject(SDL_CD * cdrom);
    71 
    71 
    72 int
    72 int
    73 SDL_SYS_CDInit (void)
    73 SDL_SYS_CDInit(void)
    74 {
    74 {
    75     metainit_t metainit = { 0, 0, 0, 0 };
    75     metainit_t metainit = { 0, 0, 0, 0 };
    76     metaopen_t metaopen;
    76     metaopen_t metaopen;
    77     int i, handle;
    77     int i, handle;
    78     struct cdrom_subchnl info;
    78     struct cdrom_subchnl info;
    79 
    79 
    80     Metainit (&metainit);
    80     Metainit(&metainit);
    81     if (metainit.version == NULL) {
    81     if (metainit.version == NULL) {
    82 #ifdef DEBUG_CDROM
    82 #ifdef DEBUG_CDROM
    83         fprintf (stderr, "MetaDOS not installed\n");
    83         fprintf(stderr, "MetaDOS not installed\n");
    84 #endif
    84 #endif
    85         return -1;
    85         return -1;
    86     }
    86     }
    87 
    87 
    88     if (metainit.drives_map == 0) {
    88     if (metainit.drives_map == 0) {
    89 #ifdef DEBUG_CDROM
    89 #ifdef DEBUG_CDROM
    90         fprintf (stderr, "No MetaDOS devices present\n");
    90         fprintf(stderr, "No MetaDOS devices present\n");
    91 #endif
    91 #endif
    92         return -1;
    92         return -1;
    93     }
    93     }
    94 
    94 
    95     SDL_numcds = 0;
    95     SDL_numcds = 0;
    98         metados_drives[SDL_numcds].device[0] = 0;
    98         metados_drives[SDL_numcds].device[0] = 0;
    99         metados_drives[SDL_numcds].device[1] = ':';
    99         metados_drives[SDL_numcds].device[1] = ':';
   100         metados_drives[SDL_numcds].device[2] = 0;
   100         metados_drives[SDL_numcds].device[2] = 0;
   101 
   101 
   102         if (metainit.drives_map & (1 << (i - 'A'))) {
   102         if (metainit.drives_map & (1 << (i - 'A'))) {
   103             handle = Metaopen (i, &metaopen);
   103             handle = Metaopen(i, &metaopen);
   104             if (handle == 0) {
   104             if (handle == 0) {
   105 
   105 
   106                 info.cdsc_format = CDROM_MSF;
   106                 info.cdsc_format = CDROM_MSF;
   107                 if ((Metaioctl
   107                 if ((Metaioctl
   108                      (i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0)
   108                      (i, METADOS_IOCTL_MAGIC, CDROMSUBCHNL, &info) == 0)
   109                     || ERRNO_TRAYEMPTY (errno)) {
   109                     || ERRNO_TRAYEMPTY(errno)) {
   110                     metados_drives[SDL_numcds].device[0] = i;
   110                     metados_drives[SDL_numcds].device[0] = i;
   111                     ++SDL_numcds;
   111                     ++SDL_numcds;
   112                 }
   112                 }
   113 
   113 
   114                 Metaclose (i);
   114                 Metaclose(i);
   115             }
   115             }
   116         }
   116         }
   117     }
   117     }
   118 
   118 
   119     /* Fill in our driver capabilities */
   119     /* Fill in our driver capabilities */
   131 
   131 
   132     return 0;
   132     return 0;
   133 }
   133 }
   134 
   134 
   135 void
   135 void
   136 SDL_SYS_CDQuit (void)
   136 SDL_SYS_CDQuit(void)
   137 {
   137 {
   138     SDL_numcds = 0;
   138     SDL_numcds = 0;
   139 }
   139 }
   140 
   140 
   141 static const char *
   141 static const char *
   142 SDL_SYS_CDName (int drive)
   142 SDL_SYS_CDName(int drive)
   143 {
   143 {
   144     return (metados_drives[drive].device);
   144     return (metados_drives[drive].device);
   145 }
   145 }
   146 
   146 
   147 static int
   147 static int
   148 SDL_SYS_CDOpen (int drive)
   148 SDL_SYS_CDOpen(int drive)
   149 {
   149 {
   150     int handle;
   150     int handle;
   151 
   151 
   152     handle =
   152     handle =
   153         Metaopen (metados_drives[drive].device[0],
   153         Metaopen(metados_drives[drive].device[0],
   154                   &(metados_drives[drive].metaopen));
   154                  &(metados_drives[drive].metaopen));
   155     if (handle == 0) {
   155     if (handle == 0) {
   156         return drive;
   156         return drive;
   157     }
   157     }
   158 
   158 
   159     return -1;
   159     return -1;
   160 }
   160 }
   161 
   161 
   162 static void
   162 static void
   163 SDL_SYS_CDClose (SDL_CD * cdrom)
   163 SDL_SYS_CDClose(SDL_CD * cdrom)
   164 {
   164 {
   165     Metaclose (metados_drives[cdrom->id].device[0]);
   165     Metaclose(metados_drives[cdrom->id].device[0]);
   166 }
   166 }
   167 
   167 
   168 static int
   168 static int
   169 SDL_SYS_CDioctl (int id, int command, void *arg)
   169 SDL_SYS_CDioctl(int id, int command, void *arg)
   170 {
   170 {
   171     int retval;
   171     int retval;
   172 
   172 
   173     retval =
   173     retval =
   174         Metaioctl (metados_drives[id].device[0], METADOS_IOCTL_MAGIC, command,
   174         Metaioctl(metados_drives[id].device[0], METADOS_IOCTL_MAGIC, command,
   175                    arg);
   175                   arg);
   176     if (retval < 0) {
   176     if (retval < 0) {
   177         SDL_SetError ("ioctl() error: %s", strerror (errno));
   177         SDL_SetError("ioctl() error: %s", strerror(errno));
   178     }
   178     }
   179     return (retval);
   179     return (retval);
   180 }
   180 }
   181 
   181 
   182 static int
   182 static int
   183 SDL_SYS_CDGetTOC (SDL_CD * cdrom)
   183 SDL_SYS_CDGetTOC(SDL_CD * cdrom)
   184 {
   184 {
   185     int i, okay;
   185     int i, okay;
   186     struct cdrom_tochdr toc;
   186     struct cdrom_tochdr toc;
   187     struct cdrom_tocentry entry;
   187     struct cdrom_tocentry entry;
   188 
   188 
   189     /* Use standard ioctl() */
   189     /* Use standard ioctl() */
   190     if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCHDR, &toc) < 0) {
   190     if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc) < 0) {
   191         return -1;
   191         return -1;
   192     }
   192     }
   193 
   193 
   194     cdrom->numtracks = toc.cdth_trk1 - toc.cdth_trk0 + 1;
   194     cdrom->numtracks = toc.cdth_trk1 - toc.cdth_trk0 + 1;
   195     if (cdrom->numtracks > SDL_MAX_TRACKS) {
   195     if (cdrom->numtracks > SDL_MAX_TRACKS) {
   204         } else {
   204         } else {
   205             cdrom->track[i].id = toc.cdth_trk0 + i;
   205             cdrom->track[i].id = toc.cdth_trk0 + i;
   206         }
   206         }
   207         entry.cdte_track = cdrom->track[i].id;
   207         entry.cdte_track = cdrom->track[i].id;
   208         entry.cdte_format = CDROM_MSF;
   208         entry.cdte_format = CDROM_MSF;
   209         if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCENTRY, &entry) < 0) {
   209         if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCENTRY, &entry) < 0) {
   210             okay = 0;
   210             okay = 0;
   211             break;
   211             break;
   212         } else {
   212         } else {
   213             if (entry.cdte_ctrl & CDROM_DATA_TRACK) {
   213             if (entry.cdte_ctrl & CDROM_DATA_TRACK) {
   214                 cdrom->track[i].type = SDL_DATA_TRACK;
   214                 cdrom->track[i].type = SDL_DATA_TRACK;
   215             } else {
   215             } else {
   216                 cdrom->track[i].type = SDL_AUDIO_TRACK;
   216                 cdrom->track[i].type = SDL_AUDIO_TRACK;
   217             }
   217             }
   218             cdrom->track[i].offset =
   218             cdrom->track[i].offset =
   219                 MSF_TO_FRAMES (entry.cdte_addr.msf.minute,
   219                 MSF_TO_FRAMES(entry.cdte_addr.msf.minute,
   220                                entry.cdte_addr.msf.second,
   220                               entry.cdte_addr.msf.second,
   221                                entry.cdte_addr.msf.frame);
   221                               entry.cdte_addr.msf.frame);
   222             cdrom->track[i].length = 0;
   222             cdrom->track[i].length = 0;
   223             if (i > 0) {
   223             if (i > 0) {
   224                 cdrom->track[i - 1].length =
   224                 cdrom->track[i - 1].length =
   225                     cdrom->track[i].offset - cdrom->track[i - 1].offset;
   225                     cdrom->track[i].offset - cdrom->track[i - 1].offset;
   226             }
   226             }
   230     return (okay ? 0 : -1);
   230     return (okay ? 0 : -1);
   231 }
   231 }
   232 
   232 
   233 /* Get CD-ROM status */
   233 /* Get CD-ROM status */
   234 static CDstatus
   234 static CDstatus
   235 SDL_SYS_CDStatus (SDL_CD * cdrom, int *position)
   235 SDL_SYS_CDStatus(SDL_CD * cdrom, int *position)
   236 {
   236 {
   237     CDstatus status;
   237     CDstatus status;
   238     struct cdrom_tochdr toc;
   238     struct cdrom_tochdr toc;
   239     struct cdrom_subchnl info;
   239     struct cdrom_subchnl info;
   240 
   240 
   241     info.cdsc_format = CDROM_MSF;
   241     info.cdsc_format = CDROM_MSF;
   242     if (SDL_SYS_CDioctl (cdrom->id, CDROMSUBCHNL, &info) < 0) {
   242     if (SDL_SYS_CDioctl(cdrom->id, CDROMSUBCHNL, &info) < 0) {
   243         if (ERRNO_TRAYEMPTY (errno)) {
   243         if (ERRNO_TRAYEMPTY(errno)) {
   244             status = CD_TRAYEMPTY;
   244             status = CD_TRAYEMPTY;
   245         } else {
   245         } else {
   246             status = CD_ERROR;
   246             status = CD_ERROR;
   247         }
   247         }
   248     } else {
   248     } else {
   249         switch (info.cdsc_audiostatus) {
   249         switch (info.cdsc_audiostatus) {
   250         case CDROM_AUDIO_INVALID:
   250         case CDROM_AUDIO_INVALID:
   251         case CDROM_AUDIO_NO_STATUS:
   251         case CDROM_AUDIO_NO_STATUS:
   252             /* Try to determine if there's a CD available */
   252             /* Try to determine if there's a CD available */
   253             if (SDL_SYS_CDioctl (cdrom->id, CDROMREADTOCHDR, &toc) == 0) {
   253             if (SDL_SYS_CDioctl(cdrom->id, CDROMREADTOCHDR, &toc) == 0) {
   254                 status = CD_STOPPED;
   254                 status = CD_STOPPED;
   255             } else {
   255             } else {
   256                 status = CD_TRAYEMPTY;
   256                 status = CD_TRAYEMPTY;
   257             }
   257             }
   258             break;
   258             break;
   275             break;
   275             break;
   276         }
   276         }
   277     }
   277     }
   278     if (position) {
   278     if (position) {
   279         if (status == CD_PLAYING || (status == CD_PAUSED)) {
   279         if (status == CD_PLAYING || (status == CD_PAUSED)) {
   280             *position = MSF_TO_FRAMES (info.cdsc_absaddr.msf.minute,
   280             *position = MSF_TO_FRAMES(info.cdsc_absaddr.msf.minute,
   281                                        info.cdsc_absaddr.msf.second,
   281                                       info.cdsc_absaddr.msf.second,
   282                                        info.cdsc_absaddr.msf.frame);
   282                                       info.cdsc_absaddr.msf.frame);
   283         } else {
   283         } else {
   284             *position = 0;
   284             *position = 0;
   285         }
   285         }
   286     }
   286     }
   287     return (status);
   287     return (status);
   288 }
   288 }
   289 
   289 
   290 /* Start play */
   290 /* Start play */
   291 static int
   291 static int
   292 SDL_SYS_CDPlay (SDL_CD * cdrom, int start, int length)
   292 SDL_SYS_CDPlay(SDL_CD * cdrom, int start, int length)
   293 {
   293 {
   294     struct cdrom_msf playtime;
   294     struct cdrom_msf playtime;
   295 
   295 
   296     FRAMES_TO_MSF (start,
   296     FRAMES_TO_MSF(start,
   297                    &playtime.cdmsf_min0, &playtime.cdmsf_sec0,
   297                   &playtime.cdmsf_min0, &playtime.cdmsf_sec0,
   298                    &playtime.cdmsf_frame0);
   298                   &playtime.cdmsf_frame0);
   299     FRAMES_TO_MSF (start + length, &playtime.cdmsf_min1, &playtime.cdmsf_sec1,
   299     FRAMES_TO_MSF(start + length, &playtime.cdmsf_min1, &playtime.cdmsf_sec1,
   300                    &playtime.cdmsf_frame1);
   300                   &playtime.cdmsf_frame1);
   301 #ifdef DEBUG_CDROM
   301 #ifdef DEBUG_CDROM
   302     fprintf (stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
   302     fprintf(stderr, "Trying to play from %d:%d:%d to %d:%d:%d\n",
   303              playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
   303             playtime.cdmsf_min0, playtime.cdmsf_sec0, playtime.cdmsf_frame0,
   304              playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
   304             playtime.cdmsf_min1, playtime.cdmsf_sec1, playtime.cdmsf_frame1);
   305 #endif
   305 #endif
   306 
   306 
   307     return SDL_SYS_CDioctl (cdrom->id, CDROMPLAYMSF, &playtime);
   307     return SDL_SYS_CDioctl(cdrom->id, CDROMPLAYMSF, &playtime);
   308 }
   308 }
   309 
   309 
   310 /* Pause play */
   310 /* Pause play */
   311 static int
   311 static int
   312 SDL_SYS_CDPause (SDL_CD * cdrom)
   312 SDL_SYS_CDPause(SDL_CD * cdrom)
   313 {
   313 {
   314     return SDL_SYS_CDioctl (cdrom->id, CDROMPAUSE, 0);
   314     return SDL_SYS_CDioctl(cdrom->id, CDROMPAUSE, 0);
   315 }
   315 }
   316 
   316 
   317 /* Resume play */
   317 /* Resume play */
   318 static int
   318 static int
   319 SDL_SYS_CDResume (SDL_CD * cdrom)
   319 SDL_SYS_CDResume(SDL_CD * cdrom)
   320 {
   320 {
   321     return SDL_SYS_CDioctl (cdrom->id, CDROMRESUME, 0);
   321     return SDL_SYS_CDioctl(cdrom->id, CDROMRESUME, 0);
   322 }
   322 }
   323 
   323 
   324 /* Stop play */
   324 /* Stop play */
   325 static int
   325 static int
   326 SDL_SYS_CDStop (SDL_CD * cdrom)
   326 SDL_SYS_CDStop(SDL_CD * cdrom)
   327 {
   327 {
   328     return SDL_SYS_CDioctl (cdrom->id, CDROMSTOP, 0);
   328     return SDL_SYS_CDioctl(cdrom->id, CDROMSTOP, 0);
   329 }
   329 }
   330 
   330 
   331 /* Eject the CD-ROM */
   331 /* Eject the CD-ROM */
   332 static int
   332 static int
   333 SDL_SYS_CDEject (SDL_CD * cdrom)
   333 SDL_SYS_CDEject(SDL_CD * cdrom)
   334 {
   334 {
   335     return SDL_SYS_CDioctl (cdrom->id, CDROMEJECT, 0);
   335     return SDL_SYS_CDioctl(cdrom->id, CDROMEJECT, 0);
   336 }
   336 }
   337 
   337 
   338 #endif /* SDL_CDROM_MINT */
   338 #endif /* SDL_CDROM_MINT */
   339 /* vi: set ts=4 sw=4 expandtab: */
   339 /* vi: set ts=4 sw=4 expandtab: */