--- /dev/null
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ * Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg0, reg1, reg2;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {®0, 1, "REG0"},\r
+ {®1, 1, "REG1"},\r
+ {®2, 1, "REG2"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ setchr8(0);\r
+ setprg8(0x8000,0xc);\r
+ setprg8(0xe000,0xf);\r
+ if(reg2&0x10)\r
+ {\r
+ setprg8(0x6000,reg0);\r
+ setprg8(0xa000,0xd);\r
+ setprg8(0xc000,0xe);\r
+ }\r
+ else\r
+ {\r
+ setprg8r(0x10,0x6000,0);\r
+ setprg4(0xa000,(0xd<<1));\r
+ setprg2(0xb000,(0xd<<2)+2);\r
+ setprg2r(0x10,0xb800,4);\r
+ setprg2r(0x10,0xc000,5);\r
+ setprg2r(0x10,0xc800,6);\r
+ setprg2r(0x10,0xd000,7);\r
+ setprg2(0xd800,(0xe<<2)+3);\r
+ }\r
+ setmirror(reg1^1);\r
+}\r
+\r
+static DECLFW(M103RamWrite0)\r
+{\r
+ WRAM[A&0x1FFF]=V;\r
+}\r
+\r
+static DECLFW(M103RamWrite1)\r
+{\r
+ WRAM[0x2000+((A-0xB800)&0x1FFF)]=V;\r
+}\r
+\r
+static DECLFW(M103Write0)\r
+{\r
+ reg0=V&0xf;\r
+ Sync();\r
+}\r
+\r
+static DECLFW(M103Write1)\r
+{\r
+ reg1=(V>>3)&1;\r
+ Sync();\r
+}\r
+\r
+static DECLFW(M103Write2)\r
+{\r
+ reg2=V;\r
+ Sync();\r
+}\r
+\r
+static void M103Power(void)\r
+{\r
+ reg0=reg1=0; reg2=0;\r
+ Sync();\r
+ SetReadHandler(0x6000,0x7FFF,CartBR);\r
+ SetWriteHandler(0x6000,0x7FFF,M103RamWrite0);\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+ SetWriteHandler(0xB800,0xD7FF,M103RamWrite1);\r
+ SetWriteHandler(0x8000,0x8FFF,M103Write0);\r
+ SetWriteHandler(0xE000,0xEFFF,M103Write1);\r
+ SetWriteHandler(0xF000,0xFFFF,M103Write2);\r
+}\r
+\r
+static void M103Close(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 Mapper103_Init(CartInfo *info)\r
+{\r
+ info->Power=M103Power;\r
+ info->Close=M103Close;\r
+ GameStateRestore=StateRestore;\r
+\r
+ WRAMSIZE=16384;\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