merge mapper code from FCEUX
[fceu.git] / boards / 57.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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
19 *\r
20 */\r
21\r
22#include "mapinc.h"\r
23\r
24static uint8 prg_reg;\r
25static uint8 chr_reg;\r
26static uint8 hrd_flag;\r
27\r
28static SFORMAT StateRegs[]=\r
29{\r
30 {&hrd_flag, 1, "DIPSW"},\r
31 {&prg_reg, 1, "PRG"},\r
32 {&chr_reg, 1, "CHR"},\r
33 {0}\r
34};\r
35\r
36static void Sync(void)\r
37{\r
38 if(prg_reg&0x80)\r
39 setprg32(0x8000,prg_reg>>6);\r
40 else\r
41 {\r
42 setprg16(0x8000,(prg_reg>>5)&3);\r
43 setprg16(0xC000,(prg_reg>>5)&3);\r
44 }\r
45 setmirror((prg_reg&8)>>3);\r
46 setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1));\r
47}\r
48\r
49static DECLFR(M57Read)\r
50{\r
51 return hrd_flag;\r
52}\r
53\r
54static DECLFW(M57Write)\r
55{\r
56 if((A&0x8800)==0x8800)\r
57 prg_reg=V;\r
58 else\r
59 chr_reg=V;\r
60 Sync();\r
61}\r
62\r
63static void M57Power(void)\r
64{\r
65 prg_reg=0;\r
66 chr_reg=0;\r
67 hrd_flag=0;\r
68 SetReadHandler(0x8000,0xFFFF,CartBR);\r
69 SetWriteHandler(0x8000,0xFFFF,M57Write);\r
70 SetReadHandler(0x6000,0x6000,M57Read);\r
71 Sync();\r
72}\r
73\r
74static void M57Reset()\r
75{\r
76 hrd_flag++;\r
77 hrd_flag&=3;\r
78 FCEU_printf("Select Register = %02x\n",hrd_flag);\r
79}\r
80\r
81static void StateRestore(int version)\r
82{\r
83 Sync();\r
84}\r
85\r
86void Mapper57_Init(CartInfo *info)\r
87{\r
88 info->Power=M57Power;\r
89 info->Reset=M57Reset;\r
90 GameStateRestore=StateRestore;\r
91 AddExState(&StateRegs, ~0, 0, 0);\r
92}\r