mappers updated to 0.98.16
[fceu.git] / boards / bmc13in1jy110.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 bank_mode;
26 static uint8 bank_value;
27 static uint8 prgb[4];
28 static SFORMAT StateRegs[]=
29 {
30   {0}
31 };
32
33 static void Sync(void)
34 {
35   FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]);  
36   switch(bank_mode&7)
37   {
38     case 0:
39          setprg32(0x8000,bank_value&7); break;
40     case 1:
41          setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]);
42          setprg16(0xC000,(bank_value&7)>>1);
43     case 4:
44          setprg32(0x8000,8+(bank_value&7)); break;
45     case 5:
46          setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]);
47          setprg16(0xC000,((8+(bank_value&7))>>1)+prgb[3]);
48     case 2:
49          setprg8(0x8000,prgb[0]>>2);
50          setprg8(0xa000,prgb[1]);
51          setprg8(0xc000,prgb[2]);
52          setprg8(0xe000,~0);
53          break;
54     case 3:
55          setprg8(0x8000,prgb[0]);
56          setprg8(0xa000,prgb[1]);
57          setprg8(0xc000,prgb[2]);
58          setprg8(0xe000,prgb[3]);
59          break;
60   }
61 }
62
63 static DECLFW(BMC13in1JY110Write)
64 {
65   FCEU_printf("%04x:%04x\n",A,V);
66   switch(A)
67   {
68     case 0x8000:
69     case 0x8001:
70     case 0x8002:
71     case 0x8003: prgb[A&3]=V; break;
72     case 0xD000: bank_mode=V; break;
73     case 0xD001: setmirror(V&3);
74     case 0xD002: break;
75     case 0xD003: bank_value=V; break;
76   }
77   Sync();
78 }
79
80 static void BMC13in1JY110Power(void)
81 {
82   prgb[0]=prgb[1]=prgb[2]=prgb[3]=0;
83   bank_mode=0;
84   bank_value=0;
85   setprg32(0x8000,0);
86   setchr8(0);
87   SetWriteHandler(0x8000,0xFFFF,BMC13in1JY110Write);
88   SetReadHandler(0x8000,0xFFFF,CartBR);
89 }
90
91 static void StateRestore(int version)
92 {
93   Sync();
94 }
95
96 void BMC13in1JY110_Init(CartInfo *info)
97 {
98   info->Power=BMC13in1JY110Power;
99   AddExState(&StateRegs, ~0, 0, 0);
100   GameStateRestore=StateRestore;
101 }
102
103