GBA: GBALoadROM can fail

This commit is contained in:
Jeffrey Pfau 2015-08-24 21:43:08 -07:00
parent 2236b27600
commit 5ee5d9f78b
3 changed files with 9 additions and 5 deletions

View File

@ -388,7 +388,7 @@ void GBADetachDebugger(struct GBA* gba) {
gba->cpu->components[GBA_COMPONENT_DEBUGGER] = 0; 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); GBAUnloadROM(gba);
gba->romVf = vf; gba->romVf = vf;
gba->pristineRomSize = vf->size(vf); gba->pristineRomSize = vf->size(vf);
@ -399,7 +399,7 @@ void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char
gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ); gba->pristineRom = vf->map(vf, gba->pristineRomSize, MAP_READ);
if (!gba->pristineRom) { if (!gba->pristineRom) {
GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM"); GBALog(gba, GBA_LOG_WARN, "Couldn't map ROM");
return; return false;
} }
gba->yankedRomSize = 0; gba->yankedRomSize = 0;
gba->memory.rom = gba->pristineRom; gba->memory.rom = gba->pristineRom;
@ -409,6 +409,7 @@ void GBALoadROM(struct GBA* gba, struct VFile* vf, struct VFile* sav, const char
gba->romCrc32 = doCrc32(gba->memory.rom, gba->memory.romSize); gba->romCrc32 = doCrc32(gba->memory.rom, gba->memory.romSize);
GBASavedataInit(&gba->memory.savedata, sav); GBASavedataInit(&gba->memory.savedata, sav);
GBAHardwareInit(&gba->memory.hw, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]); GBAHardwareInit(&gba->memory.hw, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]);
return true;
// TODO: error check // TODO: error check
} }

View File

@ -166,7 +166,7 @@ void GBASetBreakpoint(struct GBA* gba, struct ARMComponent* component, uint32_t
uint32_t* opcode); uint32_t* opcode);
void GBAClearBreakpoint(struct GBA* gba, 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 GBAYankROM(struct GBA* gba);
void GBAUnloadROM(struct GBA* gba); void GBAUnloadROM(struct GBA* gba);
void GBALoadBIOS(struct GBA* gba, struct VFile* vf); void GBALoadBIOS(struct GBA* gba, struct VFile* vf);

View File

@ -114,13 +114,16 @@ bool GBAContextLoadBIOSFromVFile(struct GBAContext* context, struct VFile* bios)
bool GBAContextStart(struct GBAContext* context) { bool GBAContextStart(struct GBAContext* context) {
struct GBAOptions opts = {}; struct GBAOptions opts = {};
GBAConfigMap(&context->config, &opts);
if (context->renderer) { if (context->renderer) {
GBAVideoAssociateRenderer(&context->gba->video, 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) { if (opts.useBios && context->bios) {
GBALoadBIOS(context->gba, context->bios); GBALoadBIOS(context->gba, context->bios);
} }