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 | |
23 | static uint8 is_large_banks; |
24 | static uint8 large_bank; |
25 | static uint8 prg_bank; |
26 | static uint8 chr_bank; |
27 | static uint8 bank_mode; |
28 | static uint8 mirroring; |
29 | static SFORMAT StateRegs[]= |
30 | { |
31 | {&large_bank, 1, "LB"}, |
32 | {&prg_bank, 1, "PRG"}, |
33 | {&chr_bank, 1, "CHR"}, |
34 | {&bank_mode, 1, "BM"}, |
35 | {&mirroring, 1, "MIRR"}, |
36 | {0} |
37 | }; |
38 | |
39 | static void Sync(void) |
40 | { |
41 | switch (bank_mode) |
42 | { |
43 | case 0x00: |
44 | case 0x10: setprg16(0x8000,large_bank|prg_bank); |
45 | setprg16(0xC000,large_bank|7); |
46 | break; |
47 | case 0x20: setprg32(0x8000,(large_bank|prg_bank)>>1); |
48 | break; |
49 | case 0x30: setprg16(0x8000,large_bank|prg_bank); |
50 | setprg16(0xC000,large_bank|prg_bank); |
51 | break; |
52 | } |
53 | setmirror(mirroring); |
54 | if(!is_large_banks) |
55 | setchr8(chr_bank); |
56 | } |
57 | |
58 | static DECLFR(BMC70in1Read) |
59 | { |
60 | if(bank_mode==0x10) |
61 | if(is_large_banks) |
62 | return CartBR((A&0xFFF0)|0x06); |
63 | else |
64 | return CartBR((A&0xFFF0)|0x0d); |
65 | else |
66 | return CartBR(A); |
67 | } |
68 | |
69 | static DECLFW(BMC70in1Write) |
70 | { |
71 | if(A&0x4000) |
72 | { |
73 | bank_mode=A&0x30; |
74 | prg_bank=A&7; |
75 | } |
76 | else |
77 | { |
78 | mirroring=((A&0x20)>>5)^1; |
79 | if(is_large_banks) |
80 | large_bank=(A&3)<<3; |
81 | else |
82 | chr_bank=A&7; |
83 | } |
84 | Sync(); |
85 | } |
86 | |
87 | static void BMC70in1Power(void) |
88 | { |
89 | setchr8(0); |
90 | bank_mode=0; |
91 | large_bank=0; |
92 | Sync(); |
93 | SetReadHandler(0x8000,0xFFFF,BMC70in1Read); |
94 | SetWriteHandler(0x8000,0xffff,BMC70in1Write); |
95 | } |
96 | |
97 | static void StateRestore(int version) |
98 | { |
99 | Sync(); |
100 | } |
101 | |
102 | void BMC70in1_Init(CartInfo *info) |
103 | { |
104 | is_large_banks=0; |
105 | info->Power=BMC70in1Power; |
106 | GameStateRestore=StateRestore; |
107 | AddExState(&StateRegs, ~0, 0, 0); |
108 | } |
109 | |
110 | void BMC70in1B_Init(CartInfo *info) |
111 | { |
112 | is_large_banks=1; |
113 | info->Power=BMC70in1Power; |
114 | GameStateRestore=StateRestore; |
115 | AddExState(&StateRegs, ~0, 0, 0); |
116 | } |