vbt
Staff member
Here are the little functions to access CD, it can help a little I think. Some parts can be improved (there is one or two global walues )
Code:
#include "sega_gfs.h"
#define MAX_FILE 128
#define MAX_OPEN 20
#define MAX_DIR 128
#define GFS_ON 1
extern int file_max;
GfsDirName dir_name[MAX_DIR];
int LoadFile(char *name, Uint8 *location, Uint32 size);
//--------------------------------------------------------------------------------------------------------------------------------------
void InitCD()
{
Sint32 ret;
Uint32 lib_work[GFS_WORK_SIZE(MAX_OPEN) / sizeof(Uint32)];
GfsDirTbl dirtbl;
GFS_DIRTBL_TYPE(&dirtbl) = GFS_DIR_NAME;
GFS_DIRTBL_DIRNAME(&dirtbl) = dir_name;
GFS_DIRTBL_NDIR(&dirtbl) = MAX_DIR;
ret = GFS_Init(MAX_OPEN, lib_work, &dirtbl);
}
//--------------------------------------------------------------------------------------------------------------------------------------
void ChangeDir(char *dirname)
{
Sint32 fid;
GfsDirTbl dirtbl;
fid = GFS_NameToId((Sint8 *)dirname);
GFS_DIRTBL_TYPE(&dirtbl) = GFS_DIR_NAME;
GFS_DIRTBL_DIRNAME(&dirtbl) = dir_name;
GFS_DIRTBL_NDIR(&dirtbl) = MAX_DIR;
for (;;) {
file_max = GFS_LoadDir(fid, &dirtbl)-2;
if ( file_max >= 0) {
break;
}
}
for (;;) {
if (GFS_SetDir(&dirtbl) == 0) {
break;
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------
int LoadFile(char *name, Uint8 *location, Uint32 size)
{
Sint32 fid, i;
for (i = 0; i < 10; i++) {
fid = GFS_NameToId(name);
if (fid >= 0) {
GFS_Load(fid, 0, location, size);
return 0;
}
}
return -1;
}
//--------------------------------------------------------------------------------------------------------------------------------------
Sint32 GetFileSize(int file_id)
{
GfsHn gfs;
Sint32 sctsize, nsct, lastsize;
gfs = GFS_Open(file_id);
GFS_GetFileSize(gfs, &sctsize, &nsct, &lastsize);
GFS_Close(gfs);
return sctsize*nsct;
}
//--------------------------------------------------------------------------------------------------------------------------------------