mappers updated to 0.98.16
[fceu.git] / boards / bmc64in1nr.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2005 CaH4e3
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
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * BMC 42-in-1 reset switch
21  */
22
23 #include "mapinc.h"
24
25 static uint8 regs[4];
26
27 static SFORMAT StateRegs[]=
28 {
29   {regs, 4, "REGS"},
30   {0}
31 };
32
33 static void Sync(void)
34 {
35   if(regs[0]&0x80)
36   {
37     if(regs[1]&0x80)
38       setprg32(0x8000,regs[1]&0x1F);
39     else
40     {
41       int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);
42       setprg16(0x8000,bank);
43       setprg16(0xC000,bank);
44     }
45   }
46   else
47   {
48     int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);
49     setprg16(0xC000,bank);
50   }
51   if(regs[0]&0x20)
52     setmirror(MI_H);
53   else
54     setmirror(MI_V);
55   setchr8((regs[2]<<2)|((regs[0]>>1)&3));
56 }
57
58 static DECLFW(BMC64in1nrWriteLo)
59 {
60   regs[A&3]=V;
61   Sync();
62 }
63
64 static DECLFW(BMC64in1nrWriteHi)
65 {
66   regs[3]=V;
67   Sync();
68 }
69
70 static void BMC64in1nrPower(void)
71 {
72   regs[0]=0x80;
73   regs[1]=0x43;
74   regs[2]=regs[3]=0;
75   Sync();
76   SetWriteHandler(0x5000,0x5003,BMC64in1nrWriteLo);
77   SetWriteHandler(0x8000,0xFFFF,BMC64in1nrWriteHi);
78   SetReadHandler(0x8000,0xFFFF,CartBR);
79 }
80
81 static void StateRestore(int version)
82 {
83   Sync();
84 }
85
86 void BMC64in1nr_Init(CartInfo *info)
87 {
88   info->Power=BMC64in1nrPower;
89   AddExState(&StateRegs, ~0, 0, 0);
90   GameStateRestore=StateRestore;
91 }
92
93