merge mapper code from FCEUX
[fceu.git] / mappers / 50.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
c62d2810 23
386f5371 24static void Mapper50IRQ(int a)
c62d2810 25{
d97315ac 26 if(IRQa)
c62d2810 27 {
d97315ac 28 if(IRQCount<4096)
29 IRQCount+=a;
30 else
31 {
32 IRQa=0;
33 X6502_IRQBegin(FCEU_IQEXT);
34 }
c62d2810 35 }
c62d2810 36}
37
d97315ac 38static void M50Restore(int version)
c62d2810 39{
d97315ac 40 setprg8(0xc000,mapbyte1[0]);
41}
42
43static DECLFW(M50W)
44{
45 if((A&0xD060)==0x4020)
46 {
47 if(A&0x100)
48 {
49 IRQa=V&1;
50 if(!IRQa) IRQCount=0;
51 X6502_IRQEnd(FCEU_IQEXT);
52 }
53 else
54 {
55 V=((V&1)<<2)|((V&2)>>1)|((V&4)>>1)|(V&8);
56 mapbyte1[0]=V;
57 setprg8(0xc000,V);
58 }
59 }
60}
61
62void Mapper50_init(void)
63{
64 SetWriteHandler(0x4020,0x5fff,M50W);
65 SetReadHandler(0x6000,0xffff,CartBR);
66 MapStateRestore=M50Restore;
67 MapIRQHook=Mapper50IRQ;
68
69 setprg8(0x6000,0xF);
70 setprg8(0x8000,0x8);
71 setprg8(0xa000,0x9);
72 setprg8(0xc000,0x0);
73 setprg8(0xe000,0xB);
c62d2810 74}
75