Home | History | Annotate | Download | only in dc
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2012 Sam Lantinga
      4 
      5     This library is free software; you can redistribute it and/or
      6     modify it under the terms of the GNU Lesser General Public
      7     License as published by the Free Software Foundation; either
      8     version 2.1 of the License, or (at your option) any later version.
      9 
     10     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Lesser General Public License for more details.
     14 
     15     You should have received a copy of the GNU Lesser General Public
     16     License along with this library; if not, write to the Free Software
     17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 
     19     Sam Lantinga
     20     slouken (at) libsdl.org
     21 */
     22 #include "SDL_config.h"
     23 
     24 #ifdef SDL_CDROM_DC
     25 
     26 /* Functions for system-level CD-ROM audio control */
     27 
     28 #include <dc/cdrom.h>
     29 #include <dc/spu.h>
     30 
     31 #include "SDL_cdrom.h"
     32 #include "../SDL_syscdrom.h"
     33 
     34 /* The system-dependent CD control functions */
     35 static const char *SDL_SYS_CDName(int drive);
     36 static int SDL_SYS_CDOpen(int drive);
     37 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom);
     38 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position);
     39 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length);
     40 static int SDL_SYS_CDPause(SDL_CD *cdrom);
     41 static int SDL_SYS_CDResume(SDL_CD *cdrom);
     42 static int SDL_SYS_CDStop(SDL_CD *cdrom);
     43 static int SDL_SYS_CDEject(SDL_CD *cdrom);
     44 static void SDL_SYS_CDClose(SDL_CD *cdrom);
     45 
     46 
     47 int  SDL_SYS_CDInit(void)
     48 {
     49 	/* Fill in our driver capabilities */
     50 	SDL_CDcaps.Name = SDL_SYS_CDName;
     51 	SDL_CDcaps.Open = SDL_SYS_CDOpen;
     52 	SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
     53 	SDL_CDcaps.Status = SDL_SYS_CDStatus;
     54 	SDL_CDcaps.Play = SDL_SYS_CDPlay;
     55 	SDL_CDcaps.Pause = SDL_SYS_CDPause;
     56 	SDL_CDcaps.Resume = SDL_SYS_CDResume;
     57 	SDL_CDcaps.Stop = SDL_SYS_CDStop;
     58 	SDL_CDcaps.Eject = SDL_SYS_CDEject;
     59 	SDL_CDcaps.Close = SDL_SYS_CDClose;
     60 
     61 	return(0);
     62 }
     63 
     64 static const char *SDL_SYS_CDName(int drive)
     65 {
     66 	return "/cd";
     67 }
     68 
     69 static int SDL_SYS_CDOpen(int drive)
     70 {
     71 	return(drive);
     72 }
     73 
     74 #define	TRACK_CDDA	0
     75 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
     76 {
     77 	CDROM_TOC toc;
     78 	int ret,i;
     79 
     80 	ret = cdrom_read_toc(&toc,0);
     81 	if (ret!=ERR_OK) {
     82 		return -1;
     83 	}
     84 
     85 	cdrom->numtracks = TOC_TRACK(toc.last)-TOC_TRACK(toc.first)+1;
     86 	for(i=0;i<cdrom->numtracks;i++) {
     87 		unsigned long entry = toc.entry[i];
     88 		cdrom->track[i].id = i+1;
     89 		cdrom->track[i].type = (TOC_CTRL(toc.entry[i])==TRACK_CDDA)?SDL_AUDIO_TRACK:SDL_DATA_TRACK;
     90 		cdrom->track[i].offset = TOC_LBA(entry)-150;
     91 		cdrom->track[i].length = TOC_LBA((i+1<toc.last)?toc.entry[i+1]:toc.leadout_sector)-TOC_LBA(entry);
     92 	}
     93 
     94 	return 0;
     95 }
     96 
     97 /* Get CD-ROM status */
     98 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
     99 {
    100 	int ret,dc_status,disc_type;
    101 
    102 	ret = cdrom_get_status(&dc_status,&disc_type);
    103 	if (ret!=ERR_OK) return CD_ERROR;
    104 
    105 	switch(dc_status) {
    106 //	case CD_STATUS_BUSY:
    107 	case CD_STATUS_PAUSED:
    108 		return CD_PAUSED;
    109 	case CD_STATUS_STANDBY:
    110 		return CD_STOPPED;
    111 	case CD_STATUS_PLAYING:
    112 		return CD_PLAYING;
    113 //	case CD_STATUS_SEEKING:
    114 //	case CD_STATUS_SCANING:
    115 	case CD_STATUS_OPEN:
    116 	case CD_STATUS_NO_DISC:
    117 		return CD_TRAYEMPTY;
    118 	default:
    119 		return	CD_ERROR;
    120 	}
    121 }
    122 
    123 /* Start play */
    124 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
    125 {
    126 	int ret = cdrom_cdda_play(start-150,start-150+length,1,CDDA_SECTORS);
    127 	return ret==ERR_OK?0:-1;
    128 }
    129 
    130 /* Pause play */
    131 static int SDL_SYS_CDPause(SDL_CD *cdrom)
    132 {
    133 	int ret=cdrom_cdda_pause();
    134 	return ret==ERR_OK?0:-1;
    135 }
    136 
    137 /* Resume play */
    138 static int SDL_SYS_CDResume(SDL_CD *cdrom)
    139 {
    140 	int ret=cdrom_cdda_resume();
    141 	return ret==ERR_OK?0:-1;
    142 }
    143 
    144 /* Stop play */
    145 static int SDL_SYS_CDStop(SDL_CD *cdrom)
    146 {
    147 	int ret=cdrom_spin_down();
    148 	return ret==ERR_OK?0:-1;
    149 }
    150 
    151 /* Eject the CD-ROM */
    152 static int SDL_SYS_CDEject(SDL_CD *cdrom)
    153 {
    154 	return -1;
    155 }
    156 
    157 /* Close the CD-ROM handle */
    158 static void SDL_SYS_CDClose(SDL_CD *cdrom)
    159 {
    160 }
    161 
    162 void SDL_SYS_CDQuit(void)
    163 {
    164 
    165 }
    166 
    167 #endif /* SDL_CDROM_DC */
    168