~ubuntu-branches/ubuntu/lucid/fceux/lucid

« back to all changes in this revision

Viewing changes to fceu/src/boards/103.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-12-14 08:05:17 UTC
  • Revision ID: james.westby@ubuntu.com-20091214080517-abi5tj8avthfan7c
Tags: upstream-2.1.2+repack
ImportĀ upstreamĀ versionĀ 2.1.2+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FCE Ultra - NES/Famicom Emulator
 
2
 *
 
3
 * Copyright notice for this file:
 
4
 *  Copyright (C) 2007 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
#include "mapinc.h"
 
22
 
 
23
static uint8 reg0, reg1, reg2;
 
24
static uint8 *WRAM=NULL;
 
25
static uint32 WRAMSIZE;
 
26
 
 
27
static SFORMAT StateRegs[]=
 
28
{
 
29
  {&reg0, 1, "REG0"},
 
30
  {&reg1, 1, "REG1"},
 
31
  {&reg2, 1, "REG2"},
 
32
  {0}
 
33
};
 
34
 
 
35
static void Sync(void)
 
36
{
 
37
  setchr8(0);
 
38
  setprg8(0x8000,0xc);
 
39
  setprg8(0xe000,0xf);
 
40
  if(reg2&0x10)
 
41
  {
 
42
    setprg8(0x6000,reg0);
 
43
    setprg8(0xa000,0xd);
 
44
    setprg8(0xc000,0xe);
 
45
  }
 
46
  else
 
47
  {
 
48
    setprg8r(0x10,0x6000,0);
 
49
    setprg4(0xa000,(0xd<<1));
 
50
    setprg2(0xb000,(0xd<<2)+2);
 
51
    setprg2r(0x10,0xb800,4);
 
52
    setprg2r(0x10,0xc000,5);
 
53
    setprg2r(0x10,0xc800,6);
 
54
    setprg2r(0x10,0xd000,7);
 
55
    setprg2(0xd800,(0xe<<2)+3);
 
56
  }
 
57
  setmirror(reg1^1);
 
58
}
 
59
 
 
60
static DECLFW(M103RamWrite0)
 
61
{
 
62
  WRAM[A&0x1FFF]=V;
 
63
}
 
64
 
 
65
static DECLFW(M103RamWrite1)
 
66
{
 
67
  WRAM[0x2000+((A-0xB800)&0x1FFF)]=V;
 
68
}
 
69
 
 
70
static DECLFW(M103Write0)
 
71
{
 
72
  reg0=V&0xf;
 
73
  Sync();
 
74
}
 
75
 
 
76
static DECLFW(M103Write1)
 
77
{
 
78
  reg1=(V>>3)&1;
 
79
  Sync();
 
80
}
 
81
 
 
82
static DECLFW(M103Write2)
 
83
{
 
84
  reg2=V;
 
85
  Sync();
 
86
}
 
87
 
 
88
static void M103Power(void)
 
89
{
 
90
  reg0=reg1=0; reg2=0;
 
91
  Sync();
 
92
  SetReadHandler(0x6000,0x7FFF,CartBR);
 
93
  SetWriteHandler(0x6000,0x7FFF,M103RamWrite0);
 
94
  SetReadHandler(0x8000,0xFFFF,CartBR);
 
95
  SetWriteHandler(0xB800,0xD7FF,M103RamWrite1);
 
96
  SetWriteHandler(0x8000,0x8FFF,M103Write0);
 
97
  SetWriteHandler(0xE000,0xEFFF,M103Write1);
 
98
  SetWriteHandler(0xF000,0xFFFF,M103Write2);
 
99
}
 
100
 
 
101
static void M103Close(void)
 
102
{
 
103
  if(WRAM)
 
104
    FCEU_gfree(WRAM);
 
105
  WRAM=NULL;
 
106
}
 
107
 
 
108
static void StateRestore(int version)
 
109
{
 
110
  Sync();
 
111
}
 
112
 
 
113
void Mapper103_Init(CartInfo *info)
 
114
{
 
115
  info->Power=M103Power;
 
116
  info->Close=M103Close;
 
117
  GameStateRestore=StateRestore;
 
118
 
 
119
  WRAMSIZE=16384;
 
120
  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
 
121
  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
 
122
  AddExState(WRAM, WRAMSIZE, 0, "WRAM");
 
123
 
 
124
  AddExState(&StateRegs, ~0, 0, 0);
 
125
}