1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 
21 /* T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches */
22 
23 #include "mapinc.h"
24 #include "mmc3.h"
25 
26 static uint8 reset_flag = 0x07;
27 
BMCT2271CW(uint32 A,uint8 V)28 static void BMCT2271CW(uint32 A, uint8 V) {
29 	uint32 va = V;
30 	if (EXPREGS[0] & 0x20) {
31 		va |= 0x200;
32 		va |= (EXPREGS[0] & 0x10) << 4;
33 	} else {
34 		va &= 0x7F;
35 		va |= (EXPREGS[0] & 0x18) << 4;
36 	}
37 	setchr1(A, va);
38 }
39 
BMCT2271PW(uint32 A,uint8 V)40 static void BMCT2271PW(uint32 A, uint8 V) {
41 	uint32 va = V & 0x3F;
42 	if (EXPREGS[0] & 0x20) {
43 		va &= 0x1F;
44 		va |= 0x40;
45 		va |= (EXPREGS[0] & 0x10) << 1;
46 	} else {
47 		va &= 0x0F;
48 		va |= (EXPREGS[0] & 0x18) << 1;
49 	}
50 	switch (EXPREGS[0] & 3) {
51 	case 0x00: setprg8(A, va); break;
52 	case 0x02:
53 	{
54 		va = (va & 0xFD) | ((EXPREGS[0] & 4) >> 1);
55 		if (A < 0xC000) {
56 			setprg16(0x8000, va >> 1);
57 			setprg16(0xC000, va >> 1);
58 		}
59 		break;
60 	}
61 	case 0x01:
62 	case 0x03: if (A < 0xC000) setprg32(0x8000, va >> 2); break;
63 	}
64 }
65 
DECLFW(BMCT2271LoWrite)66 static DECLFW(BMCT2271LoWrite) {
67 	if (!(EXPREGS[0] & 0x80))
68 		EXPREGS[0] = A & 0xFF;
69 	FixMMC3PRG(MMC3_cmd);
70 	FixMMC3CHR(MMC3_cmd);
71 }
72 
DECLFR(BMCT2271HiRead)73 static DECLFR(BMCT2271HiRead) {
74 	uint32 av = A;
75 	if (EXPREGS[0] & 0x40) av = (av & 0xFFF0) | reset_flag;
76 	return CartBR(av);
77 }
78 
BMCT2271Reset(void)79 static void BMCT2271Reset(void) {
80 	EXPREGS[0] = 0x00;
81 	reset_flag++;
82 	reset_flag &= 0x0F;
83 	MMC3RegReset();
84 }
85 
BMCT2271Power(void)86 static void BMCT2271Power(void) {
87 	EXPREGS[0] = 0x00;
88 	GenMMC3Power();
89 	SetWriteHandler(0x6000, 0x7FFF, BMCT2271LoWrite);
90 	SetReadHandler(0x8000, 0xFFFF, BMCT2271HiRead);
91 }
92 
BMCT2271_Init(CartInfo * info)93 void BMCT2271_Init(CartInfo *info) {
94 	GenMMC3_Init(info, 128, 128, 8, 0);
95 	pwrap = BMCT2271PW;
96 	cwrap = BMCT2271CW;
97 	info->Power = BMCT2271Power;
98 	info->Reset = BMCT2271Reset;
99 	AddExState(EXPREGS, 1, 0, "EXPR");
100 }
101