merge mappers from FCEU-mm
[fceu.git] / boards / smb2j.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  * FDS Conversions\r
21  *\r
22  * Super Mario Bros 2 J alt version\r
23  * as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present\r
24  *\r
25  * mapper seems wrong researched by me ;( it should be mapper 43 modification\r
26  */\r
27 \r
28 #include "mapinc.h"\r
29 \r
30 static uint8 prg, IRQa;\r
31 static uint16 IRQCount;\r
32 \r
33 static SFORMAT StateRegs[]=\r
34 {\r
35   {&prg, 1, "PRG"},\r
36   {&IRQa, 1, "IRQA"},\r
37   {&IRQCount, 2, "IRQC"},\r
38   {0}\r
39 };\r
40 \r
41 static void Sync(void)\r
42 {\r
43   setprg4r(1,0x5000,1);\r
44   setprg8r(1,0x6000,1);\r
45   setprg32(0x8000,prg);\r
46   setchr8(0);\r
47 }\r
48 \r
49 static DECLFW(UNLSMB2JWrite)\r
50 {\r
51   if(A==0x4022)\r
52   {\r
53     prg=V&1;\r
54     Sync();\r
55   }\r
56   if(A==0x4122)\r
57   {\r
58     IRQa=V;\r
59     IRQCount=0;\r
60     X6502_IRQEnd(FCEU_IQEXT);\r
61   }\r
62 }\r
63 \r
64 static void UNLSMB2JPower(void)\r
65 {\r
66   prg=~0;\r
67   Sync();\r
68   SetReadHandler(0x5000,0x7FFF,CartBR);\r
69   SetReadHandler(0x8000,0xFFFF,CartBR);\r
70   SetWriteHandler(0x4020,0xffff,UNLSMB2JWrite);\r
71 }\r
72 \r
73 static void UNLSMB2JReset(void)\r
74\r
75   prg=~0;\r
76   Sync();\r
77 }\r
78 \r
79 static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a)\r
80 {\r
81   if(IRQa)\r
82   {\r
83     IRQCount+=a*3;\r
84     if((IRQCount>>12)==IRQa)\r
85       X6502_IRQBegin(FCEU_IQEXT);\r
86   }\r
87 }\r
88 \r
89 static void StateRestore(int version)\r
90 {\r
91   Sync();\r
92 }\r
93 \r
94 void UNLSMB2J_Init(CartInfo *info)\r
95 {\r
96   info->Reset=UNLSMB2JReset;\r
97   info->Power=UNLSMB2JPower;\r
98   MapIRQHook=UNLSMB2JIRQHook;\r
99   GameStateRestore=StateRestore;\r
100   AddExState(&StateRegs, ~0, 0, 0);\r
101 }\r