initial fce ultra 0.81 import
[fceu.git] / mappers / 82.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2002 Ben Parnell
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 #define ctrl    mapbyte1[6]
24
25 static void DoCHR(void)
26 {
27  int x;
28
29  for(x=0;x<2;x++)
30   VROM_BANK2((x<<11)|((ctrl&2)<<11),mapbyte1[x]>>1);
31  for(x=0;x<4;x++)
32   VROM_BANK1((x<<10) | (((ctrl&2)^2)<<11),mapbyte1[2+x]);
33 }
34
35 static DECLFW(Mapper82_write)
36 {
37  if(A<=0x7EF5)
38  {
39   mapbyte1[A&7]=V;
40   DoCHR();
41  }
42  else
43   switch(A)
44   {
45    case 0x7ef6:ctrl=V&3;
46                MIRROR_SET2(V&1);
47                DoCHR();
48                break;
49    case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V);break;
50    case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V);break;
51    case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V);break;
52   }
53 }
54
55 void Mapper82_init(void)
56 {
57  ROM_BANK8(0xE000,~0);
58
59  /* external WRAM might end at $73FF */
60  SetWriteHandler(0x7ef0,0x7efc,Mapper82_write);
61 }
62