Add submapper 1 to mapper 452

This commit is contained in:
NewRisingSun
2022-12-29 23:12:47 +01:00
parent e85c0e2d56
commit f6b5f60399

View File

@@ -18,44 +18,85 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* DS-9-27. Absolutely insane PCB that overlays 8 KiB of WRAM into a selectable position between $8000 and $E000. */
#include "mapinc.h"
static uint8 *WRAM;
static uint32 WRAMSIZE;
static uint16 latch[2];
static uint8 submapper;
static void SetWRAM(uint16 A) {
setprg8r(0x10, A, 0);
SetWriteHandler(A, A |0x1FFF, CartBW);
}
static DECLFW(Mapper452_WriteLatch);
static void Mapper452_Sync(void) {
uint8 wramBank = latch[1] >>3 &6 |8;
if (latch[1] &2) {
setprg8(0x8000, latch[0] >>1);
setprg8(0xA000, latch[0] >>1);
setprg8(0xC000, latch[0] >>1);
setprg8(0xE000, latch[0] >>1);
setprg8r(0x10, (wramBank ^4) <<12, 0);
} else
if (latch[1] &8) {
setprg8(0x8000, latch[0] >>1 &~1 |0);
setprg8(0xA000, latch[0] >>1 &~1 |1);
setprg8(0xC000, latch[0] >>1 &~1 |2);
setprg8(0xE000, latch[0] >>1 &~1 |3 | latch[1] &4 | (latch[1] &0x04 && latch[1] &0x40? 8: 0));
SetWriteHandler(0x8000, 0xFFFF, Mapper452_WriteLatch);
if (submapper ==1) {
switch(latch[0] &0xF000) {
case 0xA000:
setprg16(0x8000, latch[0] >>1);
setprg8 (0xC000, 0);
SetWRAM(latch[0] <<4 &0x6000 |0x8000);
break;
case 0xC000:
setprg16(0x8000, latch[0] >>1 |0);
setprg16(0xC000, latch[0] >>1 |1);
SetWRAM(latch[0] <<4 &0x6000 |0x8000);
break;
case 0xD000:
setprg8(0x8000, latch[0]);
setprg8(0xA000, latch[0]);
setprg8(0xC000, latch[0]);
setprg8(0xE000, latch[0]);
SetWRAM(latch[0] <<4 &0x2000 |0x8000);
SetWRAM(latch[0] <<4 &0x2000 |0xC000);
break;
case 0xE000:
setprg16(0x8000, latch[0] >>1);
setprg16(0xC000, latch[0] &0x100? (latch[0] >>1 |7): 0);
SetWRAM(latch[0] <<4 &0x6000 |0x8000);
break;
default:
setprg16(0x8000, latch[0] >>1);
setprg16(0xC000, 0);
break;
}
setchr8(0);
setmirror(latch[0] &0x800? MI_H: MI_V);
} else {
setprg16(0x8000, latch[0] >>2);
setprg16(0xC000, 0);
uint8 wramBank = latch[1] >>3 &6 |8;
if (latch[1] &2) {
setprg8(0x8000, latch[0] >>1);
setprg8(0xA000, latch[0] >>1);
setprg8(0xC000, latch[0] >>1);
setprg8(0xE000, latch[0] >>1);
SetWRAM((wramBank ^4) <<12);
} else
if (latch[1] &8) {
setprg8(0x8000, latch[0] >>1 &~1 |0);
setprg8(0xA000, latch[0] >>1 &~1 |1);
setprg8(0xC000, latch[0] >>1 &~1 |2);
setprg8(0xE000, latch[0] >>1 &~1 |3 | latch[1] &4 | (latch[1] &0x04 && latch[1] &0x40? 8: 0));
} else {
setprg16(0x8000, latch[0] >>2);
setprg16(0xC000, 0);
}
SetWRAM(wramBank <<12);
setchr8(0);
setmirror(latch [1] &1 ^1);
}
setprg8r(0x10, wramBank <<12, 0);
setchr8(0);
setmirror(latch [1] &1 ^1);
}
static DECLFW(Mapper452_WriteLatch) {
latch[0] =A &0xFFF;
CartBW(A, V);
latch[0] =A &0xFFFF;
latch[1] =V;
Mapper452_Sync();
/* Do not relay to CartBW, as RAM mapped to locations other than $8000-$DFFF are not write-enabled. */
}
static void Mapper452_Reset(void) {
@@ -64,35 +105,32 @@ static void Mapper452_Reset(void) {
}
static void Mapper452_Power(void) {
latch[0] =latch[1] =0;
SetReadHandler(0x6000, 0xFFFF, CartBR);
Mapper452_Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xDFFF, Mapper452_WriteLatch);
SetWriteHandler(0xE000, 0xFFFF, CartBW);
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
}
static void Mapper452_Close(void) {
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}
static void StateRestore(int version) {
Mapper452_Sync();
Mapper452_Sync();
}
void Mapper452_Init(CartInfo *info) {
submapper =info->submapper;
info->Reset = Mapper452_Reset;
info->Power = Mapper452_Power;
info->Close = Mapper452_Close;
GameStateRestore = StateRestore;
WRAMSIZE = 8192;
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
WRAMSIZE =8192;
WRAM =(uint8*) FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&latch, 4, 0, "LATC");
}