| 1 | /* FCE Ultra - NES/Famicom Emulator\r |
| 2 | *\r |
| 3 | * Copyright notice for this file:\r |
| 4 | * Copyright (C) 2007 CaH4e3\r |
| 5 | *\r |
| 6 | * This program is free software; you can redistribute it and/or modify\r |
| 7 | * it under the terms of the GNU General Public License as published by\r |
| 8 | * the Free Software Foundation; either version 2 of the License, or\r |
| 9 | * (at your option) any later version.\r |
| 10 | *\r |
| 11 | * This program is distributed in the hope that it will be useful,\r |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r |
| 14 | * GNU General Public License for more details.\r |
| 15 | *\r |
| 16 | * You should have received a copy of the GNU General Public License\r |
| 17 | * along with this program; if not, write to the Free Software\r |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r |
| 19 | *\r |
| 20 | * City Fighter IV sith Sound VRC4 hacked\r |
| 21 | */\r |
| 22 | \r |
| 23 | #include "mapinc.h"\r |
| 24 | \r |
| 25 | static uint8 IRQCount;\r |
| 26 | static uint8 IRQPre;\r |
| 27 | static uint8 IRQa;\r |
| 28 | static uint8 prg_reg, prg_mode, mirr;\r |
| 29 | static uint8 chr_reg[8];\r |
| 30 | \r |
| 31 | static SFORMAT StateRegs[]=\r |
| 32 | {\r |
| 33 | {&IRQCount, 1, "IRQC"},\r |
| 34 | {&IRQPre, 1, "IRQP"},\r |
| 35 | {&IRQa, 1, "IRQA"},\r |
| 36 | {&prg_reg, 1, "PREG"},\r |
| 37 | {&prg_mode, 1, "PMOD"},\r |
| 38 | {&mirr, 1, "MIRR"},\r |
| 39 | {chr_reg, 8, "CREG"},\r |
| 40 | {0}\r |
| 41 | };\r |
| 42 | \r |
| 43 | static void Sync(void)\r |
| 44 | {\r |
| 45 | setprg32(0x8000,prg_reg>>2);\r |
| 46 | if(!prg_mode)\r |
| 47 | setprg8(0xC000,prg_reg);\r |
| 48 | int i;\r |
| 49 | for(i=0; i<8; i++)\r |
| 50 | setchr1(i<<10,chr_reg[i]); \r |
| 51 | switch (mirr)\r |
| 52 | {\r |
| 53 | case 0: setmirror(MI_V); break;\r |
| 54 | case 1: setmirror(MI_H); break;\r |
| 55 | case 2: setmirror(MI_0); break;\r |
| 56 | case 3: setmirror(MI_1); break;\r |
| 57 | }\r |
| 58 | }\r |
| 59 | \r |
| 60 | static DECLFW(UNLCITYFIGHTWrite)\r |
| 61 | {\r |
| 62 | switch(A&0xF00C)\r |
| 63 | {\r |
| 64 | case 0x9000: prg_reg=V&0xC; mirr=V&3; break;\r |
| 65 | case 0x9004:\r |
| 66 | case 0x9008:\r |
| 67 | case 0x900C: prg_reg=V&0xC; break;\r |
| 68 | case 0xC000:\r |
| 69 | case 0xC004:\r |
| 70 | case 0xC008:\r |
| 71 | case 0xC00C: prg_mode=V&1; break;\r |
| 72 | case 0xD000: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break;\r |
| 73 | case 0xD004: chr_reg[0]=(chr_reg[0]&0x0F)|(V<<4); break;\r |
| 74 | case 0xD008: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break;\r |
| 75 | case 0xD00C: chr_reg[1]=(chr_reg[1]&0x0F)|(V<<4); break;\r |
| 76 | case 0xA000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break;\r |
| 77 | case 0xA004: chr_reg[2]=(chr_reg[2]&0x0F)|(V<<4); break;\r |
| 78 | case 0xA008: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break;\r |
| 79 | case 0xA00C: chr_reg[3]=(chr_reg[3]&0x0F)|(V<<4); break;\r |
| 80 | case 0xB000: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break;\r |
| 81 | case 0xB004: chr_reg[4]=(chr_reg[4]&0x0F)|(V<<4); break;\r |
| 82 | case 0xB008: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break;\r |
| 83 | case 0xB00C: chr_reg[5]=(chr_reg[5]&0x0F)|(V<<4); break;\r |
| 84 | case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break;\r |
| 85 | case 0xE004: chr_reg[6]=(chr_reg[6]&0x0F)|(V<<4); break;\r |
| 86 | case 0xE008: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break;\r |
| 87 | case 0xE00C: chr_reg[7]=(chr_reg[7]&0x0F)|(V<<4); break;\r |
| 88 | // case 0xF004: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;\r |
| 89 | // case 0xF000: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;\r |
| 90 | case 0xF008: IRQa=V&2; X6502_IRQEnd(FCEU_IQEXT); break;\r |
| 91 | // case 0xF00C: IRQPre=16; break;\r |
| 92 | default:\r |
| 93 | FCEU_printf("bs %04x %02x\n",A,V);\r |
| 94 | }\r |
| 95 | Sync();\r |
| 96 | }\r |
| 97 | \r |
| 98 | static DECLFW(UNLCITYFIGHTWriteLo)\r |
| 99 | {\r |
| 100 | FCEU_printf("bs %04x %02x\n",A,V);\r |
| 101 | }\r |
| 102 | \r |
| 103 | static void UNLCITYFIGHTIRQ(void)\r |
| 104 | {\r |
| 105 | //if(IRQa)\r |
| 106 | {\r |
| 107 | // IRQCount--;\r |
| 108 | // if((IRQCount>>1)==0)\r |
| 109 | // X6502_IRQBegin(FCEU_IQEXT);\r |
| 110 | // if(scanline==100) X6502_IRQBegin(FCEU_IQEXT);\r |
| 111 | }\r |
| 112 | }\r |
| 113 | \r |
| 114 | static void UNLCITYFIGHTPower(void)\r |
| 115 | {\r |
| 116 | prg_reg = 0;\r |
| 117 | Sync();\r |
| 118 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
| 119 | SetWriteHandler(0x4020,0x7FFF,UNLCITYFIGHTWriteLo);\r |
| 120 | SetWriteHandler(0x8000,0xFFFF,UNLCITYFIGHTWrite);\r |
| 121 | }\r |
| 122 | \r |
| 123 | static void StateRestore(int version)\r |
| 124 | {\r |
| 125 | Sync();\r |
| 126 | }\r |
| 127 | \r |
| 128 | void UNLCITYFIGHT_Init(CartInfo *info)\r |
| 129 | {\r |
| 130 | info->Power=UNLCITYFIGHTPower;\r |
| 131 | GameHBIRQHook=UNLCITYFIGHTIRQ;\r |
| 132 | GameStateRestore=StateRestore;\r |
| 133 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 134 | }\r |