all repos — mgba @ a73cfe4496cae2e482422b18d12c566047ff17c1

mGBA Game Boy Advance Emulator

Util: Add VFS helper functions for reading/writing little endian values
Jeffrey Pfau jeffrey@endrift.com
Thu, 28 May 2015 22:57:01 -0700
commit

a73cfe4496cae2e482422b18d12c566047ff17c1

parent

6b06579277668d63411a0fc0233f04c07c95aa6c

2 files changed, 35 insertions(+), 0 deletions(-)

jump to
M src/util/vfs.csrc/util/vfs.c

@@ -44,3 +44,33 @@ vf = dir->openFile(dir, path, mode);

} return vf; } + +ssize_t VFileWrite32LE(struct VFile* vf, int32_t word) { + uint32_t leword; + STORE_32LE(word, 0, &leword); + return vf->write(vf, &leword, 4); +} + +ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword) { + uint16_t lehword; + STORE_16LE(hword, 0, &lehword); + return vf->write(vf, &lehword, 2); +} + +ssize_t VFileRead32LE(struct VFile* vf, void* word) { + uint32_t leword; + ssize_t r = vf->read(vf, &leword, 4); + if (r == 4) { + STORE_32LE(leword, 0, word); + } + return r; +} + +ssize_t VFileRead16LE(struct VFile* vf, void* hword) { + uint16_t lehword; + ssize_t r = vf->read(vf, &lehword, 2); + if (r == 2) { + STORE_16LE(lehword, 0, hword); + } + return r; +}
M src/util/vfs.hsrc/util/vfs.h

@@ -72,4 +72,9 @@ struct VFile* VDirOptionalOpenIncrementFile(struct VDir* dir, const char* realPath, const char* prefix, const char* infix, const char* suffix, int mode);

ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size); +ssize_t VFileWrite32LE(struct VFile* vf, int32_t word); +ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword); +ssize_t VFileRead32LE(struct VFile* vf, void* word); +ssize_t VFileRead16LE(struct VFile* vf, void* hword); + #endif