+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ * Copyright (C) 2012 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ *\r
+ * Many-in-one hacked mapper crap.\r
+ * \r
+ * Original BNROM is actually AxROM variations without mirroring control,\r
+ * and haven't SRAM on-board, so it must be removed from here\r
+ *\r
+ * Difficult banking is what NINA board doing, most hacks for 34 mapper are\r
+ * NINA hacks, so this is actually 34 mapper\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 regs[3];\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {regs, 3, "REGS"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ setprg8r(0x10,0x6000,0);\r
+ setprg32(0x8000,regs[0]);\r
+ setchr4(0x0000,regs[1]); \r
+ setchr4(0x1000,regs[2]); \r
+}\r
+\r
+static DECLFW(M34Write)\r
+{\r
+ if(A>=0x8000)\r
+ regs[0] = V;\r
+ else\r
+ switch(A)\r
+ {\r
+ case 0x7ffd: regs[0] = V; break;\r
+ case 0x7ffe: regs[1] = V; break;\r
+ case 0x7fff: regs[2] = V; break;\r
+ }\r
+ Sync();\r
+}\r
+\r
+static void M34Power(void)\r
+{\r
+ regs[0] = 0;\r
+ Sync();\r
+ SetReadHandler(0x6000,0x7ffc,CartBR);\r
+ SetWriteHandler(0x6000,0x7ffc,CartBW);\r
+ SetReadHandler(0x8000,0xffff,CartBR);\r
+ SetWriteHandler(0x7ffd,0xffff,M34Write);\r
+}\r
+\r
+static void M34Close(void)\r
+{\r
+ if(WRAM)\r
+ FCEU_gfree(WRAM);\r
+ WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+ Sync();\r
+}\r
+\r
+void Mapper34_Init(CartInfo *info)\r
+{\r
+ info->Power=M34Power;\r
+ info->Close=M34Close;\r
+ GameStateRestore=StateRestore;\r
+\r
+ WRAMSIZE=8192;\r
+ WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+ SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+ AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+ AddExState(&StateRegs, ~0, 0, 0);\r
+}\r