merge mappers from FCEU-mm
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19  *\r
20  * FDS Conversion\r
21  *\r
22  */\r
23 \r
24 #include "mapinc.h"\r
25 \r
26 static uint8 reg;\r
27 static uint32 IRQCount, IRQa;\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);    // Only YS-612 advdnced version\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   int transo[8]={4,3,5,3,6,3,7,3};  // According to hardware tests\r
52   switch(A&0xf1ff)\r
53   {\r
54     case 0x4022: reg=transo[V&7]; Sync(); break;\r
55     case 0x8122:                                                            // hacked version\r
56     case 0x4122: IRQa=V&1; X6502_IRQEnd(FCEU_IQEXT); IRQCount=0; break;     // original version\r
57   }\r
58 }\r
59 \r
60 static void M43Power(void)\r
61 {\r
62   reg=0;\r
63   Sync();\r
64   SetReadHandler(0x5000,0xffff,CartBR);\r
65   SetWriteHandler(0x4020,0xffff,M43Write);\r
66 }\r
67 \r
68 static void M43Reset(void)\r
69 {\r
70 }\r
71 \r
72 static void FP_FASTAPASS(1) M43IRQHook(int a)\r
73 {\r
74   IRQCount+=a;\r
75   if(IRQa)\r
76     if(IRQCount>=4096)\r
77     {\r
78       IRQa=0;\r
79       X6502_IRQBegin(FCEU_IQEXT);\r
80     }\r
81 }\r
82 \r
83 static void StateRestore(int version)\r
84 {\r
85   Sync();\r
86 }\r
87 \r
88 void Mapper43_Init(CartInfo *info)\r
89 {\r
90   info->Reset=M43Reset;\r
91   info->Power=M43Power;\r
92   MapIRQHook=M43IRQHook;\r
93   GameStateRestore=StateRestore;\r
94   AddExState(&StateRegs, ~0, 0, 0);\r
95 }\r