--- /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
+ * City Fighter IV sith Sound VRC4 hacked\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 IRQCount;\r
+static uint8 IRQPre;\r
+static uint8 IRQa;\r
+static uint8 prg_reg, prg_mode, mirr;\r
+static uint8 chr_reg[8];\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {&IRQCount, 1, "IRQC"},\r
+ {&IRQPre, 1, "IRQP"},\r
+ {&IRQa, 1, "IRQA"},\r
+ {&prg_reg, 1, "PREG"},\r
+ {&prg_mode, 1, "PMOD"},\r
+ {&mirr, 1, "MIRR"},\r
+ {chr_reg, 8, "CREG"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ setprg32(0x8000,prg_reg>>2);\r
+ if(!prg_mode)\r
+ setprg8(0xC000,prg_reg);\r
+ int i;\r
+ for(i=0; i<8; i++)\r
+ setchr1(i<<10,chr_reg[i]); \r
+ switch (mirr)\r
+ {\r
+ case 0: setmirror(MI_V); break;\r
+ case 1: setmirror(MI_H); break;\r
+ case 2: setmirror(MI_0); break;\r
+ case 3: setmirror(MI_1); break;\r
+ }\r
+}\r
+\r
+static DECLFW(UNLCITYFIGHTWrite)\r
+{\r
+ switch(A&0xF00C)\r
+ {\r
+ case 0x9000: prg_reg=V&0xC; mirr=V&3; break;\r
+ case 0x9004:\r
+ case 0x9008:\r
+ case 0x900C: prg_reg=V&0xC; break;\r
+ case 0xC000:\r
+ case 0xC004:\r
+ case 0xC008:\r
+ case 0xC00C: prg_mode=V&1; break;\r
+ case 0xD000: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break;\r
+ case 0xD004: chr_reg[0]=(chr_reg[0]&0x0F)|(V<<4); break;\r
+ case 0xD008: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break;\r
+ case 0xD00C: chr_reg[1]=(chr_reg[1]&0x0F)|(V<<4); break;\r
+ case 0xA000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break;\r
+ case 0xA004: chr_reg[2]=(chr_reg[2]&0x0F)|(V<<4); break;\r
+ case 0xA008: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break;\r
+ case 0xA00C: chr_reg[3]=(chr_reg[3]&0x0F)|(V<<4); break;\r
+ case 0xB000: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break;\r
+ case 0xB004: chr_reg[4]=(chr_reg[4]&0x0F)|(V<<4); break;\r
+ case 0xB008: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break;\r
+ case 0xB00C: chr_reg[5]=(chr_reg[5]&0x0F)|(V<<4); break;\r
+ case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break;\r
+ case 0xE004: chr_reg[6]=(chr_reg[6]&0x0F)|(V<<4); break;\r
+ case 0xE008: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break;\r
+ case 0xE00C: chr_reg[7]=(chr_reg[7]&0x0F)|(V<<4); break;\r
+// case 0xF004: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;\r
+// case 0xF000: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;\r
+ case 0xF008: IRQa=V&2; X6502_IRQEnd(FCEU_IQEXT); break;\r
+// case 0xF00C: IRQPre=16; break;\r
+ default:\r
+ FCEU_printf("bs %04x %02x\n",A,V);\r
+ }\r
+ Sync();\r
+}\r
+\r
+static DECLFW(UNLCITYFIGHTWriteLo)\r
+{\r
+ FCEU_printf("bs %04x %02x\n",A,V);\r
+}\r
+\r
+static void UNLCITYFIGHTIRQ(void)\r
+{\r
+ //if(IRQa)\r
+ {\r
+// IRQCount--;\r
+// if((IRQCount>>1)==0)\r
+// X6502_IRQBegin(FCEU_IQEXT);\r
+// if(scanline==100) X6502_IRQBegin(FCEU_IQEXT);\r
+ }\r
+}\r
+\r
+static void UNLCITYFIGHTPower(void)\r
+{\r
+ prg_reg = 0;\r
+ Sync();\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+ SetWriteHandler(0x4020,0x7FFF,UNLCITYFIGHTWriteLo);\r
+ SetWriteHandler(0x8000,0xFFFF,UNLCITYFIGHTWrite);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+ Sync();\r
+}\r
+\r
+void UNLCITYFIGHT_Init(CartInfo *info)\r
+{\r
+ info->Power=UNLCITYFIGHTPower;\r
+ GameHBIRQHook=UNLCITYFIGHTIRQ;\r
+ GameStateRestore=StateRestore;\r
+ AddExState(&StateRegs, ~0, 0, 0);\r
+}\r