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 |
386f5371 |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
e2d0dd92 |
19 | */ |
20 | |
21 | #include "mapinc.h" |
22 | #include "mmc3.h" |
23 | |
386f5371 |
24 | static uint8 *CHRRAM = NULL; // there is no more extern CHRRAM in mmc3.h |
25 | // I need chrram here and local static == local |
e2d0dd92 |
26 | static int masko8[8]={63,31,15,1,3,0,0,0}; |
27 | |
28 | static void Super24PW(uint32 A, uint8 V) |
29 | { |
30 | uint32 NV=V&masko8[EXPREGS[0]&7]; |
31 | NV|=(EXPREGS[1]<<1); |
32 | setprg8r((NV>>6)&0xF,A,NV); |
33 | } |
34 | |
35 | static void Super24CW(uint32 A, uint8 V) |
36 | { |
37 | if(EXPREGS[0]&0x20) |
38 | setchr1r(0x10,A,V); |
39 | else |
40 | { |
41 | uint32 NV=V|(EXPREGS[2]<<3); |
42 | setchr1r((NV>>9)&0xF,A,NV); |
43 | } |
44 | } |
45 | |
46 | static DECLFW(Super24Write) |
47 | { |
48 | switch(A) |
49 | { |
50 | case 0x5FF0: EXPREGS[0]=V; |
51 | FixMMC3PRG(MMC3_cmd); |
52 | FixMMC3CHR(MMC3_cmd); |
53 | break; |
54 | case 0x5FF1: EXPREGS[1]=V; |
55 | FixMMC3PRG(MMC3_cmd); |
56 | break; |
57 | case 0x5FF2: EXPREGS[2]=V; |
58 | FixMMC3CHR(MMC3_cmd); |
59 | break; |
60 | } |
61 | } |
62 | |
63 | static void Super24Power(void) |
64 | { |
65 | EXPREGS[0]=0x24; |
66 | EXPREGS[1]=159; |
67 | EXPREGS[2]=0; |
68 | GenMMC3Power(); |
69 | SetWriteHandler(0x5000,0x7FFF,Super24Write); |
70 | SetReadHandler(0x8000,0xFFFF,CartBR); |
71 | } |
72 | |
73 | static void Super24Reset(void) |
74 | { |
75 | EXPREGS[0]=0x24; |
76 | EXPREGS[1]=159; |
77 | EXPREGS[2]=0; |
78 | MMC3RegReset(); |
79 | } |
80 | |
81 | static void Super24Close(void) |
82 | { |
83 | if(CHRRAM) |
84 | FCEU_gfree(CHRRAM); |
85 | CHRRAM = NULL; |
86 | } |
87 | |
88 | void Super24_Init(CartInfo *info) |
89 | { |
90 | GenMMC3_Init(info, 128, 256, 0, 0); |
91 | info->Power=Super24Power; |
92 | info->Reset=Super24Reset; |
93 | info->Close=Super24Close; |
94 | cwrap=Super24CW; |
95 | pwrap=Super24PW; |
96 | CHRRAM=(uint8*)FCEU_gmalloc(8192); |
97 | SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); |
98 | AddExState(CHRRAM, 8192, 0, "CHRR"); |
99 | AddExState(EXPREGS, 3, 0, "BIG2"); |
100 | } |