merge mapper code from FCEUX
[fceu.git] / boards / ks7032.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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
19 */\r
20\r
21#include "mapinc.h"\r
22\r
23static uint8 reg[8], cmd, IRQa;\r
24static int32 IRQCount;\r
25\r
26static SFORMAT StateRegs[]=\r
27{\r
28 {&cmd, 1, "CMD"},\r
29 {reg, 8, "REGS"},\r
30 {&IRQa, 1, "IRQA"},\r
31 {&IRQCount, 4, "IRQC"},\r
32 {0}\r
33};\r
34\r
35static void Sync(void)\r
36{\r
37 setprg8(0x6000,reg[4]);\r
38 setprg8(0x8000,reg[1]);\r
39 setprg8(0xA000,reg[2]);\r
40 setprg8(0xC000,reg[3]);\r
41 setprg8(0xE000,~0);\r
42 setchr8(0);\r
43}\r
44\r
45static DECLFW(UNLKS7032Write)\r
46{\r
47// FCEU_printf("bs %04x %02x\n",A,V);\r
48 switch(A)\r
49 {\r
50// case 0x8FFF: reg[4]=V; Sync(); break;\r
51 case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); break;\r
52 case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); break;\r
53 case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); break;\r
54 case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); break;\r
55 case 0xC000: X6502_IRQEnd(FCEU_IQEXT); IRQa=1; break;\r
56 case 0xE000: cmd=V&7; break;\r
57 case 0xF000: reg[cmd]=V; Sync(); break;\r
58 }\r
59}\r
60\r
61static void UNLSMB2JIRQHook(int a)\r
62{\r
63 if(IRQa)\r
64 {\r
65 IRQCount+=a;\r
66 if(IRQCount>=0xFFFF)\r
67 {\r
68 IRQa=0;\r
69 IRQCount=0;\r
70 X6502_IRQBegin(FCEU_IQEXT);\r
71 }\r
72 }\r
73}\r
74\r
75static void UNLKS7032Power(void)\r
76{\r
77 Sync();\r
78 SetReadHandler(0x6000,0x7FFF,CartBR);\r
79 SetReadHandler(0x8000,0xFFFF,CartBR);\r
80 SetWriteHandler(0x4020,0xFFFF,UNLKS7032Write);\r
81}\r
82\r
83static void StateRestore(int version)\r
84{\r
85 Sync();\r
86}\r
87\r
88void UNLKS7032_Init(CartInfo *info)\r
89{\r
90 info->Power=UNLKS7032Power;\r
91 MapIRQHook=UNLSMB2JIRQHook;\r
92 GameStateRestore=StateRestore;\r
93 AddExState(&StateRegs, ~0, 0, 0);\r
94}\r