--- /dev/null
+/* 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
+ * FFE Copier Mapper\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 preg[4], creg[8];\r
+static uint8 IRQa, mirr;\r
+static int32 IRQCount, IRQLatch;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {preg, 4, "PREG"},\r
+ {creg, 8, "CREG"},\r
+ {&mirr, 1, "MIRR"},\r
+ {&IRQa, 1, "IRQA"},\r
+ {&IRQCount, 4, "IRQC"},\r
+ {&IRQLatch, 4, "IRQL"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ int i;\r
+ for(i=0; i<8; i++) setchr1(i<<10,creg[i]);\r
+ setprg8(0x8000,preg[0]);\r
+ setprg8(0xA000,preg[1]);\r
+ setprg8(0xC000,preg[2]);\r
+ setprg8(0xE000,preg[3]);\r
+ switch(mirr) {\r
+ case 0: setmirror(MI_0); break;\r
+ case 1: setmirror(MI_1); break;\r
+ case 2: setmirror(MI_H); break;\r
+ case 3: setmirror(MI_V); break;\r
+ }\r
+}\r
+\r
+static DECLFW(M17WriteMirr)\r
+{\r
+ mirr = ((A << 1) & 2)|((V >> 4) & 1);\r
+ Sync();\r
+}\r
+\r
+static DECLFW(M17WriteIRQ)\r
+{\r
+ switch(A) {\r
+ case 0x4501: IRQa=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+ case 0x4502: IRQCount&=0xFF00; IRQCount|=V; break;\r
+ case 0x4503: IRQCount&=0x00FF; IRQCount|=V<<8; IRQa=1; break;\r
+ }\r
+}\r
+\r
+static DECLFW(M17WritePrg)\r
+{\r
+ preg[A & 3] = V;\r
+ Sync();\r
+}\r
+\r
+static DECLFW(M17WriteChr)\r
+{\r
+ creg[A & 7] = V;\r
+ Sync();\r
+}\r
+\r
+static void M17Power(void)\r
+{\r
+ preg[3] = ~0;\r
+ Sync();\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+ SetWriteHandler(0x42FE,0x42FF,M17WriteMirr);\r
+ SetWriteHandler(0x4500,0x4503,M17WriteIRQ);\r
+ SetWriteHandler(0x4504,0x4507,M17WritePrg);\r
+ SetWriteHandler(0x4510,0x4517,M17WriteChr);\r
+}\r
+\r
+static void FP_FASTAPASS(1) M17IRQHook(int a)\r
+{\r
+ if(IRQa)\r
+ {\r
+ IRQCount+=a;\r
+ if(IRQCount>=0x10000)\r
+ {\r
+ X6502_IRQBegin(FCEU_IQEXT);\r
+ IRQa=0;\r
+ IRQCount=0;\r
+ }\r
+ }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+ Sync();\r
+}\r
+\r
+void Mapper17_Init(CartInfo *info)\r
+{\r
+ info->Power=M17Power;\r
+ GameHBIRQHook=M17IRQHook;\r
+ GameStateRestore=StateRestore;\r
+\r
+ AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r