ee12dec6bd29695d36b3d214694c49114a6fabe0
[fceu.git] / boards / 43.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2006 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 //ccording to nestopia, BTL_SMB2_C, otherwise known as UNL-SMB2J\r
22 \r
23 #include "mapinc.h"\r
24 \r
25 static uint8 reg;\r
26 static uint8 IRQa;\r
27 static uint32 IRQCount;\r
28 \r
29 static SFORMAT StateRegs[]=\r
30 {\r
31   {&IRQCount, 4, "IRQC"},\r
32   {&IRQa, 1, "IRQA"},\r
33   {&reg, 1, "REG"},\r
34   {0}\r
35 };\r
36 \r
37 static void Sync(void)\r
38 {\r
39   setprg4(0x5000,16);  \r
40   setprg8(0x6000,2);\r
41   setprg8(0x8000,1);\r
42   setprg8(0xa000,0);\r
43   setprg8(0xc000,reg);\r
44   setprg8(0xe000,9);\r
45   setchr8(0);\r
46 }\r
47 \r
48 static DECLFW(M43Write)\r
49 {\r
50   int transo[8]={4,3,4,4,4,7,5,6};\r
51   switch(A&0xf1ff)\r
52   {\r
53     case 0x4022: reg=transo[V&7]; Sync(); break;\r
54     case 0x8122: IRQa=V&1; IRQCount=0; break;\r
55   }\r
56 }\r
57 \r
58 static void M43Power(void)\r
59 {\r
60   reg=0;\r
61   Sync();\r
62 //  SetReadHandler(0x5000,0x5fff,CartBR);\r
63   SetReadHandler(0x5000,0xffff,CartBR);\r
64   SetWriteHandler(0x4020,0xffff,M43Write);\r
65 }\r
66 \r
67 static void M43Reset(void)\r
68 {\r
69 }\r
70 \r
71 static void M43IRQHook(int a)\r
72 {\r
73  IRQCount+=a;\r
74  if(IRQa)\r
75   if(IRQCount>=4096)\r
76   {\r
77    IRQa=0;\r
78    X6502_IRQBegin(FCEU_IQEXT);\r
79   }\r
80 }\r
81 \r
82 static void StateRestore(int version)\r
83 {\r
84   Sync();\r
85 }\r
86 \r
87 void Mapper43_Init(CartInfo *info)\r
88 {\r
89   info->Reset=M43Reset;\r
90   info->Power=M43Power;\r
91   MapIRQHook=M43IRQHook;\r
92   GameStateRestore=StateRestore;\r
93   AddExState(&StateRegs, ~0, 0, 0);\r
94 }\r