1 /* FCEUmm - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2020 negativeExponent
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 /* NES 2.0 Mapper 380 denotes the 970630C circuit board,
22 * used on a 512 KiB multicart having 42 to 80,000 listed NROM and UNROM games. */
23
24 #include "mapinc.h"
25
26 static uint16 latche;
27 static uint8 dipswitch;
28
29 static SFORMAT StateRegs[] = {
30 { &latche, 2 | FCEUSTATE_RLSB, "LATC" },
31 { &dipswitch, 1, "DPSW" },
32 { 0 }
33 };
34
Sync(void)35 static void Sync(void)
36 {
37 if (latche & 0x200)
38 {
39 if (latche & 1) /* NROM 128 */
40 {
41 setprg16(0x8000, latche >> 2);
42 setprg16(0xC000, latche >> 2);
43 }
44 else /* NROM-256 */
45 setprg32(0x8000, latche >> 3);
46 }
47 else /* UxROM */
48 {
49 setprg16(0x8000, latche >> 2);
50 setprg16(0xC000, (latche >> 2) | 7);
51 }
52 setmirror(((latche >> 1) & 1) ^ 1);
53 }
54
DECLFR(M380Read)55 static DECLFR(M380Read)
56 {
57 if (latche & 0x100)
58 return dipswitch;
59 return CartBR(A);
60 }
61
DECLFW(M380Write)62 static DECLFW(M380Write)
63 {
64 latche = A;
65 Sync();
66 }
67
M380Reset(void)68 static void M380Reset(void)
69 {
70 dipswitch = (dipswitch + 1) & 0xF;
71 latche = 0;
72 Sync();
73 }
74
M380Power(void)75 static void M380Power(void)
76 {
77 dipswitch = 0;
78 latche = 0;
79 Sync();
80 setchr8(0);
81 SetReadHandler(0x8000, 0xFFFF, M380Read);
82 SetWriteHandler(0x8000, 0xFFFF, M380Write);
83 }
84
StateRestore(int version)85 static void StateRestore(int version)
86 {
87 Sync();
88 }
89
Mapper380_Init(CartInfo * info)90 void Mapper380_Init(CartInfo *info)
91 {
92 info->Power = M380Power;
93 info->Reset = M380Reset;
94 GameStateRestore = StateRestore;
95 AddExState(&StateRegs, ~0, 0, 0);
96 }
97