@@ -36,25 +36,25 @@ struct Fio {
char *shortnames[MAX_FILE_SLOTS];///< array of short names for spriteloader's use
#if defined(LIMITED_FDS)
uint open_handles; ///< current amount of open handles
uint usage_count[MAX_FILE_SLOTS]; ///< count how many times this file has been opened
#endif /* LIMITED_FDS */
};
static Fio _fio;
/* Get current position in file */
uint32 FioGetPos()
{
return _fio.pos + (_fio.buffer - _fio.buffer_start) - FIO_BUFFER_SIZE;
return _fio.pos + (_fio.buffer - _fio.buffer_end);
}
const char *FioGetFilename(uint8 slot)
return _fio.shortnames[slot];
void FioSeekTo(uint32 pos, int mode)
if (mode == SEEK_CUR) pos += FioGetPos();
_fio.buffer = _fio.buffer_end = _fio.buffer_start + FIO_BUFFER_SIZE;
_fio.pos = pos;
@@ -83,25 +83,29 @@ void FioSeekToFile(uint8 slot, uint32 po
f = _fio.handles[slot];
assert(f != NULL);
_fio.cur_fh = f;
_fio.filename = _fio.filenames[slot];
FioSeekTo(pos, SEEK_SET);
byte FioReadByte()
if (_fio.buffer == _fio.buffer_end) {
_fio.buffer = _fio.buffer_start;
_fio.pos += fread(_fio.buffer, 1, FIO_BUFFER_SIZE, _fio.cur_fh);
size_t size = fread(_fio.buffer, 1, FIO_BUFFER_SIZE, _fio.cur_fh);
_fio.pos += size;
_fio.buffer_end = _fio.buffer_start + size;
if (size == 0) return 0;
return *_fio.buffer++;
void FioSkipBytes(int n)
for (;;) {
int m = min(_fio.buffer_end - _fio.buffer, n);
_fio.buffer += m;
n -= m;
if (n == 0) break;
FioReadByte();