From df3d5c9bbe3f5846c99e804b1bb06b268c5dd325 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 11 Dec 2016 23:40:17 +0000 Subject: [PATCH] support chrram on uxrom via nes 2.0 --- trunk/src/boards/datalatch.cpp | 61 +++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/trunk/src/boards/datalatch.cpp b/trunk/src/boards/datalatch.cpp index 342ef5bd..dd8acf8f 100644 --- a/trunk/src/boards/datalatch.cpp +++ b/trunk/src/boards/datalatch.cpp @@ -42,7 +42,7 @@ static void LatchPower(void) { if (WRAM) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } else { SetReadHandler(0x8000, 0xFFFF, CartBR); } @@ -68,15 +68,58 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 ad info->Power = LatchPower; info->Close = LatchClose; GameStateRestore = StateRestore; - if (wram) { - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; + if(info->ines2) + if(info->battery_wram_size + info->wram_size > 0) + wram = 1; + if (wram) + { + if(info->ines2) + { + //I would like to do it in this way, but FCEUX is woefully inadequate + //for instance if WRAMSIZE is large, the cheat pointers may get overwritten. and it's just a giant mess. + //WRAMSIZE = info->battery_wram_size + info->wram_size; + //WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + //if(!info->wram_size && !info->battery_wram_size) {} + //else if(info->wram_size && !info->battery_wram_size) + // SetupCartPRGMapping(0x10, WRAM, info->wram_size, 1); + //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; + //} 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; + //} + + //this is more likely the only practical scenario + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + setprg8r(0x10, 0x6000, 0); + if(info->battery_wram_size) + { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = 8192; + } } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + else + { + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + } AddExState(&latche, 1, 0, "LATC"); AddExState(&bus_conflict, 1, 0, "BUSC");