Refactor save game RAM code so that the mappers call a function to register their buffers instead of writing directly to the cartinfo variables. Added optional reset callback function that can registered and will be called when FCEU_ClearGameSave runs. This is for memory that needs to be reset to non-zero values.

This commit is contained in:
harry 2023-02-20 11:21:04 -05:00
parent b199bb9787
commit 6f2c0a84f9
41 changed files with 192 additions and 156 deletions

View File

@ -24,7 +24,7 @@
static uint16 latchea; static uint16 latchea;
static uint8 latched; static uint8 latched;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
{ &latchea, 2, "AREG" }, { &latchea, 2, "AREG" },
@ -108,8 +108,7 @@ void Mapper15_Init(CartInfo *info) {
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -27,7 +27,7 @@
static uint8 laststrobe, trigger; static uint8 laststrobe, trigger;
static uint8 reg[8]; static uint8 reg[8];
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static writefunc pcmwrite; static writefunc pcmwrite;
@ -123,8 +123,7 @@ void Mapper164_Init(CartInfo *info) {
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
@ -172,8 +171,7 @@ void Mapper163_Init(CartInfo *info) {
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);
@ -223,8 +221,7 @@ void UNLFS304_Init(CartInfo *info) {
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;

View File

@ -23,7 +23,7 @@
static uint8 reg; static uint8 reg;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -73,8 +73,7 @@ void Mapper177_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -27,7 +27,7 @@
static uint8 reg[4]; static uint8 reg[4];
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
// Tennis with VR sensor, very simple behaviour // Tennis with VR sensor, very simple behaviour
extern void GetMouseData(uint32 (&md)[3]); extern void GetMouseData(uint32 (&md)[3]);
@ -192,8 +192,7 @@ void Mapper178_Init(CartInfo *info) {
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");

View File

@ -24,7 +24,7 @@ static uint8 preg[4], creg[8];
static uint8 IRQa, mirr; static uint8 IRQa, mirr;
static int32 IRQCount, IRQLatch; static int32 IRQCount, IRQLatch;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -125,8 +125,7 @@ void Mapper18_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -22,7 +22,7 @@
static uint8 regs[8]; static uint8 regs[8];
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE = 0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -79,8 +79,7 @@ void Mapper246_Init(CartInfo *info) {
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -23,9 +23,9 @@
static uint8 creg[8], preg[2]; static uint8 creg[8], preg[2];
static int32 IRQa, IRQCount, IRQClock, IRQLatch; static int32 IRQa, IRQCount, IRQClock, IRQLatch;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static uint8 *CHRRAM = NULL; static uint8 *CHRRAM = NULL;
static uint32 CHRRAMSIZE; static uint32 CHRRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -127,8 +127,7 @@ void Mapper252_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -23,9 +23,9 @@
static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock; static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock;
static int32 IRQa, IRQCount, IRQLatch, IRQClock; static int32 IRQa, IRQCount, IRQLatch, IRQClock;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static uint8 *CHRRAM = NULL; static uint8 *CHRRAM = NULL;
static uint32 CHRRAMSIZE; static uint32 CHRRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -144,8 +144,7 @@ void Mapper253_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -24,7 +24,7 @@ static uint8 chr_reg[4];
static uint8 kogame, prg_reg, nt1, nt2, mirr; static uint8 kogame, prg_reg, nt1, nt2, mirr;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE, count; static uint32 WRAMSIZE=0, count=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -156,8 +156,7 @@ void Mapper68_Init(CartInfo *info) {
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -25,7 +25,7 @@ static uint8 cmdreg, preg[4], creg[8], mirr;
static uint8 IRQa; static uint8 IRQa;
static int32 IRQCount; static int32 IRQCount;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -266,8 +266,7 @@ void Mapper69_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
Mapper69_ESI(); Mapper69_ESI();

View File

@ -169,8 +169,7 @@ void Mapper80_Init(CartInfo *info) {
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
if (info->battery) { if (info->battery) {
info->SaveGame[0] = wram; info->addSaveGameBuf( wram, sizeof(wram) );
info->SaveGameLen[0] = 256;
} }
AddExState(&StateRegs80, ~0, 0, 0); AddExState(&StateRegs80, ~0, 0, 0);

View File

@ -25,7 +25,7 @@
static uint8 regs[9], ctrl; static uint8 regs[9], ctrl;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -90,8 +90,7 @@ void Mapper82_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -92,8 +92,7 @@ void MapperNNN_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
*/ */
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -26,7 +26,7 @@ static uint8 dipswitch;
static void (*WSync)(void); static void (*WSync)(void);
static readfunc defread; static readfunc defread;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static DECLFW(LatchWrite) { static DECLFW(LatchWrite) {
latche = A; latche = A;
@ -77,8 +77,7 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
} }

View File

@ -29,7 +29,7 @@ static uint8 IRQa;
static int16 IRQCount, IRQLatch; static int16 IRQCount, IRQLatch;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -317,8 +317,7 @@ void Mapper16_Init(CartInfo *info) {
MapIRQHook = BandaiIRQHook; MapIRQHook = BandaiIRQHook;
info->battery = 1; info->battery = 1;
info->SaveGame[0] = x24c0x_data + 256; info->addSaveGameBuf( x24c0x_data + 256, 256 );
info->SaveGameLen[0] = 256;
AddExState(x24c0x_data, 256, 0, "DATA"); AddExState(x24c0x_data, 256, 0, "DATA");
AddExState(&x24c02StateRegs, ~0, 0, 0); AddExState(&x24c02StateRegs, ~0, 0, 0);
@ -333,8 +332,7 @@ void Mapper159_Init(CartInfo *info) {
MapIRQHook = BandaiIRQHook; MapIRQHook = BandaiIRQHook;
info->battery = 1; info->battery = 1;
info->SaveGame[0] = x24c0x_data; info->addSaveGameBuf( x24c0x_data, 128 );
info->SaveGameLen[0] = 128;
AddExState(x24c0x_data, 128, 0, "DATA"); AddExState(x24c0x_data, 128, 0, "DATA");
AddExState(&x24c01StateRegs, ~0, 0, 0); AddExState(&x24c01StateRegs, ~0, 0, 0);
@ -378,8 +376,7 @@ void Mapper153_Init(CartInfo *info) {
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
@ -599,8 +596,7 @@ void Mapper157_Init(CartInfo *info) {
GameInfo->cspecial = SIS_DATACH; GameInfo->cspecial = SIS_DATACH;
info->battery = 1; info->battery = 1;
info->SaveGame[0] = x24c0x_data; info->addSaveGameBuf( x24c0x_data, 512 );
info->SaveGameLen[0] = 512;
AddExState(x24c0x_data, 512, 0, "DATA"); AddExState(x24c0x_data, 512, 0, "DATA");
AddExState(&x24c01StateRegs, ~0, 0, 0); AddExState(&x24c01StateRegs, ~0, 0, 0);
AddExState(&x24c02StateRegs, ~0, 0, 0); AddExState(&x24c02StateRegs, ~0, 0, 0);

View File

@ -252,8 +252,7 @@ void Mapper111_Init(CartInfo *info) {
if (flash) if (flash)
{ {
FLASHROM = (uint8*)FCEU_gmalloc(FLASHROMSIZE); FLASHROM = (uint8*)FCEU_gmalloc(FLASHROMSIZE);
info->SaveGame[0] = FLASHROM; info->addSaveGameBuf( FLASHROM, FLASHROMSIZE );
info->SaveGameLen[0] = FLASHROMSIZE;
AddExState(FLASHROM, FLASHROMSIZE, 0, "FROM"); AddExState(FLASHROM, FLASHROMSIZE, 0, "FROM");
AddExState(&FlashRegs, ~0, 0, 0); AddExState(&FlashRegs, ~0, 0, 0);

View File

@ -454,8 +454,7 @@ void CommonInit(CartInfo* info, int submapper)
Flash[i] = PRGptr[ROM_CHIP][i % PRGsize[ROM_CHIP]]; Flash[i] = PRGptr[ROM_CHIP][i % PRGsize[ROM_CHIP]];
} }
SetupCartPRGMapping(FLASH_CHIP, Flash, PRGsize[ROM_CHIP], 1); SetupCartPRGMapping(FLASH_CHIP, Flash, PRGsize[ROM_CHIP], 1);
info->SaveGame[1] = Flash; info->addSaveGameBuf( Flash, PRGsize[ROM_CHIP] );
info->SaveGameLen[1] = PRGsize[ROM_CHIP];
} }
AddExState(EXPREGS, 4, 0, "EXPR"); AddExState(EXPREGS, 4, 0, "EXPR");

View File

@ -2271,8 +2271,7 @@ void COOLGIRL_Init(CartInfo *info) {
AddExState(WRAM, 32 * 1024, 0, "SRAM"); AddExState(WRAM, 32 * 1024, 0, "SRAM");
if (info->battery) if (info->battery)
{ {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, 32 * 1024);
info->SaveGameLen[0] = 32 * 1024;
} }
} }
@ -2281,8 +2280,7 @@ void COOLGIRL_Init(CartInfo *info) {
SAVE_FLASH = (uint8*)FCEU_gmalloc(SAVE_FLASH_SIZE); SAVE_FLASH = (uint8*)FCEU_gmalloc(SAVE_FLASH_SIZE);
SetupCartPRGMapping(FLASH_CHIP, SAVE_FLASH, SAVE_FLASH_SIZE, 1); SetupCartPRGMapping(FLASH_CHIP, SAVE_FLASH, SAVE_FLASH_SIZE, 1);
AddExState(SAVE_FLASH, SAVE_FLASH_SIZE, 0, "SAVF"); AddExState(SAVE_FLASH, SAVE_FLASH_SIZE, 0, "SAVF");
info->SaveGame[1] = SAVE_FLASH; info->addSaveGameBuf( SAVE_FLASH, SAVE_FLASH_SIZE );
info->SaveGameLen[1] = SAVE_FLASH_SIZE;
} }
CFI = (uint8*)FCEU_gmalloc(sizeof(cfi_data) * 2); CFI = (uint8*)FCEU_gmalloc(sizeof(cfi_data) * 2);

View File

@ -85,14 +85,12 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 ad
//else if(!info->wram_size && info->battery_wram_size) //else if(!info->wram_size && info->battery_wram_size)
//{ //{
// SetupCartPRGMapping(0x10, WRAM, info->battery_wram_size, 1); // SetupCartPRGMapping(0x10, WRAM, info->battery_wram_size, 1);
// info->SaveGame[0] = WRAM; // info->addSaveGameBuf( WRAM, info->battery_wram_size );
// info->SaveGameLen[0] = info->battery_wram_size;
//} else { //} else {
// //well, this is annoying // //well, this is annoying
// SetupCartPRGMapping(0x10, WRAM, info->wram_size, 1); // SetupCartPRGMapping(0x10, WRAM, info->wram_size, 1);
// SetupCartPRGMapping(0x11, WRAM, info->battery_wram_size, 1); //? ? ? there probably isnt even a way to select this // SetupCartPRGMapping(0x11, WRAM, info->battery_wram_size, 1); //? ? ? there probably isnt even a way to select this
// info->SaveGame[0] = WRAM + info->wram_size; // info->addSaveGameBuf( WRAM + info->wram_size, info->battery_wram_size );
// info->SaveGameLen[0] = info->battery_wram_size;
//} //}
//this is more likely the only practical scenario //this is more likely the only practical scenario
@ -104,8 +102,7 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 ad
setprg8r(0x10, 0x6000, 0); setprg8r(0x10, 0x6000, 0);
if(info->battery_wram_size) if(info->battery_wram_size)
{ {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, 8192 );
info->SaveGameLen[0] = 8192;
} }
} }
else else
@ -114,8 +111,7 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 ad
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
} }
@ -158,8 +154,7 @@ void NROM_Init(CartInfo *info) {
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
} }

View File

@ -70,8 +70,7 @@ void UNLEDU2000_Init(CartInfo *info) {
WRAM = (uint8*)FCEU_gmalloc(32768); WRAM = (uint8*)FCEU_gmalloc(32768);
SetupCartPRGMapping(0x10, WRAM, 32768, 1); SetupCartPRGMapping(0x10, WRAM, 32768, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, 32768 );
info->SaveGameLen[0] = 32768;
} }
AddExState(WRAM, 32768, 0, "WRAM"); AddExState(WRAM, 32768, 0, "WRAM");
AddExState(StateRegs, ~0, 0, 0); AddExState(StateRegs, ~0, 0, 0);

