mapper fixes for ncpu, debug is broken atm
[fceu.git] / mappers / 51.c
CommitLineData
c62d2810 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 mode mapbyte1[0]
24#define page mapbyte1[1]
25
26static uint32 Get8K(uint32 A)
27{
28 uint32 bank;
c0bf6f9f 29
c62d2810 30 bank=(page<<2)|((A>>13)&1);
31
32 if(A&0x4000 && !(mode&1)) bank|=0xC;
33 if(!(A&0x8000)) bank|=0x20;
34 if(mode==2) bank|=2;
35 else bank|=(A>>13)&2;
36 return(bank);
37}
38
39static void Synco(void)
40{
41 uint32 x;
42 if(mapbyte1[0]<=2)
43 MIRROR_SET2(1);
44 else
45 MIRROR_SET2(0);
46 for(x=0x6000;x<0x10000;x+=8192)
47 ROM_BANK8(x,Get8K(x));
c0bf6f9f 48 X6502_Rebase();
c62d2810 49}
50
51static DECLFW(Write)
52{
53 if(A&0x8000) mapbyte1[1]=V&0xF;
54 else mapbyte1[0]=(mapbyte1[0]&2)|((V>>1)&1);
55
56 if(A&0x4000) mapbyte1[0]=(mapbyte1[0]&1)|((V>>3)&2);
57 Synco();
58}
59
60void Mapper51_init(void)
61{
62 SetWriteHandler(0x6000,0xFFFF,Write);
63 SetReadHandler(0x6000,0xFFFF,CartBR);
64 mapbyte1[0]=1;
65 mapbyte1[1]=0;
66 Synco();
67}