random warning fixes
[fceu.git] / boards / 178.c
CommitLineData
386f5371 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
43725da7 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
19 * \r
20 * San Guo Zhong Lie Zhuan (Ch)\r
21 * win200, etc\r
22 *\r
386f5371 23 */\r
24\r
25#include "mapinc.h"\r
26\r
43725da7 27static uint8 reg[4];\r
386f5371 28static uint8 *WRAM=NULL;\r
29static uint32 WRAMSIZE;\r
30\r
31static SFORMAT StateRegs[]=\r
32{\r
43725da7 33 {reg, 4, "REGS"},\r
386f5371 34 {0}\r
35};\r
36\r
37static void Sync(void)\r
38{\r
43725da7 39 uint8 bank = (reg[2]&3)<<3;\r
40 setmirror((reg[0]&1)^1);\r
386f5371 41 setprg8r(0x10,0x6000,0);\r
42 setchr8(0);\r
43725da7 43 if(reg[0]&2)\r
44 {\r
45 setprg16(0x8000,(reg[1]&7)|bank);\r
46 setprg16(0xC000,((~0)&7)|bank);\r
47 }\r
48 else\r
49 {\r
50 setprg16(0x8000,(reg[1]&6)|bank);\r
51 setprg16(0xC000,(reg[1]&6)|bank|1);\r
52 }\r
386f5371 53}\r
54\r
43725da7 55static DECLFW(M178Write)\r
386f5371 56{\r
43725da7 57 reg[A&3]=V;\r
386f5371 58 Sync();\r
59}\r
60\r
61static void M178Power(void)\r
62{\r
43725da7 63 reg[0]=1;\r
64 reg[1]=0;\r
65 reg[2]=0;\r
66 reg[3]=0;\r
386f5371 67 Sync();\r
68 SetReadHandler(0x6000,0x7FFF,CartBR);\r
69 SetWriteHandler(0x6000,0x7FFF,CartBW);\r
70 SetReadHandler(0x8000,0xFFFF,CartBR);\r
43725da7 71 SetWriteHandler(0x4800,0x4803,M178Write);\r
386f5371 72}\r
73\r
74static void M178Close(void)\r
75{\r
76 if(WRAM)\r
77 FCEU_gfree(WRAM);\r
78 WRAM=NULL;\r
79}\r
80\r
81\r
82static void StateRestore(int version)\r
83{\r
84 Sync();\r
85}\r
86\r
87void Mapper178_Init(CartInfo *info)\r
88{\r
89 info->Power=M178Power;\r
90 info->Close=M178Close;\r
91 GameStateRestore=StateRestore;\r
92\r
93 WRAMSIZE=8192;\r
94 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
95 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
96 if(info->battery)\r
97 {\r
98 info->SaveGame[0]=WRAM;\r
99 info->SaveGameLen[0]=WRAMSIZE;\r
100 }\r
101 AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
102\r
103 AddExState(&StateRegs, ~0, 0, 0);\r
104}\r