merge mappers from FCEU-mm
[fceu.git] / boards / 34.c
CommitLineData
386f5371 1/* FCE Ultra - NES/Famicom Emulator\r
2 *\r
3 * Copyright notice for this file:\r
43725da7 4 * Copyright (C) 2012 CaH4e3\r
386f5371 5 *\r
6 * This program is free software; you can redistribute it and/or modify\r
7 * it under the terms of the GNU General Public License as published by\r
8 * the Free Software Foundation; either version 2 of the License, or\r
9 * (at your option) any later version.\r
10 *\r
11 * This program is distributed in the hope that it will be useful,\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
14 * GNU General Public License for more details.\r
15 *\r
16 * You should have received a copy of the GNU General Public License\r
17 * along with this program; if not, write to the Free Software\r
43725da7 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
19 *\r
20 * Many-in-one hacked mapper crap.\r
21 * \r
22 * Original BNROM is actually AxROM variations without mirroring control,\r
23 * and haven't SRAM on-board, so it must be removed from here\r
24 *\r
25 * Difficult banking is what NINA board doing, most hacks for 34 mapper are\r
26 * NINA hacks, so this is actually 34 mapper\r
27 *\r
386f5371 28 */\r
29\r
30#include "mapinc.h"\r
31\r
43725da7 32static uint8 regs[3];\r
386f5371 33static uint8 *WRAM=NULL;\r
34static uint32 WRAMSIZE;\r
35\r
36static SFORMAT StateRegs[]=\r
37{\r
43725da7 38 {regs, 3, "REGS"},\r
386f5371 39 {0}\r
40};\r
41\r
42static void Sync(void)\r
43{\r
386f5371 44 setprg8r(0x10,0x6000,0);\r
43725da7 45 setprg32(0x8000,regs[0]);\r
46 setchr4(0x0000,regs[1]); \r
47 setchr4(0x1000,regs[2]); \r
386f5371 48}\r
49\r
43725da7 50static DECLFW(M34Write)\r
386f5371 51{\r
43725da7 52 if(A>=0x8000)\r
53 regs[0] = V;\r
54 else\r
55 switch(A)\r
56 {\r
57 case 0x7ffd: regs[0] = V; break;\r
58 case 0x7ffe: regs[1] = V; break;\r
59 case 0x7fff: regs[2] = V; break;\r
60 }\r
386f5371 61 Sync();\r
62}\r
63\r
43725da7 64static void M34Power(void)\r
386f5371 65{\r
43725da7 66 regs[0] = 0;\r
386f5371 67 Sync();\r
43725da7 68 SetReadHandler(0x6000,0x7ffc,CartBR);\r
69 SetWriteHandler(0x6000,0x7ffc,CartBW);\r
70 SetReadHandler(0x8000,0xffff,CartBR);\r
71 SetWriteHandler(0x7ffd,0xffff,M34Write);\r
386f5371 72}\r
73\r
43725da7 74static void M34Close(void)\r
386f5371 75{\r
76 if(WRAM)\r
77 FCEU_gfree(WRAM);\r
78 WRAM=NULL;\r
79}\r
80\r
81static void StateRestore(int version)\r
82{\r
83 Sync();\r
84}\r
85\r
43725da7 86void Mapper34_Init(CartInfo *info)\r
386f5371 87{\r
43725da7 88 info->Power=M34Power;\r
89 info->Close=M34Close;\r
386f5371 90 GameStateRestore=StateRestore;\r
91\r
92 WRAMSIZE=8192;\r
93 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
94 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
95 AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
386f5371 96\r
97 AddExState(&StateRegs, ~0, 0, 0);\r
98}\r