merge mappers from FCEU-mm
[fceu.git] / boards / 96.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 1998 BERO\r
5  *  Copyright (C) 2002 Xodnizel\r
6  *  Copyright (C) 2012 CaH4e3\r
7  *\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; either version 2 of the License, or\r
11  * (at your option) any later version.\r
12  *\r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  *\r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this program; if not, write to the Free Software\r
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
21  *\r
22  * Oeka-kids board\r
23  *\r
24  * I might want to add some code to the mapper 96 PPU hook function\r
25  * to not change CHR banks if the attribute table is being accessed,\r
26  * if I make emulation a little more accurate in the future.\r
27  *\r
28  */\r
29 \r
30 #include "mapinc.h"\r
31 \r
32 static uint8 reg, ppulatch;\r
33 \r
34 static SFORMAT StateRegs[]=\r
35 {\r
36   {&reg, 1, "REG"},\r
37   {&ppulatch, 1, "PPUL"},\r
38   {0}\r
39 };\r
40 \r
41 static void Sync(void)\r
42 {\r
43   setmirror(MI_0);\r
44   setprg32(0x8000,reg & 3);\r
45   setchr4(0x0000,(reg & 4) | ppulatch);\r
46   setchr4(0x1000,(reg & 4) | 3);\r
47 }\r
48 \r
49 static DECLFW(M96Write)\r
50 {\r
51   reg = V;\r
52   Sync();\r
53 }\r
54 \r
55 static void FP_FASTAPASS(1) M96Hook(uint32 A)\r
56 {\r
57   if((A & 0x3000) == 0x2000)\r
58   {\r
59     ppulatch = (A>>8) & 3;\r
60     Sync();\r
61   }\r
62 }\r
63 \r
64 static void M96Power(void)\r
65 {\r
66   reg = ppulatch = 0;\r
67   Sync();\r
68   SetReadHandler(0x8000,0xffff,CartBR);\r
69   SetWriteHandler(0x8000,0xffff,M96Write);\r
70 }\r
71 \r
72 static void StateRestore(int version)\r
73 {\r
74   Sync();\r
75 }\r
76 \r
77 void Mapper96_Init(CartInfo *info)\r
78 {\r
79   info->Power=M96Power;\r
80   PPU_hook=M96Hook;\r
81   GameStateRestore=StateRestore;\r
82   AddExState(&StateRegs, ~0, 0, 0);\r
83 }\r
84 \r