GBA: GBALoadROM can fail
Jeffrey Pfau jeffrey@endrift.com
Mon, 24 Aug 2015 21:43:08 -0700
3 files changed,
9 insertions(+),
5 deletions(-)
M
src/gba/gba.c
→
src/gba/gba.c
@@ -388,7 +388,7 @@ ARMHotplugDetach(gba->cpu, GBA_COMPONENT_DEBUGGER);
gba->cpu->components[GBA_COMPONENT_DEBUGGER] = 0; } -void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname) { +bool GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname) { GBAUnloadROM(gba); gba->romVf = vf; gba->pristineRomSize = vf->size(vf);@@ -399,7 +399,7 @@ }
gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ); if (!gba->pristineRom) { GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM"); - return; + return false; } gba->yankedRomSize = 0; gba->memory.rom = gba->pristineRom;@@ -409,6 +409,7 @@ gba->memory.romMask = toPow2(gba->memory.romSize) - 1;
gba->romCrc32 = doCrc32(gba->memory.rom, gba->memory.romSize); GBASavedataInit(&gba->memory.savedata, sav); GBAHardwareInit(&gba->memory.hw, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]); + return true; // TODO: error check }
M
src/gba/gba.h
→
src/gba/gba.h
@@ -166,7 +166,7 @@ void GBASetBreakpoint(struct GBA* gba, struct ARMComponent* component, uint32_t address, enum ExecutionMode mode,
uint32_t* opcode); void GBAClearBreakpoint(struct GBA* gba, uint32_t address, enum ExecutionMode mode, uint32_t opcode); -void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname); +bool GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char* fname); void GBAYankROM(struct GBA* gba); void GBAUnloadROM(struct GBA* gba); void GBALoadBIOS(struct GBA* gba, struct VFile* vf);
M
src/gba/supervisor/context.c
→
src/gba/supervisor/context.c
@@ -114,13 +114,16 @@ }
bool GBAContextStart(struct GBAContext* context) { struct GBAOptions opts = {}; - GBAConfigMap(&context->config, &opts); if (context->renderer) { GBAVideoAssociateRenderer(&context->gba->video, context->renderer); } - GBALoadROM(context->gba, context->rom, context->save, 0); + if (!GBALoadROM(context->gba, context->rom, context->save, 0)) { + return false; + } + + GBAConfigMap(&context->config, &opts); if (opts.useBios && context->bios) { GBALoadBIOS(context->gba, context->bios); }