mirror of https://github.com/mgba-emu/mgba.git
GB: Add patch support
This commit is contained in:
parent
a712216c2e
commit
3ade5188db
|
@ -9,6 +9,7 @@
|
|||
#include "gb/gb.h"
|
||||
#include "gb/renderers/software.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/patch.h"
|
||||
|
||||
struct GBCore {
|
||||
struct mCore d;
|
||||
|
@ -97,11 +98,15 @@ static bool _GBCoreLoadSave(struct mCore* core, struct VFile* vf) {
|
|||
}
|
||||
|
||||
static bool _GBCoreLoadPatch(struct mCore* core, struct VFile* vf) {
|
||||
// TODO
|
||||
UNUSED(core);
|
||||
UNUSED(vf);
|
||||
mLOG(GB, STUB, "Patches are not yet supported");
|
||||
return false;
|
||||
if (!vf) {
|
||||
return false;
|
||||
}
|
||||
struct Patch patch;
|
||||
if (!loadPatch(vf, &patch)) {
|
||||
return false;
|
||||
}
|
||||
GBApplyPatch(core->board, &patch);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _GBCoreUnloadROM(struct mCore* core) {
|
||||
|
|
18
src/gb/gb.c
18
src/gb/gb.c
|
@ -126,6 +126,24 @@ void GBUnloadROM(struct GB* gb) {
|
|||
gb->memory.sram = 0;
|
||||
}
|
||||
|
||||
void GBApplyPatch(struct GB* gb, struct Patch* patch) {
|
||||
size_t patchedSize = patch->outputSize(patch, gb->memory.romSize);
|
||||
if (!patchedSize) {
|
||||
return;
|
||||
}
|
||||
if (patchedSize > 0x400000) {
|
||||
patchedSize = 0x400000;
|
||||
}
|
||||
gb->memory.rom = anonymousMemoryMap(0x400000);
|
||||
if (!patch->applyPatch(patch, gb->pristineRom, gb->pristineRomSize, gb->memory.rom, patchedSize)) {
|
||||
mappedMemoryFree(gb->memory.rom, patchedSize);
|
||||
gb->memory.rom = gb->pristineRom;
|
||||
return;
|
||||
}
|
||||
gb->memory.romSize = patchedSize;
|
||||
gb->romCrc32 = doCrc32(gb->memory.rom, gb->memory.romSize);
|
||||
}
|
||||
|
||||
void GBDestroy(struct GB* gb) {
|
||||
GBUnloadROM(gb);
|
||||
|
||||
|
|
Loading…
Reference in New Issue