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

« back to all changes in this revision

Viewing changes to fceu/src/boards/106.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 reg[16], IRQa;
 
24
static uint32 IRQCount;
 
25
static uint8 *WRAM=NULL;
 
26
static uint32 WRAMSIZE;
 
27
 
 
28
static SFORMAT StateRegs[]=
 
29
{
 
30
  {&IRQa, 1, "IRQA"},
 
31
  {&IRQCount, 4, "IRQCOUNT"},
 
32
  {reg, 16, "REGS"},
 
33
  {0}
 
34
};
 
35
 
 
36
static void Sync(void)
 
37
{
 
38
  setchr1(0x0000,reg[0]&0xfe);
 
39
  setchr1(0x0400,reg[1]|1);
 
40
  setchr1(0x0800,reg[2]&0xfe);
 
41
  setchr1(0x0c00,reg[3]|1);
 
42
  setchr1(0x1000,reg[4]);
 
43
  setchr1(0x1400,reg[5]);
 
44
  setchr1(0x1800,reg[6]);
 
45
  setchr1(0x1c00,reg[7]);
 
46
  setprg8r(0x10,0x6000,0);
 
47
  setprg8(0x8000,(reg[0x8]&0xf)|0x10);
 
48
  setprg8(0xA000,(reg[0x9]&0x1f));
 
49
  setprg8(0xC000,(reg[0xa]&0x1f));
 
50
  setprg8(0xE000,(reg[0xb]&0xf)|0x10);
 
51
  setmirror((reg[0xc]&1)^1);
 
52
}
 
53
 
 
54
static DECLFW(M106Write)
 
55
{
 
56
  A&=0xF;
 
57
  switch(A)
 
58
  {
 
59
    case 0xD: IRQa=0; IRQCount=0; X6502_IRQEnd(FCEU_IQEXT); break;
 
60
    case 0xE: IRQCount=(IRQCount&0xFF00)|V; break;
 
61
    case 0xF: IRQCount=(IRQCount&0x00FF)|(V<<8); IRQa=1; break;
 
62
    default: reg[A]=V; Sync(); break;
 
63
  }
 
64
}
 
65
 
 
66
static void M106Power(void)
 
67
{
 
68
  reg[8]=reg[9]=reg[0xa]=reg[0xb]=-1;
 
69
  Sync();
 
70
  SetReadHandler(0x6000,0x7FFF,CartBR);
 
71
  SetReadHandler(0x8000,0xFFFF,CartBR);
 
72
  SetWriteHandler(0x6000,0x7FFF,CartBW);
 
73
  SetWriteHandler(0x8000,0xFFFF,M106Write);
 
74
}
 
75
 
 
76
static void M106Reset(void)
 
77
{
 
78
}
 
79
 
 
80
static void M106Close(void)
 
81
{
 
82
  if(WRAM)
 
83
    FCEU_gfree(WRAM);
 
84
  WRAM=NULL;
 
85
}
 
86
 
 
87
void M106CpuHook(int a)
 
88
{
 
89
  if(IRQa)
 
90
  {
 
91
    IRQCount+=a;
 
92
    if(IRQCount>0x10000)
 
93
    {
 
94
      X6502_IRQBegin(FCEU_IQEXT);
 
95
      IRQa=0;
 
96
    }
 
97
  }
 
98
}
 
99
 
 
100
static void StateRestore(int version)
 
101
{
 
102
  Sync();
 
103
}
 
104
 
 
105
void Mapper106_Init(CartInfo *info)
 
106
{
 
107
  info->Reset=M106Reset;
 
108
  info->Power=M106Power;
 
109
  info->Close=M106Close;
 
110
  MapIRQHook=M106CpuHook;
 
111
  GameStateRestore=StateRestore;
 
112
 
 
113
  WRAMSIZE=8192;
 
114
  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
 
115
  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
 
116
  AddExState(WRAM, WRAMSIZE, 0, "WRAM");
 
117
 
 
118
  AddExState(&StateRegs, ~0, 0, 0);
 
119
}