fceugx/source/fceultra/boards/sc-127.cpp

124 lines
3.1 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) 2009 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
*
2009-07-17 19:27:04 +02:00
* Wario Land II (Kirby hack)
*/
#include "mapinc.h"
static uint8 reg[8], chr[8];
2012-12-14 18:43:51 +01:00
static uint8 *WRAM = NULL;
2009-07-17 19:27:04 +02:00
static uint32 WRAMSIZE;
static uint16 IRQCount, IRQa;
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
{ reg, 8, "REGS" },
{ chr, 8, "CHRS" },
2016-09-18 05:43:24 +02:00
{ &IRQCount, 2, "IRQc" },
{ &IRQa, 2, "IRQa" },
2012-12-14 18:43:51 +01:00
{ 0 }
2009-07-17 19:27:04 +02:00
};
2012-12-14 18:43:51 +01:00
static void Sync(void) {
int i;
2016-09-18 05:43:24 +02:00
setprg8r(0x10, 0x6000, 0);
2012-12-14 18:43:51 +01:00
setprg8(0x8000, reg[0]);
setprg8(0xA000, reg[1]);
setprg8(0xC000, reg[2]);
2016-09-18 05:43:24 +02:00
setprg8(0xE000, ~0);
2012-12-14 18:43:51 +01:00
for (i = 0; i < 8; i++)
setchr1(i << 10, chr[i]);
setmirror(reg[3] ^ 1);
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static DECLFW(UNLSC127Write) {
switch (A) {
case 0x8000: reg[0] = V; break;
case 0x8001: reg[1] = V; break;
case 0x8002: reg[2] = V; break;
case 0x9000: chr[0] = V; break;
case 0x9001: chr[1] = V; break;
case 0x9002: chr[2] = V; break;
case 0x9003: chr[3] = V; break;
case 0x9004: chr[4] = V; break;
case 0x9005: chr[5] = V; break;
case 0x9006: chr[6] = V; break;
case 0x9007: chr[7] = V; break;
case 0xC002: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xC005: IRQCount = V; break;
case 0xC003: IRQa = 1; break;
case 0xD001: reg[3] = V; break;
}
Sync();
2009-07-17 19:27:04 +02:00
}
2016-09-18 05:43:24 +02:00
static DECLFR(UNLSC127ProtRead) {
return 0x20;
}
2012-12-14 18:43:51 +01:00
static void UNLSC127Power(void) {
2016-09-18 05:43:24 +02:00
IRQCount = IRQa = 0;
2012-12-14 18:43:51 +01:00
Sync();
2016-09-18 05:43:24 +02:00
SetReadHandler(0x5800, 0x5800, UNLSC127ProtRead);
2012-12-14 18:43:51 +01:00
SetReadHandler(0x6000, 0x7fff, CartBR);
SetWriteHandler(0x6000, 0x7fff, CartBW);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, UNLSC127Write);
2016-09-18 05:43:24 +02:00
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static void UNLSC127IRQ(void) {
if (IRQa) {
2016-09-18 05:43:24 +02:00
if(IRQCount > 0)
IRQCount--;
if (!IRQCount) {
2012-12-14 18:43:51 +01:00
X6502_IRQBegin(FCEU_IQEXT);
IRQa = 0;
}
}
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static void UNLSC127Reset(void) {
2016-09-18 05:43:24 +02:00
IRQCount = IRQa = 0;
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
static void UNLSC127Close(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 StateRestore(int version) {
Sync();
2009-07-17 19:27:04 +02:00
}
2012-12-14 18:43:51 +01:00
void UNLSC127_Init(CartInfo *info) {
info->Reset = UNLSC127Reset;
info->Power = UNLSC127Power;
info->Close = UNLSC127Close;
GameHBIRQHook = UNLSC127IRQ;
GameStateRestore = StateRestore;
WRAMSIZE = 8192;
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
2009-07-17 19:27:04 +02:00
}