1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2005 CaH4e3
\r
6 * This program is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * This program is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * VRC-5 (CAI Shogakko no Sansu)
\r
26 static uint8 QTAINTRAM[2048];
\r
27 static writefunc old2007wrap;
\r
29 static uint16 CHRSIZE = 8192;
\r
30 static uint16 WRAMSIZE = 8192 + 4096;
\r
31 static uint8 *CHRRAM = NULL;
\r
32 static uint8 *WRAM = NULL;
\r
34 static uint8 IRQa, K4IRQ;
\r
35 static uint32 IRQLatch, IRQCount;
\r
37 static uint8 regs[16];
\r
38 //static uint8 test[8];
\r
39 static SFORMAT StateRegs[]=
\r
41 {&IRQCount, 1, "IRQC"},
\r
42 {&IRQLatch, 1, "IRQL"},
\r
44 {&K4IRQ, 1, "KIRQ"},
\r
49 static void chrSync(void)
\r
51 setchr4r(0x10,0x0000,regs[5]&1);
\r
52 setchr4r(0x10,0x1000,0);
\r
55 static void Sync(void)
\r
58 // if(regs[0xA]&0x10)
\r
60 /* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0);
\r
61 setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1);
\r
62 setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2);
\r
63 setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3);
\r
64 setchr1r(0x10,0x1000,0);
\r
65 setchr1r(0x10,0x1400,1);
\r
66 setchr1r(0x10,0x1800,2);
\r
67 setchr1r(0x10,0x1c00,3);*/
\r
68 /* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0);
\r
69 setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1);
\r
70 setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2);
\r
71 setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3);
\r
72 setchr1r(0x10,0x1000,(((regs[5]&1)^1)<<2)+4);
\r
73 setchr1r(0x10,0x1400,(((regs[5]&1)^1)<<2)+5);
\r
74 setchr1r(0x10,0x1800,(((regs[5]&1)^1)<<2)+6);
\r
75 setchr1r(0x10,0x1c00,(((regs[5]&1)^1)<<2)+7);
\r
81 setchr1r(0x10,0x0000,(((regs[5]&1)^1)<<2)+0);
\r
82 setchr1r(0x10,0x0400,(((regs[5]&1)^1)<<2)+1);
\r
83 setchr1r(0x10,0x0800,(((regs[5]&1)^1)<<2)+2);
\r
84 setchr1r(0x10,0x0c00,(((regs[5]&1)^1)<<2)+3);
\r
85 setchr1r(0x10,0x1000,(((regs[5]&1))<<2)+4);
\r
86 setchr1r(0x10,0x1400,(((regs[5]&1))<<2)+5);
\r
87 setchr1r(0x10,0x1800,(((regs[5]&1))<<2)+6);
\r
88 setchr1r(0x10,0x1c00,(((regs[5]&1))<<2)+7);
\r
91 /* setchr1r(1,0x0000,test[0]);
\r
92 setchr1r(1,0x0400,test[1]);
\r
93 setchr1r(1,0x0800,test[2]);
\r
94 setchr1r(1,0x0c00,test[3]);
\r
95 setchr1r(1,0x1000,test[4]);
\r
96 setchr1r(1,0x1400,test[5]);
\r
97 setchr1r(1,0x1800,test[6]);
\r
98 setchr1r(1,0x1c00,test[7]);
\r
100 setprg4r(0x10,0x6000,regs[0]&1);
\r
102 setprg8r(1,0x8000,(regs[2]-0x40));
\r
104 setprg8r(0,0x8000,(regs[2]&0x3F));
\r
106 setprg8r(1,0xA000,(regs[3]-0x40));
\r
108 setprg8r(0,0xA000,(regs[3]&0x3F));
\r
110 setprg8r(1,0xC000,(regs[4]-0x40));
\r
112 setprg8r(0,0xC000,(regs[4]&0x3F));
\r
114 setprg8r(1,0xE000,~0);
\r
118 /*static DECLFW(TestWrite)
\r
124 static DECLFW(M190Write)
\r
126 // FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp);
\r
127 regs[(A&0x0F00)>>8]=V;
\r
130 case 0xd600:IRQLatch&=0xFF00;IRQLatch|=V;break;
\r
131 case 0xd700:IRQLatch&=0x00FF;IRQLatch|=V<<8;break;
\r
132 case 0xd900:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;X6502_IRQEnd(FCEU_IQEXT);break;
\r
133 case 0xd800:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break;
\r
138 static DECLFR(M190Read)
\r
140 // FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp);
\r
141 return regs[(A&0x0F00)>>8]+regs[0x0B];
\r
143 static void FP_FASTAPASS(1) VRC5IRQ(int a)
\r
148 if(IRQCount&0x10000)
\r
150 X6502_IRQBegin(FCEU_IQEXT);
\r
156 //static void FP_FASTAPASS(1) Mapper190_PPU(uint32 A)
\r
159 // setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1);
\r
164 static DECLFW(M1902007Wrap)
\r
169 QTAINTRAM[A&0x1FFF]=V;
\r
176 static void M190Power(void)
\r
187 setprg4r(0x10,0x7000,2);
\r
189 old2007wrap=GetWriteHandler(0x2007);
\r
190 SetWriteHandler(0x2007,0x2007,M1902007Wrap);
\r
192 SetReadHandler(0x6000,0xFFFF,CartBR);
\r
193 // SetWriteHandler(0x5000,0x5007,TestWrite);
\r
194 SetWriteHandler(0x6000,0x7FFF,CartBW);
\r
195 SetWriteHandler(0x8000,0xFFFF,M190Write);
\r
196 SetReadHandler(0xDC00,0xDC00,M190Read);
\r
197 SetReadHandler(0xDD00,0xDD00,M190Read);
\r
201 static void M190Close(void)
\r
204 FCEU_gfree(CHRRAM);
\r
211 static void StateRestore(int version)
\r
216 void Mapper190_Init(CartInfo *info)
\r
218 info->Power=M190Power;
\r
219 info->Close=M190Close;
\r
220 GameStateRestore=StateRestore;
\r
222 MapIRQHook=VRC5IRQ;
\r
223 // PPU_hook=Mapper190_PPU;
\r
225 CHRRAM=(uint8*)FCEU_gmalloc(CHRSIZE);
\r
226 SetupCartCHRMapping(0x10,CHRRAM,CHRSIZE,1);
\r
227 AddExState(CHRRAM, CHRSIZE, 0, "CRAM");
\r
229 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
\r
230 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
\r
231 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
\r
235 info->SaveGame[0] = WRAM;
\r
236 info->SaveGameLen[0] = WRAMSIZE - 4096;
\r
239 AddExState(&StateRegs, ~0, 0, 0);
\r