merge mappers from FCEU-mm
[fceu.git] / boards / 183.c
CommitLineData
386f5371 1/* FCE Ultra - NES/Famicom Emulator\r
2 *\r
3 * Copyright notice for this file:\r
4 * Copyright (C) 2005 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
43725da7 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
386f5371 19 *\r
20 * Gimmick Bootleg (VRC4 mapper)\r
21 */\r
22\r
23#include "mapinc.h"\r
24\r
25static uint8 prg[4];\r
26static uint8 chr[8];\r
27static uint8 IRQCount;\r
28static uint8 IRQPre;\r
29static uint8 IRQa;\r
30\r
31static SFORMAT StateRegs[]=\r
32{\r
33 {prg, 4, "PRG"},\r
34 {chr, 8, "CHR"},\r
43725da7 35 {&IRQCount, 1, "IRQC"},\r
36 {&IRQPre, 1, "IRQP"},\r
386f5371 37 {&IRQa, 1, "IRQA"},\r
38 {0}\r
39};\r
40\r
41static void SyncPrg(void)\r
42{\r
43 setprg8(0x6000,0);\r
44 setprg8(0x8000,prg[0]);\r
45 setprg8(0xA000,prg[1]);\r
46 setprg8(0xC000,prg[2]);\r
47 setprg8(0xE000,~0);\r
48}\r
49\r
50static void SyncChr(void)\r
51{\r
52 int i;\r
53 for(i=0; i<8; i++)\r
54 setchr1(i<<10,chr[i]);\r
55}\r
56\r
57static void StateRestore(int version)\r
58{\r
59 SyncPrg();\r
60 SyncChr();\r
61}\r
62\r
63static DECLFW(M183Write)\r
64{\r
65 if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C))\r
66 {\r
43725da7 67 int index=(((A>>11)-6)|(A>>3))&7;\r
386f5371 68 chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4));\r
69 SyncChr();\r
70 }\r
71 else switch (A&0xF80C)\r
72 {\r
73 case 0x8800: prg[0]=V; SyncPrg(); break;\r
74 case 0xA800: prg[1]=V; SyncPrg(); break;\r
75 case 0xA000: prg[2]=V; SyncPrg(); break;\r
76 case 0x9800: switch (V&3)\r
77 {\r
78 case 0: setmirror(MI_V); break;\r
79 case 1: setmirror(MI_H); break;\r
80 case 2: setmirror(MI_0); break;\r
81 case 3: setmirror(MI_1); break;\r
82 }\r
83 break;\r
84 case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;\r
85 case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;\r
86 case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
87 case 0xF00C: IRQPre=16; break;\r
88 }\r
89}\r
90\r
91static void M183IRQCounter(void)\r
92{\r
93 if(IRQa)\r
94 {\r
95 IRQCount++;\r
96 if((IRQCount-IRQPre)==238)\r
97 X6502_IRQBegin(FCEU_IQEXT);\r
98 }\r
99}\r
100\r
101static void M183Power(void)\r
102{\r
103 IRQPre=IRQCount=IRQa=0;\r
104 SetReadHandler(0x8000,0xFFFF,CartBR);\r
105 SetWriteHandler(0x8000,0xFFFF,M183Write);\r
106 SetReadHandler(0x6000,0x7FFF,CartBR);\r
107 SyncPrg();\r
108 SyncChr();\r
109}\r
110\r
111void Mapper183_Init(CartInfo *info)\r
112{\r
113 info->Power=M183Power;\r
114 GameHBIRQHook=M183IRQCounter;\r
115 GameStateRestore=StateRestore;\r
116 AddExState(&StateRegs, ~0, 0, 0);\r
117}\r