merge mappers from FCEU-mm
[fceu.git] / boards / vrc7.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2009 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  * YOKO Mortal Kombat V Pro, VRC7 pirate clone\r
21  */\r
22 \r
23 #include "mapinc.h"\r
24 \r
25 static uint8 prg[3], chr[8], mirr;\r
26 static uint8 IRQLatch, IRQa, IRQd;\r
27 static uint32 IRQCount, CycleCount;\r
28 \r
29 static SFORMAT StateRegs[]=\r
30 {\r
31   {prg, 3, "PRG"},\r
32   {chr, 8, "CHR"},\r
33   {&mirr, 1, "MIRR"},\r
34   {&IRQa, 1, "IRQA"},\r
35   {&IRQd, 1, "IRQD"},\r
36   {&IRQLatch, 1, "IRQC"},\r
37   {&IRQCount, 4, "IRQC"},\r
38   {&CycleCount, 4, "CYCC"},\r
39   {0}\r
40 };\r
41 \r
42 static void Sync(void)\r
43 {\r
44   uint8 i;\r
45   setprg8(0x8000,prg[0]);\r
46   setprg8(0xa000,prg[1]);\r
47   setprg8(0xc000,prg[2]);\r
48   setprg8(0xe000,~0);\r
49   for(i=0; i<8; i++)\r
50     setchr1(i<<10,chr[i]);\r
51   switch(mirr&3)\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(UNLVRC7Write)\r
61 {\r
62   switch(A&0xF008)\r
63   {\r
64     case 0x8000: prg[0]=V; Sync(); break;\r
65     case 0x8008: prg[1]=V; Sync(); break;\r
66     case 0x9000: prg[2]=V; Sync(); break;\r
67     case 0xa000: chr[0]=V; Sync(); break;\r
68     case 0xa008: chr[1]=V; Sync(); break;\r
69     case 0xb000: chr[2]=V; Sync(); break;\r
70     case 0xb008: chr[3]=V; Sync(); break;\r
71     case 0xc000: chr[4]=V; Sync(); break;\r
72     case 0xc008: chr[5]=V; Sync(); break;\r
73     case 0xd000: chr[6]=V; Sync(); break;\r
74     case 0xd008: chr[7]=V; Sync(); break;\r
75     case 0xe000: mirr=V; Sync(); break;\r
76     case 0xe008:\r
77       IRQLatch=V;\r
78       X6502_IRQEnd(FCEU_IQEXT);\r
79       break;\r
80     case 0xf000:\r
81       IRQa=V&2;\r
82       IRQd=V&1;\r
83       if(V&2)\r
84         IRQCount=IRQLatch;\r
85       CycleCount=0;\r
86       X6502_IRQEnd(FCEU_IQEXT);\r
87       break;\r
88     case 0xf008:\r
89       if(IRQd)\r
90         IRQa=1;\r
91       else\r
92         IRQa=0;\r
93       X6502_IRQEnd(FCEU_IQEXT);\r
94       break;\r
95   } \r
96 }\r
97 \r
98 static void UNLVRC7Power(void)\r
99 {\r
100   Sync();\r
101   SetReadHandler(0x8000,0xFFFF,CartBR);\r
102   SetWriteHandler(0x8000,0xFFFF,UNLVRC7Write);\r
103 }\r
104 \r
105 static void UNLVRC7IRQHook(int a)\r
106 {\r
107   if(IRQa)\r
108   {\r
109     CycleCount+=a*3;\r
110     while(CycleCount>=341)\r
111     {\r
112       CycleCount-=341;\r
113       IRQCount++;\r
114       if(IRQCount==248)\r
115       {\r
116         X6502_IRQBegin(FCEU_IQEXT);\r
117         IRQCount=IRQLatch;\r
118       }\r
119     }\r
120   }\r
121 }\r
122 \r
123 static void StateRestore(int version)\r
124 {\r
125   Sync();\r
126 }\r
127 \r
128 void UNLVRC7_Init(CartInfo *info)\r
129 {\r
130   info->Power=UNLVRC7Power;\r
131   MapIRQHook=UNLVRC7IRQHook;\r
132   GameStateRestore=StateRestore;\r
133   AddExState(&StateRegs, ~0, 0, 0);\r
134 }\r