Codechange: lets music make use of RandomAccessFile instead of the FIO slot functions

This commit is contained in:
Rubidium 2021-04-14 06:49:46 +02:00 committed by rubidium42
parent c097bc9d7d
commit 0dd339ecd8

View File

@ -15,7 +15,7 @@
#include "base_media_func.h" #include "base_media_func.h"
#include "safeguards.h" #include "safeguards.h"
#include "fios.h" #include "random_access_file_type.h"
/** /**
@ -29,15 +29,15 @@ char *GetMusicCatEntryName(const char *filename, size_t entrynum)
{ {
if (!FioCheckFileExists(filename, BASESET_DIR)) return nullptr; if (!FioCheckFileExists(filename, BASESET_DIR)) return nullptr;
FioOpenFile(CONFIG_SLOT, filename, BASESET_DIR); RandomAccessFile file(filename, BASESET_DIR);
uint32 ofs = FioReadDword(); uint32 ofs = file.ReadDword();
size_t entry_count = ofs / 8; size_t entry_count = ofs / 8;
if (entrynum < entry_count) { if (entrynum < entry_count) {
FioSeekTo(entrynum * 8, SEEK_SET); file.SeekTo(entrynum * 8, SEEK_SET);
FioSeekTo(FioReadDword(), SEEK_SET); file.SeekTo(file.ReadDword(), SEEK_SET);
byte namelen = FioReadByte(); byte namelen = file.ReadByte();
char *name = MallocT<char>(namelen + 1); char *name = MallocT<char>(namelen + 1);
FioReadBlock(name, namelen); file.ReadBlock(name, namelen);
name[namelen] = '\0'; name[namelen] = '\0';
return name; return name;
} }
@ -57,17 +57,17 @@ byte *GetMusicCatEntryData(const char *filename, size_t entrynum, size_t &entryl
entrylen = 0; entrylen = 0;
if (!FioCheckFileExists(filename, BASESET_DIR)) return nullptr; if (!FioCheckFileExists(filename, BASESET_DIR)) return nullptr;
FioOpenFile(CONFIG_SLOT, filename, BASESET_DIR); RandomAccessFile file(filename, BASESET_DIR);
uint32 ofs = FioReadDword(); uint32 ofs = file.ReadDword();
size_t entry_count = ofs / 8; size_t entry_count = ofs / 8;
if (entrynum < entry_count) { if (entrynum < entry_count) {
FioSeekTo(entrynum * 8, SEEK_SET); file.SeekTo(entrynum * 8, SEEK_SET);
size_t entrypos = FioReadDword(); size_t entrypos = file.ReadDword();
entrylen = FioReadDword(); entrylen = file.ReadDword();
FioSeekTo(entrypos, SEEK_SET); file.SeekTo(entrypos, SEEK_SET);
FioSkipBytes(FioReadByte()); file.SkipBytes(file.ReadByte());
byte *data = MallocT<byte>(entrylen); byte *data = MallocT<byte>(entrylen);
FioReadBlock(data, entrylen); file.ReadBlock(data, entrylen);
return data; return data;
} }
return nullptr; return nullptr;