mappers updated to 0.98.16
[fceu.git] / boards / sheroes.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2006 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 #include "mmc3.h"
23
24 //static uint8 *CHRRAM;
25 static uint8 tekker;
26
27 static void MSHCW(uint32 A, uint8 V)
28 {
29   if(EXPREGS[0]&0x40)
30     setchr8r(0x10,0);
31   else
32   {
33     if(A<0x800)
34       setchr1(A,V|((EXPREGS[0]&8)<<5));
35     else if(A<0x1000)
36       setchr1(A,V|((EXPREGS[0]&4)<<6));
37     else if(A<0x1800)
38       setchr1(A,V|((EXPREGS[0]&1)<<8));
39     else
40       setchr1(A,V|((EXPREGS[0]&2)<<7));
41   }
42 }
43
44 static DECLFW(MSHWrite)
45 {
46   EXPREGS[0]=V;
47   FixMMC3CHR(MMC3_cmd);
48 }
49
50 static DECLFR(MSHRead)
51 {
52   return(tekker);
53 }
54
55 static void MSHReset(void)
56 {
57   MMC3RegReset();
58   tekker^=0xFF;
59 }
60
61 static void MSHPower(void)
62 {
63   tekker=0x00;
64   GenMMC3Power();
65   SetWriteHandler(0x4100,0x4100,MSHWrite);
66   SetReadHandler(0x4100,0x4100,MSHRead);
67 }
68
69 static void MSHClose(void)
70 {
71   if(CHRRAM)
72     FCEU_gfree(CHRRAM);
73   CHRRAM=NULL;
74 }
75
76 void UNLSHeroes_Init(CartInfo *info)
77 {
78   GenMMC3_Init(info, 256, 512, 0, 0);
79   cwrap=MSHCW;
80   info->Power=MSHPower;
81   info->Reset=MSHReset;
82   info->Close=MSHClose;
83   CHRRAM = (uint8*)FCEU_gmalloc(8192);
84   SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
85   AddExState(EXPREGS, 4, 0, "EXPR");
86 }