+/* 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
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static void SA9602BPW(uint32 A, uint8 V)\r
+{\r
+ setprg8r(EXPREGS[1],A,V&0x3F);\r
+ if(MMC3_cmd&0x40)\r
+ setprg8r(0,0x8000,~(1));\r
+ else\r
+ setprg8r(0,0xc000,~(1));\r
+ setprg8r(0,0xe000,~(0));\r
+}\r
+\r
+static DECLFW(SA9602BWrite)\r
+{\r
+ switch(A & 0xe001)\r
+ {\r
+ case 0x8000: EXPREGS[0] = V; break;\r
+ case 0x8001:\r
+ if((EXPREGS[0] & 7) < 6)\r
+ {\r
+ EXPREGS[1] = V >> 6;\r
+ FixMMC3PRG(MMC3_cmd);\r
+ }\r
+ break;\r
+ }\r
+ MMC3_CMDWrite(A, V);\r
+}\r
+\r
+static void SA9602BPower(void)\r
+{\r
+ EXPREGS[0]=EXPREGS[1]=0;\r
+ GenMMC3Power();\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+ SetWriteHandler(0x8000,0xBFFF,SA9602BWrite);\r
+}\r
+\r
+void SA9602B_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 0, 0, 0);\r
+ pwrap=SA9602BPW;\r
+ mmc3opts|=2;\r
+ info->SaveGame[0]=UNIFchrrama;\r
+ info->SaveGameLen[0]=32 * 1024;\r
+ info->Power=SA9602BPower;\r
+ AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r