merge mapper code from FCEUX
[fceu.git] / boards / 121.c
CommitLineData
386f5371 1/* FCE Ultra - NES/Famicom Emulator\r
2 *\r
3 * Copyright notice for this file:\r
4 * Copyright (C) 2007-2008 Mad Dumper, 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 * Panda prince pirate.\r
20 * MK4, MK6, A9711 board, MAPPER 187 the same!\r
21 * UNL6035052_Init seems to be the same too, but with prot array in reverse\r
22 */\r
23\r
24#include "mapinc.h"\r
25#include "mmc3.h"\r
26\r
27static uint8 readbyte = 0;\r
28\r
29static DECLFW(M121Write)\r
30{\r
31// FCEU_printf("write: %04x:%04x\n",A&0xE003,V);\r
32 if((A&0xF003)==0x8003)\r
33 {\r
34// FCEU_printf(" prot write");\r
35// FCEU_printf("write: %04x:%04x\n",A,V);\r
36 if (V==0xAB) setprg8(0xE000,7);\r
37 else if(V==0x26) setprg8(0xE000,8);\r
38// else if(V==0x26) setprg8(0xE000,1); // MK3\r
39// else if(V==0x26) setprg8(0xE000,0x15); // sonic 3D blast, 8003 - command (0x26), 8001 - data 0x2A (<<1 = 0x15)\r
40 else if(V==0xFF) setprg8(0xE000,9);\r
41 else if(V==0x28) setprg8(0xC000,0xC);\r
42 else if(V==0xEC) setprg8(0xE000,0xD); \r
43// else if(V==0xEC) setprg8(0xE000,0xC);//MK3\r
44 else if(V==0xEF) setprg8(0xE000,0xD); // damn mess, need real hardware to figure out bankswitching\r
45 else if(V==0x2A) setprg8(0xA000,0x0E);\r
46// else if(V==0x2A) setprg8(0xE000,0x0C); // MK3\r
47 else if(V==0x20) setprg8(0xE000,0x13);\r
48 else if(V==0x29) setprg8(0xE000,0x1B);\r
49 else \r
50 {\r
51// FCEU_printf(" unknown");\r
52 FixMMC3PRG(MMC3_cmd);\r
53 MMC3_CMDWrite(A,V);\r
54 }\r
55// FCEU_printf("\n");\r
56 }\r
57 else\r
58 {\r
59// FixMMC3PRG(MMC3_cmd);\r
60 MMC3_CMDWrite(A,V);\r
61 }\r
62}\r
63\r
64static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 };\r
65static DECLFW(M121LoWrite)\r
66{\r
67 EXPREGS[0] = prot_array[V&3]; // 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter)\r
68// FCEU_printf("write: %04x:%04x\n",A,V);\r
69}\r
70\r
71static DECLFR(M121Read)\r
72{ \r
73// FCEU_printf("read: %04x\n",A);\r
74 return EXPREGS[0];\r
75}\r
76\r
77static void M121Power(void)\r
78{\r
79 GenMMC3Power();\r
80// Write_IRQFM(0x4017,0x40);\r
81 SetReadHandler(0x5000,0x5FFF,M121Read);\r
82 SetWriteHandler(0x5000,0x5FFF,M121LoWrite);\r
83 SetWriteHandler(0x8000,0x9FFF,M121Write);\r
84}\r
85\r
86void Mapper121_Init(CartInfo *info)\r
87{\r
88 GenMMC3_Init(info, 128, 256, 8, 0);\r
89 info->Power=M121Power;\r
90 AddExState(EXPREGS, 2, 0, "EXPR");\r
91}\r