merge PCM 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
43725da7 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
c62d2810 19 */
20
21#include "mapinc.h"
22
23#define rg mapbyte1
24
25static void DoSync(uint32 A)
26{
43725da7 27 uint32 S = A & 1;
28 uint32 p = (A >> 2) & 0x1F;
386f5371 29 p += (A&0x100) ? 0x20 : 0;
43725da7 30 uint32 o = (A>>7)&1;
31 uint32 L = (A>>9)&1;
386f5371 32
33 if (o && !S )
43725da7 34 {
386f5371 35 ROM_BANK16(0x8000,p);
36 ROM_BANK16(0xC000,p);
43725da7 37 }
386f5371 38 if (o && S )
43725da7 39 {
386f5371 40 ROM_BANK16(0x8000,p);
41 ROM_BANK16(0xC000,p+1);
43725da7 42 }
386f5371 43 if (!o && !S && !L )
43725da7 44 {
386f5371 45 ROM_BANK16(0x8000,p);
46 ROM_BANK16(0xC000,p&0x38);
43725da7 47 }
386f5371 48 if (!o && S && !L )
43725da7 49 {
386f5371 50 ROM_BANK16(0x8000,p&0x3E);
51 ROM_BANK16(0xC000,p&0x38);
43725da7 52 }
386f5371 53 if (!o && !S && L)
54 {
55 ROM_BANK16(0x8000,p);
56 ROM_BANK16(0xC000,p|7);
57 }
58 if (!o && S && L )
59 {
60 ROM_BANK16(0x8000,p&0x3E);
61 ROM_BANK16(0xC000,p|7);
62 }
c62d2810 63
43725da7 64 rg[0]=A;
65 rg[1]=A>>8;
c62d2810 66
43725da7 67 MIRROR_SET((A>>1)&1);
c62d2810 68}
69
70static DECLFW(Mapper227_write)
71{
43725da7 72 DoSync(A);
c62d2810 73}
74
75static void M227Reset(void)
76{
43725da7 77 DoSync(0);
c62d2810 78}
79
80static void M227Restore(int version)
81{
43725da7 82 DoSync(rg[0]|(rg[1]<<8));
c62d2810 83}
84
85void Mapper227_init(void)
86{
43725da7 87 SetWriteHandler(0x8000,0xffff,Mapper227_write);
88 MapperReset=M227Reset;
89 GameStateRestore=M227Restore;
90 M227Reset();
c62d2810 91}