d97315ac |
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 |
19 | * NTDEC, ASDER games |
d97315ac |
20 | */ |
21 | |
22 | #include "mapinc.h" |
23 | |
24 | static uint8 reg[8]; |
386f5371 |
25 | static uint8 mirror, cmd, bank; |
d97315ac |
26 | static uint8 *WRAM=NULL; |
e2d0dd92 |
27 | |
d97315ac |
28 | static SFORMAT StateRegs[]= |
29 | { |
30 | {&cmd, 1, "CMD"}, |
31 | {&mirror, 1, "MIRR"}, |
386f5371 |
32 | {&bank, 1, "BANK"}, |
d97315ac |
33 | {reg, 8, "REGS"}, |
34 | {0} |
35 | }; |
36 | |
37 | static void Sync(void) |
38 | { |
39 | setmirror(mirror^1); |
40 | setprg8(0x8000,reg[0]); |
41 | setprg8(0xA000,reg[1]); |
386f5371 |
42 | setchr2(0x0000,(reg[2]>>1)); |
43 | setchr2(0x0800,(reg[3]>>1)); |
44 | setchr1(0x1000,((bank&0x10)<<4)|reg[4]); |
45 | setchr1(0x1400,((bank&0x20)<<3)|reg[5]); |
46 | setchr1(0x1800,((bank&0x40)<<2)|reg[6]); |
47 | setchr1(0x1C00,((bank&0x80)<<1)|reg[7]); |
d97315ac |
48 | } |
49 | |
50 | static DECLFW(M112Write) |
51 | { |
52 | switch(A) |
53 | { |
54 | case 0xe000: mirror=V&1; Sync(); ;break; |
55 | case 0x8000: cmd=V&7; break; |
56 | case 0xa000: reg[cmd]=V; Sync(); break; |
386f5371 |
57 | case 0xc000: bank=V; Sync(); break; |
d97315ac |
58 | } |
59 | } |
60 | |
61 | static void M112Close(void) |
62 | { |
63 | if(WRAM) |
64 | FCEU_gfree(WRAM); |
65 | WRAM = NULL; |
66 | } |
67 | |
68 | static void M112Power(void) |
69 | { |
386f5371 |
70 | bank=0; |
d97315ac |
71 | setprg16(0xC000,~0); |
72 | setprg8r(0x10,0x6000,0); |
73 | SetReadHandler(0x8000,0xFFFF,CartBR); |
74 | SetWriteHandler(0x8000,0xFFFF,M112Write); |
386f5371 |
75 | SetWriteHandler(0x4020,0x5FFF,M112Write); |
d97315ac |
76 | SetReadHandler(0x6000,0x7FFF,CartBR); |
77 | SetWriteHandler(0x6000,0x7FFF,CartBW); |
78 | } |
79 | |
80 | static void StateRestore(int version) |
81 | { |
82 | Sync(); |
83 | } |
84 | |
85 | void Mapper112_Init(CartInfo *info) |
86 | { |
87 | info->Power=M112Power; |
88 | info->Close=M112Close; |
89 | GameStateRestore=StateRestore; |
90 | WRAM=(uint8*)FCEU_gmalloc(8192); |
91 | SetupCartPRGMapping(0x10,WRAM,8192,1); |
92 | AddExState(WRAM, 8192, 0, "WRAM"); |
93 | AddExState(&StateRegs, ~0, 0, 0); |
94 | } |