★ SGL User's Manual ★ PROGRAMMER'S STRUCTThis chapter describes how to access a CD-ROM using the CD-ROM library. By using the CD-ROM library, you can read data and programs from the CD-ROM and play music. This chapter also contains a list of function references for the CD-ROM library.
caution | CD-ROM library functions are listed later in this chapter, not in the separate “Function Reference ”. |
|---|
Figure 12-1 CD-ROM access flow
Figure 12-2 Sector structure
buf [i]. type = CDBUF_COPY; buf [i]. trans.copy.addr = address of read area; buf [i]. trans.copy.unit = Read area size unit (CDBUF_FORM1 / CDBUF_FORM2 / CDBUF_BYTE); buf [i]. trans.copy.size = number of units in read area;
buf [i]. type = CDBUF_FUNC; buf [i]. trans.func.func. = Function pointer; buf [i]. trans.func.obj = value to pass to the first argument of the function;
Flow 12-1 Sample program 1 (reading the file sample_cd1 / main.c)
/ ***************************************************** ****************************
*
* Copyright (c) 1994 SEGA
*
* File: main.c
* Date: 1995-02-20
* Version: 0.00
* Auther:
****************************************************** ************************** /
#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)
{
Sint32 ndir;
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 dividing and reading a file on a CD-ROM, and is an example of using a basic library that reads a file from a CD-ROM. The procedure is explained along with Flow 12-2.
Flow 12-2 Sample program 2 (split reading of file sample_cd2 / main.c)
/ ***************************************************** ****************************
*
* Copyright (c) 1994 SEGA
*
* File: main.c
* Date: 1995-02-20
* Version: 0.00
* Auther:
****************************************************** ************************** /
#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 (look-ahead sample_cd3 / main.c)
/ ***************************************************** ****************************
* Copyright (c) 1994 SEGA
*
* File: main.c
* Date: 1995-02-20
* Version: 0.00
* Auther:
*
****************************************************** ************************** /
#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
* Auther:
*
****************************************************** ************************** /
#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)
{
Sint32 ndir;
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 the 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 Read area size is in 2048 bytes CDBUF_FORM2 Read area size is in 2324 bytes CDBUF_BYTE Read area size is in bytes size Number of units in read area (0 if not read) -------------------------------------------------- ----- 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 | Read area information (corresponds to the key at the time of opening) |
cdhn | File handle |
|---|---|
buf | Read area information |
ndata | Number of valid data in the transfer area (NULL if not required) |
cdhn | File handle |
|---|---|
key | Key information for classifying data |
TRUE | normal termination |
|---|---|
FLASE | An unopened key 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 |
ndata | If a file handle is specified, the number of valid data in the transfer area (NULL if not required) |
|---|
CDSTAT_PAUSE
Loading is stopped
CDSTAT_DOING
Loading
CDSTAT_WAIT
Waiting for transfer
CDSTAT_COMPLETED
Loading completed
When CDREQ_FREE is specified
Number of free sectors in the CD block
When CDREQ_FAD is specified
Pickup position
When CDREQ_DRV is specified
CD drive status
CDDRV-BUSY
During state transition
CDDRV_PAUSE
During the pose
CDDRV_STDBY
stand-by
CDDRV_PLAY
Playing a CD
CDDRV_SEEK
Seeking
CDDRV_SCAN
Scan playback
CDDRV_OPEN
The tray is open
CDDRV_NODISC
No disk
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 | Reed Ella | (-1) |
| CDERR_NODISC | No disc is set | (-2) |
| CDERR_CDROM | The disc is not a CR-ROM | (-3) |
| CDERR_IPARA | Invalid initialization parameter | (-Four) |
| CDERR_DIR | Move to other than directory | (-6) |
| CDERR_NEXIST | The file does not exist | (-9) |
| CDERR_NUM | Negative number of bytes | (-14) |
| CDERR_PUINUSE | Pickup is in operation | (-20) |
| CDERR_ALIGN | The work area is not on the 4-byte boundary | (-twenty one) |
| CDERR_TMOUT | time out | (-twenty two) |
| CDERR_OPEN | Tray open | (-twenty three) |
| CDERR_FATAL | CD drive is <FATAL> | (-twenty five) |
| CDERR_BUSY | During state transition | (-50) |
★ SGL User's Manual ★ PROGRAMMER'S STRUCT