fceugx/source/fceultra/boards/ks7017.cpp

116 lines
2.8 KiB
C++
Raw Normal View History

2012-12-14 18:18:20 +01:00
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 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
*
* FDS Conversion
*
*/
#include "mapinc.h"
static uint8 reg, mirr;
static int32 IRQa, IRQCount, IRQLatch;
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 SFORMAT StateRegs[] =
2012-12-14 18:18:20 +01:00
{
2012-12-14 18:43:51 +01:00
{ &mirr, 1, "MIRR" },
{ &reg, 1, "REGS" },
{ &IRQa, 4, "IRQA" },
{ &IRQCount, 4, "IRQC" },
{ &IRQLatch, 4, "IRQL" },
{ 0 }
2012-12-14 18:18:20 +01:00
};
2012-12-14 18:43:51 +01:00
static void Sync(void) {
setprg16(0x8000, reg);
setprg16(0xC000, 2);
setmirror(mirr);
2012-12-14 18:18:20 +01:00
}
2012-12-14 18:43:51 +01:00
static DECLFW(UNLKS7017Write) {
// FCEU_printf("bs %04x %02x\n",A,V);
if ((A & 0xFF00) == 0x4A00) {
reg = ((A >> 2) & 3) | ((A >> 4) & 4);
} else if ((A & 0xFF00) == 0x5100) {
Sync();
} else if (A == 0x4020) {
X6502_IRQEnd(FCEU_IQEXT);
IRQCount &= 0xFF00;
IRQCount |= V;
} else if (A == 0x4021) {
X6502_IRQEnd(FCEU_IQEXT);
IRQCount &= 0xFF;
IRQCount |= V << 8;
IRQa = 1;
} else if (A == 0x4025) {
mirr = ((V & 8) >> 3) ^ 1;
}
2012-12-14 18:18:20 +01:00
}
2012-12-14 18:43:51 +01:00
static DECLFR(FDSRead4030) {
X6502_IRQEnd(FCEU_IQEXT);
return X.IRQlow & FCEU_IQEXT ? 1 : 0;
2012-12-14 18:18:20 +01:00
}
2012-12-14 18:43:51 +01:00
static void UNL7017IRQ(int a) {
if (IRQa) {
IRQCount -= a;
if (IRQCount <= 0) {
IRQa = 0;
X6502_IRQBegin(FCEU_IQEXT);
}
}
2012-12-14 18:18:20 +01:00
}
2012-12-14 18:43:51 +01:00
static void UNLKS7017Power(void) {
Sync();
setchr8(0);
setprg8r(0x10, 0x6000, 0);
SetReadHandler(0x6000, 0x7FFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetReadHandler(0x4030, 0x4030, FDSRead4030);
SetWriteHandler(0x4020, 0x5FFF, UNLKS7017Write);
2016-09-18 05:43:24 +02:00
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
2012-12-14 18:18:20 +01:00
}
2012-12-14 18:43:51 +01:00
static void UNLKS7017Close(void) {
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
2012-12-14 18:18:20 +01:00
}
2012-12-14 18:43:51 +01:00
static void StateRestore(int version) {
Sync();
2012-12-14 18:18:20 +01:00
}
2012-12-14 18:43:51 +01:00
void UNLKS7017_Init(CartInfo *info) {
info->Power = UNLKS7017Power;
info->Close = UNLKS7017Close;
MapIRQHook = UNL7017IRQ;
2012-12-14 18:18:20 +01:00
2012-12-14 18:43:51 +01:00
WRAMSIZE = 8192;
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
2012-12-14 18:18:20 +01:00
2012-12-14 18:43:51 +01:00
GameStateRestore = StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
2012-12-14 18:18:20 +01:00
}