KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Functions
cdrom.h File Reference

CD access to the GD-ROM drive. More...

#include <sys/cdefs.h>
#include <arch/types.h>

Go to the source code of this file.

Data Structures

struct  CDROM_TOC
 TOC structure returned by the BIOS. More...
 

Macros

#define CMD_PIOREAD   16
 Read via PIO. More...
 
#define CMD_DMAREAD   17
 Read via DMA. More...
 
#define CMD_GETTOC   18
 Read TOC. More...
 
#define CMD_GETTOC2   19
 Read TOC. More...
 
#define CMD_PLAY   20
 Play track. More...
 
#define CMD_PLAY2   21
 Play sectors. More...
 
#define CMD_PAUSE   22
 Pause playback. More...
 
#define CMD_RELEASE   23
 Resume from pause. More...
 
#define CMD_INIT   24
 Initialize the drive. More...
 
#define CMD_SEEK   27
 Seek to a new position. More...
 
#define CMD_READ   28
 Read raw sectors. More...
 
#define CMD_STOP   33
 Stop the disc from spinning. More...
 
#define CMD_GETSCD   34
 Get subcode data. More...
 
#define CMD_GETSES   35
 Get session. More...
 
#define ERR_OK   0
 No error. More...
 
#define ERR_NO_DISC   1
 No disc in drive. More...
 
#define ERR_DISC_CHG   2
 Disc changed, but not reinitted yet. More...
 
#define ERR_SYS   3
 System error. More...
 
#define ERR_ABORTED   4
 Command aborted. More...
 
#define ERR_NO_ACTIVE   5
 System inactive? More...
 
#define FAILED   -1
 Command failed. More...
 
#define NO_ACTIVE   0
 System inactive? More...
 
#define PROCESSING   1
 Processing command. More...
 
#define COMPLETED   2
 Command completed successfully. More...
 
#define ABORTED   3
 Command aborted before completion. More...
 
#define CDDA_TRACKS   1
 Play by track number. More...
 
#define CDDA_SECTORS   2
 Play by sector number. More...
 
#define CDROM_READ_WHOLE_SECTOR   0x1000
 Read the whole sector. More...
 
#define CDROM_READ_DATA_AREA   0x2000
 Read the data area. More...
 
#define CD_SUB_Q_CHANNEL   0
 Read Q Channel Subcode Data. More...
 
#define CD_SUB_CURRENT_POSITION   1
 Read all Subcode Data for most recent sector. More...
 
#define CD_SUB_MEDIA_CATALOG   2
 Read the Media Catalog Subcode Data. More...
 
#define CD_SUB_TRACK_ISRC   3
 Read the ISRC Subcode Data. More...
 
#define CDROM_READ_PIO   0
 Read sector(s) in PIO mode. More...
 
#define CDROM_READ_DMA   1
 Read sector(s) in DMA mode. More...
 
#define CD_STATUS_BUSY   0
 Drive is busy. More...
 
#define CD_STATUS_PAUSED   1
 Disc is paused. More...
 
#define CD_STATUS_STANDBY   2
 Drive is in standby. More...
 
#define CD_STATUS_PLAYING   3
 Drive is currently playing. More...
 
#define CD_STATUS_SEEKING   4
 Drive is currently seeking. More...
 
#define CD_STATUS_SCANNING   5
 Drive is scanning. More...
 
#define CD_STATUS_OPEN   6
 Disc tray is open. More...
 
#define CD_STATUS_NO_DISC   7
 No disc inserted. More...
 
#define CD_CDDA   0
 Audio CD (Red book) More...
 
#define CD_CDROM   0x10
 CD-ROM or CD-R (Yellow book) More...
 
#define CD_CDROM_XA   0x20
 CD-ROM XA (Yellow book extension) More...
 
#define CD_CDI   0x30
 CD-i (Green book) More...
 
#define CD_GDROM   0x80
 GD-ROM. More...
 
#define TOC_LBA(n)   ((n) & 0x00ffffff)
 Get the FAD address of a TOC entry. More...
 
#define TOC_ADR(n)   ( ((n) & 0x0f000000) >> 24 )
 Get the address of a TOC entry. More...
 