View File

@ -141,8 +141,7 @@ void Mapper6_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -28,7 +28,7 @@
static uint8 DRegs[4]; static uint8 DRegs[4];
static uint8 Buffer, BufferShift; static uint8 Buffer, BufferShift;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static int kanji_pos, kanji_page, r40C0; static int kanji_pos, kanji_page, r40C0;
@ -256,8 +256,7 @@ void FNS_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
AddExState(DRegs, 4, 0, "DREG"); AddExState(DRegs, 4, 0, "DREG");
AddExState(&lreset, 8, 1, "LRST"); AddExState(&lreset, 8, 1, "LRST");

View File

@ -306,8 +306,7 @@ static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int bram) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (bram) { if (bram) {
info->SaveGame[0] = WRAM + NONBRAMSIZE; info->addSaveGameBuf( WRAM + NONBRAMSIZE, bram * 1024 );
info->SaveGameLen[0] = bram * 1024;
} }
} }
if (!chr) { if (!chr) {

View File

@ -25,7 +25,7 @@
static uint8 is10; static uint8 is10;
static uint8 creg[4], latch0, latch1, preg, mirr; static uint8 creg[4], latch0, latch1, preg, mirr;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -130,8 +130,7 @@ void Mapper10_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -324,8 +324,7 @@ void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) {
if (battery) { if (battery) {
mmc3opts |= 2; mmc3opts |= 2;
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
// KT-008 boards hack 2-in-1, TODO assign to new ines mapper, most dump of KT-boards on the net are mapper 4, so need database or goodnes fix support // KT-008 boards hack 2-in-1, TODO assign to new ines mapper, most dump of KT-boards on the net are mapper 4, so need database or goodnes fix support

View File

@ -1021,22 +1021,23 @@ static void GenMMC5_Init(CartInfo *info, int wsize, int battery) {
MMC5battery = battery; MMC5battery = battery;
if (battery) { if (battery) {
info->SaveGame[0] = WRAM; uint32 saveGameSize = 0;
if (info->ines2) if (info->ines2)
{ {
info->SaveGameLen[0] = info->battery_wram_size; saveGameSize = info->battery_wram_size;
} }
else else
{ {
//this is more complex than it looks because it MUST BE, I guess. is there an assumption that only 8KB of 16KB is battery backed? That's NES mappers for you //this is more complex than it looks because it MUST BE, I guess. is there an assumption that only 8KB of 16KB is battery backed? That's NES mappers for you
//I added 64KB for the new 64KB homebrews //I added 64KB for the new 64KB homebrews
if (wsize <= 16) if (wsize <= 16)
info->SaveGameLen[0] = 8192; saveGameSize = 8192;
else if(wsize == 64) else if(wsize == 64)
info->SaveGameLen[0] = 64*1024; saveGameSize = 64*1024;
else else
info->SaveGameLen[0] = 32768; saveGameSize = 32768;
} }
info->addSaveGameBuf( WRAM, saveGameSize );
} }
MMC5HackVROMMask = CHRmask4[0]; MMC5HackVROMMask = CHRmask4[0];

View File

@ -429,10 +429,8 @@ void Mapper19_Init(CartInfo *info) {
AddExState(N106_StateRegs, ~0, 0, 0); AddExState(N106_StateRegs, ~0, 0, 0);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, 8192 );
info->SaveGameLen[0] = 8192; info->addSaveGameBuf( IRAM, 128 );
info->SaveGame[1] = IRAM;
info->SaveGameLen[1] = 128;
} }
} }

View File

@ -320,8 +320,7 @@ void UNLOneBus_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
} }
} }

