perfect vsync, bugfixes
[fceu.git] / boards / 208.c
CommitLineData
d97315ac 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
e2d0dd92 4 * Copyright (C) 2005 CaH4e3
d97315ac 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"
e2d0dd92 22#include "mmc3.h"
d97315ac 23
e2d0dd92 24static uint8 lut[256]={
d97315ac 25 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
26 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
27 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
28 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
29 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
31 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
32 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
34 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
35 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
36 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
37 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
e2d0dd92 41};
d97315ac 42
e2d0dd92 43static void M208PW(uint32 A, uint8 V)
d97315ac 44{
e2d0dd92 45 setprg32(0x8000,EXPREGS[5]);
d97315ac 46}
47
e2d0dd92 48static DECLFW(M208Write)
d97315ac 49{
e2d0dd92 50 EXPREGS[5]=(V&0x1)|((V>>3)&0x2);
51 FixMMC3PRG(MMC3_cmd);
d97315ac 52}
53
e2d0dd92 54static DECLFW(M208ProtWrite)
d97315ac 55{
e2d0dd92 56 if(A<=0x57FF)
57 EXPREGS[4]=V;
58 else
59 EXPREGS[(A&0x03)]=V^lut[EXPREGS[4]];
d97315ac 60}
61
e2d0dd92 62static DECLFR(M208ProtRead)
d97315ac 63{
e2d0dd92 64 return(EXPREGS[(A&0x3)]);
d97315ac 65}
66
e2d0dd92 67static void M208Power(void)
d97315ac 68{
e2d0dd92 69 EXPREGS[5]=3;
70 GenMMC3Power();
71 SetWriteHandler(0x4800,0x4FFF,M208Write);
72 SetWriteHandler(0x5000,0x5fff,M208ProtWrite);
73 SetReadHandler(0x5800,0x5FFF,M208ProtRead);
74 SetReadHandler(0x8000,0xffff,CartBR);
d97315ac 75}
76
77void Mapper208_Init(CartInfo *info)
78{
e2d0dd92 79 GenMMC3_Init(info, 128, 256, 0, 0);
80 pwrap=M208PW;
81 info->Power=M208Power;
82 AddExState(EXPREGS, 6, 0, "EXPR");
d97315ac 83}