Mercurial > sdl-ios-xcode
comparison test/testcdrom.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | b2b476a4a73c |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include "SDL.h" | 9 #include "SDL.h" |
10 | 10 |
11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 11 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
12 static void quit(int rc) | 12 static void |
13 { | 13 quit (int rc) |
14 SDL_Quit(); | 14 { |
15 exit(rc); | 15 SDL_Quit (); |
16 } | 16 exit (rc); |
17 | 17 } |
18 static void PrintStatus(int driveindex, SDL_CD *cdrom) | 18 |
19 { | 19 static void |
20 CDstatus status; | 20 PrintStatus (int driveindex, SDL_CD * cdrom) |
21 char *status_str; | 21 { |
22 | 22 CDstatus status; |
23 status = SDL_CDStatus(cdrom); | 23 char *status_str; |
24 switch (status) { | 24 |
25 case CD_TRAYEMPTY: | 25 status = SDL_CDStatus (cdrom); |
26 status_str = "tray empty"; | 26 switch (status) { |
27 break; | 27 case CD_TRAYEMPTY: |
28 case CD_STOPPED: | 28 status_str = "tray empty"; |
29 status_str = "stopped"; | 29 break; |
30 break; | 30 case CD_STOPPED: |
31 case CD_PLAYING: | 31 status_str = "stopped"; |
32 status_str = "playing"; | 32 break; |
33 break; | 33 case CD_PLAYING: |
34 case CD_PAUSED: | 34 status_str = "playing"; |
35 status_str = "paused"; | 35 break; |
36 break; | 36 case CD_PAUSED: |
37 case CD_ERROR: | 37 status_str = "paused"; |
38 status_str = "error state"; | 38 break; |
39 break; | 39 case CD_ERROR: |
40 } | 40 status_str = "error state"; |
41 printf("Drive %d status: %s\n", driveindex, status_str); | 41 break; |
42 if ( status >= CD_PLAYING ) { | 42 } |
43 int m, s, f; | 43 printf ("Drive %d status: %s\n", driveindex, status_str); |
44 FRAMES_TO_MSF(cdrom->cur_frame, &m, &s, &f); | 44 if (status >= CD_PLAYING) { |
45 printf("Currently playing track %d, %d:%2.2d\n", | 45 int m, s, f; |
46 cdrom->track[cdrom->cur_track].id, m, s); | 46 FRAMES_TO_MSF (cdrom->cur_frame, &m, &s, &f); |
47 } | 47 printf ("Currently playing track %d, %d:%2.2d\n", |
48 } | 48 cdrom->track[cdrom->cur_track].id, m, s); |
49 | 49 } |
50 static void ListTracks(SDL_CD *cdrom) | 50 } |
51 { | 51 |
52 int i; | 52 static void |
53 int m, s, f; | 53 ListTracks (SDL_CD * cdrom) |
54 char* trtype; | 54 { |
55 | 55 int i; |
56 SDL_CDStatus(cdrom); | 56 int m, s, f; |
57 printf("Drive tracks: %d\n", cdrom->numtracks); | 57 char *trtype; |
58 for ( i=0; i<cdrom->numtracks; ++i ) { | 58 |
59 FRAMES_TO_MSF(cdrom->track[i].length, &m, &s, &f); | 59 SDL_CDStatus (cdrom); |
60 if ( f > 0 ) | 60 printf ("Drive tracks: %d\n", cdrom->numtracks); |
61 ++s; | 61 for (i = 0; i < cdrom->numtracks; ++i) { |
62 switch(cdrom->track[i].type) | 62 FRAMES_TO_MSF (cdrom->track[i].length, &m, &s, &f); |
63 { | 63 if (f > 0) |
64 case SDL_AUDIO_TRACK: | 64 ++s; |
65 trtype="audio"; | 65 switch (cdrom->track[i].type) { |
66 break; | 66 case SDL_AUDIO_TRACK: |
67 case SDL_DATA_TRACK: | 67 trtype = "audio"; |
68 trtype="data"; | 68 break; |
69 break; | 69 case SDL_DATA_TRACK: |
70 default: | 70 trtype = "data"; |
71 trtype="unknown"; | 71 break; |
72 break; | 72 default: |
73 } | 73 trtype = "unknown"; |
74 printf("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i, | 74 break; |
75 cdrom->track[i].id, m, s, cdrom->track[i].length, trtype); | 75 } |
76 } | 76 printf ("\tTrack (index %d) %d: %d:%2.2d / %d [%s track]\n", i, |
77 } | 77 cdrom->track[i].id, m, s, cdrom->track[i].length, trtype); |
78 | 78 } |
79 static void PrintUsage(char *argv0) | 79 } |
80 { | 80 |
81 fprintf(stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0); | 81 static void |
82 fprintf(stderr, "Where 'command' is one of:\n"); | 82 PrintUsage (char *argv0) |
83 fprintf(stderr, " -status\n"); | 83 { |
84 fprintf(stderr, " -list\n"); | 84 fprintf (stderr, "Usage: %s [drive#] [command] [command] ...\n", argv0); |
85 fprintf(stderr, " -play [first_track] [first_frame] [num_tracks] [num_frames]\n"); | 85 fprintf (stderr, "Where 'command' is one of:\n"); |
86 fprintf(stderr, " -pause\n"); | 86 fprintf (stderr, " -status\n"); |
87 fprintf(stderr, " -resume\n"); | 87 fprintf (stderr, " -list\n"); |
88 fprintf(stderr, " -stop\n"); | 88 fprintf (stderr, |
89 fprintf(stderr, " -eject\n"); | 89 " -play [first_track] [first_frame] [num_tracks] [num_frames]\n"); |
90 fprintf(stderr, " -sleep <milliseconds>\n"); | 90 fprintf (stderr, " -pause\n"); |
91 } | 91 fprintf (stderr, " -resume\n"); |
92 | 92 fprintf (stderr, " -stop\n"); |
93 int main(int argc, char *argv[]) | 93 fprintf (stderr, " -eject\n"); |
94 { | 94 fprintf (stderr, " -sleep <milliseconds>\n"); |
95 int drive; | 95 } |
96 int i; | 96 |
97 SDL_CD *cdrom; | 97 int |
98 | 98 main (int argc, char *argv[]) |
99 /* Initialize SDL first */ | 99 { |
100 if ( SDL_Init(SDL_INIT_CDROM) < 0 ) { | 100 int drive; |
101 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 101 int i; |
102 return(1); | 102 SDL_CD *cdrom; |
103 } | 103 |
104 | 104 /* Initialize SDL first */ |
105 /* Find out how many CD-ROM drives are connected to the system */ | 105 if (SDL_Init (SDL_INIT_CDROM) < 0) { |
106 if ( SDL_CDNumDrives() == 0 ) { | 106 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
107 printf("No CD-ROM devices detected\n"); | 107 return (1); |
108 quit(0); | 108 } |
109 } | 109 |
110 printf("Drives available: %d\n", SDL_CDNumDrives()); | 110 /* Find out how many CD-ROM drives are connected to the system */ |
111 for ( i=0; i<SDL_CDNumDrives(); ++i ) { | 111 if (SDL_CDNumDrives () == 0) { |
112 printf("Drive %d: \"%s\"\n", i, SDL_CDName(i)); | 112 printf ("No CD-ROM devices detected\n"); |
113 } | 113 quit (0); |
114 | 114 } |
115 /* Open the CD-ROM */ | 115 printf ("Drives available: %d\n", SDL_CDNumDrives ()); |
116 drive = 0; | 116 for (i = 0; i < SDL_CDNumDrives (); ++i) { |
117 i=1; | 117 printf ("Drive %d: \"%s\"\n", i, SDL_CDName (i)); |
118 if ( argv[i] && isdigit(argv[i][0]) ) { | 118 } |
119 drive = atoi(argv[i++]); | 119 |
120 } | 120 /* Open the CD-ROM */ |
121 cdrom = SDL_CDOpen(drive); | 121 drive = 0; |
122 if ( cdrom == NULL ) { | 122 i = 1; |
123 fprintf(stderr, "Couldn't open drive %d: %s\n", drive, | 123 if (argv[i] && isdigit (argv[i][0])) { |
124 SDL_GetError()); | 124 drive = atoi (argv[i++]); |
125 quit(2); | 125 } |
126 } | 126 cdrom = SDL_CDOpen (drive); |
127 if (cdrom == NULL) { | |
128 fprintf (stderr, "Couldn't open drive %d: %s\n", drive, | |
129 SDL_GetError ()); | |
130 quit (2); | |
131 } | |
127 #ifdef TEST_NULLCD | 132 #ifdef TEST_NULLCD |
128 cdrom = NULL; | 133 cdrom = NULL; |
129 #endif | 134 #endif |
130 | 135 |
131 /* Find out which function to perform */ | 136 /* Find out which function to perform */ |
132 for ( ; argv[i]; ++i ) { | 137 for (; argv[i]; ++i) { |
133 if ( strcmp(argv[i], "-status") == 0 ) { | 138 if (strcmp (argv[i], "-status") == 0) { |
134 /* PrintStatus(drive, cdrom); */ | 139 /* PrintStatus(drive, cdrom); */ |
135 } else | 140 } else if (strcmp (argv[i], "-list") == 0) { |
136 if ( strcmp(argv[i], "-list") == 0 ) { | 141 ListTracks (cdrom); |
137 ListTracks(cdrom); | 142 } else if (strcmp (argv[i], "-play") == 0) { |
138 } else | 143 int strack, sframe; |
139 if ( strcmp(argv[i], "-play") == 0 ) { | 144 int ntrack, nframe; |
140 int strack, sframe; | 145 |
141 int ntrack, nframe; | 146 strack = 0; |
142 | 147 if (argv[i + 1] && isdigit (argv[i + 1][0])) { |
143 strack = 0; | 148 strack = atoi (argv[++i]); |
144 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | 149 } |
145 strack = atoi(argv[++i]); | 150 sframe = 0; |
146 } | 151 if (argv[i + 1] && isdigit (argv[i + 1][0])) { |
147 sframe = 0; | 152 sframe = atoi (argv[++i]); |
148 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | 153 } |
149 sframe = atoi(argv[++i]); | 154 ntrack = 0; |
150 } | 155 if (argv[i + 1] && isdigit (argv[i + 1][0])) { |
151 ntrack = 0; | 156 ntrack = atoi (argv[++i]); |
152 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | 157 } |
153 ntrack = atoi(argv[++i]); | 158 nframe = 0; |
154 } | 159 if (argv[i + 1] && isdigit (argv[i + 1][0])) { |
155 nframe = 0; | 160 nframe = atoi (argv[++i]); |
156 if ( argv[i+1] && isdigit(argv[i+1][0]) ) { | 161 } |
157 nframe = atoi(argv[++i]); | 162 if (CD_INDRIVE (SDL_CDStatus (cdrom))) { |
158 } | 163 if (SDL_CDPlayTracks (cdrom, strack, sframe, |
159 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) { | 164 ntrack, nframe) < 0) { |
160 if ( SDL_CDPlayTracks(cdrom, strack, sframe, | 165 fprintf (stderr, |
161 ntrack, nframe) < 0 ) { | 166 "Couldn't play tracks %d/%d for %d/%d: %s\n", |
162 fprintf(stderr, | 167 strack, sframe, ntrack, nframe, SDL_GetError ()); |
163 "Couldn't play tracks %d/%d for %d/%d: %s\n", | 168 } |
164 strack, sframe, ntrack, nframe, SDL_GetError()); | 169 } else { |
165 } | 170 fprintf (stderr, "No CD in drive!\n"); |
166 } else { | 171 } |
167 fprintf(stderr, "No CD in drive!\n"); | 172 } else if (strcmp (argv[i], "-pause") == 0) { |
168 } | 173 if (SDL_CDPause (cdrom) < 0) { |
169 } else | 174 fprintf (stderr, "Couldn't pause CD: %s\n", SDL_GetError ()); |
170 if ( strcmp(argv[i], "-pause") == 0 ) { | 175 } |
171 if ( SDL_CDPause(cdrom) < 0 ) { | 176 } else if (strcmp (argv[i], "-resume") == 0) { |
172 fprintf(stderr, "Couldn't pause CD: %s\n", | 177 if (SDL_CDResume (cdrom) < 0) { |
173 SDL_GetError()); | 178 fprintf (stderr, "Couldn't resume CD: %s\n", SDL_GetError ()); |
174 } | 179 } |
175 } else | 180 } else if (strcmp (argv[i], "-stop") == 0) { |
176 if ( strcmp(argv[i], "-resume") == 0 ) { | 181 if (SDL_CDStop (cdrom) < 0) { |
177 if ( SDL_CDResume(cdrom) < 0 ) { | 182 fprintf (stderr, "Couldn't eject CD: %s\n", SDL_GetError ()); |
178 fprintf(stderr, "Couldn't resume CD: %s\n", | 183 } |
179 SDL_GetError()); | 184 } else if (strcmp (argv[i], "-eject") == 0) { |
180 } | 185 if (SDL_CDEject (cdrom) < 0) { |
181 } else | 186 fprintf (stderr, "Couldn't eject CD: %s\n", SDL_GetError ()); |
182 if ( strcmp(argv[i], "-stop") == 0 ) { | 187 } |
183 if ( SDL_CDStop(cdrom) < 0 ) { | 188 } else if ((strcmp (argv[i], "-sleep") == 0) && |
184 fprintf(stderr, "Couldn't eject CD: %s\n", | 189 (argv[i + 1] && isdigit (argv[i + 1][0]))) { |
185 SDL_GetError()); | 190 SDL_Delay (atoi (argv[++i])); |
186 } | 191 printf ("Delayed %d milliseconds\n", atoi (argv[i])); |
187 } else | 192 } else { |
188 if ( strcmp(argv[i], "-eject") == 0 ) { | 193 PrintUsage (argv[0]); |
189 if ( SDL_CDEject(cdrom) < 0 ) { | 194 SDL_CDClose (cdrom); |
190 fprintf(stderr, "Couldn't eject CD: %s\n", | 195 quit (1); |
191 SDL_GetError()); | 196 } |
192 } | 197 } |
193 } else | 198 PrintStatus (drive, cdrom); |
194 if ( (strcmp(argv[i], "-sleep") == 0) && | 199 SDL_CDClose (cdrom); |
195 (argv[i+1] && isdigit(argv[i+1][0])) ) { | 200 SDL_Quit (); |
196 SDL_Delay(atoi(argv[++i])); | 201 |
197 printf("Delayed %d milliseconds\n", atoi(argv[i])); | 202 return (0); |
198 } else { | 203 } |
199 PrintUsage(argv[0]); | |
200 SDL_CDClose(cdrom); | |
201 quit(1); | |
202 } | |
203 } | |
204 PrintStatus(drive, cdrom); | |
205 SDL_CDClose(cdrom); | |
206 SDL_Quit(); | |
207 | |
208 return(0); | |
209 } |