View File

@ -54,8 +54,7 @@ void SA9602B_Init(CartInfo *info) {
GenMMC3_Init(info, 512, 0, 0, 0); GenMMC3_Init(info, 512, 0, 0, 0);
pwrap = SA9602BPW; pwrap = SA9602BPW;
mmc3opts |= 2; mmc3opts |= 2;
info->SaveGame[0] = UNIFchrrama; info->addSaveGameBuf( UNIFchrrama, 32 * 1024 );
info->SaveGameLen[0] = 32 * 1024;
info->Power = SA9602BPower; info->Power = SA9602BPower;
AddExState(EXPREGS, 2, 0, "EXPR"); AddExState(EXPREGS, 2, 0, "EXPR");
} }

View File

@ -24,7 +24,7 @@ static uint8 preg[8];
static uint8 IRQa; static uint8 IRQa;
static int16 IRQCount, IRQLatch; static int16 IRQCount, IRQLatch;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
/* /*
static uint8 *CHRRAM = NULL; static uint8 *CHRRAM = NULL;
static uint32 CHRRAMSIZE; static uint32 CHRRAMSIZE;
@ -187,8 +187,7 @@ void UNLSB2000_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -21,7 +21,7 @@
#include "mapinc.h" #include "mapinc.h"
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
unsigned int *GetKeyboard(void); // FIXME: 10/28 - now implemented in SDL as well. should we rename this to a FCEUI_* function? unsigned int *GetKeyboard(void); // FIXME: 10/28 - now implemented in SDL as well. should we rename this to a FCEUI_* function?
@ -90,8 +90,7 @@ void Transformer_Init(CartInfo *info) {
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
} }

View File

@ -168,6 +168,18 @@ static void UNROM512LatchClose(void) {
flash_data = NULL; flash_data = NULL;
} }
static void UNROM512_FlashReset(void)
{
if (flash_data)
{
size_t flash_size = PRGsize[ROM_CHIP];
// Copy ROM to flash data
for (size_t i = 0; i < flash_size; i++) {
flash_data[i] = PRGptr[ROM_CHIP][i];
}
}
}
void UNROM512_Init(CartInfo *info) { void UNROM512_Init(CartInfo *info) {
info->Power = UNROM512LatchPower; info->Power = UNROM512LatchPower;
info->Close = UNROM512LatchClose; info->Close = UNROM512LatchClose;
@ -205,9 +217,7 @@ void UNROM512_Init(CartInfo *info) {
flash_data[i] = PRGptr[ROM_CHIP][i]; flash_data[i] = PRGptr[ROM_CHIP][i];
} }
SetupCartPRGMapping(FLASH_CHIP, flash_data, flash_size, 1); SetupCartPRGMapping(FLASH_CHIP, flash_data, flash_size, 1);
// SaveGame is commented out due to movie issue where FCEU_ClearGameSave is clearing flash to zeros info->addSaveGameBuf( flash_data, flash_size, UNROM512_FlashReset );
//info->SaveGame[0] = flash_data;
//info->SaveGameLen[0] = PRGsize[ROM_CHIP];
flash_id[0] = 0xBF; flash_id[0] = 0xBF;
flash_id[1] = 0xB5 + (ROM_size >> 4); flash_id[1] = 0xB5 + (ROM_size >> 4);

View File

@ -185,8 +185,7 @@ static void VRC24_Init(CartInfo *info) {
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if(info->battery) { if(info->battery) {
info->SaveGame[0]=WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0]=WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -254,11 +254,10 @@ void QTAi_Init(CartInfo *info) {
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM;
// note, only extrnal cart's SRAM is battery backed, the the part on the main cartridge is just // note, only extrnal cart's SRAM is battery backed, the the part on the main cartridge is just
// an additional work ram. so we may save only half here, but I forgot what part is saved lol, will // an additional work ram. so we may save only half here, but I forgot what part is saved lol, will
// find out later. // find out later.
info->SaveGameLen[0] = WRAMSIZE; info->addSaveGameBuf( WRAM, WRAMSIZE );
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -28,7 +28,7 @@ static uint8 prg[2], chr[8], mirr;
static uint8 IRQLatch, IRQa, IRQd, IRQMode; static uint8 IRQLatch, IRQa, IRQd, IRQMode;
static int32 IRQCount, CycleCount; static int32 IRQCount, CycleCount;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
@ -379,8 +379,7 @@ void Mapper26_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
AddExState(&StateRegs, ~0, 0, 0); AddExState(&StateRegs, ~0, 0, 0);

View File

@ -24,7 +24,7 @@ static uint8 vrc7idx, preg[3], creg[8], mirr;
static uint8 IRQLatch, IRQa, IRQd, IRQMode; static uint8 IRQLatch, IRQa, IRQd, IRQMode;
static int32 IRQCount, CycleCount; static int32 IRQCount, CycleCount;
static uint8 *WRAM = NULL; static uint8 *WRAM = NULL;
static uint32 WRAMSIZE; static uint32 WRAMSIZE=0;
#include "emu2413.h" #include "emu2413.h"
@ -204,8 +204,7 @@ void Mapper85_Init(CartInfo *info) {
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if (info->battery) { if (info->battery) {
info->SaveGame[0] = WRAM; info->addSaveGameBuf( WRAM, WRAMSIZE );
info->SaveGameLen[0] = WRAMSIZE;
} }
GameStateRestore = StateRestore; GameStateRestore = StateRestore;
VRC7_ESI(); VRC7_ESI();

View File

@ -536,18 +536,26 @@ void FCEU_GeniePower(void) {
} }
void FCEU_SaveGameSave(CartInfo *LocalHWInfo) { void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { {
if (LocalHWInfo->battery && !LocalHWInfo->SaveGame.empty())
{
FILE *sp; FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav");
if ((sp = FCEUD_UTF8fopen(soot, "wb")) == NULL) { if ((sp = FCEUD_UTF8fopen(soot, "wb")) == NULL)
{
FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n", soot.c_str()); FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n", soot.c_str());
} else { }
for (int x = 0; x < 4; x++) else
if (LocalHWInfo->SaveGame[x]) { {
fwrite(LocalHWInfo->SaveGame[x], 1, for (size_t x = 0; x < LocalHWInfo->SaveGame.size(); x++)
LocalHWInfo->SaveGameLen[x], sp); {
if (LocalHWInfo->SaveGame[x].bufptr)
{
fwrite(LocalHWInfo->SaveGame[x].bufptr, 1,
LocalHWInfo->SaveGame[x].buflen, sp);
}
} }
} }
} }
@ -556,19 +564,21 @@ void FCEU_SaveGameSave(CartInfo *LocalHWInfo) {
// hack, movie.cpp has to communicate with this function somehow // hack, movie.cpp has to communicate with this function somehow
int disableBatteryLoading = 0; int disableBatteryLoading = 0;
void FCEU_LoadGameSave(CartInfo *LocalHWInfo) { void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading) { {
if (LocalHWInfo->battery && !LocalHWInfo->SaveGame.empty() && !disableBatteryLoading)
{
FILE *sp; FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav");
sp = FCEUD_UTF8fopen(soot, "rb"); sp = FCEUD_UTF8fopen(soot, "rb");
if (sp != NULL) if (sp != NULL)
{ {
for (int x = 0; x < 4; x++) for (size_t x = 0; x < LocalHWInfo->SaveGame.size(); x++)
{ {
if (LocalHWInfo->SaveGame[x]) if (LocalHWInfo->SaveGame[x].bufptr)
{ {
if ( fread(LocalHWInfo->SaveGame[x], 1, LocalHWInfo->SaveGameLen[x], sp) != static_cast<size_t>(LocalHWInfo->SaveGameLen[x]) ) if ( fread(LocalHWInfo->SaveGame[x].bufptr, 1, LocalHWInfo->SaveGame[x].buflen, sp) != LocalHWInfo->SaveGame[x].buflen )
{ {
FCEU_printf("Warning save game data read came up short!\n"); FCEU_printf("Warning save game data read came up short!\n");
} }
@ -579,10 +589,20 @@ void FCEU_LoadGameSave(CartInfo *LocalHWInfo) {
} }
//clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though) //clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though)
void FCEU_ClearGameSave(CartInfo *LocalHWInfo) { void FCEU_ClearGameSave(CartInfo *LocalHWInfo)
if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { {
for (int x = 0; x < 4; x++) if (LocalHWInfo->battery && !LocalHWInfo->SaveGame.empty())
if (LocalHWInfo->SaveGame[x]) {
memset(LocalHWInfo->SaveGame[x], 0, LocalHWInfo->SaveGameLen[x]); for (size_t x = 0; x < LocalHWInfo->SaveGame.size(); x++)
{
if (LocalHWInfo->SaveGame[x].bufptr)
{
memset(LocalHWInfo->SaveGame[x].bufptr, 0, LocalHWInfo->SaveGame[x].buflen);
}
if (LocalHWInfo->SaveGame[x].resetFunc)
{
LocalHWInfo->SaveGame[x].resetFunc();
}
}
} }
} }

View File

@ -1,13 +1,38 @@
#ifndef CART_H #ifndef CART_H
#define CART_H #define CART_H
typedef struct { #include <vector>
struct CartInfo
{
// Set by mapper/board code: // Set by mapper/board code:
void (*Power)(void); void (*Power)(void);
void (*Reset)(void); void (*Reset)(void);
void (*Close)(void); void (*Close)(void);
uint8 *SaveGame[4]; // Pointers to memory to save/load.
uint32 SaveGameLen[4]; // How much memory to save/load. struct SaveGame_t
{
uint8 *bufptr; // Pointer to memory to save/load.
uint32 buflen; // How much memory to save/load.
void (*resetFunc)(void); // Callback to reset save game memory
SaveGame_t(void)
: bufptr(nullptr), buflen(0), resetFunc(nullptr)
{
}
};
std::vector <SaveGame_t> SaveGame;
void addSaveGameBuf( uint8* bufptrIn, uint32 buflenIn, void (*resetFuncIn)(void) = nullptr )
{
SaveGame_t tmp;
tmp.bufptr = bufptrIn;
tmp.buflen = buflenIn;
tmp.resetFunc = resetFuncIn;
SaveGame.push_back( tmp );
}
// Set by iNES/UNIF loading code. // Set by iNES/UNIF loading code.
int mirror; // As set in the header or chunk. int mirror; // As set in the header or chunk.
@ -27,7 +52,33 @@ typedef struct {
uint32 CRC32; // Should be set by the iNES/UNIF loading uint32 CRC32; // Should be set by the iNES/UNIF loading
// code, used by mapper/board code, maybe // code, used by mapper/board code, maybe
// other code in the future. // other code in the future.
} CartInfo;
CartInfo(void)
{
clear();
}
void clear(void)
{
Power = nullptr;
Reset = nullptr;
Close = nullptr;
SaveGame.clear();
mirror = 0;
mirrorAs2Bits = 0;
battery = 0;
ines2 = 0;
submapper = 0;
wram_size = 0;
battery_wram_size = 0;
vram_size = 0;
battery_vram_size = 0;
memset( MD5, 0, sizeof(MD5));
CRC32 = 0;
};
};
extern CartInfo *currCartInfo; extern CartInfo *currCartInfo;

View File

@ -810,7 +810,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) {
head.cleanup(); head.cleanup();
memset(&iNESCart, 0, sizeof(iNESCart)); iNESCart.clear();
iNES2 = ((head.ROM_type2 & 0x0C) == 0x08); iNES2 = ((head.ROM_type2 & 0x0C) == 0x08);
if(iNES2) if(iNES2)

View File

@ -984,23 +984,23 @@ bool MovieData::loadSaveramFrom(std::vector<uint8>* buf)
return false; return false;
} }
for(int i=0;i<4;i++) for (size_t i=0;i<currCartInfo->SaveGame.size();i++)
{ {
int len = ms.read32le(); int len = ms.read32le();
if(!currCartInfo->SaveGame[i] && len!=0) if( (currCartInfo->SaveGame[i].bufptr == nullptr) && (len!=0) )
{ {
FCEU_PrintError("movie battery load mismatch 2"); FCEU_PrintError("movie battery load mismatch 2");
return false; return false;
} }
if(currCartInfo->SaveGameLen[i] != static_cast<unsigned int>(len)) if(currCartInfo->SaveGame[i].buflen != static_cast<size_t>(len))
{ {
FCEU_PrintError("movie battery load mismatch 3"); FCEU_PrintError("movie battery load mismatch 3");
return false; return false;
} }
ms.fread(currCartInfo->SaveGame[i], len); ms.fread(currCartInfo->SaveGame[i].bufptr, len);
} }
return true; return true;
@ -1011,16 +1011,15 @@ void MovieData::dumpSaveramTo(std::vector<uint8>* buf, int compressionLevel)
EMUFILE_MEMORY ms(buf); EMUFILE_MEMORY ms(buf);
ms.write32le(currCartInfo->battery?1:0); ms.write32le(currCartInfo->battery?1:0);
for(int i=0;i<4;i++) for(size_t i=0;i<currCartInfo->SaveGame.size();i++)
{ {
if(!currCartInfo->SaveGame[i]) if (!currCartInfo->SaveGame[i].bufptr)
{ {
ms.write32le((u32)0); ms.write32le((u32)0);
continue; continue;
} }
ms.write32le( static_cast<uint32>(currCartInfo->SaveGame[i].buflen) );
ms.write32le(currCartInfo->SaveGameLen[i]); ms.fwrite(currCartInfo->SaveGame[i].bufptr, currCartInfo->SaveGame[i].buflen);
ms.fwrite(currCartInfo->SaveGame[i], currCartInfo->SaveGameLen[i]);
} }
} }

View File

@ -104,7 +104,7 @@ static void ResetUNIF(void) {
vramo = 0; vramo = 0;
boardname = 0; boardname = 0;
mirrortodo = 0; mirrortodo = 0;
memset(&UNIFCart, 0, sizeof(UNIFCart)); UNIFCart.clear();
UNIFchrrama = 0; UNIFchrrama = 0;
} }