|
|
|
@ -30,136 +30,12 @@
|
|
|
|
|
|
|
|
|
|
#include "safeguards.h"
|
|
|
|
|
|
|
|
|
|
static SpriteFile *_fio_current_file; ///< current file handle for the Fio functions
|
|
|
|
|
static std::array<SpriteFile *, MAX_FILE_SLOTS> _fio_files; ///< array of random access files we can have open
|
|
|
|
|
|
|
|
|
|
/** Whether the working directory should be scanned. */
|
|
|
|
|
static bool _do_scan_working_directory = true;
|
|
|
|
|
|
|
|
|
|
extern std::string _config_file;
|
|
|
|
|
extern std::string _highscore_file;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transition helper to get the SpriteFile associated with a given slot.
|
|
|
|
|
*/
|
|
|
|
|
SpriteFile *FioGetSpriteFile(int slot)
|
|
|
|
|
{
|
|
|
|
|
return _fio_files[slot];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get position in the current file.
|
|
|
|
|
* @return Position in the file.
|
|
|
|
|
*/
|
|
|
|
|
size_t FioGetPos()
|
|
|
|
|
{
|
|
|
|
|
return _fio_current_file->GetPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the filename associated with a slot.
|
|
|
|
|
* @param slot Index of queried file.
|
|
|
|
|
* @return Name of the file.
|
|
|
|
|
*/
|
|
|
|
|
const char *FioGetFilename(uint slot)
|
|
|
|
|
{
|
|
|
|
|
return _fio_current_file->GetSimplifiedFilename().c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Seek in the current file.
|
|
|
|
|
* @param pos New position.
|
|
|
|
|
* @param mode Type of seek (\c SEEK_CUR means \a pos is relative to current position, \c SEEK_SET means \a pos is absolute).
|
|
|
|
|
*/
|
|
|
|
|
void FioSeekTo(size_t pos, int mode)
|
|
|
|
|
{
|
|
|
|
|
_fio_current_file->SeekTo(pos, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Switch to a different file and seek to a position.
|
|
|
|
|
* @param slot Slot number of the new file.
|
|
|
|
|
* @param pos New absolute position in the new file.
|
|
|
|
|
*/
|
|
|
|
|
void FioSeekToFile(uint slot, size_t pos)
|
|
|
|
|
{
|
|
|
|
|
SpriteFile *file = _fio_files[slot];
|
|
|
|
|
assert(file != nullptr);
|
|
|
|
|
_fio_current_file = file;
|
|
|
|
|
_fio_current_file->SeekTo(pos, SEEK_SET);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read a byte from the file.
|
|
|
|
|
* @return Read byte.
|
|
|
|
|
*/
|
|
|
|
|
byte FioReadByte()
|
|
|
|
|
{
|
|
|
|
|
return _fio_current_file->ReadByte();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Skip \a n bytes ahead in the file.
|
|
|
|
|
* @param n Number of bytes to skip reading.
|
|
|
|
|
*/
|
|
|
|
|
void FioSkipBytes(int n)
|
|
|
|
|
{
|
|
|
|
|
return _fio_current_file->SkipBytes(n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read a word (16 bits) from the file (in low endian format).
|
|
|
|
|
* @return Read word.
|
|
|
|
|
*/
|
|
|
|
|
uint16 FioReadWord()
|
|
|
|
|
{
|
|
|
|
|
return _fio_current_file->ReadWord();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read a double word (32 bits) from the file (in low endian format).
|
|
|
|
|
* @return Read word.
|
|
|
|
|
*/
|
|
|
|
|
uint32 FioReadDword()
|
|
|
|
|
{
|
|
|
|
|
return _fio_current_file->ReadDword();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read a block.
|
|
|
|
|
* @param ptr Destination buffer.
|
|
|
|
|
* @param size Number of bytes to read.
|
|
|
|
|
*/
|
|
|
|
|
void FioReadBlock(void *ptr, size_t size)
|
|
|
|
|
{
|
|
|
|
|
_fio_current_file->ReadBlock(ptr, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Close all slotted open files. */
|
|
|
|
|
void FioCloseAll()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i != lengthof(_fio_files); i++) {
|
|
|
|
|
delete _fio_files[i];
|
|
|
|
|
_fio_files[i] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Open a slotted file.
|
|
|
|
|
* @param slot Index to assign.
|
|
|
|
|
* @param filename Name of the file at the disk.
|
|
|
|
|
* @param subdir The sub directory to search this file in.
|
|
|
|
|
* @param palette_remap Whether palette remapping needs to take place.
|
|
|
|
|
*/
|
|
|
|
|
SpriteFile &FioOpenFile(int slot, const std::string &filename, Subdirectory subdir, bool palette_remap)
|
|
|
|
|
{
|
|
|
|
|
SpriteFile *file = new SpriteFile(filename, subdir, palette_remap);
|
|
|
|
|
delete _fio_files[slot];
|
|
|
|
|
_fio_files[slot] = file;
|
|
|
|
|
_fio_current_file = file;
|
|
|
|
|
return *file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char * const _subdirs[] = {
|
|
|
|
|
"",
|
|
|
|
|
"save" PATHSEP,
|
|
|
|
|