2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
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.
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.
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
22 #include "SDL_config.h"
26 /* Functions for system-level CD-ROM audio control */
31 #include "SDL_cdrom.h"
32 #include "../SDL_syscdrom.h"
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);
47 int SDL_SYS_CDInit(void)
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;
64 static const char *SDL_SYS_CDName(int drive)
69 static int SDL_SYS_CDOpen(int drive)
75 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom)
80 ret = cdrom_read_toc(&toc,0);
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);
97 /* Get CD-ROM status */
98 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position)
100 int ret,dc_status,disc_type;
102 ret = cdrom_get_status(&dc_status,&disc_type);
103 if (ret!=ERR_OK) return CD_ERROR;
106 // case CD_STATUS_BUSY:
107 case CD_STATUS_PAUSED:
109 case CD_STATUS_STANDBY:
111 case CD_STATUS_PLAYING:
113 // case CD_STATUS_SEEKING:
114 // case CD_STATUS_SCANING:
116 case CD_STATUS_NO_DISC:
124 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length)
126 int ret = cdrom_cdda_play(start-150,start-150+length,1,CDDA_SECTORS);
127 return ret==ERR_OK?0:-1;
131 static int SDL_SYS_CDPause(SDL_CD *cdrom)
133 int ret=cdrom_cdda_pause();
134 return ret==ERR_OK?0:-1;
138 static int SDL_SYS_CDResume(SDL_CD *cdrom)
140 int ret=cdrom_cdda_resume();
141 return ret==ERR_OK?0:-1;
145 static int SDL_SYS_CDStop(SDL_CD *cdrom)
147 int ret=cdrom_spin_down();
148 return ret==ERR_OK?0:-1;
151 /* Eject the CD-ROM */
152 static int SDL_SYS_CDEject(SDL_CD *cdrom)
157 /* Close the CD-ROM handle */
158 static void SDL_SYS_CDClose(SDL_CD *cdrom)
162 void SDL_SYS_CDQuit(void)
167 #endif /* SDL_CDROM_DC */