#define TOC_CTRL(n)   ( ((n) & 0xf0000000) >> 28 )
 Get the control data of a TOC entry. More...
 
#define TOC_TRACK(n)   ( ((n) & 0x00ff0000) >> 16 )
 Get the track number of a TOC entry. More...
 

Functions

int cdrom_set_sector_size (int size)
 Set the sector size for read sectors. More...
 
int cdrom_exec_cmd (int cmd, void *param)
 Execute a CD-ROM command. More...
 
int cdrom_get_status (int *status, int *disc_type)
 Get the status of the GD-ROM drive. More...
 
int cdrom_change_dataype (int sector_part, int cdxa, int sector_size)
 Change the datatype of disc. More...
 
int cdrom_reinit ()
 Re-initialize the GD-ROM drive. More...
 
int cdrom_reinit_ex (int sector_part, int cdxa, int sector_size)
 Re-initialize the GD-ROM drive with custom parameters. More...
 
int cdrom_read_toc (CDROM_TOC *toc_buffer, int session)
 Read the table of contents from the disc. More...
 
int cdrom_read_sectors_ex (void *buffer, int sector, int cnt, int mode)
 Read one or more sector from a CD-ROM. More...
 
int cdrom_read_sectors (void *buffer, int sector, int cnt)
 Read one or more sector from a CD-ROM in PIO mode. More...
 
int cdrom_get_subcode (void *buffer, int buflen, int which)
 Read subcode data from the most recently read sectors. More...
 
uint32 cdrom_locate_data_track (CDROM_TOC *toc)
 Locate the sector of the data track. More...
 
int cdrom_cdda_play (uint32 start, uint32 end, uint32 loops, int mode)
 Play CDDA audio tracks or sectors. More...
 
int cdrom_cdda_pause ()
 Pause CDDA audio playback. More...
 
int cdrom_cdda_resume ()
 Resume CDDA audio playback after a pause. More...
 
int cdrom_spin_down ()
 Spin down the CD. More...
 
int cdrom_init ()
 Initialize the GD-ROM for reading CDs. More...
 
void cdrom_shutdown ()
 Shutdown the CD reading system. More...
 

Detailed Description

CD access to the GD-ROM drive.

This file contains the interface to the Dreamcast's GD-ROM drive. It is simply called cdrom.h and cdrom.c because, by design, you cannot directly use this code to read the high-density area of GD-ROMs. This is the way it always has been, and always will be.

The way things are set up, as long as you're using fs_iso9660 to access the CD, it will automatically detect and react to disc changes for you.

This file only facilitates reading raw sectors and doing other fairly low- level things with CDs. If you're looking for higher-level stuff, like normal file reading, consult with the stuff for the fs and for fs_iso9660.

Author
Dan Potter
See also
kos/fs.h
dc/fs_iso9660.h

Function Documentation

int cdrom_cdda_pause ( )

Pause CDDA audio playback.

Returns
CD-ROM command responses
int cdrom_cdda_play ( uint32  start,
uint32  end,
uint32  loops,
int  mode 
)

Play CDDA audio tracks or sectors.

This function starts playback of CDDA audio.

Parameters
startThe track or sector to start playback from.
endThe track or sector to end playback at.
loopsThe number of times to repeat (max of 15).
modeThe mode to play (see CDDA read modes).
Returns
CD-ROM command responses
int cdrom_cdda_resume ( )

Resume CDDA audio playback after a pause.

Returns
CD-ROM command responses
int cdrom_change_dataype ( int  sector_part,
int  cdxa,
int  sector_size 
)

Change the datatype of disc.

This function will take in all parameters to pass to the change_datatype syscall. This allows these parameters to be modified without a reinit. Each parameter allows -1 as a default, which is tied to the former static values provided by cdrom_reinit and cdrom_set_sector_size.

Parameters
sector_partHow much of each sector to return.
cdxaWhat CDXA mode to read as (if applicable).
sector_sizeWhat sector size to read (eg. - 2048, 2532).
Returns
CD-ROM command responses
See also
CD-ROM Read Sector Part
int cdrom_exec_cmd ( int  cmd,
void *  param 
)

Execute a CD-ROM command.

This function executes the specified command using the BIOS syscall for executing GD-ROM commands. This is now thread-safe to be called by users.

