fceugx/source/fceultra/boards/112.cpp

91 lines
2.4 KiB
C++
Raw Normal View History

2009-07-17 19:27:04 +02:00
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 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
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
*
2009-07-17 19:27:04 +02:00
* NTDEC, ASDER games
2012-12-14 18:43:51 +01:00
*
2009-07-17 19:27:04 +02:00
*/
#include "mapinc.h"
static uint8 reg[8];
static uint8 mirror, cmd, bank;
2012-12-14 18:43:51 +01:00
static uint8 *WRAM = NULL;
2009-07-17 19:27:04 +02:00
2012-12-14 18:43:51 +01:00
static SFORMAT StateRegs[] =
2009-07-17 19:27:04 +02:00
{
2012-12-14 18:43:51 +01:00
{ &cmd, 1, "CMD" },
{ &mirror, 1, "MIRR" },
{ &bank, 1, "BANK" },
{ reg, 8, "REGS" },
{ 0 }
2009-07-17 19:27:04 +02:00
};
2012-12-14 18:43:51 +01:00
static void Sync(void) {
setmirror(mirror ^ 1);
setprg8(0x8000, reg[0]);
setprg8(0xA000, reg[1]);
setchr2(0x0000, (reg[2] >> 1));
setchr2(0x0800, (reg[3] >> 1));
setchr1(0x1000, ((bank & 0x10) << 4) | reg[4]);
setchr1(0x1400, ((bank & 0x20) << 3) | reg[5]);
setchr1(0x1800, ((bank & 0x40) << 2) | reg[6]);
setchr1(0x1C00, ((bank & 0x80) << 1) | reg[7]);
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static DECLFW(M112Write) {
switch (A) {
case 0xe000: mirror = V & 1; Sync();; break;
case 0x8000: cmd = V & 7; break;
case 0xa000: reg[cmd] = V; Sync(); break;
case 0xc000: bank = V; Sync(); break;
}
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static void M112Close(void) {
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static void M112Power(void) {
bank = 0;
setprg16(0xC000, ~0);
setprg8r(0x10, 0x6000, 0);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, M112Write);
SetWriteHandler(0x4020, 0x5FFF, M112Write);
SetReadHandler(0x6000, 0x7FFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
FCEU_CheatAddRAM(8, 0x6000, WRAM);
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static void StateRestore(int version) {
Sync();
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
void Mapper112_Init(CartInfo *info) {
info->Power = M112Power;
info->Close = M112Close;
GameStateRestore = StateRestore;
WRAM = (uint8*)FCEU_gmalloc(8192);
SetupCartPRGMapping(0x10, WRAM, 8192, 1);
AddExState(WRAM, 8192, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
2009-07-17 19:27:04 +02:00
}