KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
cdrom.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/cdrom.h
4 Copyright (C) 2000-2001 Megan Potter
5 Copyright (C) 2014 Donald Haase
6 Copyright (C) 2023 Ruslan Rostovtsev
7*/
8
9#ifndef __DC_CDROM_H
10#define __DC_CDROM_H
11
12#include <sys/cdefs.h>
13__BEGIN_DECLS
14
15#include <arch/types.h>
16
17/** \file dc/cdrom.h
18 \brief CD access to the GD-ROM drive.
19 \ingroup gdrom
20
21 This file contains the interface to the Dreamcast's GD-ROM drive. It is
22 simply called cdrom.h and cdrom.c because, by design, you cannot directly
23 use this code to read the high-density area of GD-ROMs. This is the way it
24 always has been, and always will be.
25
26 The way things are set up, as long as you're using fs_iso9660 to access the
27 CD, it will automatically detect and react to disc changes for you.
28
29 This file only facilitates reading raw sectors and doing other fairly low-
30 level things with CDs. If you're looking for higher-level stuff, like
31 normal file reading, consult with the stuff for the fs and for fs_iso9660.
32
33 \author Megan Potter
34 \author Ruslan Rostovtsev
35 \see kos/fs.h
36 \see dc/fs_iso9660.h
37*/
38
39/** \defgroup gdrom GD-ROM
40 \brief Driver for the Dreamcast's GD-ROM drive
41 \ingroup vfs
42*/
43
44/** \defgroup cd_cmd_codes Syscall Command Codes
45 \brief Command codes for GD-ROM syscalsl
46 \ingroup gdrom
47
48 These are the syscall command codes used to actually do stuff with the
49 GD-ROM drive. These were originally provided by maiwe.
50
51 @{
52*/
53#define CMD_CHECK_LICENSE 2 /**< \brief Check license */
54#define CMD_REQ_SPI_CMD 4 /**< \brief Request to Sega Packet Interface */
55#define CMD_PIOREAD 16 /**< \brief Read via PIO */
56#define CMD_DMAREAD 17 /**< \brief Read via DMA */
57#define CMD_GETTOC 18 /**< \brief Read TOC */
58#define CMD_GETTOC2 19 /**< \brief Read TOC */
59#define CMD_PLAY 20 /**< \brief Play track */
60#define CMD_PLAY2 21 /**< \brief Play sectors */
61#define CMD_PAUSE 22 /**< \brief Pause playback */
62#define CMD_RELEASE 23 /**< \brief Resume from pause */
63#define CMD_INIT 24 /**< \brief Initialize the drive */
64#define CMD_DMA_ABORT 25 /**< \brief Abort DMA transfer */
65#define CMD_OPEN_TRAY 26 /**< \brief Open CD tray (on DevBox?) */
66#define CMD_SEEK 27 /**< \brief Seek to a new position */
67#define CMD_DMAREAD_STREAM 28 /**< \brief Stream DMA until end/abort */
68#define CMD_NOP 29 /**< \brief No operation */
69#define CMD_REQ_MODE 30 /**< \brief Request mode */
70#define CMD_SET_MODE 31 /**< \brief Setup mode */
71#define CMD_SCAN_CD 32 /**< \brief Scan CD */
72#define CMD_STOP 33 /**< \brief Stop the disc from spinning */
73#define CMD_GETSCD 34 /**< \brief Get subcode data */
74#define CMD_GETSES 35 /**< \brief Get session */
75#define CMD_REQ_STAT 36 /**< \brief Request stat */
76#define CMD_PIOREAD_STREAM 37 /**< \brief Stream PIO until end/abort */
77#define CMD_DMAREAD_STREAM_EX 38 /**< \brief Stream DMA transfer */
78#define CMD_PIOREAD_STREAM_EX 39 /**< \brief Stream PIO transfer */
79#define CMD_GET_VERS 40 /**< \brief Get syscall driver version */
80#define CMD_MAX 47 /**< \brief Max of GD syscall commands */
81/** @} */
82
83/** \defgroup cd_cmd_response Command Responses
84 \brief Responses from GD-ROM syscalls
85 \ingroup gdrom
86
87 These are the values that the various functions can return as error codes.
88 @{
89*/
90#define ERR_OK 0 /**< \brief No error */
91#define ERR_NO_DISC 1 /**< \brief No disc in drive */
92#define ERR_DISC_CHG 2 /**< \brief Disc changed, but not reinitted yet */
93#define ERR_SYS 3 /**< \brief System error */
94#define ERR_ABORTED 4 /**< \brief Command aborted */
95#define ERR_NO_ACTIVE 5 /**< \brief System inactive? */
96#define ERR_TIMEOUT 6 /**< \brief Aborted due to timeout */
97/** @} */
98
99/** \defgroup cd_cmd_status Command Status Responses
100 \brief GD-ROM status responses
101 \ingroup gdrom
102
103 These are the raw values the status syscall returns.
104 @{
105*/
106#define FAILED -1 /**< \brief Command failed */
107#define NO_ACTIVE 0 /**< \brief System inactive? */
108#define PROCESSING 1 /**< \brief Processing command */
109#define COMPLETED 2 /**< \brief Command completed successfully */
110#define STREAMING 3 /**< \brief Stream type command is in progress */
111#define BUSY 4 /**< \brief GD syscalls is busy */
112/** @} */
113
114/** \defgroup cd_cmd_ata_status ATA Statuses
115 \brief ATA statuses for GD-ROM driver
116 \ingroup gdrom
117
118 @{
119*/
120#define ATA_STAT_INTERNAL 0x00
121#define ATA_STAT_IRQ 0x01
122#define ATA_STAT_DRQ_0 0x02
123#define ATA_STAT_DRQ_1 0x03
124#define ATA_STAT_BUSY 0x04
125/** @} */
126
127/** \defgroup cdda_read_modes CDDA Read Modes
128 \brief Read modes for CDDA
129 \ingroup gdrom
130
131 Valid values to pass to the cdrom_cdda_play() function for the mode
132 parameter.
133 @{
134*/
135#define CDDA_TRACKS 1 /**< \brief Play by track number */
136#define CDDA_SECTORS 2 /**< \brief Play by sector number */
137/** @} */
138
139/** \defgroup cd_read_sector_part Read Sector Part
140 \brief Whether to read data or whole sector
141 \ingroup gdrom
142
143 Parts of the a CD-ROM sector to read. These are possible values for the
144 third parameter word sent with the change data type syscall.
145 @{
146*/
147#define CDROM_READ_WHOLE_SECTOR 0x1000 /**< \brief Read the whole sector */
148#define CDROM_READ_DATA_AREA 0x2000 /**< \brief Read the data area */
149/** @} */
150
151/** \defgroup cd_read_subcode_type Read Subcode Type
152 \brief Types of data to read from sector subcode
153 \ingroup gdrom
154
155 Types of data available to read from the sector subcode. These are
156 possible values for the first parameter sent to the GETSCD syscall.
157 @{
158*/
159#define CD_SUB_Q_ALL 0 /**< \brief Read all Subcode Data */
160#define CD_SUB_Q_CHANNEL 1 /**< \brief Read Q Channel Subcode Data */
161#define CD_SUB_MEDIA_CATALOG 2 /**< \brief Read the Media Catalog
162 Subcode Data */
163#define CD_SUB_TRACK_ISRC 3 /**< \brief Read the ISRC Subcode Data */
164#define CD_SUB_RESERVED 4 /**< \brief Reserved */
165/** @} */
166
167/** \defgroup cd_subcode_audio Subcode Audio Status
168 \brief GETSCD syscall response codes
169 \ingroup gdrom
170
171 Information about CDDA playback from GETSCD syscall.
172 @{
173*/
174#define CD_SUB_AUDIO_STATUS_INVALID 0x00
175#define CD_SUB_AUDIO_STATUS_PLAYING 0x11
176#define CD_SUB_AUDIO_STATUS_PAUSED 0x12
177#define CD_SUB_AUDIO_STATUS_ENDED 0x13
178#define CD_SUB_AUDIO_STATUS_ERROR 0x14
179#define CD_SUB_AUDIO_STATUS_NO_INFO 0x15
180/** @} */
181
182/** \defgroup cd_read_sector_mode Read Sector Mode
183 \brief Mode to use when reading sectors
184 \ingroup gdrom
185
186 How to read the sectors of a CD, via PIO or DMA. 4th parameter of
187 cdrom_read_sectors_ex.
188 @{
189*/
190#define CDROM_READ_PIO 0 /**< \brief Read sector(s) in PIO mode */
191#define CDROM_READ_DMA 1 /**< \brief Read sector(s) in DMA mode */
192/** @} */
193
194/** \defgroup cd_status_values Status Values
195 \brief Status values for GD-ROM drive
196 \ingroup gdrom
197
198 These are the values that can be returned as the status parameter from the
199 cdrom_get_status() function.
200 @{
201*/
202#define CD_STATUS_READ_FAIL -1 /**< \brief Can't read status */
203#define CD_STATUS_BUSY 0 /**< \brief Drive is busy */
204#define CD_STATUS_PAUSED 1 /**< \brief Disc is paused */
205#define CD_STATUS_STANDBY 2 /**< \brief Drive is in standby */
206#define CD_STATUS_PLAYING 3 /**< \brief Drive is currently playing */
207#define CD_STATUS_SEEKING 4 /**< \brief Drive is currently seeking */
208#define CD_STATUS_SCANNING 5 /**< \brief Drive is scanning */
209#define CD_STATUS_OPEN 6 /**< \brief Disc tray is open */
210#define CD_STATUS_NO_DISC 7 /**< \brief No disc inserted */
211#define CD_STATUS_RETRY 8 /**< \brief Retry is needed */
212#define CD_STATUS_ERROR 9 /**< \brief System error */
213#define CD_STATUS_FATAL 12 /**< \brief Need reset syscalls */
214/** @} */
215
216/** \defgroup cd_disc_types Drive Disc Types
217 \brief Disc types within GD-ROM drive
218 \ingroup gdrom
219
220 These are the values that can be returned as the disc_type parameter from
221 the cdrom_get_status() function.
222 @{
223*/
224#define CD_CDDA 0x00 /**< \brief Audio CD (Red book) or no disc */
225#define CD_CDROM 0x10 /**< \brief CD-ROM or CD-R (Yellow book) */
226#define CD_CDROM_XA 0x20 /**< \brief CD-ROM XA (Yellow book extension) */
227#define CD_CDI 0x30 /**< \brief CD-i (Green book) */
228#define CD_GDROM 0x80 /**< \brief GD-ROM */
229#define CD_FAIL 0xf0 /**< \brief Need reset syscalls */
230/** @} */
231
232/** \brief TOC structure returned by the BIOS.
233 \ingroup gdrom
234
235 This is the structure that the CMD_GETTOC2 syscall command will return for
236 the TOC. Note the data is in FAD, not LBA/LSN.
237
238 \headerfile dc/cdrom.h
239*/
240typedef struct {
241 uint32 entry[99]; /**< \brief TOC space for 99 tracks */
242 uint32 first; /**< \brief Point A0 information (1st track) */
243 uint32 last; /**< \brief Point A1 information (last track) */
244 uint32 leadout_sector; /**< \brief Point A2 information (leadout) */
245} CDROM_TOC;
246
247/** \defgroup cd_toc_access TOC Access Macros
248 \brief Macros used to access the TOC
249 \ingroup gdrom
250
251 @{
252*/
253/** \brief Get the FAD address of a TOC entry.
254 \param n The actual entry from the TOC to look at.
255 \return The FAD of the entry.
256*/
257#define TOC_LBA(n) ((n) & 0x00ffffff)
258
259/** \brief Get the address of a TOC entry.
260 \param n The entry from the TOC to look at.
261 \return The entry's address.
262*/
263#define TOC_ADR(n) ( ((n) & 0x0f000000) >> 24 )
264
265/** \brief Get the control data of a TOC entry.
266 \param n The entry from the TOC to look at.
267 \return The entry's control value.
268*/
269#define TOC_CTRL(n) ( ((n) & 0xf0000000) >> 28 )
270
271/** \brief Get the track number of a TOC entry.
272 \param n The entry from the TOC to look at.
273 \return The entry's track.
274*/
275#define TOC_TRACK(n) ( ((n) & 0x00ff0000) >> 16 )
276/** @} */
277
278/** \brief Set the sector size for read sectors.
279 \ingroup gdrom
280
281 This function sets the sector size that the cdrom_read_sectors() function
282 will return. Be sure to set this to the correct value for the type of
283 sectors you're trying to read. Common values are 2048 (for reading CD-ROM
284 sectors) or 2352 (for reading raw sectors).
285
286 \param size The size of the sector data.
287
288 \return \ref cd_cmd_response
289*/
291
292/** \brief Execute a CD-ROM command.
293 \ingroup gdrom
294
295 This function executes the specified command using the BIOS syscall for
296 executing GD-ROM commands.
297
298 \param cmd The command number to execute.
299 \param param Data to pass to the syscall.
300
301 \return \ref cd_cmd_response
302*/
303int cdrom_exec_cmd(int cmd, void *param);
304
305/** \brief Execute a CD-ROM command with timeout.
306 \ingroup gdrom
307
308 This function executes the specified command using the BIOS syscall for
309 executing GD-ROM commands with timeout.
310
311 \param cmd The command number to execute.
312 \param param Data to pass to the syscall.
313 \param timeout Timeout in milliseconds.
314
315 \return \ref cd_cmd_response
316*/
317int cdrom_exec_cmd_timed(int cmd, void *param, int timeout);
318
319/** \brief Get the status of the GD-ROM drive.
320 \ingroup gdrom
321
322 \param status Space to return the drive's status.
323 \param disc_type Space to return the type of disc in the drive.
324
325 \return \ref cd_cmd_response
326 \see cd_status_values
327 \see cd_disc_types
328*/
329int cdrom_get_status(int *status, int *disc_type);
330
331/** \brief Change the datatype of disc.
332 \ingroup gdrom
333
334 \note This function is formally deprecated. It should not
335 be used in any future code, and may be removed in
336 the future. You should instead use
337 cdrom_change_datatype.
338*/
339int cdrom_change_dataype(int sector_part, int cdxa, int sector_size)
340 __depr("Use cdrom_change_datatype instead.");
341
342/** \brief Change the datatype of disc.
343 \ingroup gdrom
344
345 This function will take in all parameters to pass to the change_datatype
346 syscall. This allows these parameters to be modified without a reinit.
347 Each parameter allows -1 as a default, which is tied to the former static
348 values provided by cdrom_reinit and cdrom_set_sector_size.
349
350 \param sector_part How much of each sector to return.
351 \param cdxa What CDXA mode to read as (if applicable).
352 \param sector_size What sector size to read (eg. - 2048, 2532).
353
354 \return \ref cd_cmd_response
355 \see cd_read_sector_part
356*/
357int cdrom_change_datatype(int sector_part, int cdxa, int sector_size);
358
359/** \brief Re-initialize the GD-ROM drive.
360 \ingroup gdrom
361
362 This function is for reinitializing the GD-ROM drive after a disc change to
363 its default settings. Calls cdrom_reinit(-1,-1,-1)
364
365 \return \ref cd_cmd_response
366 \see cdrom_reinit_ex
367*/
368int cdrom_reinit(void);
369
370/** \brief Re-initialize the GD-ROM drive with custom parameters.
371 \ingroup gdrom
372
373 At the end of each cdrom_reinit(), cdrom_change_datatype is called.
374 This passes in the requested values to that function after
375 reinitialization, as opposed to defaults.
376
377 \param sector_part How much of each sector to return.
378 \param cdxa What CDXA mode to read as (if applicable).
379 \param sector_size What sector size to read (eg. - 2048, 2532).
380
381 \return \ref cd_cmd_response
382 \see cd_read_sector_part
383 \see cdrom_change_datatype
384*/
385int cdrom_reinit_ex(int sector_part, int cdxa, int sector_size);
386
387/** \brief Read the table of contents from the disc.
388 \ingroup gdrom
389
390 This function reads the TOC from the specified session of the disc.
391
392 \param toc_buffer Space to store the returned TOC in.
393 \param session The session of the disc to read.
394 \return \ref cd_cmd_response
395*/
396int cdrom_read_toc(CDROM_TOC *toc_buffer, int session);
397
398/** \brief Read one or more sector from a CD-ROM.
399 \ingroup gdrom
400
401 This function reads the specified number of sectors from the disc, starting
402 where requested. This will respect the size of the sectors set with
403 cdrom_change_datatype(). The buffer must have enough space to store the
404 specified number of sectors.
405
406 \param buffer Space to store the read sectors.
407 \param sector The sector to start reading from.
408 \param cnt The number of sectors to read.
409 \param mode DMA or PIO
410 \return \ref cd_cmd_response
411 \see cd_read_sector_mode
412*/
413int cdrom_read_sectors_ex(void *buffer, int sector, int cnt, int mode);
414
415/** \brief Read one or more sector from a CD-ROM in PIO mode.
416 \ingroup gdrom
417
418 Default version of cdrom_read_sectors_ex, which forces PIO mode.
419
420 \param buffer Space to store the read sectors.
421 \param sector The sector to start reading from.
422 \param cnt The number of sectors to read.
423 \return \ref cd_cmd_response
424 \see cdrom_read_sectors_ex
425*/
426int cdrom_read_sectors(void *buffer, int sector, int cnt);
427
428/** \brief Read subcode data from the most recently read sectors.
429 \ingroup gdrom
430
431 After reading sectors, this can pull subcode data regarding the sectors
432 read. If reading all subcode data with CD_SUB_CURRENT_POSITION, this needs
433 to be performed one sector at a time.
434
435 \param buffer Space to store the read subcode data.
436 \param buflen Amount of data to be read.
437 \param which Which subcode type do you wish to get.
438
439 \return \ref cd_cmd_response
440 \see cd_read_subcode_type
441*/
442int cdrom_get_subcode(void *buffer, int buflen, int which);
443
444/** \brief Locate the sector of the data track.
445 \ingroup gdrom
446
447 This function will search the toc for the last entry that has a CTRL value
448 of 4, and return its FAD address.
449
450 \param toc The TOC to search through.
451 \return The FAD of the track, or 0 if none is found.
452*/
454
455/** \brief Play CDDA audio tracks or sectors.
456 \ingroup gdrom
457
458 This function starts playback of CDDA audio.
459
460 \param start The track or sector to start playback from.
461 \param end The track or sector to end playback at.
462 \param loops The number of times to repeat (max of 15).
463 \param mode The mode to play (see \ref cdda_read_modes).
464 \return \ref cd_cmd_response
465*/
466int cdrom_cdda_play(uint32 start, uint32 end, uint32 loops, int mode);
467
468/** \brief Pause CDDA audio playback.
469 \ingroup gdrom
470
471 \return \ref cd_cmd_response
472*/
474
475/** \brief Resume CDDA audio playback after a pause.
476 \ingroup gdrom
477
478 \return \ref cd_cmd_response
479*/
481
482/** \brief Spin down the CD.
483 \ingroup gdrom
484
485 This stops the disc in the drive from spinning until it is accessed again.
486
487 \return \ref cd_cmd_response
488*/
490
491/** \brief Initialize the GD-ROM for reading CDs.
492 \ingroup gdrom
493
494 This initializes the CD-ROM reading system, reactivating the drive and
495 handling initial setup of the disc.
496*/
497void cdrom_init(void);
498
499/** \brief Shutdown the CD reading system.
500 \ingroup gdrom
501 */
502void cdrom_shutdown(void);
503
504__END_DECLS
505
506#endif /* __DC_CDROM_H */
int cdrom_change_datatype(int sector_part, int cdxa, int sector_size)
Change the datatype of disc.
int cdrom_spin_down(void)
Spin down the CD.
uint32 cdrom_locate_data_track(CDROM_TOC *toc)
Locate the sector of the data track.
int cdrom_cdda_play(uint32 start, uint32 end, uint32 loops, int mode)
Play CDDA audio tracks or sectors.
int cdrom_cdda_resume(void)
Resume CDDA audio playback after a pause.
int cdrom_cdda_pause(void)
Pause CDDA audio playback.
int cdrom_reinit(void)
Re-initialize the GD-ROM drive.
void cdrom_init(void)
Initialize the GD-ROM for reading CDs.
int cdrom_set_sector_size(int size)
Set the sector size for read sectors.
int cdrom_reinit_ex(int sector_part, int cdxa, int sector_size)
Re-initialize the GD-ROM drive with custom parameters.
int cdrom_read_sectors_ex(void *buffer, int sector, int cnt, int mode)
Read one or more sector from a CD-ROM.
int cdrom_read_toc(CDROM_TOC *toc_buffer, int session)
Read the table of contents from the disc.
void cdrom_shutdown(void)
Shutdown the CD reading system.
int cdrom_get_status(int *status, int *disc_type)
Get the status of the GD-ROM drive.
int cdrom_change_dataype(int sector_part, int cdxa, int sector_size) __depr("Use cdrom_change_datatype instead.")
Change the datatype of disc.
int cdrom_exec_cmd_timed(int cmd, void *param, int timeout)
Execute a CD-ROM command with timeout.
int cdrom_get_subcode(void *buffer, int buflen, int which)
Read subcode data from the most recently read sectors.
int cdrom_exec_cmd(int cmd, void *param)
Execute a CD-ROM command.
int cdrom_read_sectors(void *buffer, int sector, int cnt)
Read one or more sector from a CD-ROM in PIO mode.
#define __depr(m)
Mark something as deprecated, with an informative message.
Definition cdefs.h:119
unsigned long uint32
32-bit unsigned integer
Definition types.h:33
TOC structure returned by the BIOS.
Definition cdrom.h:240
uint32 first
Point A0 information (1st track)
Definition cdrom.h:242
uint32 leadout_sector
Point A2 information (leadout)
Definition cdrom.h:244
uint32 last
Point A1 information (last track)
Definition cdrom.h:243
Common integer types.