This chapter explains how to access CD-ROM using the CD-ROM library. By using the CD-ROM library, you can read data and programs from CD-ROMs and play music. This chapter also includes a list of CD-ROM library function references.
Note | The CD-ROM library functions are not listed in the separate " Function Reference ", but are listed in the latter half of this chapter . |
---|
Figure 12-1 Flow of CD-ROM access
Figure 12-2 Sector structure
buf[ i ]. type = CDBUF_COPY; buf[ i ]. trans.copy.addr = address of read area; buf[ i ]. trans.copy.unit = unit of read area size (CDBUF_FORM1/CDBUF_FORM2/CDBUF_BYTE); buf[ i ]. trans.copy.size = number of read area units;
buf[ i ]. type = CDBUF_FUNC; buf[ i ]. trans.func.func. = function pointer; buf[ i ]. trans.func.obj = value passed to the first argument of the function;
Flow 12-1 Sample program 1 (load file sample_cd1/main.c)
/************************************************* **************************** * * Copyright (c) 1994 SEGA * *File:main.c *Date :1995-02-20 * Version:0.00 *Author: ************************************************** **********************************/ #include "sgl.h" #include "sgl_cd.h" /************************************************* ***************************/ #define MAX_FILE 128 #define READSECT 50 /************************************************* ***************************/ Sint32 dirwork[SLCD_WORK_SIZE(MAX_FILE)]; Sint32 readbuf[ READSECT * CDBUF_FORM1 / sizeof(Sint32)]; /************************************************* ***************************/ void ss_main(void) { Sint32ndir; CDHN cdhn; CDKEY key[2]; CDBUF buf[2]; Sint32 stat; Sint32 len[2]; Sint32 ypos = 1; slInitSystem(TV_320x224, NULL, 1); ndir = slCdInit(MAX_FILE, dirwork); slPrint("slCdInit:", slLocate(1,ypos)); slPrintFX(toFIXED(ndir), slLocate(11, ypos)); ypos++; key[0].cn = key[0].sm = key[0].ci = CDKEY_NONE; key[1].cn = CDKEY_TERM; cdhn = slCdOpen("S2100D0_.M", key); slPrint("slCdOpen:", slLocate(1, ypos)); slDispHex((Uint32)cdhn, slLocate(11, ypos)); buf[0].type = CDBUF_COPY; buf[0].trans.copy.addr = readbuf; buf[0].trans.copy.unit = CDBUF_FORM1; buf[0].trans.copy.size = READSECT; buf[1].type = CDBUF_TERM; slCdLoadFile(cdhn, buf); ypos++; while (1) { slSynch(); stat = slCdGetStatus(cdhn, len); slPrint("stat:", slLocate(1, ypos)); slDispHex((Uint32)stat, slLocate(7, ypos)); ypos++; if (ypos >= 27) ypos = 1; if (stat == CDSTAT_COMPLETED) break; } while (1); }
This sample program is a process for reading files on a CD-ROM into parts, and is an example of how to use a basic library for reading files from a CD-ROM. I will explain the steps according to Flow 12-2.
Flow 12-2 Sample program 2 (divided file reading sample_cd2/main.c)
/************************************************* **************************** * * Copyright (c) 1994 SEGA * *File:main.c *Date :1995-02-20 * Version:0.00 *Author: ************************************************** **********************************/ #include "sgl.h" #include "sgl_cd.h" /************************************************* ***************************/ #define MAX_OPEN 128 #define FNAME "S2100D0_.M" #define slsize 2 /************************************************* ***************************/ Sint32 lib_work[SLCD_WORK_SIZE(MAX_OPEN)]; Sint32 readbuf[ (CDBUF_FORM1 * slsize) / sizeof(Sint32) ]; /************************************************* ***************************/ void ss_main(void) { Sint32 ndir; Sint32 ypos = 1 ; Sint32 ret ; Sint32 ndata[2] ; CDHN cdhn; CDKEY key[2]; CDBUF buf[2]; slInitSystem(TV_320x224, NULL, 1); ndir = slCdInit(MAX_OPEN, lib_work); slPrint("slCdInit:", slLocate(1,ypos)); slPrintFX(toFIXED(ndir), slLocate(11, ypos)); ypos++; key[0].cn = key[0].sm = key[0].ci = CDKEY_NONE; key[1].cn = CDKEY_TERM ; cdhn = slCdOpen(FNAME, key); slPrint("slCdOpen:", slLocate(1, ypos)); slDispHex((Uint32)cdhn, slLocate(11, ypos)); buf[0].type = CDBUF_COPY ; buf[0].trans.copy.addr = readbuf; buf[0].trans.copy.unit = CDBUF_FORM1 ; buf[0].trans.copy.size = slsize; buf[1].type = CDBUF_TERM ; ypos++; slCdLoadFile(cdhn, buf); while( 1 ){ slSynch(); ret = slCdGetStatus( cdhn, ndata ); slPrint("stat:", slLocate(1, ypos)); slDispHex( (Uint32)ret, slLocate(7, ypos)); ypos++; if (ypos >= 27) ypos = 3; if ( ret == CDSTAT_COMPLETED ) break; if ( ndata[0] == CDBUF_FORM1 * slsize ){ slCdResetBuf(cdhn, &(key[0])); } } while( 1 ); }
Figure 12-3 CD buffer
buf[ i ]. type = CDBUF_COPY; buf[ i ]. trans.copy.addr = NULL; buf[ i ]. trans.copy.unit = CDBUF_FORM1; buf[ i ]. trans.copy.size = 0;
Flow 12-3 Sample program 3 (read ahead sample_cd3/main.c)
/************************************************* **************************** * Copyright (c) 1994 SEGA * *File:main.c *Date :1995-02-20 * Version:0.00 *Author: * ************************************************** **********************************/ #include "sgl.h" #include "sgl_cd.h" /************************************************* ***************************/ #define MAX_OPEN 128 #define FNAME "S2100D0_.M" #define slsize 2 /************************************************* ***************************/ Sint32 lib_work[SLCD_WORK_SIZE(MAX_OPEN)]; Sint32 readbuf[ (CDBUF_FORM1 * slsize) / sizeof(Sint32)]; /************************************************* ***************************/ void ss_main(void) { Sint32 ndir; Sint32 ypos = 1 ; Sint32 ret ; Sint32 ndata[2] ; CDHN cdhn; CDKEY key[2]; CDBUF buf[2]; slInitSystem(TV_320x224, NULL, 1); ndir = slCdInit(MAX_OPEN, lib_work); slPrint("slCdInit:", slLocate(1,ypos)); slPrintFX(toFIXED(ndir), slLocate(11, ypos)); ypos++; key[0].cn = key[0].sm = key[0].ci = CDKEY_NONE; key[1].cn = CDKEY_TERM ; cdhn = slCdOpen(FNAME, key); slPrint("slCdOpen:", slLocate(1, ypos)); slDispHex((Uint32)cdhn, slLocate(11, ypos)); buf[0].type = CDBUF_COPY ; buf[0].trans.copy.addr = NULL ; buf[0].trans.copy.unit = CDBUF_FORM1 ; buf[0].trans.copy.size = 0; buf[1].type = CDBUF_TERM ; slCdLoadFile( cdhn, buf ); ypos++; while( 1 ){ slSynch(); ret = slCdGetStatus( cdhn, NULL ); slPrint("stat1:", slLocate(1, ypos)); slDispHex( (Uint32)ret, slLocate(7, ypos)); ypos++; if (ypos >= 27) ypos = 3; if ( ret == CDSTAT_WAIT ) { buf[0].trans.copy.addr = readbuf; buf[0].trans.copy.size = slsize; break ; } } slCdLoadFile( cdhn, buf ); while( 1 ){ slSynch(); ret = slCdGetStatus( cdhn, ndata ); slPrint("stat2:", slLocate(1, ypos)); slDispHex( ret, slLocate(7, ypos)); ypos++; slPrint("ndata:", slLocate(1, ypos)); slDispHex( ndata[0], slLocate(7, ypos)); ypos++; if (ypos >= 27) ypos = 3; if ( ret == CDSTAT_COMPLETED ) break; if ( ndata[0] == CDBUF_FORM1 * slsize ){ slCdLoadFile(cdhn, buf); } } while( 1 ); }
buf[ 0 ]. type = CDBUF_COPY; buf[ 0 ]. trans.copy.addr = NULL; buf[ 0 ]. trans.copy.unit = CDBUF_FORM1; buf[ 0 ]. trans.copy.size = 0; buf[ 1 ]. type = CDBUF_TERM;
Flow 12-4 Sample program 4 (CDDA file playback sample_cd4/main.c)
/************************************************* **************************** * * Copyright (c) 1994 SEGA * *File:main.c *Date :1995-02-20 * Version:0.00 *Author: * ************************************************** **********************************/ #include "sgl.h" #include "sgl_cd.h" #include "sddrvs.dat" /************************************************* ***************************/ #define WIN_ORG_X 0 #define WIN_ORG_Y 0 #define WIN_SIZE_X 320 #define WIN_SIZE_Y 240 #define MAX_FILE 128 Sint32 dirwork[SLCD_WORK_SIZE(MAX_FILE)]; Uint8 sdmap[] = { 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x80, 0x00, 0x10, 0x01, 0x30, 0x00, 0x00, 0x00, 0x10, 0x00, 0x11, 0x01, 0x40, 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x01, 0x60, 0x00, 0x00, 0x00, 0x06, 0x00, 0x21, 0x01, 0x68, 0x00, 0x00, 0x00, 0x06, 0x00, 0x22, 0x01, 0x70, 0x00, 0x00, 0x00, 0x06, 0x00, 0x23, 0x01, 0x78, 0x00, 0x00, 0x00, 0x06, 0x00, 0x24, 0x01, 0x80, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x01, 0x86, 0x00, 0x00, 0x04, 0x00, 0x00, 0x30, 0x05, 0xA0, 0x00, 0x00, 0x02, 0x00, 0x00, 0xFF, 0xFF }; /************************************************* ***************************/ void ss_main(void) { Sint32ndir; CDHN cdhn; CDBUF buf[2]; CDKEY key[2]; Sint32 stat; slInitSystem(TV_320x224, NULL, 1); slInitSound(sddrvstsk, sizeof(sddrvstsk), sdmap, sizeof(sdmap)); slCDDAOn(127, 127, 0, 0); ndir = slCdInit(MAX_FILE, dirwork); key[0].cn = CDKEY_NONE; key[0].sm = CDKEY_NONE; key[0].ci = CDKEY_NONE; key[1].cn = CDKEY_TERM; cdhn = slCdOpen("cdda1", key); buf[0].type = CDBUF_COPY; buf[0].trans.copy.addr = NULL; buf[0].trans.copy.unit = CDBUF_FORM1; buf[0].trans.copy.size = 0; buf[1].type = CDBUF_TERM; slCdLoadFile(cdhn, buf); while (1) { slSynch(); stat = slCdGetStatus(cdhn, NULL); if (stat == CDSTAT_COMPLETED) break; } while (1) ; }
Figure 12-4 Internal structure of CD-ROM library
typedef struct { Sint16 cn; Sint16 sm; Sint16 ci; }CDKEY;
cn | channel number |
---|---|
sm | submode |
ci | Coding information |
typedef struct { void *addr; Sint32 unit; Sint32 size; } TRANS_COPY; typedef struct { Sint32 (*func) (void *obj, Uint32 *addr, Sint32 adinc, Sint32 nsct); void *obj; } TRANS_FUNC; typedef struct { Sint32 type; union { TRANS_COPY copy; TRANS_FUNC fucn; }trans; }CDBUF;
type CDBUF_COPY Copy to work RAM CDBUF_FUNC Transfer function CDBUF_TERM Termination ------------------------------------------------------- If type = CDBUF_COPY : copy ------------------------------------------------------- addr Address of read area (NULL if not read) unit CDBUF_FORM1 The size of the read area is 2048 bytes. CDBUF_FORM2 The size of the read area is 2324 bytes. CDBUF_BYTE The size of the read area is in bytes. size Number of units for reading area (0 if not reading) ------------------------------------------------------- If type = CDBUF_FUNC : func ------------------------------------------------------- func Transfer function obj object
nfile | Maximum number of files in one directory |
---|---|
work | work area |
pathname | Path name (relative path/absolute path can be specified) |
---|
pathname | Path name (relative path/absolute path can be specified) |
---|---|
key | Key information for classifying stream data |
cdhn | file handle |
---|---|
buf | Reading area information (corresponds to the key when opening) |
cdhn | file handle |
---|---|
buf | Reading area information |
data | Number of valid data in transfer area (NULL if unnecessary) |
cdhn | file handle |
---|---|
key | Key information for classifying data |
TRUE | normal termination |
---|---|
FLASE | A key that is not open was specified. |
cdhn | file handle |
---|
cdhn | file handle |
---|
cdhn | file handle |
---|
CDREQ_FREECD | Get the number of free sectors in a block |
---|---|
CDREQ_FAD | Current pickup position |
CDREQ_DRVCD | Drive status |
data | If a file handle is specified, the number of valid data in the transfer area |
---|
CDSTAT_PAUSE
Loading stopped
CDSTAT_DOING
Loading
CDSTAT_WAIT
Transfer waiting state
CDSTAT_COMPLETED
Loading completed
If CDREQ_FREE is specified
Number of free sectors in CD block
When specifying CDREQ_FAD
pickup position
If CDREQ_DRV is specified
CD drive status
CDDRV-BUSY
State transition in progress
CDDRV_PAUSE
Pausing
CDDRV_STDBY
stand-by
CDDRV_PLAY
CD playing
CDDRV_SEEK
Seeking in progress
CDDRV_SCAN
Scan playback in progress
CDDRV_OPEN
tray is open
CDDRV_NODISC
no disc
CDDRV_RETRY
Read retry processing in progress
CDDRV_ERROR
Read error occurred
CDDRV_FATAL
Fatal error occurred
constant name | meaning | constant value |
---|---|---|
CDERR_OK | normal termination | (0) |
CDERR_RDERR | Read error | (-1) |
CDERR_NODISC | Disc is not set | (-2) |
CDERR_CDROM | Disk is not CR-ROM | (-3) |
CDERR_IPARA | Invalid initialization parameter | (-Four) |
CDERR_DIR | Move outside the directory | (-6) |
CDERR_NEXIST | File does not exist | (-9) |
CDERR_NUM | Negative number of bytes etc. | (-14) |
CDERR_PUINUSE | Pickup in operation | (-20) |
CDERR_ALIGN | The work area is not on a 4-byte boundary | (-twenty one) |
CDERR_TMOUT | timeout | (-twenty two) |
CDERR_OPEN | tray open | (-twenty three) |
CDERR_FATAL | CD drive< FATAL> | (-twenty five) |
CDERR_BUSY | State transition in progress | (-50) |