initial fce ultra 0.81 import
[fceu.git] / mappers / 226.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 rg mapbyte1
24 static void DoPRG(void)
25 {
26   int32 b=((rg[0]>>1)&0xF) | ((rg[0]>>3)&0x10) | ((rg[1]&1)<<5);
27   if(rg[0]&0x20)        // 16 KB
28   {
29    ROM_BANK16(0x8000,(b<<1)|(rg[0]&1));
30    ROM_BANK16(0xC000,(b<<1)|(rg[0]&1));
31   }
32   else
33    ROM_BANK32(b);
34 }
35
36 static DECLFW(Mapper226_write)
37 {
38  rg[A&1]=V;
39  DoPRG();
40  if(A&1)
41  {
42   if(rg[1]&2)
43    PPUCHRRAM=0;  // Write protected.
44   else
45    PPUCHRRAM=0xFF; // Not write protected.
46  }
47  else
48   MIRROR_SET2((rg[0]>>6)&1);
49 }
50
51 static void M26Reset(void)
52 {
53  rg[0]=rg[1]=0;
54  DoPRG();
55  PPUCHRRAM=0xFF;
56  MIRROR_SET2(0);
57 }
58
59 static void M26Restore(int version)
60 {
61  DoPRG();
62  if(rg[1]&2)
63   PPUCHRRAM=0;  // Write protected.
64  else
65   PPUCHRRAM=0xFF; // Not write protected.
66  MIRROR_SET2((rg[0]>>6)&1);
67 }
68
69 void Mapper226_init(void)
70 {
71   SetWriteHandler(0x8000,0xffff,Mapper226_write);
72   MapperReset=M26Reset;
73   GameStateRestore=M26Restore;
74   M26Reset();
75 }
76
77 #ifdef OLD      // What the heck is this??
78 DECLFW(Mapper226_write)
79 {
80  MIRROR_SET((A>>13)&1);
81  VROM_BANK8(A&0x7F);
82  if(A&0x1000)
83   {
84    if(A&0x40)
85     {
86      ROM_BANK16(0x8000,(((A>>7))<<1)+1);
87      ROM_BANK16(0xC000,(((A>>7))<<1)+1);
88     }
89     else
90     {
91      ROM_BANK16(0x8000,(((A>>7))<<1));
92      ROM_BANK16(0xC000,(((A>>7))<<1));
93     }
94   }
95   else
96   {
97    ROM_BANK32(A>>7);
98   }
99 }
100
101 void Mapper226_init(void)
102 {
103   SetWriteHandler(0x8000,0xffff,Mapper226_write);
104 }
105 #endif