Page[] mappings in mapper code, X.DB update for games with no controls
[fceu.git] / boards / konami-qtai.c
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  * CAI Shogakko no Sansu
21  */
22
23 #include "mapinc.h"
24
25 static uint8 *CHRRAM=NULL;
26 static uint8 SWRAM[4096];
27
28 static uint8 regs[16];
29 static uint8 WRAM[4096];
30 static SFORMAT StateRegs[]=
31 {
32   {&regs, 16, "REGS"},
33   {WRAM, 4096, "WRAM"},
34   {0}
35 };
36
37 static void Sync(void)
38 {
39   if(regs[5]&0x40)
40   {
41     setchr4r(0,0x1000,regs[5]&0x3F);
42   }
43   else
44   {
45     setchr4r(0x10,0x0000,regs[5]);
46     setchr4r(0x10,0x1000,regs[5]^1);
47   }
48   setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F));
49   setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F));
50   setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F));
51   setprg8r(1,0xE000,~0);
52   setmirror((regs[0xA]&3));
53 }
54
55 static DECLFW(M190Write)
56 {
57 // FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp);
58   regs[(A&0x0F00)>>8]=V;
59   Sync();
60 }
61
62 static DECLFR(M190Read)
63 {
64 // FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp);
65   return regs[(A&0x0F00)>>8];
66 }
67
68 static DECLFR(AWRAM)
69 {
70   return(WRAM[A-0x7000]);
71 }
72 static DECLFW(BWRAM)
73 {
74   WRAM[A-0x7000]=V;
75 }
76
77 static DECLFR(ASWRAM)
78 {
79   return(SWRAM[A-0x6000]);
80 }
81 static DECLFW(BSWRAM)
82 {
83   SWRAM[A-0x6000]=V;
84 }
85
86 static void M190Power(void)
87 {
88   setvram8(CHRRAM);
89   SetReadHandler(0x8000,0xFFFF,CartBR);
90   SetWriteHandler(0x8000,0xFFFF,M190Write);
91 // SetReadHandler(0xDA00,0xDA00,M190Read);
92 // SetReadHandler(0xDB00,0xDB00,M190Read);
93   SetReadHandler(0xDC00,0xDC00,M190Read);
94   SetReadHandler(0xDD00,0xDD00,M190Read);
95   SetReadHandler(0x7000,0x7FFF,AWRAM);
96   SetWriteHandler(0x7000,0x7FFF,BWRAM);
97   SetReadHandler(0x6000,0x6FFF,ASWRAM);
98   SetWriteHandler(0x6000,0x6FFF,BSWRAM);
99 #ifdef ASM_6502
100   Page[14]=Page[15]=WRAM-0x7000;
101   Page[12]=Page[13]=SWRAM-0x6000;
102 #endif
103   Sync();
104 }
105
106 static void M190Close(void)
107 {
108   if(CHRRAM)
109     FCEU_gfree(CHRRAM);
110   CHRRAM=NULL;
111 }
112
113 static void StateRestore(int version)
114 {
115   Sync();
116 }
117
118 void Mapper190_Init(CartInfo *info)
119 {
120   info->Power=M190Power;
121   info->Close=M190Close;
122   if(info->battery)
123   {
124     info->SaveGame[0]=SWRAM;
125     info->SaveGameLen[0]=4096;
126   }
127   GameStateRestore=StateRestore;
128   CHRRAM=(uint8*)FCEU_gmalloc(8192);
129   SetupCartCHRMapping(0x10,CHRRAM,8192,1);
130   AddExState(CHRRAM, 8192, 0, "CHRRAM");
131   AddExState(&StateRegs, ~0, 0, 0);
132 }