load keys again after plat init
[fceu.git] / mappers / 68.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2002 Xodnizel
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 static void Fixerit(void)
24 {
25  switch(mapbyte2[0]&3)
26  {
27   case 0:vnapage[0]=vnapage[2]=CHRptr[0]+(((mapbyte1[0]|128)&CHRmask1[0])<<10);
28          vnapage[1]=vnapage[3]=CHRptr[0]+(((mapbyte1[1]|128)&CHRmask1[0])<<10);
29          break;
30   case 1:vnapage[0]=vnapage[1]=CHRptr[0]+(((mapbyte1[0]|128)&CHRmask1[0])<<10);
31          vnapage[2]=vnapage[3]=CHRptr[0]+(((mapbyte1[1]|128)&CHRmask1[0])<<10);
32          break;
33   case 2:vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((mapbyte1[0]|128)&CHRmask1[0])<<10);
34          break;
35   case 3:vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((mapbyte1[1]|128)&CHRmask1[0])<<10);
36          break;
37  }
38 }
39
40 DECLFW(Mapper68_write)
41 {
42 // FCEU_printf("%04x,%04x\n",A,V);
43  A&=0xF000;
44
45  if(A>=0x8000 && A<=0xB000)
46  {
47   VROM_BANK2((A-0x8000)>>1,V);
48  }
49  else switch(A)
50  {
51   case 0xc000:mapbyte1[0]=V;
52               if(VROM_size && mapbyte2[0]&0x10)
53                Fixerit();
54               break;
55
56   case 0xd000:mapbyte1[1]=V;
57               if(VROM_size && mapbyte2[0]&0x10)
58                Fixerit();
59               break;
60
61   case 0xe000: mapbyte2[0]=V;
62                if(!(V&0x10))
63                {
64                 switch(V&3)
65                 {
66                  case 0:MIRROR_SET2(1);break;
67                  case 1:MIRROR_SET2(0);break;
68                  case 2:onemir(0);break;
69                  case 3:onemir(1);break;
70                 }
71                }
72                else if(VROM_size)
73                {
74                 Fixerit();
75                 PPUNTARAM=0;
76                }
77                break;
78   case 0xf000: ROM_BANK16(0x8000,V);break;
79  }
80 }
81
82 static void Mapper68_StateRestore(int version)
83 {
84               if(!(mapbyte2[0]&0x10))
85               {
86                switch(mapbyte2[0]&3)
87                {
88                 case 0:MIRROR_SET(0);break;
89                 case 1:MIRROR_SET(1);break;
90                 case 2:onemir(0);break;
91                 case 3:onemir(1);break;
92                }
93               }
94               else if(VROM_size)
95               {
96                 Fixerit();
97                 PPUNTARAM=0;
98               }
99 }
100
101 void Mapper68_init(void)
102 {
103  SetWriteHandler(0x8000,0xffff,Mapper68_write);
104  MapStateRestore=Mapper68_StateRestore;
105 }