random warning fixes
[fceu.git] / boards / dance2000.c
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
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19  * \r
20  * Dance 2000 12-in-1\r
21  *\r
22  */\r
23 \r
24 #include "mapinc.h"\r
25 \r
26 static uint8 prg, mirr, prgmode;\r
27 static uint8 *WRAM=NULL;\r
28 static uint32 WRAMSIZE;\r
29 \r
30 static SFORMAT StateRegs[]=\r
31 {\r
32   {&prg, 1, "REGS"},\r
33   {&mirr, 1, "MIRR"},\r
34   {&prgmode, 1, "MIRR"},\r
35   {0}\r
36 };\r
37 \r
38 static void Sync(void)\r
39 {\r
40   setmirror(mirr);\r
41   setprg8r(0x10,0x6000,0);\r
42   setchr8(0);\r
43   if(prgmode)\r
44     setprg32(0x8000,prg&7);\r
45   else {\r
46     setprg16(0x8000,prg&0x0f);\r
47     setprg16(0xC000,0);\r
48   }\r
49 }\r
50 \r
51 static DECLFW(UNLD2000Write)\r
52 {\r
53 //  FCEU_printf("write %04x:%04x\n",A,V);\r
54   switch(A) {\r
55     case 0x5000: prg = V; Sync(); break;\r
56     case 0x5200: mirr = (V & 1)^1; prgmode = V & 4; Sync(); break;\r
57 //    default: FCEU_printf("write %04x:%04x\n",A,V);\r
58   }\r
59 }\r
60 \r
61 static DECLFR(UNLD2000Read)\r
62 {\r
63   if(prg & 0x40)\r
64     return X.DB;\r
65   else\r
66     return CartBR(A);\r
67 }\r
68 \r
69 static void UNLD2000Power(void)\r
70 {\r
71   prg = prgmode = 0;\r
72   Sync();\r
73   SetReadHandler(0x6000,0x7FFF,CartBR);\r
74   SetWriteHandler(0x6000,0x7FFF,CartBW);\r
75   SetReadHandler(0x8000,0xFFFF,UNLD2000Read);\r
76   SetWriteHandler(0x4020,0x5FFF,UNLD2000Write);\r
77 }\r
78 \r
79 static void UNLAX5705IRQ(void)\r
80 {\r
81   if(scanline > 174) setchr4(0x0000,1);\r
82   else setchr4(0x0000,0);\r
83 }\r
84 \r
85 static void UNLD2000Close(void)\r
86 {\r
87   if(WRAM)\r
88     FCEU_gfree(WRAM);\r
89   WRAM=NULL;\r
90 }\r
91 \r
92 \r
93 static void StateRestore(int version)\r
94 {\r
95   Sync();\r
96 }\r
97 \r
98 void UNLD2000_Init(CartInfo *info)\r
99 {\r
100   info->Power=UNLD2000Power;\r
101   info->Close=UNLD2000Close;\r
102   GameHBIRQHook=UNLAX5705IRQ;\r
103   GameStateRestore=StateRestore;\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   AddExState(&StateRegs, ~0, 0, 0);\r
111 }\r