merge mapper code from FCEUX
[fceu.git] / mappers / 227.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//zero 14-apr-2012 - redid this entirely to match bizhawk
24
c62d2810 25#define rg mapbyte1
26
27static void DoSync(uint32 A)
28{
386f5371 29 int S = A & 1;
30 int M_horz = (A>>1)&1;
31 int p = (A >> 2) & 0x1F;
32 p += (A&0x100) ? 0x20 : 0;
33 bool o = (A>>7)&1;
34 bool L = (A>>9)&1;
35
36 if (o && !S )
37 {
38 ROM_BANK16(0x8000,p);
39 ROM_BANK16(0xC000,p);
40 }
41 if (o && S )
42 {
43 ROM_BANK16(0x8000,p);
44 ROM_BANK16(0xC000,p+1);
45 }
46 if (!o && !S && !L )
47 {
48 ROM_BANK16(0x8000,p);
49 ROM_BANK16(0xC000,p&0x38);
50 }
51 if (!o && S && !L )
52 {
53 ROM_BANK16(0x8000,p&0x3E);
54 ROM_BANK16(0xC000,p&0x38);
55 }
56 if (!o && !S && L)
57 {
58 ROM_BANK16(0x8000,p);
59 ROM_BANK16(0xC000,p|7);
60 }
61 if (!o && S && L )
62 {
63 ROM_BANK16(0x8000,p&0x3E);
64 ROM_BANK16(0xC000,p|7);
65 }
c62d2810 66
67 rg[0]=A;
68 rg[1]=A>>8;
69
70 MIRROR_SET((A>>1)&1);
c62d2810 71}
72
73static DECLFW(Mapper227_write)
74{
c62d2810 75 DoSync(A);
76}
77
78static void M227Reset(void)
79{
c62d2810 80 DoSync(0);
81}
82
83static void M227Restore(int version)
84{
85 DoSync(rg[0]|(rg[1]<<8));
86}
87
88void Mapper227_init(void)
89{
386f5371 90 SetWriteHandler(0x8000,0xffff,Mapper227_write);
c62d2810 91 MapperReset=M227Reset;
92 GameStateRestore=M227Restore;
93 M227Reset();
94}