--- /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 reg[4], IRQa;\r
+static int16 IRQCount, IRQPause;\r
+\r
+static int16 Count = 0x0000;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {reg, 4, "REGS"},\r
+ {&IRQa, 1, "IRQA"},\r
+ {&IRQCount, 2, "IRQC"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ setprg32(0x8000,0);\r
+ setchr8(0);\r
+}\r
+\r
+//#define Count 0x1800\r
+#define Pause 0x010\r
+\r
+static DECLFW(UNL3DBlockWrite)\r
+{\r
+ switch(A)\r
+ {\r
+//4800 32\r
+//4900 37\r
+//4a00 01\r
+//4e00 18\r
+ case 0x4800: reg[0]=V; break;\r
+ case 0x4900: reg[1]=V; break;\r
+ case 0x4a00: reg[2]=V; break;\r
+ case 0x4e00: reg[3]=V; IRQCount=Count; IRQPause=Pause; IRQa=1; X6502_IRQEnd(FCEU_IQEXT); break;\r
+ } \r
+}\r
+\r
+static void UNL3DBlockPower(void)\r
+{\r
+ Sync();\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+ SetWriteHandler(0x4800,0x4E00,UNL3DBlockWrite);\r
+}\r
+\r
+static void UNL3DBlockReset(void)\r
+{\r
+ Count+=0x10;\r
+ FCEU_printf("Count=%04x\n",Count);\r
+}\r
+\r
+static void UNL3DBlockIRQHook(int a)\r
+{\r
+ if(IRQa)\r
+ {\r
+ if(IRQCount>0)\r
+ {\r
+ IRQCount-=a;\r
+ }\r
+ else\r
+ {\r
+ if(IRQPause>0)\r
+ {\r
+ IRQPause-=a;\r
+ X6502_IRQBegin(FCEU_IQEXT);\r
+ }\r
+ else\r
+ {\r
+ IRQCount=Count; \r
+ IRQPause=Pause;\r
+ X6502_IRQEnd(FCEU_IQEXT);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+ Sync();\r
+}\r
+\r
+void UNL3DBlock_Init(CartInfo *info)\r
+{\r
+ info->Power=UNL3DBlockPower;\r
+ info->Reset=UNL3DBlockReset;\r
+ MapIRQHook=UNL3DBlockIRQHook;\r
+ GameStateRestore=StateRestore;\r
+ AddExState(&StateRegs, ~0, 0, 0);\r
+}\r