Welcome to mirror list, hosted at ThFree Co, Russian Federation.

konami-qtai.c « boards - github.com/ClusterM/fceux.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ff552e10328535f77ece6fb9996c44f42b7c1b0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* FCE Ultra - NES/Famicom Emulator
 *
 * Copyright notice for this file:
 *  Copyright (C) 2005 CaH4e3
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * CAI Shogakko no Sansu
 */

#include "mapinc.h"

static uint8 *CHRRAM=NULL;
static uint8 SWRAM[4096];

static uint8 regs[16];
static uint8 WRAM[4096];
static SFORMAT StateRegs[]=
{
  {&regs, 16, "REGS"},
  {WRAM, 4096, "WRAM"},
  {0}
};

static void Sync(void)
{
  if(regs[5]&0x40)
  {
    setchr4r(0,0x1000,regs[5]&0x3F);
  }
  else
  {
    setchr4r(0x10,0x0000,regs[5]);
    setchr4r(0x10,0x1000,regs[5]^1);
  }
  setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F));
  setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F));
  setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F));
  setprg8r(1,0xE000,~0);
  setmirror((regs[0xA]&3));
}

static DECLFW(M190Write)
{
// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp);
  regs[(A&0x0F00)>>8]=V;
  Sync();
}

static DECLFR(M190Read)
{
// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp);
  return regs[(A&0x0F00)>>8];
}

static DECLFR(AWRAM)
{
  return(WRAM[A-0x7000]);
}
static DECLFW(BWRAM)
{
  WRAM[A-0x7000]=V;
}

static DECLFR(ASWRAM)
{
  return(SWRAM[A-0x6000]);
}
static DECLFW(BSWRAM)
{
  SWRAM[A-0x6000]=V;
}

static void M190Power(void)
{
  setvram8(CHRRAM);
  SetReadHandler(0x8000,0xFFFF,CartBR);
  SetWriteHandler(0x8000,0xFFFF,M190Write);
// SetReadHandler(0xDA00,0xDA00,M190Read);
// SetReadHandler(0xDB00,0xDB00,M190Read);
  SetReadHandler(0xDC00,0xDC00,M190Read);
  SetReadHandler(0xDD00,0xDD00,M190Read);
  SetReadHandler(0x7000,0x7FFF,AWRAM);
  SetWriteHandler(0x7000,0x7FFF,BWRAM);
  SetReadHandler(0x6000,0x6FFF,ASWRAM);
  SetWriteHandler(0x6000,0x6FFF,BSWRAM);
  Sync();
}

static void M190Close(void)
{
  if(CHRRAM)
    FCEU_gfree(CHRRAM);
  CHRRAM=NULL;
}

static void StateRestore(int version)
{
  Sync();
}

void Mapper190_Init(CartInfo *info)
{
  info->Power=M190Power;
  info->Close=M190Close;
  if(info->battery)
  {
    info->SaveGame[0]=SWRAM;
    info->SaveGameLen[0]=4096;
  }
  GameStateRestore=StateRestore;
  CHRRAM=(uint8*)FCEU_gmalloc(8192);
  SetupCartCHRMapping(0x10,CHRRAM,8192,1);
  AddExState(CHRRAM, 8192, 0, "CHRRAM");
  AddExState(&StateRegs, ~0, 0, 0);
}