Parameters
cmdThe command number to execute.
paramData to pass to the syscall.
Returns
CD-ROM command responses
int cdrom_get_status ( int *  status,
int *  disc_type 
)

Get the status of the GD-ROM drive.

Parameters
statusSpace to return the drive's status.
disc_typeSpace to return the type of disc in the drive.
Returns
CD-ROM command responses
See also
CD-ROM status values
CD-ROM drive disc types
int cdrom_get_subcode ( void *  buffer,
int  buflen,
int  which 
)

Read subcode data from the most recently read sectors.

After reading sectors, this can pull subcode data regarding the sectors read. If reading all subcode data with CD_SUB_CURRENT_POSITION, this needs to be performed one sector at a time.

Parameters
bufferSpace to store the read subcode data.
buflenAmount of data to be read.
whichWhich subcode type do you wish to get.
Returns
CD-ROM command responses
See also
CD-ROM Read Subcode Type
int cdrom_init ( )

Initialize the GD-ROM for reading CDs.

This initializes the CD-ROM reading system, reactivating the drive and handling initial setup of the disc.

Return values
0On success.
-1Already initted, shutdown before initting again.
uint32 cdrom_locate_data_track ( CDROM_TOC toc)

Locate the sector of the data track.

This function will search the toc for the last entry that has a CTRL value of 4, and return its FAD address.

Parameters
tocThe TOC to search through.
Returns
The FAD of the track, or 0 if none is found.
int cdrom_read_sectors ( void *  buffer,
int  sector,
int  cnt 
)

Read one or more sector from a CD-ROM in PIO mode.

Default version of cdrom_read_sectors_ex, which forces PIO mode.

Parameters
bufferSpace to store the read sectors.
sectorThe sector to start reading from.
cntThe number of sectors to read.
Returns
CD-ROM command responses
See also
cdrom_read_sectors_ex
int cdrom_read_sectors_ex ( void *  buffer,
int  sector,
int  cnt,
int  mode 
)

Read one or more sector from a CD-ROM.

This function reads the specified number of sectors from the disc, starting where requested. This will respect the size of the sectors set with cdrom_change_dataype(). The buffer must have enough space to store the specified number of sectors.

Parameters
bufferSpace to store the read sectors.
sectorThe sector to start reading from.
cntThe number of sectors to read.
modeDMA or PIO
Returns
CD-ROM command responses
See also
CD-ROM Read Sector Mode
int cdrom_read_toc ( CDROM_TOC toc_buffer,
int  session 
)

Read the table of contents from the disc.

This function reads the TOC from the specified session of the disc.

Parameters
toc_bufferSpace to store the returned TOC in.
sessionThe session of the disc to read.
Returns
CD-ROM command responses
int cdrom_reinit ( )

Re-initialize the GD-ROM drive.

This function is for reinitializing the GD-ROM drive after a disc change to its default settings. Calls cdrom_reinit(-1,-1,-1)

Returns
CD-ROM command responses
See also
cdrom_reinit_ex
int cdrom_reinit_ex ( int  sector_part,
int  cdxa,
int  sector_size 
)

Re-initialize the GD-ROM drive with custom parameters.

At the end of each cdrom_reinit(), cdrom_change_datatype is called. This passes in the requested values to that function after reinitialization, as opposed to defaults.

Parameters
sector_partHow much of each sector to return.
cdxaWhat CDXA mode to read as (if applicable).
sector_sizeWhat sector size to read (eg. - 2048, 2532).
Returns
CD-ROM command responses
See also
CD-ROM Read Sector Part
cdrom_change_datatype
int cdrom_set_sector_size ( int  size)

Set the sector size for read sectors.

This function sets the sector size that the cdrom_read_sectors() function will return. Be sure to set this to the correct value for the type of sectors you're trying to read. Common values are 2048 (for reading CD-ROM sectors) or 2352 (for reading raw sectors).

Parameters
sizeThe size of the sector data.
Returns
CD-ROM command responses
void cdrom_shutdown ( )

Shutdown the CD reading system.

int cdrom_spin_down ( )

Spin down the CD.

This stops the disc in the drive from spinning until it is accessed again.

Returns
CD-ROM command responses