From 254ebe543631a9ced7e5c8200776b5806e67e229 Mon Sep 17 00:00:00 2001 From: Oggom Date: Sun, 28 Jun 2015 03:38:55 +0200 Subject: [PATCH 1/2] Backport r172 - cheat ram fix sync with FCEUX --- src/boards/112.c | 1 + src/boards/15.c | 2 +- src/boards/156.c | 1 + src/boards/164.c | 9 +- src/boards/177.c | 1 + src/boards/178.c | 1 + src/boards/18.c | 1 + src/boards/186.c | 1 + src/boards/228.c | 1 + src/boards/246.c | 1 + src/boards/252.c | 1 + src/boards/253.c | 1 + src/boards/32.c | 1 + src/boards/34.c | 1 + src/boards/68.c | 1 + src/boards/69.c | 4 +- src/boards/79.c | 1 + src/boards/80.c | 1 + src/boards/82.c | 1 + src/boards/99.c | 1 + src/boards/KS7012.c | 1 + src/boards/KS7017.c | 1 + src/boards/KS7037.c | 1 + src/boards/addrlatch.c | 1 + src/boards/bandai.c | 2 + src/boards/coolboy.c | 7 +- src/boards/dance2000.c | 1 + src/boards/datalatch.c | 4 + src/boards/edu2000.c | 1 + src/boards/famicombox.c | 14 +- src/boards/ffe.c | 1 + src/boards/lh32.c | 1 + src/boards/lh53.c | 1 + src/boards/mmc2and4.c | 2 + src/boards/mmc5.c | 325 ++++++++++++++++++++++----------------- src/boards/onebus.c | 22 +-- src/boards/pec-586.c | 1 + src/boards/transformer.c | 3 +- src/boards/vrc2and4.c | 7 +- src/boards/vrc3.c | 3 +- src/boards/vrc5.c | 1 + src/boards/vrc6.c | 7 +- src/boards/vrc7.c | 1 + src/boards/yoko.c | 1 + src/ines.h | 1 + src/ppu.h | 1 + zzz_todo.txt | 1 + 47 files changed, 266 insertions(+), 178 deletions(-) diff --git a/src/boards/112.c b/src/boards/112.c index 6c184b1..a95cb5b 100644 --- a/src/boards/112.c +++ b/src/boards/112.c @@ -72,6 +72,7 @@ static void M112Power(void) { SetWriteHandler(0x4020, 0x5FFF, M112Write); SetReadHandler(0x6000, 0x7FFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(8, 0x6000, WRAM); } static void StateRestore(int version) { diff --git a/src/boards/15.c b/src/boards/15.c index 9eae1d7..5e70baf 100644 --- a/src/boards/15.c +++ b/src/boards/15.c @@ -76,6 +76,7 @@ static void M15Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetWriteHandler(0x8000, 0xFFFF, M15Write); SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); Sync(); } @@ -99,7 +100,6 @@ void Mapper15_Init(CartInfo *info) { WRAMSIZE = 8192; WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); if (info->battery) { info->SaveGame[0] = WRAM; info->SaveGameLen[0] = WRAMSIZE; diff --git a/src/boards/156.c b/src/boards/156.c index a484299..24ba371 100644 --- a/src/boards/156.c +++ b/src/boards/156.c @@ -92,6 +92,7 @@ static void M156Power(void) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); SetWriteHandler(0xC000, 0xCFFF, M156Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M156Close(void) { diff --git a/src/boards/164.c b/src/boards/164.c index c4d9fdd..35052ff 100644 --- a/src/boards/164.c +++ b/src/boards/164.c @@ -351,7 +351,7 @@ static DECLFR(ReadLow) { case 0x5100: return reg[2] | reg[0] | reg[1] | reg[3] ^ 0xff; break; case 0x5500: if (trigger) - return reg[2] | reg[1]; // Lei Dian Huang Bi Ka Qiu Chuan Shuo (NJ046) may broke other games + return reg[2] | reg[1]; // Lei Dian Huang Bi Ka Qiu Chuan Shuo (NJ046) may broke other games else return 0; } @@ -368,7 +368,7 @@ static void M163HB(void) { setchr4(0x1000, 1); } /* - if(scanline>=127) // Hu Lu Jin Gang (NJ039) (Ch) [!] don't like it + if(scanline>=127) // Hu Lu Jin Gang (NJ039) (Ch) [!] don't like it { setchr4(0x0000,1); setchr4(0x1000,1); @@ -397,6 +397,7 @@ static void Power(void) { SetWriteHandler(0x5000, 0x5FFF, Write); SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); WSync(); } @@ -431,7 +432,7 @@ static DECLFW(Write2) { trigger ^= 1; } laststrobe = V; - } else if (A == 0x5100 && V == 6) //damn thoose protected games + } else if (A == 0x5100 && V == 6) //damn thoose protected games setprg32(0x8000, 3); else switch (A & 0x7300) { @@ -450,6 +451,7 @@ static void Power2(void) { SetWriteHandler(0x5000, 0x5FFF, Write2); SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); WSync(); } @@ -503,6 +505,7 @@ static void Power3(void) { SetWriteHandler(0x5000, 0x5FFF, Write3); SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); WSync(); } diff --git a/src/boards/177.c b/src/boards/177.c index 04fd9c8..0416060 100644 --- a/src/boards/177.c +++ b/src/boards/177.c @@ -50,6 +50,7 @@ static void M177Power(void) { SetWriteHandler(0x6000, 0x7fff, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, M177Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M177Close(void) { diff --git a/src/boards/178.c b/src/boards/178.c index cfd0392..775fece 100644 --- a/src/boards/178.c +++ b/src/boards/178.c @@ -133,6 +133,7 @@ static void M178Power(void) { SetReadHandler(0x6000, 0x7fff, CartBR); SetWriteHandler(0x6000, 0x7fff, CartBW); SetReadHandler(0x8000, 0xffff, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M178SndClk(int a) { diff --git a/src/boards/18.c b/src/boards/18.c index 43b4515..c0018ca 100644 --- a/src/boards/18.c +++ b/src/boards/18.c @@ -89,6 +89,7 @@ static void M18Power(void) { SetWriteHandler(0x8000, 0x9FFF, M18WritePrg); SetWriteHandler(0xA000, 0xDFFF, M18WriteChr); SetWriteHandler(0xE000, 0xFFFF, M18WriteIRQ); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void FP_FASTAPASS(1) M18IRQHook(int a) { diff --git a/src/boards/186.c b/src/boards/186.c index 137beaa..10902dc 100644 --- a/src/boards/186.c +++ b/src/boards/186.c @@ -69,6 +69,7 @@ static void M186Power(void) { SetWriteHandler(0x4200, 0x43FF, M186Write); SetReadHandler(0x4400, 0x4FFF, ASWRAM); SetWriteHandler(0x4400, 0x4FFF, BSWRAM); + FCEU_CheatAddRAM(32, 0x6000, WRAM); regs[0] = regs[1] = regs[2] = regs[3]; Sync(); } diff --git a/src/boards/228.c b/src/boards/228.c index bf39739..9b63da3 100644 --- a/src/boards/228.c +++ b/src/boards/228.c @@ -61,6 +61,7 @@ static DECLFW(M228Write) { static void M228Reset(void) { areg = 0x8000; vreg = 0; + memset(mram, 0, sizeof(mram)); Sync(); } diff --git a/src/boards/246.c b/src/boards/246.c index fe605e4..3d673d8 100644 --- a/src/boards/246.c +++ b/src/boards/246.c @@ -54,6 +54,7 @@ static void M246Power(void) { SetReadHandler(0x6800, 0x6FFF, CartBR); SetWriteHandler(0x6800, 0x6FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M246Close(void) { diff --git a/src/boards/252.c b/src/boards/252.c index 2c4b24b..9962e08 100644 --- a/src/boards/252.c +++ b/src/boards/252.c @@ -80,6 +80,7 @@ static void M252Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, M252Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M252IRQ(int a) { diff --git a/src/boards/253.c b/src/boards/253.c index e79662a..3ed9bfe 100644 --- a/src/boards/253.c +++ b/src/boards/253.c @@ -96,6 +96,7 @@ static void M253Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, M253Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M253Close(void) { diff --git a/src/boards/32.c b/src/boards/32.c index 12f380a..50b91da 100644 --- a/src/boards/32.c +++ b/src/boards/32.c @@ -75,6 +75,7 @@ static void M32Power(void) { SetWriteHandler(0x9000, 0x9FFF, M32Write1); SetWriteHandler(0xA000, 0xAFFF, M32Write2); SetWriteHandler(0xB000, 0xBFFF, M32Write3); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M32Close(void) { diff --git a/src/boards/34.c b/src/boards/34.c index 71f1b30..5c27b00 100644 --- a/src/boards/34.c +++ b/src/boards/34.c @@ -66,6 +66,7 @@ static void M34Power(void) { SetWriteHandler(0x6000, 0x7ffc, CartBW); SetReadHandler(0x8000, 0xffff, CartBR); SetWriteHandler(0x7ffd, 0xffff, M34Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M34Close(void) { diff --git a/src/boards/68.c b/src/boards/68.c index a38e567..710f443 100644 --- a/src/boards/68.c +++ b/src/boards/68.c @@ -134,6 +134,7 @@ static void M68Power(void) { SetWriteHandler(0xF000, 0xFFFF, M68WriteROM); SetWriteHandler(0x6000, 0x6000, M68WriteLo); SetWriteHandler(0x6001, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M68Close(void) { diff --git a/src/boards/69.c b/src/boards/69.c index 3babcd6..4a2dfb6 100644 --- a/src/boards/69.c +++ b/src/boards/69.c @@ -2,6 +2,7 @@ * * Copyright notice for this file: * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -166,7 +167,7 @@ static void DoAYSQ(int x) { } static void DoAYSQHQ(int x) { - int32 V; + uint32 V; int32 freq = ((sreg[x << 1] | ((sreg[(x << 1) + 1] & 15) << 8)) + 1) << 4; int32 amp = (sreg[0x8 + x] & 15) << 6; @@ -231,6 +232,7 @@ static void M69Power(void) { SetWriteHandler(0xA000, 0xBFFF, M69Write1); SetWriteHandler(0xC000, 0xDFFF, M69SWrite0); SetWriteHandler(0xE000, 0xFFFF, M69SWrite1); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M69Close(void) { diff --git a/src/boards/79.c b/src/boards/79.c index 0aa35e2..14d9ac7 100644 --- a/src/boards/79.c +++ b/src/boards/79.c @@ -2,6 +2,7 @@ * * Copyright notice for this file: * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/boards/80.c b/src/boards/80.c index 7b81702..a882f4b 100644 --- a/src/boards/80.c +++ b/src/boards/80.c @@ -2,6 +2,7 @@ * * Copyright notice for this file: * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/boards/82.c b/src/boards/82.c index c073997..f810753 100644 --- a/src/boards/82.c +++ b/src/boards/82.c @@ -68,6 +68,7 @@ static void M82Power(void) { SetReadHandler(0x6000, 0xffff, CartBR); SetWriteHandler(0x6000, 0x7fff, CartBW); SetWriteHandler(0x7ef0, 0x7efc, M82Write); // external WRAM might end at $73FF + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M82Close(void) { diff --git a/src/boards/99.c b/src/boards/99.c index e54ebd7..cf3bb14 100644 --- a/src/boards/99.c +++ b/src/boards/99.c @@ -51,6 +51,7 @@ static void M99Power(void) { SetWriteHandler(0x4016, 0x4016, M99Write); SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M99Close(void) { diff --git a/src/boards/KS7012.c b/src/boards/KS7012.c index 63550af..c9de10c 100644 --- a/src/boards/KS7012.c +++ b/src/boards/KS7012.c @@ -54,6 +54,7 @@ static void UNLKS7012Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, UNLKS7012Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void UNLKS7012Reset(void) { diff --git a/src/boards/KS7017.c b/src/boards/KS7017.c index 8f4c072..d0d5c0c 100644 --- a/src/boards/KS7017.c +++ b/src/boards/KS7017.c @@ -87,6 +87,7 @@ static void UNLKS7017Power(void) { SetReadHandler(0x8000, 0xFFFF, CartBR); SetReadHandler(0x4030, 0x4030, FDSRead4030); SetWriteHandler(0x4020, 0x5FFF, UNLKS7017Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void UNLKS7017Close(void) { diff --git a/src/boards/KS7037.c b/src/boards/KS7037.c index efe43f2..232e758 100644 --- a/src/boards/KS7037.c +++ b/src/boards/KS7037.c @@ -82,6 +82,7 @@ static void LH10Power(void) { SetWriteHandler(0x8000, 0xBFFF, UNLKS7037Write); SetWriteHandler(0xC000, 0xDFFF, CartBW); SetWriteHandler(0xE000, 0xFFFF, UNLKS7037Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void Close(void) { diff --git a/src/boards/addrlatch.c b/src/boards/addrlatch.c index 299f6e4..dc0128e 100644 --- a/src/boards/addrlatch.c +++ b/src/boards/addrlatch.c @@ -44,6 +44,7 @@ static void LatchPower(void) { if (WRAM) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } else SetReadHandler(0x6000, 0xFFFF, defread); SetWriteHandler(addrreg0, addrreg1, LatchWrite); diff --git a/src/boards/bandai.c b/src/boards/bandai.c index 327add0..856ba9d 100644 --- a/src/boards/bandai.c +++ b/src/boards/bandai.c @@ -2,6 +2,7 @@ * * Copyright notice for this file: * Copyright (C) 2007 CaH4e3 + * Copyright (C) 2011 FCEUX team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -269,6 +270,7 @@ static void M153Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, BandaiWrite); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } diff --git a/src/boards/coolboy.c b/src/boards/coolboy.c index 2e6d704..a5c5ffa 100644 --- a/src/boards/coolboy.c +++ b/src/boards/coolboy.c @@ -1,4 +1,4 @@ -/* FCE Ultra - NES/Famicom Emulator +п»ї/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2015 CaH4e3 @@ -45,12 +45,9 @@ static void COOLBOYCW(uint32 A, uint8 V) { } static void COOLBOYPW(uint32 A, uint8 V) { - uint32 mask, shift; + uint32 mask = 0x3F; uint32 base = ((EXPREGS[0] & 0x07) >> 0) | ((EXPREGS[1] & 0x10) >> 1) | ((EXPREGS[1] & 0x0C) << 2) | ((EXPREGS[0] & 0x30) << 2); switch(EXPREGS[0] & 0xC0) { - case 0x00: - mask = 0x3F; - break; case 0x80: mask = 0x1F; break; diff --git a/src/boards/dance2000.c b/src/boards/dance2000.c index 4494f7b..78fc4b7 100644 --- a/src/boards/dance2000.c +++ b/src/boards/dance2000.c @@ -70,6 +70,7 @@ static void UNLD2000Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, UNLD2000Read); SetWriteHandler(0x5000, 0x5FFF, UNLD2000Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void FP_FASTAPASS(1) UNL2000Hook(uint32 A) { diff --git a/src/boards/datalatch.c b/src/boards/datalatch.c index 354429b..17c9f1c 100644 --- a/src/boards/datalatch.c +++ b/src/boards/datalatch.c @@ -19,6 +19,7 @@ */ #include "mapinc.h" +#include "../ines.h" static uint8 latche, latcheinit, bus_conflict; static uint16 addrreg0, addrreg1; @@ -41,6 +42,7 @@ static void LatchPower(void) { if (WRAM) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } else { SetReadHandler(0x8000, 0xFFFF, CartBR); } @@ -99,6 +101,8 @@ static void NROMPower(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + #ifdef DEBUG_MAPPER SetWriteHandler(0x4020, 0xFFFF, NROMWrite); #endif diff --git a/src/boards/edu2000.c b/src/boards/edu2000.c index a872639..36f1ad1 100644 --- a/src/boards/edu2000.c +++ b/src/boards/edu2000.c @@ -48,6 +48,7 @@ static void UNLEDU2000Power(void) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0xFFFF, CartBW); SetWriteHandler(0x8000, 0xFFFF, UNLEDU2000HiWrite); + FCEU_CheatAddRAM(32, 0x6000, WRAM); reg = 0; Sync(); } diff --git a/src/boards/famicombox.c b/src/boards/famicombox.c index 1930ad9..a47823f 100644 --- a/src/boards/famicombox.c +++ b/src/boards/famicombox.c @@ -53,14 +53,14 @@ static DECLFW(SSSNROMWrite) { static DECLFR(SSSNROMRead) { // FCEU_printf("read %04x\n",A); switch (A & 7) { - case 0: return regs[0] = 0xff; // clear all exceptions + case 0: return regs[0] = 0xff; // clear all exceptions case 2: return 0xc0; // DIP selftest + freeplay case 3: return 0x00; // 0, 1 - attract - // 2 - // 4 - menu - // 8 - self check and game casette check - // 10 - lock? - // 20 - game title & count display + // 2 + // 4 - menu + // 8 - self check and game casette check + // 10 - lock? + // 20 - game title & count display case 7: return 0x22; // TV type, key not turned, relay B default: return 0; } @@ -79,6 +79,7 @@ static void SSSNROMPower(void) { SetReadHandler(0x6000, 0x7FFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void SSSNROMReset(void) { @@ -109,7 +110,6 @@ void SSSNROM_Init(CartInfo *info) { WRAMSIZE = 16384; WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); AddExState(&StateRegs, ~0, 0, 0); } diff --git a/src/boards/ffe.c b/src/boards/ffe.c index 48b1c70..ff68125 100644 --- a/src/boards/ffe.c +++ b/src/boards/ffe.c @@ -102,6 +102,7 @@ static void FFEPower(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x6000, 0x7FFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, FFEWriteLatch); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void FP_FASTAPASS(1) FFEIRQHook(int a) { diff --git a/src/boards/lh32.c b/src/boards/lh32.c index 2150aee..3983327 100644 --- a/src/boards/lh32.c +++ b/src/boards/lh32.c @@ -52,6 +52,7 @@ static void LH32Power(void) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0xC000, 0xDFFF, CartBW); SetWriteHandler(0x6000, 0x6000, LH32Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void LH32Close(void) { diff --git a/src/boards/lh53.c b/src/boards/lh53.c index a0c56b0..7cfc5b3 100644 --- a/src/boards/lh53.c +++ b/src/boards/lh53.c @@ -80,6 +80,7 @@ static void LH53Power(void) { SetWriteHandler(0xB800, 0xD7FF, LH53RamWrite); SetWriteHandler(0xE000, 0xEFFF, LH53IRQaWrite); SetWriteHandler(0xF000, 0xFFFF, LH53Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void LH53Close(void) { diff --git a/src/boards/mmc2and4.c b/src/boards/mmc2and4.c index 194163b..46b81aa 100644 --- a/src/boards/mmc2and4.c +++ b/src/boards/mmc2and4.c @@ -2,6 +2,7 @@ * * Copyright notice for this file: * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -94,6 +95,7 @@ static void MMC2and4Power(void) { if (is10) { SetReadHandler(0x6000, 0x7FFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0xA000, 0xFFFF, MMC2and4Write); diff --git a/src/boards/mmc5.c b/src/boards/mmc5.c index 593d51f..7867c3c 100644 --- a/src/boards/mmc5.c +++ b/src/boards/mmc5.c @@ -78,7 +78,7 @@ static uint8 PRGBanks[4]; static uint8 WRAMPage; static uint16 CHRBanksA[8], CHRBanksB[4]; static uint8 WRAMMaskEnable[2]; -uint8 mmc5ABMode; /* A=0, B=1 */ +uint8 mmc5ABMode; /* A=0, B=1 */ static uint8 IRQScanline, IRQEnable; static uint8 CHRMode, NTAMirroring, NTFill, ATFill; @@ -88,12 +88,13 @@ static uint8 MMC5LineCounter; static uint8 mmc5psize, mmc5vsize; static uint8 mul[2]; +static uint32 WRAMSIZE = 0; static uint8 *WRAM = NULL; static uint8 *MMC5fill = NULL; static uint8 *ExRAM = NULL; -static uint8 MMC5WRAMsize; -static uint8 MMC5WRAMIndex[8]; +static uint8 MMC5WRAMsize; //configuration, not state +static uint8 MMC5WRAMIndex[8]; //configuration, not state static uint8 MMC5ROMWrProtect[4]; static uint8 MMC5MemIn[5]; @@ -108,32 +109,32 @@ typedef struct __cartdata { cartdata MMC5CartList[] = { - { 0x6f4e4312, 4 }, /* Aoki Ookami to Shiroki Mejika - Genchou Hishi */ - { 0x15fe6d0f, 2 }, /* Bandit Kings of Ancient China */ - { 0x671f23a8, 0 }, /* Castlevania III - Dracula's Curse (E) */ - { 0xcd4e7430, 0 }, /* Castlevania III - Dracula's Curse (KC) */ - { 0xed2465be, 0 }, /* Castlevania III - Dracula's Curse (U) */ - { 0xfe3488d1, 2 }, /* Daikoukai Jidai */ - { 0x0ec6c023, 1 }, /* Gemfire */ - { 0x0afb395e, 0 }, /* Gun Sight */ - { 0x1ced086f, 2 }, /* Ishin no Arashi */ - { 0x9cbadc25, 1 }, /* Just Breed */ - { 0x6396b988, 2 }, /* L'Empereur (J) */ - { 0x9c18762b, 2 }, /* L'Empereur (U) */ - { 0xb0480ae9, 0 }, /* Laser Invasion */ - { 0xb4735fac, 0 }, /* Metal Slader Glory */ - { 0xf540677b, 4 }, /* Nobunaga no Yabou - Bushou Fuuun Roku */ - { 0xeee9a682, 2 }, /* Nobunaga no Yabou - Sengoku Gunyuu Den (J) (PRG0) */ - { 0xf9b4240f, 2 }, /* Nobunaga no Yabou - Sengoku Gunyuu Den (J) (PRG1) */ - { 0x8ce478db, 2 }, /* Nobunaga's Ambition 2 */ - { 0xf011e490, 4 }, /* Romance of The Three Kingdoms II */ - { 0xbc80fb52, 1 }, /* Royal Blood */ - { 0x184c2124, 4 }, /* Sangokushi II (J) (PRG0) */ - { 0xee8e6553, 4 }, /* Sangokushi II (J) (PRG1) */ - { 0xd532e98f, 1 }, /* Shin 4 Nin Uchi Mahjong - Yakuman Tengoku */ - { 0x39f2ce4b, 2 }, /* Suikoden - Tenmei no Chikai */ - { 0xbb7f829a, 0 }, /* Uchuu Keibitai SDF */ - { 0xaca15643, 2 }, /* Uncharted Waters */ + { 0x6f4e4312, 4 }, /* Aoki Ookami to Shiroki Mejika - Genchou Hishi */ + { 0x15fe6d0f, 2 }, /* Bandit Kings of Ancient China */ + { 0x671f23a8, 0 }, /* Castlevania III - Dracula's Curse (E) */ + { 0xcd4e7430, 0 }, /* Castlevania III - Dracula's Curse (KC) */ + { 0xed2465be, 0 }, /* Castlevania III - Dracula's Curse (U) */ + { 0xfe3488d1, 2 }, /* Daikoukai Jidai */ + { 0x0ec6c023, 1 }, /* Gemfire */ + { 0x0afb395e, 0 }, /* Gun Sight */ + { 0x1ced086f, 2 }, /* Ishin no Arashi */ + { 0x9cbadc25, 1 }, /* Just Breed */ + { 0x6396b988, 2 }, /* L'Empereur (J) */ + { 0x9c18762b, 2 }, /* L'Empereur (U) */ + { 0xb0480ae9, 0 }, /* Laser Invasion */ + { 0xb4735fac, 0 }, /* Metal Slader Glory */ + { 0xf540677b, 4 }, /* Nobunaga no Yabou - Bushou Fuuun Roku */ + { 0xeee9a682, 2 }, /* Nobunaga no Yabou - Sengoku Gunyuu Den (J) (PRG0) */ + { 0xf9b4240f, 2 }, /* Nobunaga no Yabou - Sengoku Gunyuu Den (J) (PRG1) */ + { 0x8ce478db, 2 }, /* Nobunaga's Ambition 2 */ + { 0xf011e490, 4 }, /* Romance of The Three Kingdoms II */ + { 0xbc80fb52, 1 }, /* Royal Blood */ + { 0x184c2124, 4 }, /* Sangokushi II (J) (PRG0) */ + { 0xee8e6553, 4 }, /* Sangokushi II (J) (PRG1) */ + { 0xd532e98f, 1 }, /* Shin 4 Nin Uchi Mahjong - Yakuman Tengoku */ + { 0x39f2ce4b, 2 }, /* Suikoden - Tenmei no Chikai */ + { 0xbb7f829a, 0 }, /* Uchuu Keibitai SDF */ + { 0xaca15643, 2 }, /* Uncharted Waters */ }; #define MMC5_NOCARTS (sizeof(MMC5CartList) / sizeof(MMC5CartList[0])) @@ -141,7 +142,7 @@ int DetectMMC5WRAMSize(uint32 crc32) { int x; for (x = 0; x < MMC5_NOCARTS; x++) { if (crc32 == MMC5CartList[x].crc32) { - if (MMC5CartList[x].size > 1) + if(MMC5CartList[x].size > 1) FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); return(MMC5CartList[x].size * 8); } @@ -153,11 +154,11 @@ static void BuildWRAMSizeTable(void) { int x; for (x = 0; x < 8; x++) { switch (MMC5WRAMsize) { - case 0: MMC5WRAMIndex[x] = 255; break; //X,X,X,X,X,X,X,X - case 1: MMC5WRAMIndex[x] = (x > 3) ? 255 : 0; break; //0,0,0,0,X,X,X,X - case 2: MMC5WRAMIndex[x] = (x & 4) >> 2; break; //0,0,0,0,1,1,1,1 - case 4: MMC5WRAMIndex[x] = (x > 3) ? 255 : (x & 3); break; //0,1,2,3,X,X,X,X - case 8: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7 + case 0: MMC5WRAMIndex[x] = 255; break; //X,X,X,X,X,X,X,X + case 1: MMC5WRAMIndex[x] = (x > 3) ? 255 : 0; break; //0,0,0,0,X,X,X,X + case 2: MMC5WRAMIndex[x] = (x & 4) >> 2; break; //0,0,0,0,1,1,1,1 + case 4: MMC5WRAMIndex[x] = (x > 3) ? 255 : (x & 3); break; //0,1,2,3,X,X,X,X + case 8: MMC5WRAMIndex[x] = x; break; //0,1,2,3,4,5,6,7 } } } @@ -189,7 +190,7 @@ static void MMC5CHRA(void) { for (x = 0; x < 8; x++) { setchr1(x << 10, CHRBanksA[x]); MMC5SPRVROM_BANK1(x << 10, CHRBanksA[x]); - } + } break; } } @@ -221,7 +222,7 @@ static void MMC5CHRB(void) { for (x = 0; x < 8; x++) { setchr1(x << 10, CHRBanksB[x & 3]); MMC5BGVROM_BANK1(x << 10, CHRBanksB[x & 3]); - } + } break; } } @@ -230,6 +231,7 @@ static void FASTAPASS(2) MMC5WRAM(uint32 A, uint32 V) { V = MMC5WRAMIndex[V & 7]; if (V != 255) { setprg8r(0x10, A, V); + FCEU_CheatAddRAM(8, 0x6000, (WRAM + ((V * 8192) & (WRAMSIZE - 1)))); MMC5MemIn[(A - 0x6000) >> 13] = 1; } else MMC5MemIn[(A - 0x6000) >> 13] = 0; @@ -299,96 +301,96 @@ static void MMC5PRG(void) { static DECLFW(Mapper5_write) { switch (A) { - case 0x5100: - mmc5psize = V; - MMC5PRG(); - break; - case 0x5101: - mmc5vsize = V; - if (!mmc5ABMode) { - MMC5CHRB(); - MMC5CHRA(); - } else { - MMC5CHRA(); - MMC5CHRB(); - } - break; - case 0x5102: - WRAMMaskEnable[0] = V; - break; - case 0x5103: - WRAMMaskEnable[1] = V; - break; - case 0x5104: - CHRMode = V; - MMC5HackCHRMode = V & 3; - break; - case 0x5105: - { - int x; - for (x = 0; x < 4; x++) { - switch ((V >> (x << 1)) & 3) { - case 0: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM; break; - case 1: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM + 0x400; break; - case 2: PPUNTARAM |= 1 << x; vnapage[x] = ExRAM; break; - case 3: PPUNTARAM &= ~(1 << x); vnapage[x] = MMC5fill; break; + case 0x5100: + mmc5psize = V; + MMC5PRG(); + break; + case 0x5101: + mmc5vsize = V; + if (!mmc5ABMode) { + MMC5CHRB(); + MMC5CHRA(); + } else { + MMC5CHRA(); + MMC5CHRB(); } + break; + case 0x5102: + WRAMMaskEnable[0] = V; + break; + case 0x5103: + WRAMMaskEnable[1] = V; + break; + case 0x5104: + CHRMode = V; + MMC5HackCHRMode = V & 3; + break; + case 0x5105: + { + int x; + for (x = 0; x < 4; x++) { + switch ((V >> (x << 1)) & 3) { + case 0: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM; break; + case 1: PPUNTARAM |= 1 << x; vnapage[x] = NTARAM + 0x400; break; + case 2: PPUNTARAM |= 1 << x; vnapage[x] = ExRAM; break; + case 3: PPUNTARAM &= ~(1 << x); vnapage[x] = MMC5fill; break; + } + } + NTAMirroring = V; + break; } - NTAMirroring = V; - break; - } - case 0x5106: - if (V != NTFill) - FCEU_dwmemset(MMC5fill, (V | (V << 8) | (V << 16) | (V << 24)), 0x3c0); - NTFill = V; - break; - case 0x5107: - if (V != ATFill) { - unsigned char moop = V | (V << 2) | (V << 4) | (V << 6); - FCEU_dwmemset(MMC5fill + 0x3c0, moop | (moop << 8) | (moop << 16) | (moop << 24), 0x40); + case 0x5106: + if (V != NTFill) + FCEU_dwmemset(MMC5fill, (V | (V << 8) | (V << 16) | (V << 24)), 0x3c0); + NTFill = V; + break; + case 0x5107: + if (V != ATFill) { + unsigned char moop = V | (V << 2) | (V << 4) | (V << 6); + FCEU_dwmemset(MMC5fill + 0x3c0, moop | (moop << 8) | (moop << 16) | (moop << 24), 0x40); + } + ATFill = V; + break; + case 0x5113: + WRAMPage = V; + MMC5WRAM(0x6000, V & 7); + break; + case 0x5114: + case 0x5115: + case 0x5116: + case 0x5117: + PRGBanks[A & 3] = V; + MMC5PRG(); + break; + case 0x5120: + case 0x5121: + case 0x5122: + case 0x5123: + case 0x5124: + case 0x5125: + case 0x5126: + case 0x5127: + mmc5ABMode = 0; + CHRBanksA[A & 7] = V | ((MMC50x5130 & 0x3) << 8); + MMC5CHRA(); + break; + case 0x5128: + case 0x5129: + case 0x512a: + case 0x512b: + mmc5ABMode = 1; + CHRBanksB[A & 3] = V | ((MMC50x5130 & 0x3) << 8); + MMC5CHRB(); + break; + case 0x5130: MMC50x5130 = V; break; + case 0x5200: MMC5HackSPMode = V; break; + case 0x5201: MMC5HackSPScroll = (V >> 3) & 0x1F; break; + case 0x5202: MMC5HackSPPage = V & 0x3F; break; + case 0x5203: X6502_IRQEnd(FCEU_IQEXT); IRQScanline = V; break; + case 0x5204: X6502_IRQEnd(FCEU_IQEXT); IRQEnable = V & 0x80; break; + case 0x5205: mul[0] = V; break; + case 0x5206: mul[1] = V; break; } - ATFill = V; - break; - case 0x5113: - WRAMPage = V; - MMC5WRAM(0x6000, V & 7); - break; - case 0x5114: - case 0x5115: - case 0x5116: - case 0x5117: - PRGBanks[A & 3] = V; - MMC5PRG(); - break; - case 0x5120: - case 0x5121: - case 0x5122: - case 0x5123: - case 0x5124: - case 0x5125: - case 0x5126: - case 0x5127: - mmc5ABMode = 0; - CHRBanksA[A & 7] = V | ((MMC50x5130 & 0x3) << 8); - MMC5CHRA(); - break; - case 0x5128: - case 0x5129: - case 0x512a: - case 0x512b: - mmc5ABMode = 1; - CHRBanksB[A & 3] = V | ((MMC50x5130 & 0x3) << 8); - MMC5CHRB(); - break; - case 0x5130: MMC50x5130 = V; break; - case 0x5200: MMC5HackSPMode = V; break; - case 0x5201: MMC5HackSPScroll = (V >> 3) & 0x1F; break; - case 0x5202: MMC5HackSPPage = V & 0x3F; break; - case 0x5203: X6502_IRQEnd(FCEU_IQEXT); IRQScanline = V; break; - case 0x5204: X6502_IRQEnd(FCEU_IQEXT); IRQEnable = V & 0x80; break; - case 0x5205: mul[0] = V; break; - case 0x5206: mul[1] = V; break; - } } static DECLFR(MMC5_ReadROMRAM) { @@ -400,7 +402,7 @@ static DECLFR(MMC5_ReadROMRAM) { static DECLFW(MMC5_WriteROMRAM) { if ((A >= 0x8000) && (MMC5ROMWrProtect[(A - 0x8000) >> 13])) - return; + return; if (MMC5MemIn[(A - 0x6000) >> 13]) if (((WRAMMaskEnable[0] & 3) | ((WRAMMaskEnable[1] & 3) << 2)) == 6) Page[A >> 11][A] = V; @@ -426,7 +428,7 @@ static DECLFR(MMC5_read) { #endif MMC5IRQR &= 0x40; return x; - } + } case 0x5205: return(mul[0] * mul[1]); case 0x5206: @@ -455,31 +457,56 @@ void MMC5Synco(void) { MMC5CHRA(); MMC5CHRB(); } + + //in case the fill register changed, we need to overwrite the fill buffer FCEU_dwmemset(MMC5fill, NTFill | (NTFill << 8) | (NTFill << 16) | (NTFill << 24), 0x3c0); { unsigned char moop = ATFill | (ATFill << 2) | (ATFill << 4) | (ATFill << 6); FCEU_dwmemset(MMC5fill + 0x3c0, moop | (moop << 8) | (moop << 16) | (moop << 24), 0x40); } - X6502_IRQEnd(FCEU_IQEXT); + MMC5HackCHRMode = CHRMode & 3; + + //zero 17-apr-2013 - why the heck should this happen here? anything in a `synco` should be depending on the state. + //im going to leave it commented out to see what happens + //X6502_IRQEnd(FCEU_IQEXT); } void MMC5_hb(int scanline) { - if (scanline == 240) { + //zero 24-jul-2014 - revised for newer understanding, to fix metal slader glory credits. see r7371 in bizhawk + + int sl = scanline + 1; + int ppuon = (PPU[1] & 0x18); + + if (!ppuon || sl >= 241) + { + // whenever rendering is off for any reason (vblank or forced disable + // the irq counter resets, as well as the inframe flag (easily verifiable from software) + MMC5IRQR &= ~0x40; + MMC5IRQR &= ~0x80; MMC5LineCounter = 0; - MMC5IRQR = 0x40; + X6502_IRQEnd(FCEU_IQEXT); return; } - if (MMC5LineCounter < 240) { - if (MMC5LineCounter == IRQScanline) { + + if (!(MMC5IRQR&0x40)) + { + MMC5IRQR |= 0x40; + MMC5IRQR &= ~0x80; + MMC5LineCounter = 0; + X6502_IRQEnd(FCEU_IQEXT); + } + else + { + MMC5LineCounter++; + if (MMC5LineCounter == IRQScanline) + { MMC5IRQR |= 0x80; if (IRQEnable & 0x80) X6502_IRQBegin(FCEU_IQEXT); } - MMC5LineCounter++; } - if (MMC5LineCounter == 240) - MMC5IRQR = 0; + } void MMC5_StateRestore(int version) { @@ -617,7 +644,7 @@ static void Do5SQHQ(int P) { if (dc < rthresh) WaveHi[V] += amp; vc--; - if (vc <= 0) { /* Less than zero when first started. */ + if (vc <= 0) { /* Less than zero when first started. */ vc = wl; dc = (dc + 1) & 7; } @@ -682,8 +709,11 @@ void NSFMMC5_Init(void) { } void NSFMMC5_Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; FCEU_gfree(ExRAM); - ExRAM = 0; + ExRAM = NULL; } static void GenMMC5Reset(void) { @@ -715,7 +745,7 @@ static void GenMMC5Reset(void) { SetReadHandler(0x5205, 0x5206, MMC5_read); // GameHBIRQHook=MMC5_hb; - FCEU_CheatAddRAM(8, 0x6000, WRAM); +// FCEU_CheatAddRAM(8, 0x6000, WRAM); FCEU_CheatAddRAM(1, 0x5c00, ExRAM); } @@ -733,6 +763,15 @@ static SFORMAT MMC5_StateRegs[] = { { &NTFill, 1, "NTFL" }, { &ATFill, 1, "ATFL" }, + //zero 17-apr-2013 - added + { &MMC5IRQR, 1, "IRQR" }, + { &MMC5LineCounter, 1, "LCTR" }, + { &mmc5psize, 1, "PSIZ" }, + { &mmc5vsize, 1, "VSIZ" }, + { mul, 2, "MUL2" }, + { MMC5ROMWrProtect, 4, "WRPR" }, + { MMC5MemIn, 5, "MEMI" }, + { &MMC5Sound.wl[0], 2 | FCEUSTATE_RLSB, "SDW0" }, { &MMC5Sound.wl[1], 2 | FCEUSTATE_RLSB, "SDW1" }, { MMC5Sound.env, 2, "SDEV" }, @@ -740,6 +779,15 @@ static SFORMAT MMC5_StateRegs[] = { { &MMC5Sound.running, 1, "SDRU" }, { &MMC5Sound.raw, 1, "SDRW" }, { &MMC5Sound.rawcontrol, 1, "SDRC" }, + + //zero 17-apr-2013 - added + { &MMC5Sound.dcount[0], 4 | FCEUSTATE_RLSB, "DCT0" }, + { &MMC5Sound.dcount[1], 4 | FCEUSTATE_RLSB, "DCT1" }, + { &MMC5Sound.BC[0], 4 | FCEUSTATE_RLSB, "BC00" }, + { &MMC5Sound.BC[1], 4 | FCEUSTATE_RLSB, "BC01" }, + { &MMC5Sound.BC[2], 4 | FCEUSTATE_RLSB, "BC02" }, + { &MMC5Sound.vcount[0], 4 | FCEUSTATE_RLSB, "VCT0" }, + { &MMC5Sound.vcount[1], 4 | FCEUSTATE_RLSB, "VCT1" }, { 0 } }; @@ -783,7 +831,8 @@ static void GenMMC5_Init(CartInfo *info, int wsize, int battery) { } void Mapper5_Init(CartInfo *info) { - GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery); + WRAMSIZE = DetectMMC5WRAMSize(info->CRC32); + GenMMC5_Init(info, WRAMSIZE, info->battery); } // ELROM seems to have 0KB of WRAM diff --git a/src/boards/onebus.c b/src/boards/onebus.c index 4ce0ff5..8b92fb2 100644 --- a/src/boards/onebus.c +++ b/src/boards/onebus.c @@ -79,7 +79,6 @@ static void PSync(void) { uint8 bank2 = (cpu410x[0xb] & 0x40) ? (cpu410x[0x9]) : (~1); uint8 bank3 = ~0; -// FCEU_printf(" PRG OFFSET: %08x\n", (block | (bank0 & mask)) * 8192); // FCEU_printf(" PRG: %04x [%02x]",0x8000^pswap,block | (bank0 & mask)); setprg8(0x8000 ^ pswap, block | (bank0 & mask)); // FCEU_printf(" %04x [%02x]",0xa000^pswap,block | (bank1 & mask)); @@ -105,22 +104,13 @@ static void CSync(void) { uint8 bank6 = ppu201x[0x4]; uint8 bank7 = ppu201x[0x5]; -// FCEU_printf(" CHR OFFSET: %08x\n", (block | (bank0 & mask)) * 1024); -// FCEU_printf(" CHR: %04x [%02x]", 0x0000^cswap,block | (bank0 & mask)); setchr1(0x0000 ^ cswap, block | (bank0 & mask)); -// FCEU_printf(" %04x [%02x]",0x0400^cswap,block | (bank1 & mask)); setchr1(0x0400 ^ cswap, block | (bank1 & mask)); -// FCEU_printf(" %04x [%02x]",0x0800^cswap,block | (bank2 & mask)); setchr1(0x0800 ^ cswap, block | (bank2 & mask)); -// FCEU_printf(" %04x [%02x]",0x0c00^cswap,block | (bank3 & mask)); setchr1(0x0c00 ^ cswap, block | (bank3 & mask)); -// FCEU_printf(" %04x [%02x]",0x1000^cswap,block | (bank4 & mask)); setchr1(0x1000 ^ cswap, block | (bank4 & mask)); -// FCEU_printf(" %04x [%02x]",0x1400^cswap,block | (bank5 & mask)); setchr1(0x1400 ^ cswap, block | (bank5 & mask)); -// FCEU_printf(" %04x [%02x]",0x1800^cswap,block | (bank6 & mask)); setchr1(0x1800 ^ cswap, block | (bank6 & mask)); -// FCEU_printf(" %04x [%02x]\n",0x1c00^cswap,block | (bank7 & mask)); setchr1(0x1c00 ^ cswap, block | (bank7 & mask)); setmirror(mirror & 1); @@ -190,19 +180,19 @@ static void UNLOneBusIRQHook(void) { } static DECLFW(UNLOneBusWriteAPU40XX) { -// FCEU_printf("APU %04x:%04x\n",A,V); +// if(((A & 0x3f)!=0x16) && ((apu40xx[0x30] & 0x10) || ((A & 0x3f)>0x17)))FCEU_printf("APU %04x:%04x\n",A,V); apu40xx[A & 0x3f] = V; switch (A & 0x3f) { case 0x12: if (apu40xx[0x30] & 0x10) { pcm_addr = V << 6; } - break; + break; case 0x13: if (apu40xx[0x30] & 0x10) { pcm_size = (V << 4) + 1; } - break; + break; case 0x15: if (apu40xx[0x30] & 0x10) { pcm_enable = V & 0x10; @@ -214,7 +204,7 @@ static DECLFW(UNLOneBusWriteAPU40XX) { pcm_latch = pcm_clock; V &= 0xef; } - break; + break; } defapuwrite[A & 0x3f](A, V); } @@ -227,7 +217,7 @@ static DECLFR(UNLOneBusReadAPU40XX) { if (apu40xx[0x30] & 0x10) { result = (result & 0x7f) | pcm_irq; } - break; + break; } return result; } @@ -243,7 +233,7 @@ static void UNLOneBusCpuHook(int a) { pcm_enable = 0; X6502_IRQBegin(FCEU_IQEXT); } else { - uint16 addr = pcm_addr | ((apu40xx[0x30]^3) << 14); + uint16 addr = pcm_addr | ((apu40xx[0x30]^3) << 14); uint8 raw_pcm = ARead[addr](addr) >> 1; defapuwrite[0x11](0x4011, raw_pcm); pcm_addr++; diff --git a/src/boards/pec-586.c b/src/boards/pec-586.c index 6de80af..0eac60c 100644 --- a/src/boards/pec-586.c +++ b/src/boards/pec-586.c @@ -101,6 +101,7 @@ static void UNLPEC586Power(void) { SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x5000, 0x5fff, UNLPEC586Write); SetReadHandler(0x5000, 0x5fff, UNLPEC586Read); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void UNLPEC586Close(void) { diff --git a/src/boards/transformer.c b/src/boards/transformer.c index c57ac44..63502a7 100644 --- a/src/boards/transformer.c +++ b/src/boards/transformer.c @@ -42,7 +42,7 @@ static void FP_FASTAPASS(1) TransformerIRQHook(int a) { else TransformerChar = i | 0x80; X6502_IRQBegin(FCEU_IQEXT); - memcpy((void*)&oldkeys[0], (void*)TransformerKeys, 256); + memcpy((void*)&oldkeys[0], (void*)TransformerKeys, sizeof(oldkeys)); break; } } @@ -71,6 +71,7 @@ static void TransformerPower(void) { SetReadHandler(0x6000, 0x7FFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); MapIRQHook = TransformerIRQHook; } diff --git a/src/boards/vrc2and4.c b/src/boards/vrc2and4.c index 69449c6..d759724 100644 --- a/src/boards/vrc2and4.c +++ b/src/boards/vrc2and4.c @@ -19,6 +19,7 @@ * * VRC-2/VRC-4 Konami * VRC-4 Pirate + * */ #include "mapinc.h" @@ -136,8 +137,8 @@ static DECLFW(M21Write) { } static DECLFW(M22Write) { - if (A == 0xC007) { // Ganbare Goemon Gaiden does strange things!!! at the end credits - weirdo = 8; // quick dirty hack, seems there is no other games with such PCB, so + if ((A >= 0xC004) && (A <= 0xC007)) { // Ganbare Goemon Gaiden does strange things!!! at the end credits + weirdo = 1; // quick dirty hack, seems there is no other games with such PCB, so // we never know if it will not work for something else lol } A |= ((A >> 2) & 0x3); // It's just swapped lines from 21 mapper @@ -172,6 +173,7 @@ static void M23Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, M23Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M25Power(void) { @@ -182,6 +184,7 @@ static void M25Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x8000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, M22Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } void FP_FASTAPASS(1) VRC24IRQHook(int a) { diff --git a/src/boards/vrc3.c b/src/boards/vrc3.c index 6826a9c..315cad8 100644 --- a/src/boards/vrc3.c +++ b/src/boards/vrc3.c @@ -74,7 +74,7 @@ static DECLFW(M73Write) { } static void M73IRQHook(int a) { - uint32 i; + int32 i; if (!IRQa) return; for (i = 0; i < a; i++) { if (IRQm) { @@ -106,6 +106,7 @@ static void M73Power(void) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); SetWriteHandler(0x8000, 0xFFFF, M73Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void M73Close(void) { diff --git a/src/boards/vrc5.c b/src/boards/vrc5.c index d9e783b..2ab2a6f 100644 --- a/src/boards/vrc5.c +++ b/src/boards/vrc5.c @@ -184,6 +184,7 @@ static void M190Power(void) { SetWriteHandler(0x8000, 0xFFFF, M190Write); SetReadHandler(0xDC00, 0xDC00, M190Read); SetReadHandler(0xDD00, 0xDD00, M190Read); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); Sync(); } diff --git a/src/boards/vrc6.c b/src/boards/vrc6.c index 531d4c5..79a0bdc 100644 --- a/src/boards/vrc6.c +++ b/src/boards/vrc6.c @@ -127,6 +127,7 @@ static void VRC6Power(void) { SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x6000, 0x7FFF, CartBW); SetWriteHandler(0x8000, 0xFFFF, VRC6Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void VRC6IRQHook(int a) { @@ -244,11 +245,11 @@ static INLINE void DoSQVHQ(int x) { if (vpsg1[(x << 2) | 0x2] & 0x80) { if (vpsg1[x << 2] & 0x80) { - for (V = cvbc[x]; V < SOUNDTS; V++) + for (V = cvbc[x]; V < (int)SOUNDTS; V++) WaveHi[V] += amp; } else { int32 thresh = (vpsg1[x << 2] >> 4) & 7; - for (V = cvbc[x]; V < SOUNDTS; V++) { + for (V = cvbc[x]; V < (int)SOUNDTS; V++) { if (dcount[x] > thresh) WaveHi[V] += amp; vcount[x]--; @@ -276,7 +277,7 @@ static void DoSawVHQ(void) { int32 V; if (vpsg2[2] & 0x80) { - for (V = cvbc[2]; V < SOUNDTS; V++) { + for (V = cvbc[2]; V < (int)SOUNDTS; V++) { WaveHi[V] += (((phaseacc >> 3) & 0x1f) << 8) * 6 / 8; vcount[2]--; if (vcount[2] <= 0) { diff --git a/src/boards/vrc7.c b/src/boards/vrc7.c index 9900222..8e2f2c8 100644 --- a/src/boards/vrc7.c +++ b/src/boards/vrc7.c @@ -151,6 +151,7 @@ static void VRC7Power(void) { SetWriteHandler(0x6000, 0x7FFF, CartBW); SetReadHandler(0x6000, 0xFFFF, CartBR); SetWriteHandler(0x8000, 0xFFFF, VRC7Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void VRC7Close(void) { diff --git a/src/boards/yoko.c b/src/boards/yoko.c index 1714f8a..e0fc504 100644 --- a/src/boards/yoko.c +++ b/src/boards/yoko.c @@ -174,6 +174,7 @@ static void M83Power(void) { SetWriteHandler(0x6000, 0x7fff, CartBW);// Pirate Dragon Ball Z Party [p1] used if for saves instead of seraial EEPROM SetReadHandler(0x8000, 0xffff, CartBR); SetWriteHandler(0x8000, 0xffff, M83Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); } static void UNLYOKOReset(void) { diff --git a/src/ines.h b/src/ines.h index 1c9ca00..5e3531d 100644 --- a/src/ines.h +++ b/src/ines.h @@ -122,6 +122,7 @@ void Mapper112_Init(CartInfo *); void Mapper113_Init(CartInfo *); void Mapper114_Init(CartInfo *); void Mapper115_Init(CartInfo *); +void Mapper116_Init(CartInfo *); void Mapper117_Init(CartInfo *); void Mapper119_Init(CartInfo *); void Mapper120_Init(CartInfo *); diff --git a/src/ppu.h b/src/ppu.h index 03b51b7..96338a1 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -21,5 +21,6 @@ void FCEUPPU_SaveState(void); void FCEUPPU_LoadState(int version); extern int scanline; +extern uint8 PPU[4]; #endif diff --git a/zzz_todo.txt b/zzz_todo.txt index 2bb7e07..262482b 100644 --- a/zzz_todo.txt +++ b/zzz_todo.txt @@ -15,6 +15,7 @@ N 004 mapper - "Long Zhu Ying Xiong (As) [p1].nes" 016 mapper - as like 157, добавить EEPROM эмуляцию. 126 mapper - "PowerJoy 84-in-1 (PJ-008) (Unl) [!]" не эмулируется (Nestopia) 253 mapper - плохая синхронизация IRQ, проблема в вычислениях тайминга или в ядре? + 015 mapper - вешается при загрузке-сейве Yuefei (Unl) [h1] Готово: From 204f62767c79e53332d3962e48dd4836ed854350 Mon Sep 17 00:00:00 2001 From: Oggom Date: Sun, 28 Jun 2015 03:39:57 +0200 Subject: [PATCH 2/2] Backport r173 - UNIF-DRAGONFIGHTER - new board for a new dump --- Fceuwin.dev | 376 +++++++++++++++---------------- src/boards/BMW8544.c | 79 +++++++ src/drivers/libretro/fceu/unif.c | 1 + src/unif.c | 1 + src/unif.h | 1 + 5 files changed, 270 insertions(+), 188 deletions(-) create mode 100644 src/boards/BMW8544.c diff --git a/Fceuwin.dev b/Fceuwin.dev index 3f76e3c..856654d 100644 --- a/Fceuwin.dev +++ b/Fceuwin.dev @@ -1,7 +1,7 @@ [Project] FileName=Fceuwin.dev Name=Fceu -UnitCount=297 +UnitCount=298 Type=0 Ver=1 ObjFiles= @@ -2297,18 +2297,8 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit260] -FileName=src\boards\addrlatch.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - [Unit266] -FileName=src\boards\246.c +FileName=src\boards\32.c CompileCpp=0 Folder=boards Compile=1 @@ -2318,9 +2308,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit270] -FileName=src\boards\40.c +FileName=src\boards\41.c CompileCpp=0 -Folder=boards/fds conversions +Folder=boards/multigame boards Compile=1 Link=1 Priority=1000 @@ -2328,16 +2318,6 @@ OverrideBuildCmd=0 BuildCmd= [Unit272] -FileName=src\boards\42.c -CompileCpp=0 -Folder=boards/fds conversions -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit273] FileName=src\boards\46.c CompileCpp=0 Folder=boards/multigame boards @@ -2347,107 +2327,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit275] -FileName=src\boards\51.c -CompileCpp=0 -Folder=boards/multigame boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit276] -FileName=src\boards\62.c -CompileCpp=0 -Folder=boards/multigame boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit277] -FileName=src\boards\80.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit278] -FileName=src\boards\79.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit279] -FileName=src\boards\77.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit280] -FileName=src\boards\vrc1.c -CompileCpp=0 -Folder=boards/vrc based -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit281] -FileName=src\boards\vrc3.c -CompileCpp=0 -Folder=boards/vrc based -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit282] -FileName=src\boards\72.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit284] -FileName=src\boards\36.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit285] -FileName=src\boards\65.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit274] +[Unit273] FileName=src\boards\50.c CompileCpp=0 Folder=boards/fds conversions @@ -2457,7 +2337,77 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit283] +[Unit275] +FileName=src\boards\62.c +CompileCpp=0 +Folder=boards/multigame boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit276] +FileName=src\boards\80.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit277] +FileName=src\boards\79.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit278] +FileName=src\boards\77.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit279] +FileName=src\boards\vrc1.c +CompileCpp=0 +Folder=boards/vrc based +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit280] +FileName=src\boards\vrc3.c +CompileCpp=0 +Folder=boards/vrc based +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit281] +FileName=src\boards\72.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit282] FileName=src\boards\71.c CompileCpp=0 Folder=boards @@ -2467,6 +2417,46 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit284] +FileName=src\boards\65.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit285] +FileName=src\boards\67.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit274] +FileName=src\boards\51.c +CompileCpp=0 +Folder=boards/multigame boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit283] +FileName=src\boards\36.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + [Unit23] FileName=src\video.c CompileCpp=0 @@ -2488,16 +2478,6 @@ OverrideBuildCmd=0 BuildCmd= [Unit261] -FileName=src\boards\228.c -CompileCpp=0 -Folder=boards/multigame boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit262] FileName=src\boards\230.c CompileCpp=0 Folder=boards/multigame boards @@ -2507,8 +2487,8 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit264] -FileName=src\boards\234.c +[Unit262] +FileName=src\boards\232.c CompileCpp=0 Folder=boards/multigame boards Compile=1 @@ -2517,7 +2497,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit265] +[Unit264] FileName=src\boards\244.c CompileCpp=0 Folder=boards @@ -2527,8 +2507,8 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit267] -FileName=src\boards\32.c +[Unit265] +FileName=src\boards\246.c CompileCpp=0 Folder=boards Compile=1 @@ -2537,7 +2517,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit268] +[Unit267] FileName=src\boards\33.c CompileCpp=0 Folder=boards @@ -2547,7 +2527,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit269] +[Unit268] FileName=src\boards\252.c CompileCpp=0 Folder=boards/vrc based @@ -2557,10 +2537,20 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit271] -FileName=src\boards\41.c +[Unit269] +FileName=src\boards\40.c CompileCpp=0 -Folder=boards/multigame boards +Folder=boards/fds conversions +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit271] +FileName=src\boards\42.c +CompileCpp=0 +Folder=boards/fds conversions Compile=1 Link=1 Priority=1000 @@ -2568,7 +2558,7 @@ OverrideBuildCmd=0 BuildCmd= [Unit263] -FileName=src\boards\232.c +FileName=src\boards\234.c CompileCpp=0 Folder=boards/multigame boards Compile=1 @@ -2588,16 +2578,6 @@ OverrideBuildCmd=0 BuildCmd= [Unit287] -FileName=src\boards\vrc6.c -CompileCpp=0 -Folder=boards/vrc based -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit288] FileName=src\boards\mmc2and4.c CompileCpp=0 Folder=boards @@ -2607,7 +2587,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit289] +[Unit288] FileName=src\boards\69.c CompileCpp=0 Folder=boards @@ -2617,7 +2597,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit290] +[Unit289] FileName=src\boards\vrc7.c CompileCpp=0 Folder=boards/vrc based @@ -2627,7 +2607,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit291] +[Unit290] FileName=src\boards\emu2413.c CompileCpp=0 Folder=boards/vrc based @@ -2637,7 +2617,7 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit292] +[Unit291] FileName=src\boards\mapinc.h CompileCpp=0 Folder=_Headers @@ -2647,8 +2627,18 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit292] +FileName=src\boards\emu2413.h +CompileCpp=0 +Folder=_Headers +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + [Unit297] -FileName=src\boards\158B.c +FileName=src\boards\BMW8544.c CompileCpp=0 Folder=boards/mmc3 based Compile=1 @@ -2657,20 +2647,10 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= -[Unit298] -FileName=src\boards\addrlatch.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - [Unit286] -FileName=src\boards\67.c +FileName=src\boards\vrc6.c CompileCpp=0 -Folder=boards +Folder=boards/vrc based Compile=1 Link=1 Priority=1000 @@ -3088,9 +3068,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit293] -FileName=src\boards\emu2413.h +FileName=src\boards\178.c CompileCpp=0 -Folder=_Headers +Folder=boards/multigame boards Compile=1 Link=1 Priority=1000 @@ -3098,9 +3078,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit294] -FileName=src\boards\178.c +FileName=src\boards\mihunche.c CompileCpp=0 -Folder=boards/multigame boards +Folder=boards Compile=1 Link=1 Priority=1000 @@ -3158,16 +3138,6 @@ OverrideBuildCmd=0 BuildCmd= [Unit295] -FileName=src\boards\mihunche.c -CompileCpp=0 -Folder=boards -Compile=1 -Link=1 -Priority=1000 -OverrideBuildCmd=0 -BuildCmd= - -[Unit296] FileName=src\boards\coolboy.c CompileCpp=0 Folder=boards/mmc3 based @@ -3177,3 +3147,33 @@ Priority=1000 OverrideBuildCmd=0 BuildCmd= +[Unit296] +FileName=src\boards\158B.c +CompileCpp=0 +Folder=boards/mmc3 based +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit298] +FileName=src\boards\addrlatch.c +CompileCpp=0 +Folder=boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit260] +FileName=src\boards\228.c +CompileCpp=0 +Folder=boards/multigame boards +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/src/boards/BMW8544.c b/src/boards/BMW8544.c new file mode 100644 index 0000000..6db8a80 --- /dev/null +++ b/src/boards/BMW8544.c @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2015 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * "Dragon Fighter" protected MMC3 based custom mapper board + * mostly hacky implementation, I can't verify if this mapper can read a RAM of the + * console or watches the bus writes somehow. + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void UNLBMW8544PW(uint32 A, uint8 V) { + if(A == 0x8000) + setprg8(A,EXPREGS[0] & 0x1F); // the real hardware has this bank overrided with it's own register, + else // but MMC3 prg swap still works and you can actually change bank C000 at the same time if use 0x46 cmd + setprg8(A,V); +} + +static void UNLBMW8544CW(uint32 A, uint8 V) { + if(A == 0x0000) + setchr2(0x0000,(V >> 1) ^ EXPREGS[1]); + else if (A == 0x0800) + setchr2(0x0800,(V >> 1) | ((EXPREGS[2] & 0x40) << 1)); + else if (A == 0x1000) + setchr4(0x1000, EXPREGS[2] & 0x3F); + +} + +static DECLFW(UNLBMW8544ProtWrite) { + if(!(A & 1)) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + } +} + +static DECLFR(UNLBMW8544ProtRead) { + if(!fceuindbg) { + if(!(A & 1)) { + if((EXPREGS[0] & 0xE0) == 0xC0) { + EXPREGS[1] = ARead[0x6a](0x6a); // program can latch some data from the BUS, but I can't say how exactly, + } else { // without more euipment and skills ;) probably here we can try to get any write + EXPREGS[2] = ARead[0xff](0xff); // before the read operation + } + FixMMC3CHR(MMC3_cmd & 0x7F); // there are more different behaviour of the board isn't used by game itself, so unimplemented here and + } // actually will break the current logic ;) + } + return 0; +} + +static void UNLBMW8544Power(void) { + GenMMC3Power(); + SetWriteHandler(0x6000, 0x6FFF, UNLBMW8544ProtWrite); + SetReadHandler(0x6000, 0x6FFF, UNLBMW8544ProtRead); +} + +void UNLBMW8544_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + pwrap = UNLBMW8544PW; + cwrap = UNLBMW8544CW; + info->Power = UNLBMW8544Power; + AddExState(EXPREGS, 3, 0, "EXPR"); +} diff --git a/src/drivers/libretro/fceu/unif.c b/src/drivers/libretro/fceu/unif.c index 26f79a3..10151bc 100644 --- a/src/drivers/libretro/fceu/unif.c +++ b/src/drivers/libretro/fceu/unif.c @@ -451,6 +451,7 @@ static BMAPPING bmap[] = { { "YOKO", UNLYOKO_Init, 0 }, { "COOLBOY", COOLBOY_Init, BMCFLAG_256KCHRR }, { "158B", UNL158B_Init, 0 }, + { "DRAGONFIGHTER", UNLBMW8544_Init, 0}, #ifdef COPYFAMI { "COPYFAMI_MMC3", MapperCopyFamiMMC3_Init, 0 }, diff --git a/src/unif.c b/src/unif.c index 4420d2c..af012be 100644 --- a/src/unif.c +++ b/src/unif.c @@ -451,6 +451,7 @@ static BMAPPING bmap[] = { { "YOKO", UNLYOKO_Init, 0 }, { "COOLBOY", COOLBOY_Init, BMCFLAG_256KCHRR }, { "158B", UNL158B_Init, 0 }, + { "DRAGONFIGHTER", UNLBMW8544_Init, 0}, #ifdef COPYFAMI { "COPYFAMI_MMC3", MapperCopyFamiMMC3_Init, 0 }, diff --git a/src/unif.h b/src/unif.h index 7821507..bca1ad1 100644 --- a/src/unif.h +++ b/src/unif.h @@ -147,6 +147,7 @@ void UNLYOKO_Init(CartInfo *info); void UNROM_Init(CartInfo *info); void COOLBOY_Init(CartInfo *info); void UNL158B_Init(CartInfo *info); +void UNLBMW8544_Init(CartInfo *info); #ifdef COPYFAMI void MapperCopyFamiMMC3_Init(CartInfo *info);