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

« back to all changes in this revision

Viewing changes to fceu/src/boards/ks7032.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[8], cmd, IRQa;
 
24
static int32 IRQCount;
 
25
 
 
26
static SFORMAT StateRegs[]=
 
27
{
 
28
  {&cmd, 1, "CMD"},
 
29
  {reg, 8, "REGS"},
 
30
  {&IRQa, 1, "IRQA"},
 
31
  {&IRQCount, 4, "IRQC"},
 
32
  {0}
 
33
};
 
34
 
 
35
static void Sync(void)
 
36
{
 
37
  setprg8(0x6000,reg[4]);
 
38
  setprg8(0x8000,reg[1]);
 
39
  setprg8(0xA000,reg[2]);
 
40
  setprg8(0xC000,reg[3]);
 
41
  setprg8(0xE000,~0);
 
42
  setchr8(0);
 
43
}
 
44
 
 
45
static DECLFW(UNLKS7032Write)
 
46
{
 
47
//  FCEU_printf("bs %04x %02x\n",A,V);
 
48
  switch(A)
 
49
  {
 
50
//    case 0x8FFF: reg[4]=V; Sync(); break;
 
51
    case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); break;
 
52
    case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); break;
 
53
    case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); break;
 
54
    case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); break;
 
55
    case 0xC000: X6502_IRQEnd(FCEU_IQEXT); IRQa=1; break;
 
56
    case 0xE000: cmd=V&7; break;
 
57
    case 0xF000: reg[cmd]=V; Sync(); break;
 
58
  }
 
59
}
 
60
 
 
61
static void UNLSMB2JIRQHook(int a)
 
62
{
 
63
  if(IRQa)
 
64
  {
 
65
    IRQCount+=a;
 
66
    if(IRQCount>=0xFFFF)
 
67
    {
 
68
      IRQa=0;
 
69
      IRQCount=0;
 
70
      X6502_IRQBegin(FCEU_IQEXT);
 
71
    }
 
72
  }
 
73
}
 
74
 
 
75
static void UNLKS7032Power(void)
 
76
{
 
77
  Sync();
 
78
  SetReadHandler(0x6000,0x7FFF,CartBR);
 
79
  SetReadHandler(0x8000,0xFFFF,CartBR);
 
80
  SetWriteHandler(0x4020,0xFFFF,UNLKS7032Write);
 
81
}
 
82
 
 
83
static void StateRestore(int version)
 
84
{
 
85
  Sync();
 
86
}
 
87
 
 
88
void UNLKS7032_Init(CartInfo *info)
 
89
{
 
90
  info->Power=UNLKS7032Power;
 
91
  MapIRQHook=UNLSMB2JIRQHook;
 
92
  GameStateRestore=StateRestore;
 
93
  AddExState(&StateRegs, ~0, 0, 0);
 
94
}