merge mapper code from FCEUX
[fceu.git] / boards / 199.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
19  *\r
20  * Dragon Ball Z 2 - Gekishin Freeza! (C)\r
21  * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C)\r
22  * San Guo Zhi 2 (C)\r
23  *\r
24  */\r
25 \r
26 #include "mapinc.h"\r
27 #include "mmc3.h"\r
28 \r
29 static uint8 *CHRRAM=NULL; // and here too\r
30 \r
31 static void M199PW(uint32 A, uint8 V)\r
32 {\r
33   setprg8(A,V);\r
34   setprg8(0xC000,EXPREGS[0]);\r
35   setprg8(0xE000,EXPREGS[1]);\r
36 }\r
37 \r
38 static void M199CW(uint32 A, uint8 V)\r
39 {\r
40   setchr1r((V<8)?0x10:0x00,A,V);\r
41   setchr1r((DRegBuf[0]<8)?0x10:0x00,0x0000,DRegBuf[0]);\r
42   setchr1r((EXPREGS[2]<8)?0x10:0x00,0x0400,EXPREGS[2]);\r
43   setchr1r((DRegBuf[1]<8)?0x10:0x00,0x0800,DRegBuf[1]);\r
44   setchr1r((EXPREGS[3]<8)?0x10:0x00,0x0c00,EXPREGS[3]);\r
45 }\r
46 \r
47 static void M199MW(uint8 V)\r
48 {\r
49 //    FCEU_printf("%02x\n",V);\r
50   switch(V&3)\r
51   {\r
52     case 0: setmirror(MI_V); break;\r
53     case 1: setmirror(MI_H); break;\r
54     case 2: setmirror(MI_0); break;\r
55     case 3: setmirror(MI_1); break;\r
56   }\r
57 }\r
58 \r
59 static DECLFW(M199Write)\r
60 {\r
61   if((A==0x8001)&&(MMC3_cmd&8))\r
62   {\r
63 //    FCEU_printf("%02x=>%02x\n",MMC3_cmd,V);\r
64     EXPREGS[MMC3_cmd&3]=V;\r
65     FixMMC3PRG(MMC3_cmd);\r
66     FixMMC3CHR(MMC3_cmd);\r
67   }\r
68   else    \r
69     if(A<0xC000)\r
70       MMC3_CMDWrite(A,V);\r
71     else\r
72       MMC3_IRQWrite(A,V);\r
73 }\r
74 \r
75 static void M199Power(void)\r
76 {\r
77   EXPREGS[0]=~1;\r
78   EXPREGS[1]=~0;\r
79   EXPREGS[2]=1;\r
80   EXPREGS[3]=3;\r
81   GenMMC3Power();\r
82   SetWriteHandler(0x8000,0xFFFF,M199Write);\r
83 }\r
84 \r
85 void Mapper199_Init(CartInfo *info)\r
86 {\r
87   int CHRRAMSize=1024*8;\r
88   GenMMC3_Init(info, 512, 256, 8, info->battery);\r
89   cwrap=M199CW;\r
90   pwrap=M199PW;\r
91   mwrap=M199MW;\r
92   info->Power=M199Power;\r
93   CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
94   SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
95   AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
96   AddExState(EXPREGS, 4, 0, "EXPR");\r
97 }\r