--- /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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ *\r
+ * FDS Conversion\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg, IRQa;\r
+static int32 IRQCount;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {®, 1, "REG"},\r
+ {&IRQa, 1, "IRQA"},\r
+ {&IRQCount, 4, "IRQC"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ setchr8(0);\r
+ setprg8(0x6000,reg);\r
+ setprg8(0x8000,0xc);\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
+ setprg8(0xe000,0xf);\r
+}\r
+\r
+static DECLFW(LH53RamWrite)\r
+{\r
+ WRAM[(A-0xB800)&0x1FFF]=V;\r
+}\r
+\r
+static DECLFW(LH53Write)\r
+{\r
+ reg=V;\r
+ Sync();\r
+}\r
+\r
+static DECLFW(LH53IRQaWrite)\r
+{\r
+ IRQa = V&2;\r
+ IRQCount = 0;\r
+ if(!IRQa)\r
+ X6502_IRQEnd(FCEU_IQEXT);\r
+}\r
+\r
+static void FP_FASTAPASS(1) LH53IRQ(int a)\r
+{\r
+ if(IRQa)\r
+ {\r
+ IRQCount+=a;\r
+ if(IRQCount>7560)\r
+ X6502_IRQBegin(FCEU_IQEXT);\r
+ }\r
+}\r
+\r
+static void LH53Power(void)\r
+{\r
+ Sync();\r
+ SetReadHandler(0x6000,0xFFFF,CartBR);\r
+ SetWriteHandler(0xB800,0xD7FF,LH53RamWrite);\r
+ SetWriteHandler(0xE000,0xEFFF,LH53IRQaWrite);\r
+ SetWriteHandler(0xF000,0xFFFF,LH53Write);\r
+}\r
+\r
+static void LH53Close(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 LH53_Init(CartInfo *info)\r
+{\r
+ info->Power=LH53Power;\r
+ info->Close=LH53Close;\r
+ MapIRQHook=LH53IRQ;\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