12 #include "../../gfx.h"
14 #if GFX_USE_GFILE && GFILE_NEED_ROMFS
21 #define ROMFS_DIR_VER_MAX 0x0000
24 #define ROMFS_CMP_UNCOMPRESSED 0
26 typedef struct ROMFS_DIRENTRY {
29 const struct ROMFS_DIRENTRY * next;
35 #define ROMFS_DIRENTRY_HEAD 0
36 #include "romfs_files.h"
42 static const ROMFS_DIRENTRY *FsROMHead = ROMFS_DIRENTRY_HEAD;
44 typedef struct ROMFileList {
46 const ROMFS_DIRENTRY *pdir;
50 static gBool ROMExists(
const char *fname);
51 static gFileSize ROMFilesize(
const char *fname);
52 static gBool ROMOpen(
GFILE *f,
const char *fname);
53 static void ROMClose(
GFILE *f);
54 static int ROMRead(
GFILE *f,
void *buf,
int size);
55 static gBool ROMSetpos(
GFILE *f, gFileSize pos);
56 static gFileSize ROMGetsize(
GFILE *f);
57 static gBool ROMEof(
GFILE *f);
58 #if GFILE_NEED_FILELISTS
59 static gfileList *ROMFlOpen(
const char *path, gBool dirs);
60 static const char *ROMFlRead(gfileList *pfl);
61 static void ROMFlClose(gfileList *pfl);
64 const GFILEVMT FsROMVMT = {
65 GFSFLG_CASESENSITIVE|GFSFLG_SEEKABLE|GFSFLG_FAST,
67 0, ROMExists, ROMFilesize, 0,
68 ROMOpen, ROMClose, ROMRead, 0,
69 ROMSetpos, ROMGetsize, ROMEof,
71 #if GFILE_NEED_FILELISTS
72 ROMFlOpen, ROMFlRead, ROMFlClose
76 static const ROMFS_DIRENTRY *ROMFindFile(
const char *fname)
78 const ROMFS_DIRENTRY *p;
80 for(p = FsROMHead; p; p = p->next) {
81 if (p->ver <= ROMFS_DIR_VER_MAX && p->cmp == ROMFS_CMP_UNCOMPRESSED && !strcmp(p->name, fname))
87 static gBool ROMExists(
const char *fname)
89 return ROMFindFile(fname) != 0;
92 static gFileSize ROMFilesize(
const char *fname)
94 const ROMFS_DIRENTRY *p;
96 if (!(p = ROMFindFile(fname)))
return (gFileSize)-1;
100 static gBool ROMOpen(
GFILE *f,
const char *fname)
102 const ROMFS_DIRENTRY *p;
104 if (!(p = ROMFindFile(fname)))
return gFalse;
109 static void ROMClose(
GFILE *f)
114 static int ROMRead(
GFILE *f,
void *buf,
int size)
116 const ROMFS_DIRENTRY *p;
118 p = (
const ROMFS_DIRENTRY *)f->obj;
119 if (p->size - f->pos < size)
120 size = p->size - f->pos;
121 if (size <= 0)
return 0;
122 memcpy(buf, p->file+f->pos, size);
126 static gBool ROMSetpos(
GFILE *f, gFileSize pos)
128 return pos <= ((
const ROMFS_DIRENTRY *)f->obj)->size;
131 static gFileSize ROMGetsize(
GFILE *f)
133 return ((
const ROMFS_DIRENTRY *)f->obj)->size;
136 static gBool ROMEof(
GFILE *f)
138 return f->pos >= ((
const ROMFS_DIRENTRY *)f->obj)->size;
141 #if GFILE_NEED_FILELISTS
142 static gfileList *ROMFlOpen(
const char *path, gBool dirs) {
151 if (!(p =
gfxAlloc(
sizeof(ROMFileList))))
159 static const char *ROMFlRead(gfileList *pfl) {
160 #define rfl ((ROMFileList *)pfl)
164 rfl->pdir = FsROMHead;
165 return FsROMHead->name;
169 if (rfl->pdir->next) {
170 rfl->pdir = rfl->pdir->next;
171 return rfl->pdir->name;
178 static void ROMFlClose(gfileList *pfl) {
GFILE file system header.
struct GFILE GFILE
A file pointer.
void * gfxAlloc(gMemSize sz)
Allocate memory.
void gfxFree(void *ptr)
Free memory.