Files
ci-libretro-fceumm/src/boards/449.c

106 lines
2.4 KiB
C
Raw Normal View History

2022-07-27 13:35:33 +02:00
/* FCEUmm - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2022
*
* 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
*/
#include "mapinc.h"
static uint16 latchAddr;
static uint8 latchData;
static uint8 dipswitch;
2023-03-27 21:24:28 +02:00
static uint8 dipselect;
2022-07-27 13:35:33 +02:00
static SFORMAT StateRegs[] =
{
{ &latchAddr, 2, "ADDR" },
{ &latchData, 1, "DATA" },
{ &latchData, 1, "DIPS" },
2023-03-27 21:24:28 +02:00
{ &dipselect, 1, "DSEL" },
2022-07-27 13:35:33 +02:00
{ 0 }
};
static void Mapper449_Sync(void)
{
int prg =latchAddr >>2 &0x1F | latchAddr >>3 &0x20;
if (~latchAddr &0x080)
{
setprg16(0x8000, prg);
setprg16(0xC000, prg |7);
}
else
{
if (latchAddr &0x001)
{
setprg32(0x8000, prg >>1);
}
else
{
setprg16(0x8000, prg);
setprg16(0xC000, prg);
}
}
setchr8(latchData);
setmirror(latchAddr &0x002? MI_H: MI_V);
}
static DECLFR(Mapper449_Read)
{
2023-03-27 21:24:28 +02:00
if (dipselect)
return dipswitch &0x3;
else
if (latchAddr &0x200)
2023-03-27 21:24:28 +02:00
return CartBR(A | dipswitch &0xF);
else
return CartBR(A);
}
2023-03-27 21:24:28 +02:00
static DECLFW(Mapper449_WriteDIPSelect)
{
dipselect =V &1;
}
2022-07-27 13:35:33 +02:00
static DECLFW(Mapper449_WriteLatch)
{
latchData =V;
latchAddr =A &0xFFFF;
Mapper449_Sync();
}
static void Mapper449_Reset(void)
{
2023-03-27 21:24:28 +02:00
dipswitch++;
2022-07-27 13:35:33 +02:00
latchAddr =latchData =0;
Mapper449_Sync();
}
static void Mapper449_Power(void)
{
2023-03-27 21:24:28 +02:00
dipselect =dipswitch =latchAddr =latchData =0;
2022-07-27 13:35:33 +02:00
Mapper449_Sync();
2023-03-27 21:24:28 +02:00
SetWriteHandler(0x6000, 0x7FFF, Mapper449_WriteDIPSelect);
2022-07-27 13:35:33 +02:00
SetWriteHandler(0x8000, 0xFFFF, Mapper449_WriteLatch);
SetReadHandler(0x6000, 0x7FFF, CartBR);
SetReadHandler(0x8000, 0xFFFF, Mapper449_Read);
2022-07-27 13:35:33 +02:00
}
void Mapper449_Init(CartInfo *info)
{
info->Power = Mapper449_Power;
info->Reset = Mapper449_Reset;
AddExState(StateRegs, ~0, 0, 0);
}