merge mapper code from FCEUX
[fceu.git] / mappers / 228.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
d97315ac 4 * Copyright (C) 2002 Xodnizel
c62d2810 5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
386f5371 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c62d2810 19 */
20
21#include "mapinc.h"
22
386f5371 23//16 bits of ram in total
24//only use bottom 4 bits as ram though
25static uint8 mapper228_ram[4];
26
27static SFORMAT StateRegs[]=
28{
29 { mapper228_ram, 4, "MAPPER_RAM" },
30 { 0 }
31};
32
33static DECLFR(Mapper228_read)
34{
35 return mapper228_ram[A & 3] & 0xF;
36}
37
c62d2810 38static DECLFW(Mapper228_write)
39{
386f5371 40 uint32 page, pagel, pageh;
c62d2810 41
386f5371 42 //write to ram
43 if (A < 0x6000)
44 {
45 mapper228_ram[A & 3] = V;
46 return;
47 }
48 MIRROR_SET((A >> 13) & 1);
49 page = (A >> 7) & 0x3F;
c62d2810 50
386f5371 51 if( (page & 0x30) == 0x30)
52 page -= 0x10;
c62d2810 53
386f5371 54 pagel = pageh = (page << 1) + (((A >> 6) & 1) & ((A >> 5) & 1));
55 pageh += ((A >> 5) & 1) ^ 1;
56
57 ROM_BANK16(0x8000,pagel);
58 ROM_BANK16(0xC000,pageh);
59 VROM_BANK8( (V&0x3) | ((A&0xF)<<2) );
c62d2810 60}
61
62static void A52Reset(void)
63{
386f5371 64 Mapper228_write(0x8000, 0);
c62d2810 65}
66
67void Mapper228_init(void)
68{
386f5371 69 MapperReset=A52Reset;
70 A52Reset();
71 SetWriteHandler(0x8000, 0xFFFF, Mapper228_write);
72 SetWriteHandler(0x4020, 0x5FFF, Mapper228_write);
73 SetReadHandler (0x4020, 0x5FFF, Mapper228_read);
74 AddExState(StateRegs, ~0, 0, 0);
c62d2810 75}
76