merge x6502 code FCEUX
[fceu.git] / boards / dance2000.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 * Dance 2000 12-in-1\r
21 *\r
386f5371 22 */\r
23\r
24#include "mapinc.h"\r
25\r
43725da7 26static uint8 prg, mirr, prgmode;\r
386f5371 27static uint8 *WRAM=NULL;\r
28static uint32 WRAMSIZE;\r
29\r
30static SFORMAT StateRegs[]=\r
31{\r
43725da7 32 {&prg, 1, "REGS"},\r
33 {&mirr, 1, "MIRR"},\r
34 {&prgmode, 1, "MIRR"},\r
386f5371 35 {0}\r
36};\r
37\r
38static void Sync(void)\r
39{\r
43725da7 40 setmirror(mirr);\r
386f5371 41 setprg8r(0x10,0x6000,0);\r
43725da7 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
386f5371 49}\r
50\r
43725da7 51static DECLFW(UNLD2000Write)\r
386f5371 52{\r
43725da7 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
61static DECLFR(UNLD2000Read)\r
62{\r
63 if(prg & 0x40)\r
64 return X.DB;\r
65 else\r
66 return CartBR(A);\r
386f5371 67}\r
68\r
43725da7 69static void UNLD2000Power(void)\r
386f5371 70{\r
43725da7 71 prg = prgmode = 0;\r
386f5371 72 Sync();\r
43725da7 73 SetReadHandler(0x6000,0x7FFF,CartBR);\r
74 SetWriteHandler(0x6000,0x7FFF,CartBW);\r
75 SetReadHandler(0x8000,0xFFFF,UNLD2000Read);\r
76 SetWriteHandler(0x4020,0x5FFF,UNLD2000Write);\r
386f5371 77}\r
78\r
43725da7 79static void UNLAX5705IRQ(void)\r
386f5371 80{\r
43725da7 81 if(scanline > 174) setchr4(0x0000,1);\r
82 else setchr4(0x0000,0);\r
386f5371 83}\r
84\r
43725da7 85static void UNLD2000Close(void)\r
386f5371 86{\r
87 if(WRAM)\r
88 FCEU_gfree(WRAM);\r
89 WRAM=NULL;\r
90}\r
91\r
43725da7 92\r
386f5371 93static void StateRestore(int version)\r
94{\r
95 Sync();\r
96}\r
97\r
43725da7 98void UNLD2000_Init(CartInfo *info)\r
386f5371 99{\r
43725da7 100 info->Power=UNLD2000Power;\r
101 info->Close=UNLD2000Close;\r
102 GameHBIRQHook=UNLAX5705IRQ;\r
386f5371 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
386f5371 109\r
110 AddExState(&StateRegs, ~0, 0, 0);\r
111}\r