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 | |
24 | static uint8 unromchr; |
25 | |
26 | static void BMCFK23CCW(uint32 A, uint8 V) |
27 | { |
28 | if(EXPREGS[0]&0x40) |
29 | setchr8((EXPREGS[2]&0xFC)|unromchr); |
30 | else |
31 | { |
32 | uint16 base=(EXPREGS[2]&0x7F)<<3; |
33 | setchr1(A,V|base); |
34 | if(EXPREGS[3]&2) |
35 | { |
36 | setchr1(0x0400,EXPREGS[6]|base); |
37 | setchr1(0x0C00,EXPREGS[7]|base); |
38 | } |
39 | } |
40 | } |
41 | |
42 | static void BMCFK23CPW(uint32 A, uint8 V) |
43 | { |
44 | if(EXPREGS[0]&4) |
45 | setprg32(0x8000,EXPREGS[1]>>1); |
46 | else |
47 | { |
48 | if(EXPREGS[0]&2) |
49 | setprg8(A,(V&(0x3F>>(EXPREGS[0]&3)))|(EXPREGS[1]<<1)); |
50 | else |
51 | setprg8(A,V); |
52 | if(EXPREGS[3]&2) |
53 | { |
54 | setprg8(0xC000,EXPREGS[4]); |
55 | setprg8(0xE000,EXPREGS[5]); |
56 | } |
57 | } |
58 | } |
59 | |
60 | static DECLFW(BMCFK23C8003Write) |
61 | { |
62 | if(EXPREGS[0]&0x40) |
63 | { |
64 | unromchr=V&3; |
65 | FixMMC3CHR(MMC3_cmd); |
66 | } |
67 | else |
68 | { |
69 | if((A==0x8001)&&(EXPREGS[3]&2&&MMC3_cmd&8)) |
70 | { |
71 | EXPREGS[4|(MMC3_cmd&3)]=V; |
72 | FixMMC3PRG(MMC3_cmd); |
73 | FixMMC3CHR(MMC3_cmd); |
74 | } |
75 | else |
76 | MMC3_CMDWrite(A,V); |
77 | } |
78 | } |
79 | |
80 | static DECLFW(BMCFK23CWrite) |
81 | { |
82 | EXPREGS[A&3]=V; |
83 | FixMMC3PRG(MMC3_cmd); |
84 | FixMMC3CHR(MMC3_cmd); |
85 | } |
86 | |
87 | static void BMCFK23CReset(void) |
88 | { |
89 | EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; |
90 | EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; |
91 | MMC3RegReset(); |
92 | } |
93 | |
94 | static void BMCFK23CPower(void) |
95 | { |
96 | EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; |
97 | EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; |
98 | GenMMC3Power(); |
99 | SetWriteHandler(0x5ff0,0x5fff,BMCFK23CWrite); |
100 | SetWriteHandler(0x8000,0x8003,BMCFK23C8003Write); |
101 | } |
102 | |
103 | void BMCFK23C_Init(CartInfo *info) |
104 | { |
105 | GenMMC3_Init(info, 512, 256, 8, 0); |
106 | cwrap=BMCFK23CCW; |
107 | pwrap=BMCFK23CPW; |
108 | info->Power=BMCFK23CPower; |
109 | info->Reset=BMCFK23CReset; |
110 | AddExState(EXPREGS, 8, 0, "EXPR"); |
111 | AddExState(&unromchr, 1, 0, "UNCHR"); |
112 | } |