perfect vsync, bugfixes
[fceu.git] / boards / 57.c
CommitLineData
e2d0dd92 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2005 CaH4e3
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
22#include "mapinc.h"
23
24static uint8 prg_reg;
25static uint8 chr_reg;
26static uint8 hrd_flag;
27
28static SFORMAT StateRegs[]=
29{
30 {&prg_reg, 1, "PRG"},
31 {&chr_reg, 1, "CHR"},
32 {0}
33};
34
35static void Sync(void)
36{
37 if(prg_reg&0x80)
38 setprg32(0x8000,prg_reg>>6);
39 else
40 {
41 setprg16(0x8000,(prg_reg>>5)&3);
42 setprg16(0xC000,(prg_reg>>5)&3);
43 }
44 setmirror((prg_reg&8)>>3);
45 setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1));
46}
47
48static DECLFR(M57Read)
49{
50 return hrd_flag;
51}
52
53static DECLFW(M57Write)
54{
55 if((A&0x8800)==0x8800)
56 prg_reg=V;
57 else
58 chr_reg=V;
59 Sync();
60}
61
62static void M57Power(void)
63{
64 prg_reg=0;
65 chr_reg=0;
66 hrd_flag=0;
67 SetReadHandler(0x8000,0xFFFF,CartBR);
68 SetWriteHandler(0x8000,0xFFFF,M57Write);
69 SetReadHandler(0x6000,0x6000,M57Read);
70 Sync();
71}
72
73static void M57Reset()
74{
75 if(hrd_flag==3)
76 hrd_flag=0;
77 else
78 hrd_flag++;
79 FCEU_printf("Select Register = %02x\n",hrd_flag);
80}
81
82static void StateRestore(int version)
83{
84 Sync();
85}
86
87void Mapper57_Init(CartInfo *info)
88{
89 info->Power=M57Power;
90 info->Reset=M57Reset;
91 GameStateRestore=StateRestore;
92 AddExState(&StateRegs, ~0, 0, 0);
93}