From 4759fe64337b53b9ff92e33c2265f4069e401704 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Wed, 10 May 2017 04:07:50 +0800 Subject: [PATCH 1/4] add Mapper 158 --- src/boards/tengen.c | 105 +++++++++++++++++++++++++++++++++----------- src/ines.c | 2 +- src/ines.h | 1 + 3 files changed, 82 insertions(+), 26 deletions(-) diff --git a/src/boards/tengen.c b/src/boards/tengen.c index 70428b6..1672885 100644 --- a/src/boards/tengen.c +++ b/src/boards/tengen.c @@ -18,11 +18,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* Mapper 64 - Tengen 800032 Rambo-1 + * Mapper 158 - Tengen 800037 (Alien Syndrome Unl) +*/ + #include "mapinc.h" static uint8 cmd, mirr, regs[11]; static uint8 rmode, IRQmode, IRQCount, IRQa, IRQLatch; +static void (*cwrap)(uint32 A, uint8 V); +static void (*mwrap)(uint8 V); +static int nomirror; + static SFORMAT StateRegs[] = { { regs, 11, "REGS" }, { &cmd, 1, "CMDR" }, @@ -35,20 +43,20 @@ static SFORMAT StateRegs[] = { { 0 } }; -static void FP_FASTAPASS(1) M64IRQHook(int a) { +static void FP_FASTAPASS(1) RAMBO1IRQHook(int a) { static int32 smallcount; if (IRQmode) { smallcount += a; while (smallcount >= 4) { smallcount -= 4; IRQCount--; - if (IRQCount == 0xFF) + if(IRQCount == 0xFF) if (IRQa) X6502_IRQBegin(FCEU_IQEXT); } } } -static void M64HBHook(void) { +static void RAMBO1HBHook(void) { if ((!IRQmode) && (scanline != 240)) { rmode = 0; IRQCount--; @@ -63,28 +71,31 @@ static void M64HBHook(void) { static void Sync(void) { if (cmd & 0x20) { - setchr1(0x0000, regs[0]); - setchr1(0x0400, regs[8]); - setchr1(0x0800, regs[1]); - setchr1(0x0C00, regs[9]); + cwrap(0x0000, regs[0]); + cwrap(0x0400, regs[8]); + cwrap(0x0800, regs[1]); + cwrap(0x0C00, regs[9]); } else { - setchr2(0x0000, regs[0] >> 1); - setchr2(0x0800, regs[1] >> 1); + cwrap(0x0000, (regs[0] & 0xFE)); + cwrap(0x0400, (regs[0] & 0xFE) | 1); + cwrap(0x0800, (regs[1] & 0xFE)); + cwrap(0x0C00, (regs[1] & 0xFE) | 1); } - setchr1(0x1000, regs[2]); - setchr1(0x1400, regs[3]); - setchr1(0x1800, regs[4]); - setchr1(0x1C00, regs[5]); - setprg8(0x8000, regs[6]); - setprg8(0xA000, regs[7]); - setprg8(0xC000, regs[10]); + cwrap(0x1000, regs[2]); + cwrap(0x1400, regs[3]); + cwrap(0x1800, regs[4]); + cwrap(0x1C00, regs[5]); + setprg8(0x8000,regs[6]); + setprg8(0xA000,regs[7]); + setprg8(0xC000,regs[10]); setprg8(0xE000, ~0); - setmirror(mirr); + if (mwrap) mwrap(mirr); } -static DECLFW(M64Write) { + +static DECLFW(RAMBO1_Write) { switch (A & 0xF001) { - case 0xA000: mirr = (V & 1) ^ 1; Sync(); break; + case 0xA000: if (mwrap) mwrap(V); break; case 0x8000: cmd = V; break; case 0x8001: if ((cmd & 0xF) < 10) @@ -117,23 +128,67 @@ static DECLFW(M64Write) { } } -static void M64Power(void) { +static void GENMWRAP(uint8 V) { + mirr = V; + setmirror((V & 1) ^ 1); +} + +static void GENNOMWRAP(uint8 V) { + mirr = V; +} + +static void RAMBO1Power(void) { cmd = mirr = 0; regs[0] = regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = ~0; regs[6] = regs[7] = regs[8] = regs[9] = regs[10] = ~0; Sync(); SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M64Write); + SetWriteHandler(0x8000,0xFFFF, RAMBO1_Write); } static void StateRestore(int version) { Sync(); } -void Mapper64_Init(CartInfo *info) { - info->Power = M64Power; - GameHBIRQHook = M64HBHook; - MapIRQHook = M64IRQHook; +static void RAMBO1_Init(CartInfo *info) { + info->Power = RAMBO1Power; + GameHBIRQHook = RAMBO1HBHook; + MapIRQHook = RAMBO1IRQHook; GameStateRestore = StateRestore; AddExState(&StateRegs, ~0, 0, 0); } + +static void M64CWRAP(uint32 A, uint8 V) { + setchr1(A, V); +} + +void Mapper64_Init(CartInfo *info) { + cwrap = M64CWRAP; + mwrap = GENMWRAP; + RAMBO1_Init(info); +} + +static uint8 M158MIR[8]; +static uint8 PPUCHRBus; + +static void FP_FASTAPASS(1) M158PPU(uint32 A) { + A &= 0x1FFF; + A >>= 10; + PPUCHRBus = A; + setmirror(MI_0 + M158MIR[A]); +} + +static void M158CWRAP(uint32 A, uint8 V) { + M158MIR[A >> 10] = (V >> 7) & 1; + if (PPUCHRBus == (A >> 10)) + setmirror(MI_0 + ((V >> 7) & 1)); + setchr1(A, V); +} + +void Mapper158_Init(CartInfo *info) { + cwrap = M158CWRAP; + mwrap = GENNOMWRAP; + PPU_hook = M158PPU; + RAMBO1_Init(info); + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} diff --git a/src/ines.c b/src/ines.c index c1a6c3c..0c579a9 100644 --- a/src/ines.c +++ b/src/ines.c @@ -547,7 +547,7 @@ static BMAPPINGLocal bmap[] = { {(uint8_t*)"", 155, Mapper155_Init}, {(uint8_t*)"", 156, Mapper156_Init}, {(uint8_t*)"BANDAI BARCODE", 157, Mapper157_Init}, -// {(uint8_t*)"", 158, Mapper158_Init}, + {(uint8_t*)"TENGEN 800037", 158, Mapper158_Init}, {(uint8_t*)"BANDAI 24C01", 159, Mapper159_Init}, // Different type of EEPROM on the bandai board {(uint8_t*)"SA009", 160, SA009_Init}, // {(uint8_t*)"", 161, Mapper161_Init}, diff --git a/src/ines.h b/src/ines.h index 12b65fb..28e84ea 100644 --- a/src/ines.h +++ b/src/ines.h @@ -140,6 +140,7 @@ void Mapper154_Init(CartInfo *); void Mapper155_Init(CartInfo *); void Mapper156_Init(CartInfo *); void Mapper157_Init(CartInfo *); +void Mapper158_Init(CartInfo *); void Mapper159_Init(CartInfo *); void Mapper163_Init(CartInfo *); void Mapper164_Init(CartInfo *); From 1815643134131112d96531449f475ed247fd9e57 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Wed, 10 May 2017 04:09:25 +0800 Subject: [PATCH 2/4] update ines-correct, move Alien Syndrome (Tengen) to M158 --- src/ines-correct.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ines-correct.h b/src/ines-correct.h index 7c13377..202c183 100644 --- a/src/ines-correct.h +++ b/src/ines-correct.h @@ -154,7 +154,6 @@ {0xa1dc16c0, 116, -1}, /* Street Heroes (Sachen) [b1] */ {0xe40dfb7e, 116, -1}, /* Somari (P conf.) */ {0xc9371ebb, 116, -1}, /* Somari (W conf.) */ - {0xcbf4366f, 118, 8}, /* Alien Syndrome (U.S. unlicensed) */ {0x78b657ac, 118, -1}, /* Armadillo */ {0x90c773c1, 118, -1}, /* Goal! 2 */ {0xb9b4d9e0, 118, -1}, /* NES Play Action Football */ @@ -199,6 +198,7 @@ {0x0be0a328, 157, 8}, /* Datach SD Gundam Wars */ {0x5b457641, 157, 8}, /* Datach Ultraman Club */ {0xf51a7f46, 157, 8}, /* Datach Yuu Yuu Hakusho */ + {0xcbf4366f, 158, 8}, /* Alien Syndrome (U.S. unlicensed) */ {0xe170404c, 159, -1}, /* SD Gundam Gaiden - Knight Gundam Monogatari (J) (V1.0) [!] */ {0x276ac722, 159, -1}, /* SD Gundam Gaiden - Knight Gundam Monogatari (J) (V1.1) [!] */ {0x0cf42e69, 159, -1}, /* Magical Taruruuto-kun - Fantastic World!! (J) (V1.0) [!] */ From d6cdc8089496f48868c895f1f5c14175740dbf3c Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Wed, 10 May 2017 04:13:42 +0800 Subject: [PATCH 3/4] Update tengen.c --- src/boards/tengen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/boards/tengen.c b/src/boards/tengen.c index 1672885..26fdf0c 100644 --- a/src/boards/tengen.c +++ b/src/boards/tengen.c @@ -85,9 +85,9 @@ static void Sync(void) { cwrap(0x1400, regs[3]); cwrap(0x1800, regs[4]); cwrap(0x1C00, regs[5]); - setprg8(0x8000,regs[6]); - setprg8(0xA000,regs[7]); - setprg8(0xC000,regs[10]); + setprg8(0x8000, regs[6]); + setprg8(0xA000, regs[7]); + setprg8(0xC000, regs[10]); setprg8(0xE000, ~0); if (mwrap) mwrap(mirr); } From 605b88f842d610779e885091cad328fe02556df3 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Wed, 10 May 2017 04:16:56 +0800 Subject: [PATCH 4/4] Update tengen.c --- src/boards/tengen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/boards/tengen.c b/src/boards/tengen.c index 26fdf0c..ff254a7 100644 --- a/src/boards/tengen.c +++ b/src/boards/tengen.c @@ -50,7 +50,7 @@ static void FP_FASTAPASS(1) RAMBO1IRQHook(int a) { while (smallcount >= 4) { smallcount -= 4; IRQCount--; - if(IRQCount == 0xFF) + if (IRQCount == 0xFF) if (IRQa) X6502_IRQBegin(FCEU_IQEXT); } } @@ -143,7 +143,7 @@ static void RAMBO1Power(void) { regs[6] = regs[7] = regs[8] = regs[9] = regs[10] = ~0; Sync(); SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000,0xFFFF, RAMBO1_Write); + SetWriteHandler(0x8000, 0xFFFF, RAMBO1_Write); } static void StateRestore(int version) {