Mercurial > sdl-ios-xcode
comparison src/cdrom/dc/SDL_syscdrom.c @ 509:dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Oct 2002 16:50:56 +0000 |
parents | |
children | b8d311d90021 |
comparison
equal
deleted
inserted
replaced
508:9ff7e90aaa94 | 509:dad72daf44b3 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 BERO | |
20 bero@geocities.co.jp | |
21 | |
22 based on win32/SDL_syscdrom.c by | |
23 | |
24 Sam Lantinga | |
25 slouken@libsdl.org | |
26 */ | |
27 | |
28 #ifdef SAVE_RCSID | |
29 static char rcsid = | |
30 "@(#) $Id$"; | |
31 #endif | |
32 | |
33 /* Functions for system-level CD-ROM audio control */ | |
34 | |
35 #include <stdlib.h> | |
36 #include <stdio.h> | |
37 #include <dc/cdrom.h> | |
38 #include <dc/spu.h> | |
39 | |
40 #include "SDL_error.h" | |
41 #include "SDL_cdrom.h" | |
42 #include "SDL_syscdrom.h" | |
43 | |
44 /* The system-dependent CD control functions */ | |
45 static const char *SDL_SYS_CDName(int drive); | |
46 static int SDL_SYS_CDOpen(int drive); | |
47 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom); | |
48 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position); | |
49 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length); | |
50 static int SDL_SYS_CDPause(SDL_CD *cdrom); | |
51 static int SDL_SYS_CDResume(SDL_CD *cdrom); | |
52 static int SDL_SYS_CDStop(SDL_CD *cdrom); | |
53 static int SDL_SYS_CDEject(SDL_CD *cdrom); | |
54 static void SDL_SYS_CDClose(SDL_CD *cdrom); | |
55 | |
56 | |
57 int SDL_SYS_CDInit(void) | |
58 { | |
59 /* Fill in our driver capabilities */ | |
60 SDL_CDcaps.Name = SDL_SYS_CDName; | |
61 SDL_CDcaps.Open = SDL_SYS_CDOpen; | |
62 SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC; | |
63 SDL_CDcaps.Status = SDL_SYS_CDStatus; | |
64 SDL_CDcaps.Play = SDL_SYS_CDPlay; | |
65 SDL_CDcaps.Pause = SDL_SYS_CDPause; | |
66 SDL_CDcaps.Resume = SDL_SYS_CDResume; | |
67 SDL_CDcaps.Stop = SDL_SYS_CDStop; | |
68 SDL_CDcaps.Eject = SDL_SYS_CDEject; | |
69 SDL_CDcaps.Close = SDL_SYS_CDClose; | |
70 | |
71 return(0); | |
72 } | |
73 | |
74 static const char *SDL_SYS_CDName(int drive) | |
75 { | |
76 return "/cd"; | |
77 } | |
78 | |
79 static int SDL_SYS_CDOpen(int drive) | |
80 { | |
81 return(drive); | |
82 } | |
83 | |
84 #define TRACK_CDDA 0 | |
85 static int SDL_SYS_CDGetTOC(SDL_CD *cdrom) | |
86 { | |
87 CDROM_TOC toc; | |
88 int ret,i; | |
89 | |
90 ret = cdrom_read_toc(&toc,0); | |
91 if (ret!=ERR_OK) { | |
92 return -1; | |
93 } | |
94 | |
95 cdrom->numtracks = TOC_TRACK(toc.last)-TOC_TRACK(toc.first)+1; | |
96 for(i=0;i<cdrom->numtracks;i++) { | |
97 unsigned long entry = toc.entry[i]; | |
98 cdrom->track[i].id = i+1; | |
99 cdrom->track[i].type = (TOC_CTRL(toc.entry[i])==TRACK_CDDA)?SDL_AUDIO_TRACK:SDL_DATA_TRACK; | |
100 cdrom->track[i].offset = TOC_LBA(entry)-150; | |
101 cdrom->track[i].length = TOC_LBA((i+1<toc.last)?toc.entry[i+1]:toc.dunno)-TOC_LBA(entry); | |
102 } | |
103 | |
104 return 0; | |
105 } | |
106 | |
107 /* Get CD-ROM status */ | |
108 static CDstatus SDL_SYS_CDStatus(SDL_CD *cdrom, int *position) | |
109 { | |
110 CDstatus status; | |
111 int ret,dc_status,disc_type; | |
112 | |
113 ret = cdrom_get_status(&dc_status,&disc_type); | |
114 if (ret!=ERR_OK) return CD_ERROR; | |
115 | |
116 switch(dc_status) { | |
117 // case CD_STATUS_BUSY: | |
118 case CD_STATUS_PAUSED: | |
119 return CD_PAUSED; | |
120 case CD_STATUS_STANDBY: | |
121 return CD_STOPPED; | |
122 case CD_STATUS_PLAYING: | |
123 return CD_PLAYING; | |
124 // case CD_STATUS_SEEKING: | |
125 // case CD_STATUS_SCANING: | |
126 case CD_STATUS_OPEN: | |
127 case CD_STATUS_NO_DISC: | |
128 return CD_TRAYEMPTY; | |
129 default: | |
130 return CD_ERROR; | |
131 } | |
132 } | |
133 | |
134 /* Start play */ | |
135 static int SDL_SYS_CDPlay(SDL_CD *cdrom, int start, int length) | |
136 { | |
137 int ret = cdrom_cdda_play(start-150,start-150+length,1,CDDA_SECTORS); | |
138 return ret==ERR_OK?0:-1; | |
139 } | |
140 | |
141 /* Pause play */ | |
142 static int SDL_SYS_CDPause(SDL_CD *cdrom) | |
143 { | |
144 int ret=cdrom_cdda_pause(); | |
145 return ret==ERR_OK?0:-1; | |
146 } | |
147 | |
148 /* Resume play */ | |
149 static int SDL_SYS_CDResume(SDL_CD *cdrom) | |
150 { | |
151 int ret=cdrom_cdda_resume(); | |
152 return ret==ERR_OK?0:-1; | |
153 } | |
154 | |
155 /* Stop play */ | |
156 static int SDL_SYS_CDStop(SDL_CD *cdrom) | |
157 { | |
158 int ret=cdrom_spin_down(); | |
159 return ret==ERR_OK?0:-1; | |
160 } | |
161 | |
162 /* Eject the CD-ROM */ | |
163 static int SDL_SYS_CDEject(SDL_CD *cdrom) | |
164 { | |
165 return -1; | |
166 } | |
167 | |
168 /* Close the CD-ROM handle */ | |
169 static void SDL_SYS_CDClose(SDL_CD *cdrom) | |
170 { | |
171 } | |
172 | |
173 void SDL_SYS_CDQuit(void) | |
174 { | |
175 | |
176 } |