couple of mapper fixes (#482)

* Fix a couple of mapper issues

- Implement info->Close, to free any unallocated memory (e.g. WRAM)
- Add missing GameStateRestore function
- Add missing state variable

* Simplify header parsing

* Update ines-correct.h

Co-authored-by: negativeExponent <negativeExponent@users.noreply.github.com>
This commit is contained in:
negativeExponent
2022-01-24 02:20:46 +08:00
committed by GitHub
parent eb06d17e79
commit 758a51eacb
9 changed files with 157 additions and 61 deletions

View File

@@ -25,6 +25,8 @@
#include "mapinc.h"
#include "../ines.h"
static uint8 *WRAM;
static uint32 WRAMSIZE;
static uint8 reg[4];
static SFORMAT StateRegs[] =
{
@@ -88,20 +90,36 @@ static void reset(void)
sync();
}
static void close(void)
{
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}
static void StateRestore(int version)
{
sync();
}
void Mapper163_Init (CartInfo *info)
{
uint8 *WRAM;
uint32 WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
info->Power = power;
info->Reset = reset;
info->Close = close;
GameHBIRQHook = hblank;
GameStateRestore = StateRestore;
AddExState(StateRegs, ~0, 0, 0);
WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
if (info->battery) {
info->SaveGame[0] = WRAM;
info->SaveGameLen[0] = info->PRGRamSaveSize;
info->SaveGameLen[0] = WRAMSIZE;
}
}