merge mappers from FCEU-mm
[fceu.git] / boards / 156.c
CommitLineData
386f5371 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 * DIS23C01 DAOU ROM CONTROLLER, Korea\r
21 * Metal Force (K)\r
22 * Buzz and Waldog (K)\r
23 * General's Son (K)\r
24 *\r
25 */\r
26\r
27#include "mapinc.h"\r
28\r
29static uint8 chrlo[8], chrhi[8], prg, mirr, mirrisused = 0;\r
43725da7 30static uint8 *WRAM=NULL;\r
386f5371 31static uint32 WRAMSIZE;\r
32\r
33static SFORMAT StateRegs[]=\r
34{\r
35 {&prg, 1, "PREG"},\r
43725da7 36 {chrlo, 8, "CRGL"},\r
37 {chrhi, 8, "CRGH"},\r
386f5371 38 {&mirr, 1, "MIRR"},\r
39 {0}\r
40};\r
41\r
42static void Sync(void)\r
43{\r
44 uint32 i;\r
45 for(i=0; i<8; i++)\r
46 setchr1(i<<10, chrlo[i]|(chrhi[i] << 8));\r
47 setprg8r(0x10,0x6000,0);\r
48 setprg16(0x8000,prg);\r
49 setprg16(0xC000,~0);\r
50 if(mirrisused)\r
51 setmirror(mirr ^ 1);\r
52 else\r
53 setmirror(MI_0);\r
54}\r
55\r
56static DECLFW(M156Write)\r
57{\r
58 switch(A) {\r
59 case 0xC000:\r
60 case 0xC001:\r
61 case 0xC002:\r
62 case 0xC003: chrlo[A&3] = V; Sync(); break;\r
63 case 0xC004:\r
64 case 0xC005:\r
65 case 0xC006:\r
66 case 0xC007: chrhi[A&3] = V; Sync(); break;\r
67 case 0xC008:\r
68 case 0xC009:\r
69 case 0xC00A:\r
70 case 0xC00B: chrlo[4+(A&3)] = V; Sync(); break;\r
71 case 0xC00C:\r
72 case 0xC00D:\r
73 case 0xC00E:\r
74 case 0xC00F: chrhi[4+(A&3)] = V; Sync(); break;\r
75 case 0xC010: prg = V; Sync(); break;\r
76 case 0xC014: mirr = V; mirrisused = 1; Sync(); break;\r
77 }\r
78}\r
79\r
386f5371 80static void M156Power(void)\r
81{\r
82 Sync();\r
83 SetReadHandler(0x6000,0xFFFF,CartBR);\r
84 SetWriteHandler(0x6000,0x7FFF,CartBW);\r
85 SetWriteHandler(0xC000,0xCFFF,M156Write);\r
386f5371 86}\r
87\r
88static void M156Close(void)\r
89{\r
90 if(WRAM)\r
91 FCEU_gfree(WRAM);\r
92 WRAM=NULL;\r
93}\r
94\r
95static void StateRestore(int version)\r
96{\r
97 Sync();\r
98}\r
99\r
100void Mapper156_Init(CartInfo *info)\r
101{\r
102 info->Power=M156Power;\r
103 info->Close=M156Close;\r
104\r
105 WRAMSIZE=8192;\r
106 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
107 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
108 AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
109\r
110 GameStateRestore=StateRestore;\r
111 AddExState(&StateRegs, ~0, 0, 0);\r
112}\r