diff --git a/src/boards/15.cpp b/src/boards/15.cpp index 01f55cd5..2558fdcc 100644 --- a/src/boards/15.cpp +++ b/src/boards/15.cpp @@ -24,7 +24,7 @@ static uint16 latchea; static uint8 latched; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { { &latchea, 2, "AREG" }, @@ -108,8 +108,7 @@ void Mapper15_Init(CartInfo *info) { WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/164.cpp b/src/boards/164.cpp index 6eb963bf..c4344d0f 100644 --- a/src/boards/164.cpp +++ b/src/boards/164.cpp @@ -27,7 +27,7 @@ static uint8 laststrobe, trigger; static uint8 reg[8]; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static writefunc pcmwrite; @@ -123,8 +123,7 @@ void Mapper164_Init(CartInfo *info) { AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; @@ -172,8 +171,7 @@ void Mapper163_Init(CartInfo *info) { AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; AddExState(&StateRegs, ~0, 0, 0); @@ -223,8 +221,7 @@ void UNLFS304_Init(CartInfo *info) { AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; diff --git a/src/boards/177.cpp b/src/boards/177.cpp index 0416060e..9525939e 100644 --- a/src/boards/177.cpp +++ b/src/boards/177.cpp @@ -23,7 +23,7 @@ static uint8 reg; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -73,8 +73,7 @@ void Mapper177_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/178.cpp b/src/boards/178.cpp index d5773293..5dc7709d 100644 --- a/src/boards/178.cpp +++ b/src/boards/178.cpp @@ -27,7 +27,7 @@ static uint8 reg[4]; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; // Tennis with VR sensor, very simple behaviour extern void GetMouseData(uint32 (&md)[3]); @@ -192,8 +192,7 @@ void Mapper178_Init(CartInfo *info) { WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(WRAM, WRAMSIZE, 0, "WRAM"); diff --git a/src/boards/18.cpp b/src/boards/18.cpp index a9ac4b67..bbf65f69 100644 --- a/src/boards/18.cpp +++ b/src/boards/18.cpp @@ -24,7 +24,7 @@ static uint8 preg[4], creg[8]; static uint8 IRQa, mirr; static int32 IRQCount, IRQLatch; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -125,8 +125,7 @@ void Mapper18_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/246.cpp b/src/boards/246.cpp index ec069deb..3e00f040 100644 --- a/src/boards/246.cpp +++ b/src/boards/246.cpp @@ -22,7 +22,7 @@ static uint8 regs[8]; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE = 0; static SFORMAT StateRegs[] = { @@ -79,8 +79,7 @@ void Mapper246_Init(CartInfo *info) { AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/252.cpp b/src/boards/252.cpp index 9962e088..51de2e98 100644 --- a/src/boards/252.cpp +++ b/src/boards/252.cpp @@ -23,9 +23,9 @@ static uint8 creg[8], preg[2]; static int32 IRQa, IRQCount, IRQClock, IRQLatch; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; +static uint32 CHRRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -127,8 +127,7 @@ void Mapper252_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/253.cpp b/src/boards/253.cpp index 3ed9bfec..04bbb095 100644 --- a/src/boards/253.cpp +++ b/src/boards/253.cpp @@ -23,9 +23,9 @@ static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock; static int32 IRQa, IRQCount, IRQLatch, IRQClock; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; +static uint32 CHRRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -144,8 +144,7 @@ void Mapper253_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/68.cpp b/src/boards/68.cpp index 710f4437..32adeb65 100644 --- a/src/boards/68.cpp +++ b/src/boards/68.cpp @@ -24,7 +24,7 @@ static uint8 chr_reg[4]; static uint8 kogame, prg_reg, nt1, nt2, mirr; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE, count; +static uint32 WRAMSIZE=0, count=0; static SFORMAT StateRegs[] = { @@ -156,8 +156,7 @@ void Mapper68_Init(CartInfo *info) { WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/69.cpp b/src/boards/69.cpp index bc256211..9975abfd 100644 --- a/src/boards/69.cpp +++ b/src/boards/69.cpp @@ -25,7 +25,7 @@ static uint8 cmdreg, preg[4], creg[8], mirr; static uint8 IRQa; static int32 IRQCount; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -266,8 +266,7 @@ void Mapper69_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; Mapper69_ESI(); diff --git a/src/boards/80.cpp b/src/boards/80.cpp index b99132c2..5480aec3 100644 --- a/src/boards/80.cpp +++ b/src/boards/80.cpp @@ -169,8 +169,7 @@ void Mapper80_Init(CartInfo *info) { GameStateRestore = StateRestore; if (info->battery) { - info->SaveGame[0] = wram; - info->SaveGameLen[0] = 256; + info->addSaveGameBuf( wram, sizeof(wram) ); } AddExState(&StateRegs80, ~0, 0, 0); diff --git a/src/boards/82.cpp b/src/boards/82.cpp index a1a68b66..01e4f7a4 100644 --- a/src/boards/82.cpp +++ b/src/boards/82.cpp @@ -25,7 +25,7 @@ static uint8 regs[9], ctrl; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -90,8 +90,7 @@ void Mapper82_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/__dummy_mapper.cpp b/src/boards/__dummy_mapper.cpp index 505f9169..17cdba57 100644 --- a/src/boards/__dummy_mapper.cpp +++ b/src/boards/__dummy_mapper.cpp @@ -92,8 +92,7 @@ void MapperNNN_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } */ AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/addrlatch.cpp b/src/boards/addrlatch.cpp index 67ae7d55..b3f44c88 100644 --- a/src/boards/addrlatch.cpp +++ b/src/boards/addrlatch.cpp @@ -26,7 +26,7 @@ static uint8 dipswitch; static void (*WSync)(void); static readfunc defread; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static DECLFW(LatchWrite) { latche = A; @@ -77,8 +77,7 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(WRAM, WRAMSIZE, 0, "WRAM"); } diff --git a/src/boards/bandai.cpp b/src/boards/bandai.cpp index d6670f56..e908a3ae 100644 --- a/src/boards/bandai.cpp +++ b/src/boards/bandai.cpp @@ -29,7 +29,7 @@ static uint8 IRQa; static int16 IRQCount, IRQLatch; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -317,8 +317,7 @@ void Mapper16_Init(CartInfo *info) { MapIRQHook = BandaiIRQHook; info->battery = 1; - info->SaveGame[0] = x24c0x_data + 256; - info->SaveGameLen[0] = 256; + info->addSaveGameBuf( x24c0x_data + 256, 256 ); AddExState(x24c0x_data, 256, 0, "DATA"); AddExState(&x24c02StateRegs, ~0, 0, 0); @@ -333,8 +332,7 @@ void Mapper159_Init(CartInfo *info) { MapIRQHook = BandaiIRQHook; info->battery = 1; - info->SaveGame[0] = x24c0x_data; - info->SaveGameLen[0] = 128; + info->addSaveGameBuf( x24c0x_data, 128 ); AddExState(x24c0x_data, 128, 0, "DATA"); AddExState(&x24c01StateRegs, ~0, 0, 0); @@ -378,8 +376,7 @@ void Mapper153_Init(CartInfo *info) { AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; @@ -599,8 +596,7 @@ void Mapper157_Init(CartInfo *info) { GameInfo->cspecial = SIS_DATACH; info->battery = 1; - info->SaveGame[0] = x24c0x_data; - info->SaveGameLen[0] = 512; + info->addSaveGameBuf( x24c0x_data, 512 ); AddExState(x24c0x_data, 512, 0, "DATA"); AddExState(&x24c01StateRegs, ~0, 0, 0); AddExState(&x24c02StateRegs, ~0, 0, 0); diff --git a/src/boards/cheapocabra.cpp b/src/boards/cheapocabra.cpp index 31837815..55483018 100644 --- a/src/boards/cheapocabra.cpp +++ b/src/boards/cheapocabra.cpp @@ -252,8 +252,7 @@ void Mapper111_Init(CartInfo *info) { if (flash) { FLASHROM = (uint8*)FCEU_gmalloc(FLASHROMSIZE); - info->SaveGame[0] = FLASHROM; - info->SaveGameLen[0] = FLASHROMSIZE; + info->addSaveGameBuf( FLASHROM, FLASHROMSIZE ); AddExState(FLASHROM, FLASHROMSIZE, 0, "FROM"); AddExState(&FlashRegs, ~0, 0, 0); diff --git a/src/boards/coolboy.cpp b/src/boards/coolboy.cpp index 48e218be..13a1e61a 100644 --- a/src/boards/coolboy.cpp +++ b/src/boards/coolboy.cpp @@ -454,8 +454,7 @@ void CommonInit(CartInfo* info, int submapper) Flash[i] = PRGptr[ROM_CHIP][i % PRGsize[ROM_CHIP]]; } SetupCartPRGMapping(FLASH_CHIP, Flash, PRGsize[ROM_CHIP], 1); - info->SaveGame[1] = Flash; - info->SaveGameLen[1] = PRGsize[ROM_CHIP]; + info->addSaveGameBuf( Flash, PRGsize[ROM_CHIP] ); } AddExState(EXPREGS, 4, 0, "EXPR"); diff --git a/src/boards/coolgirl.cpp b/src/boards/coolgirl.cpp index 95dcf825..d9a22331 100644 --- a/src/boards/coolgirl.cpp +++ b/src/boards/coolgirl.cpp @@ -2271,8 +2271,7 @@ void COOLGIRL_Init(CartInfo *info) { AddExState(WRAM, 32 * 1024, 0, "SRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = 32 * 1024; + info->addSaveGameBuf( WRAM, 32 * 1024); } } @@ -2281,8 +2280,7 @@ void COOLGIRL_Init(CartInfo *info) { SAVE_FLASH = (uint8*)FCEU_gmalloc(SAVE_FLASH_SIZE); SetupCartPRGMapping(FLASH_CHIP, SAVE_FLASH, SAVE_FLASH_SIZE, 1); AddExState(SAVE_FLASH, SAVE_FLASH_SIZE, 0, "SAVF"); - info->SaveGame[1] = SAVE_FLASH; - info->SaveGameLen[1] = SAVE_FLASH_SIZE; + info->addSaveGameBuf( SAVE_FLASH, SAVE_FLASH_SIZE ); } CFI = (uint8*)FCEU_gmalloc(sizeof(cfi_data) * 2); diff --git a/src/boards/datalatch.cpp b/src/boards/datalatch.cpp index 77b61328..a5bbf544 100644 --- a/src/boards/datalatch.cpp +++ b/src/boards/datalatch.cpp @@ -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) //{ // SetupCartPRGMapping(0x10, WRAM, info->battery_wram_size, 1); - // info->SaveGame[0] = WRAM; - // info->SaveGameLen[0] = info->battery_wram_size; + // info->addSaveGameBuf( WRAM, info->battery_wram_size ); //} else { // //well, this is annoying // SetupCartPRGMapping(0x10, WRAM, info->wram_size, 1); // 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->SaveGameLen[0] = info->battery_wram_size; + // info->addSaveGameBuf( WRAM + info->wram_size, info->battery_wram_size ); //} //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); if(info->battery_wram_size) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = 8192; + info->addSaveGameBuf( WRAM, 8192 ); } } else @@ -114,8 +111,7 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 ad WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(WRAM, WRAMSIZE, 0, "WRAM"); } @@ -158,8 +154,7 @@ void NROM_Init(CartInfo *info) { WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(WRAM, WRAMSIZE, 0, "WRAM"); } diff --git a/src/boards/edu2000.cpp b/src/boards/edu2000.cpp index 36f1ad1b..7c1270e0 100644 --- a/src/boards/edu2000.cpp +++ b/src/boards/edu2000.cpp @@ -70,8 +70,7 @@ void UNLEDU2000_Init(CartInfo *info) { WRAM = (uint8*)FCEU_gmalloc(32768); SetupCartPRGMapping(0x10, WRAM, 32768, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = 32768; + info->addSaveGameBuf( WRAM, 32768 ); } AddExState(WRAM, 32768, 0, "WRAM"); AddExState(StateRegs, ~0, 0, 0); diff --git a/src/boards/ffe.cpp b/src/boards/ffe.cpp index 51e591ee..674f0d22 100644 --- a/src/boards/ffe.cpp +++ b/src/boards/ffe.cpp @@ -141,8 +141,7 @@ void Mapper6_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/fns.cpp b/src/boards/fns.cpp index 5bb4a4e3..8b5c75ec 100644 --- a/src/boards/fns.cpp +++ b/src/boards/fns.cpp @@ -28,7 +28,7 @@ static uint8 DRegs[4]; static uint8 Buffer, BufferShift; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static uint8 *WRAM = NULL; static int kanji_pos, kanji_page, r40C0; @@ -256,8 +256,7 @@ void FNS_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); AddExState(DRegs, 4, 0, "DREG"); AddExState(&lreset, 8, 1, "LRST"); diff --git a/src/boards/mmc1.cpp b/src/boards/mmc1.cpp index bfe07a78..2265aa7e 100644 --- a/src/boards/mmc1.cpp +++ b/src/boards/mmc1.cpp @@ -306,8 +306,7 @@ static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int bram) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (bram) { - info->SaveGame[0] = WRAM + NONBRAMSIZE; - info->SaveGameLen[0] = bram * 1024; + info->addSaveGameBuf( WRAM + NONBRAMSIZE, bram * 1024 ); } } if (!chr) { diff --git a/src/boards/mmc2and4.cpp b/src/boards/mmc2and4.cpp index 5d9d73d6..3bde6f7e 100644 --- a/src/boards/mmc2and4.cpp +++ b/src/boards/mmc2and4.cpp @@ -25,7 +25,7 @@ static uint8 is10; static uint8 creg[4], latch0, latch1, preg, mirr; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -130,8 +130,7 @@ void Mapper10_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/mmc3.cpp b/src/boards/mmc3.cpp index 635d61e5..17d9509b 100644 --- a/src/boards/mmc3.cpp +++ b/src/boards/mmc3.cpp @@ -324,8 +324,7 @@ void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) { if (battery) { mmc3opts |= 2; - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, 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 diff --git a/src/boards/mmc5.cpp b/src/boards/mmc5.cpp index 35132731..a5e1e164 100644 --- a/src/boards/mmc5.cpp +++ b/src/boards/mmc5.cpp @@ -1021,22 +1021,23 @@ static void GenMMC5_Init(CartInfo *info, int wsize, int battery) { MMC5battery = battery; if (battery) { - info->SaveGame[0] = WRAM; + uint32 saveGameSize = 0; if (info->ines2) { - info->SaveGameLen[0] = info->battery_wram_size; + saveGameSize = info->battery_wram_size; } 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 //I added 64KB for the new 64KB homebrews if (wsize <= 16) - info->SaveGameLen[0] = 8192; + saveGameSize = 8192; else if(wsize == 64) - info->SaveGameLen[0] = 64*1024; + saveGameSize = 64*1024; else - info->SaveGameLen[0] = 32768; + saveGameSize = 32768; } + info->addSaveGameBuf( WRAM, saveGameSize ); } MMC5HackVROMMask = CHRmask4[0]; diff --git a/src/boards/n106.cpp b/src/boards/n106.cpp index cbbbc790..59399e1e 100644 --- a/src/boards/n106.cpp +++ b/src/boards/n106.cpp @@ -429,10 +429,8 @@ void Mapper19_Init(CartInfo *info) { AddExState(N106_StateRegs, ~0, 0, 0); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = 8192; - info->SaveGame[1] = IRAM; - info->SaveGameLen[1] = 128; + info->addSaveGameBuf( WRAM, 8192 ); + info->addSaveGameBuf( IRAM, 128 ); } } diff --git a/src/boards/onebus.cpp b/src/boards/onebus.cpp index 4336b77f..4391394e 100644 --- a/src/boards/onebus.cpp +++ b/src/boards/onebus.cpp @@ -320,8 +320,7 @@ void UNLOneBus_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } } } diff --git a/src/boards/sa-9602b.cpp b/src/boards/sa-9602b.cpp index a6a19bbe..409e5dd0 100644 --- a/src/boards/sa-9602b.cpp +++ b/src/boards/sa-9602b.cpp @@ -54,8 +54,7 @@ void SA9602B_Init(CartInfo *info) { GenMMC3_Init(info, 512, 0, 0, 0); pwrap = SA9602BPW; mmc3opts |= 2; - info->SaveGame[0] = UNIFchrrama; - info->SaveGameLen[0] = 32 * 1024; + info->addSaveGameBuf( UNIFchrrama, 32 * 1024 ); info->Power = SA9602BPower; AddExState(EXPREGS, 2, 0, "EXPR"); } diff --git a/src/boards/sb-2000.cpp b/src/boards/sb-2000.cpp index c2ea454a..cf3ad0e4 100644 --- a/src/boards/sb-2000.cpp +++ b/src/boards/sb-2000.cpp @@ -24,7 +24,7 @@ static uint8 preg[8]; static uint8 IRQa; static int16 IRQCount, IRQLatch; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; /* static uint8 *CHRRAM = NULL; static uint32 CHRRAMSIZE; @@ -187,8 +187,7 @@ void UNLSB2000_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/transformer.cpp b/src/boards/transformer.cpp index b1252552..642afbf6 100644 --- a/src/boards/transformer.cpp +++ b/src/boards/transformer.cpp @@ -21,7 +21,7 @@ #include "mapinc.h" 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? @@ -90,8 +90,7 @@ void Transformer_Init(CartInfo *info) { WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(WRAM, WRAMSIZE, 0, "WRAM"); } diff --git a/src/boards/unrom512.cpp b/src/boards/unrom512.cpp index 2fbe03dc..f2599f3a 100644 --- a/src/boards/unrom512.cpp +++ b/src/boards/unrom512.cpp @@ -168,6 +168,18 @@ static void UNROM512LatchClose(void) { 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) { info->Power = UNROM512LatchPower; info->Close = UNROM512LatchClose; @@ -205,9 +217,7 @@ void UNROM512_Init(CartInfo *info) { flash_data[i] = PRGptr[ROM_CHIP][i]; } 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->SaveGame[0] = flash_data; - //info->SaveGameLen[0] = PRGsize[ROM_CHIP]; + info->addSaveGameBuf( flash_data, flash_size, UNROM512_FlashReset ); flash_id[0] = 0xBF; flash_id[1] = 0xB5 + (ROM_size >> 4); diff --git a/src/boards/vrc2and4.cpp b/src/boards/vrc2and4.cpp index 3b7974b1..564c51bd 100644 --- a/src/boards/vrc2and4.cpp +++ b/src/boards/vrc2and4.cpp @@ -185,8 +185,7 @@ static void VRC24_Init(CartInfo *info) { AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if(info->battery) { - info->SaveGame[0]=WRAM; - info->SaveGameLen[0]=WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/vrc5.cpp b/src/boards/vrc5.cpp index 07de8010..0c9e3625 100644 --- a/src/boards/vrc5.cpp +++ b/src/boards/vrc5.cpp @@ -254,11 +254,10 @@ void QTAi_Init(CartInfo *info) { AddExState(WRAM, WRAMSIZE, 0, "WRAM"); 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 // an additional work ram. so we may save only half here, but I forgot what part is saved lol, will // find out later. - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/vrc6.cpp b/src/boards/vrc6.cpp index 51f58ebb..030f74c8 100644 --- a/src/boards/vrc6.cpp +++ b/src/boards/vrc6.cpp @@ -28,7 +28,7 @@ static uint8 prg[2], chr[8], mirr; static uint8 IRQLatch, IRQa, IRQd, IRQMode; static int32 IRQCount, CycleCount; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; static SFORMAT StateRegs[] = { @@ -379,8 +379,7 @@ void Mapper26_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/vrc7.cpp b/src/boards/vrc7.cpp index 38e5d83b..a37d76ff 100644 --- a/src/boards/vrc7.cpp +++ b/src/boards/vrc7.cpp @@ -24,7 +24,7 @@ static uint8 vrc7idx, preg[3], creg[8], mirr; static uint8 IRQLatch, IRQa, IRQd, IRQMode; static int32 IRQCount, CycleCount; static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; +static uint32 WRAMSIZE=0; #include "emu2413.h" @@ -204,8 +204,7 @@ void Mapper85_Init(CartInfo *info) { SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + info->addSaveGameBuf( WRAM, WRAMSIZE ); } GameStateRestore = StateRestore; VRC7_ESI(); diff --git a/src/cart.cpp b/src/cart.cpp index 55741b7f..fd829320 100644 --- a/src/cart.cpp +++ b/src/cart.cpp @@ -536,19 +536,27 @@ void FCEU_GeniePower(void) { } -void FCEU_SaveGameSave(CartInfo *LocalHWInfo) { - if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { +void FCEU_SaveGameSave(CartInfo *LocalHWInfo) +{ + if (LocalHWInfo->battery && !LocalHWInfo->SaveGame.empty()) + { FILE *sp; 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()); - } else { - for (int x = 0; x < 4; x++) - if (LocalHWInfo->SaveGame[x]) { - fwrite(LocalHWInfo->SaveGame[x], 1, - LocalHWInfo->SaveGameLen[x], sp); + } + else + { + for (size_t x = 0; x < LocalHWInfo->SaveGame.size(); x++) + { + 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 int disableBatteryLoading = 0; -void FCEU_LoadGameSave(CartInfo *LocalHWInfo) { - if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading) { +void FCEU_LoadGameSave(CartInfo *LocalHWInfo) +{ + if (LocalHWInfo->battery && !LocalHWInfo->SaveGame.empty() && !disableBatteryLoading) + { FILE *sp; std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); sp = FCEUD_UTF8fopen(soot, "rb"); 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(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"); } @@ -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) -void FCEU_ClearGameSave(CartInfo *LocalHWInfo) { - if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { - for (int x = 0; x < 4; x++) - if (LocalHWInfo->SaveGame[x]) - memset(LocalHWInfo->SaveGame[x], 0, LocalHWInfo->SaveGameLen[x]); +void FCEU_ClearGameSave(CartInfo *LocalHWInfo) +{ + if (LocalHWInfo->battery && !LocalHWInfo->SaveGame.empty()) + { + 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(); + } + } } } diff --git a/src/cart.h b/src/cart.h index ecc67948..0b581335 100644 --- a/src/cart.h +++ b/src/cart.h @@ -1,20 +1,45 @@ #ifndef CART_H #define CART_H -typedef struct { +#include + +struct CartInfo +{ // Set by mapper/board code: void (*Power)(void); void (*Reset)(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; + + 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. int mirror; // As set in the header or chunk. - // iNES/UNIF specific. Intended - // to help support games like "Karnov" - // that are not really MMC3 but are - // set to mapper 4. + // iNES/UNIF specific. Intended + // to help support games like "Karnov" + // that are not really MMC3 but are + // set to mapper 4. int mirrorAs2Bits; int battery; // Presence of an actual battery. int ines2; @@ -27,7 +52,33 @@ typedef struct { uint32 CRC32; // Should be set by the iNES/UNIF loading // code, used by mapper/board code, maybe // 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; diff --git a/src/ines.cpp b/src/ines.cpp index c2824a37..be7543a6 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -810,7 +810,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { head.cleanup(); - memset(&iNESCart, 0, sizeof(iNESCart)); + iNESCart.clear(); iNES2 = ((head.ROM_type2 & 0x0C) == 0x08); if(iNES2) diff --git a/src/movie.cpp b/src/movie.cpp index 018cccc8..f3d422db 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -984,23 +984,23 @@ bool MovieData::loadSaveramFrom(std::vector* buf) return false; } - for(int i=0;i<4;i++) + for (size_t i=0;iSaveGame.size();i++) { 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"); return false; } - if(currCartInfo->SaveGameLen[i] != static_cast(len)) + if(currCartInfo->SaveGame[i].buflen != static_cast(len)) { FCEU_PrintError("movie battery load mismatch 3"); return false; } - ms.fread(currCartInfo->SaveGame[i], len); + ms.fread(currCartInfo->SaveGame[i].bufptr, len); } return true; @@ -1011,16 +1011,15 @@ void MovieData::dumpSaveramTo(std::vector* buf, int compressionLevel) EMUFILE_MEMORY ms(buf); ms.write32le(currCartInfo->battery?1:0); - for(int i=0;i<4;i++) + for(size_t i=0;iSaveGame.size();i++) { - if(!currCartInfo->SaveGame[i]) + if (!currCartInfo->SaveGame[i].bufptr) { ms.write32le((u32)0); continue; } - - ms.write32le(currCartInfo->SaveGameLen[i]); - ms.fwrite(currCartInfo->SaveGame[i], currCartInfo->SaveGameLen[i]); + ms.write32le( static_cast(currCartInfo->SaveGame[i].buflen) ); + ms.fwrite(currCartInfo->SaveGame[i].bufptr, currCartInfo->SaveGame[i].buflen); } } diff --git a/src/unif.cpp b/src/unif.cpp index be20535a..9bcc44f7 100644 --- a/src/unif.cpp +++ b/src/unif.cpp @@ -104,7 +104,7 @@ static void ResetUNIF(void) { vramo = 0; boardname = 0; mirrortodo = 0; - memset(&UNIFCart, 0, sizeof(UNIFCart)); + UNIFCart.clear(); UNIFchrrama = 0; }