still reverting r167 sound change
[fceu.git] / boards / 187.c
CommitLineData
e2d0dd92 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2005 CaH4e3
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "mapinc.h"
22#include "mmc3.h"
23
24static void M187CW(uint32 A, uint8 V)
25{
26 if((A&0x1000)==((MMC3_cmd&0x80)<<5))
27 setchr1(A,V|0x100);
28 else
29 setchr1(A,V);
30}
31
32static void M187PW(uint32 A, uint8 V)
33{
34 if(EXPREGS[0]&0x80)
35 {
36 uint8 bank=EXPREGS[0]&0x1F;
37 if(EXPREGS[0]&0x20)
38 setprg32(0x8000,bank>>2);
39 else
40 {
41 setprg16(0x8000,bank);
42 setprg16(0xC000,bank);
43 }
44 }
45 else
46 setprg8(A,V&0x3F);
47}
48
49static DECLFW(M187Write8000)
50{
51 EXPREGS[2]=1;
52 MMC3_CMDWrite(A,V);
53}
54
55static DECLFW(M187Write8001)
56{
57 if(EXPREGS[2])
58 MMC3_CMDWrite(A,V);
59}
60
61static DECLFW(M187Write8003)
62{
63 EXPREGS[2]=0;
64 if(V==0x28)setprg8(0xC000,0x17);
65 else if(V==0x2A)setprg8(0xA000,0x0F);
66}
67
68
69static DECLFW(M187WriteLo)
70{
71 EXPREGS[1]=V;
72 if(A==0x5000)
73 {
74 EXPREGS[0]=V;
75 FixMMC3PRG(MMC3_cmd);
76 }
77}
78
79static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 };
80static DECLFR(M187Read)
81{
82 return prot_data[EXPREGS[1]&3];
83}
84
85static void M187Power(void)
86{
87 EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0;
88 GenMMC3Power();
39e1ccff 89 Write_IRQFM(0x4017,0x40);
e2d0dd92 90 SetReadHandler(0x5000,0x5FFF,M187Read);
91 SetWriteHandler(0x5000,0x5FFF,M187WriteLo);
92 SetWriteHandler(0x8000,0x8000,M187Write8000);
93 SetWriteHandler(0x8001,0x8001,M187Write8001);
94 SetWriteHandler(0x8003,0x8003,M187Write8003);
95}
96
97void Mapper187_Init(CartInfo *info)
98{
99 GenMMC3_Init(info, 256, 256, 0, 0);
100 pwrap=M187PW;
101 cwrap=M187CW;
102 info->Power=M187Power;
103 AddExState(EXPREGS, 3, 0, "EXPR");
104}