2008-09-02 03:55:12 +02:00
|
|
|
/* FCE Ultra - NES/Famicom Emulator
|
|
|
|
*
|
|
|
|
* Copyright notice for this file:
|
2009-07-17 19:27:04 +02:00
|
|
|
* Copyright (C) 2002 Xodnizel 2006 CaH4e3
|
2008-09-02 03:55:12 +02:00
|
|
|
*
|
|
|
|
* 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
|
2012-12-14 18:18:20 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
2012-12-14 18:43:51 +01:00
|
|
|
* It seems that 162/163/164 mappers are the same mapper with just different
|
|
|
|
* mapper modes enabled or disabled in software or hardware, need more nanjing
|
|
|
|
* carts
|
2008-09-02 03:55:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mapinc.h"
|
|
|
|
|
2012-12-14 18:18:20 +01:00
|
|
|
static uint8 laststrobe, trigger;
|
|
|
|
static uint8 reg[8];
|
2012-12-14 18:43:51 +01:00
|
|
|
static uint8 *WRAM = NULL;
|
2012-12-14 18:18:20 +01:00
|
|
|
static uint32 WRAMSIZE;
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static writefunc pcmwrite;
|
|
|
|
|
|
|
|
static void (*WSync)(void);
|
2012-12-14 18:18:20 +01:00
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static SFORMAT StateRegs[] =
|
2008-09-02 03:55:12 +02:00
|
|
|
{
|
2012-12-14 18:43:51 +01:00
|
|
|
{ &laststrobe, 1, "STB" },
|
|
|
|
{ &trigger, 1, "TRG" },
|
|
|
|
{ reg, 8, "REGS" },
|
|
|
|
{ 0 }
|
2008-09-02 03:55:12 +02:00
|
|
|
};
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void Sync(void) {
|
|
|
|
setprg8r(0x10, 0x6000, 0);
|
|
|
|
setprg32(0x8000, (reg[0] << 4) | (reg[1] & 0xF));
|
2012-12-14 18:18:20 +01:00
|
|
|
setchr8(0);
|
2008-09-02 03:55:12 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void StateRestore(int version) {
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync();
|
2008-09-02 03:55:12 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static DECLFR(ReadLow) {
|
|
|
|
switch (A & 0x7700) {
|
|
|
|
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
|
|
|
|
else
|
|
|
|
return 0;
|
2012-12-14 18:18:20 +01:00
|
|
|
}
|
|
|
|
return 4;
|
2009-07-17 19:27:04 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void M163HB(void) {
|
|
|
|
if (reg[1] & 0x80) {
|
|
|
|
if (scanline == 239) {
|
|
|
|
setchr4(0x0000, 0);
|
|
|
|
setchr4(0x1000, 0);
|
|
|
|
} else if (scanline == 127) {
|
|
|
|
setchr4(0x0000, 1);
|
|
|
|
setchr4(0x1000, 1);
|
2012-12-14 18:18:20 +01:00
|
|
|
}
|
|
|
|
/*
|
2012-12-14 18:43:51 +01:00
|
|
|
if(scanline>=127) // Hu Lu Jin Gang (NJ039) (Ch) [!] don't like it
|
|
|
|
{
|
|
|
|
setchr4(0x0000,1);
|
|
|
|
setchr4(0x1000,1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setchr4(0x0000,0);
|
|
|
|
setchr4(0x1000,0);
|
|
|
|
}
|
2012-12-14 18:18:20 +01:00
|
|
|
*/
|
|
|
|
}
|
2008-09-20 03:02:49 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static DECLFW(Write) {
|
|
|
|
switch (A & 0x7300) {
|
|
|
|
case 0x5100: reg[0] = V; WSync(); break;
|
|
|
|
case 0x5000: reg[1] = V; WSync(); break;
|
|
|
|
case 0x5300: reg[2] = V; break;
|
|
|
|
case 0x5200: reg[3] = V; WSync(); break;
|
2012-12-14 18:18:20 +01:00
|
|
|
}
|
2008-09-02 03:55:12 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void Power(void) {
|
|
|
|
memset(reg, 0, 8);
|
|
|
|
reg[1] = 0xFF;
|
|
|
|
SetWriteHandler(0x5000, 0x5FFF, Write);
|
|
|
|
SetReadHandler(0x6000, 0xFFFF, CartBR);
|
|
|
|
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
2018-08-13 17:04:20 +02:00
|
|
|
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync();
|
2008-09-02 03:55:12 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void Close(void) {
|
|
|
|
if (WRAM)
|
2012-12-14 18:18:20 +01:00
|
|
|
FCEU_gfree(WRAM);
|
2012-12-14 18:43:51 +01:00
|
|
|
WRAM = NULL;
|
2008-09-02 03:55:12 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
void Mapper164_Init(CartInfo *info) {
|
|
|
|
info->Power = Power;
|
|
|
|
info->Close = Close;
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync = Sync;
|
|
|
|
|
|
|
|
WRAMSIZE = 8192;
|
2012-12-14 18:43:51 +01:00
|
|
|
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
|
|
|
|
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
2012-12-14 18:18:20 +01:00
|
|
|
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
if (info->battery) {
|
|
|
|
info->SaveGame[0] = WRAM;
|
|
|
|
info->SaveGameLen[0] = WRAMSIZE;
|
2012-12-14 18:18:20 +01:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
GameStateRestore = StateRestore;
|
2012-12-14 18:18:20 +01:00
|
|
|
AddExState(&StateRegs, ~0, 0, 0);
|
2008-09-02 03:55:12 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static DECLFW(Write2) {
|
|
|
|
if (A == 0x5101) {
|
|
|
|
if (laststrobe && !V) {
|
|
|
|
trigger ^= 1;
|
|
|
|
}
|
|
|
|
laststrobe = V;
|
|
|
|
} else if (A == 0x5100 && V == 6) //damn thoose protected games
|
|
|
|
setprg32(0x8000, 3);
|
2012-12-14 18:18:20 +01:00
|
|
|
else
|
2012-12-14 18:43:51 +01:00
|
|
|
switch (A & 0x7300) {
|
|
|
|
case 0x5200: reg[0] = V; WSync(); break;
|
|
|
|
case 0x5000: reg[1] = V; WSync(); if (!(reg[1] & 0x80) && (scanline < 128)) setchr8(0); /* setchr8(0); */ break;
|
|
|
|
case 0x5300: reg[2] = V; break;
|
|
|
|
case 0x5100: reg[3] = V; WSync(); break;
|
|
|
|
}
|
2008-09-20 03:02:49 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void Power2(void) {
|
|
|
|
memset(reg, 0, 8);
|
|
|
|
laststrobe = 1;
|
|
|
|
pcmwrite = GetWriteHandler(0x4011);
|
|
|
|
SetReadHandler(0x5000, 0x5FFF, ReadLow);
|
|
|
|
SetWriteHandler(0x5000, 0x5FFF, Write2);
|
|
|
|
SetReadHandler(0x6000, 0xFFFF, CartBR);
|
|
|
|
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
2018-08-13 17:04:20 +02:00
|
|
|
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync();
|
2008-09-20 03:02:49 +02:00
|
|
|
}
|
2008-09-02 03:55:12 +02:00
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
void Mapper163_Init(CartInfo *info) {
|
|
|
|
info->Power = Power2;
|
|
|
|
info->Close = Close;
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync = Sync;
|
2012-12-14 18:43:51 +01:00
|
|
|
GameHBIRQHook = M163HB;
|
2012-12-14 18:18:20 +01:00
|
|
|
|
|
|
|
WRAMSIZE = 8192;
|
2012-12-14 18:43:51 +01:00
|
|
|
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
|
|
|
|
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
2012-12-14 18:18:20 +01:00
|
|
|
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
if (info->battery) {
|
|
|
|
info->SaveGame[0] = WRAM;
|
|
|
|
info->SaveGameLen[0] = WRAMSIZE;
|
2012-12-14 18:18:20 +01:00
|
|
|
}
|
2012-12-14 18:43:51 +01:00
|
|
|
GameStateRestore = StateRestore;
|
2012-12-14 18:18:20 +01:00
|
|
|
AddExState(&StateRegs, ~0, 0, 0);
|
2008-09-20 03:02:49 +02:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void Sync3(void) {
|
2012-12-14 18:18:20 +01:00
|
|
|
setchr8(0);
|
2012-12-14 18:43:51 +01:00
|
|
|
setprg8r(0x10, 0x6000, 0);
|
|
|
|
switch (reg[3] & 7) {
|
|
|
|
case 0:
|
|
|
|
case 2: setprg32(0x8000, (reg[0] & 0xc) | (reg[1] & 2) | ((reg[2] & 0xf) << 4)); break;
|
|
|
|
case 1:
|
|
|
|
case 3: setprg32(0x8000, (reg[0] & 0xc) | (reg[2] & 0xf) << 4); break;
|
|
|
|
case 4:
|
|
|
|
case 6: setprg32(0x8000, (reg[0] & 0xe) | ((reg[1] >> 1) & 1) | ((reg[2] & 0xf) << 4)); break;
|
|
|
|
case 5:
|
|
|
|
case 7: setprg32(0x8000, (reg[0] & 0xf) | ((reg[2] & 0xf) << 4)); break;
|
2012-12-14 18:18:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static DECLFW(Write3) {
|
|
|
|
// FCEU_printf("bs %04x %02x\n",A,V);
|
|
|
|
reg[(A >> 8) & 3] = V;
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync();
|
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
static void Power3(void) {
|
|
|
|
reg[0] = 3;
|
|
|
|
reg[1] = 0;
|
|
|
|
reg[2] = 0;
|
|
|
|
reg[3] = 7;
|
|
|
|
SetWriteHandler(0x5000, 0x5FFF, Write3);
|
|
|
|
SetReadHandler(0x6000, 0xFFFF, CartBR);
|
|
|
|
SetWriteHandler(0x6000, 0x7FFF, CartBW);
|
2018-08-13 17:04:20 +02:00
|
|
|
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync();
|
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
void UNLFS304_Init(CartInfo *info) {
|
|
|
|
info->Power = Power3;
|
|
|
|
info->Close = Close;
|
2012-12-14 18:18:20 +01:00
|
|
|
WSync = Sync3;
|
|
|
|
|
|
|
|
WRAMSIZE = 8192;
|
2012-12-14 18:43:51 +01:00
|
|
|
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
|
|
|
|
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
2012-12-14 18:18:20 +01:00
|
|
|
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
if (info->battery) {
|
|
|
|
info->SaveGame[0] = WRAM;
|
|
|
|
info->SaveGameLen[0] = WRAMSIZE;
|
2012-12-14 18:18:20 +01:00
|
|
|
}
|
|
|
|
|
2012-12-14 18:43:51 +01:00
|
|
|
GameStateRestore = StateRestore;
|
2012-12-14 18:18:20 +01:00
|
|
|
AddExState(&StateRegs, ~0, 0, 0);
|
2008-09-02 03:55:12 +02:00
|
|
|
}
|