1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Xodnizel
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.
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.
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
23 static void AYSound(int Count);
24 static void AYSoundHQ(void);
25 static void DoAYSQ(int x);
26 static void DoAYSQHQ(int x);
28 #define sunselect mapbyte1[0]
29 #define sungah mapbyte1[1]
30 static uint8 sunindex;
32 static DECLFW(SUN5BWRAM)
34 if((sungah&0xC0)==0xC0)
38 static DECLFR(SUN5AWRAM)
40 if((sungah&0xC0)==0x40)
45 static DECLFW(Mapper69_SWL)
50 static DECLFW(Mapper69_SWH)
53 GameExpSound.Fill=AYSound;
54 GameExpSound.HiFill=AYSoundHQ;
55 if(FSettings.SndRate);
60 case 8:if(FSettings.soundq>=1) DoAYSQHQ(0); else DoAYSQ(0);break;
63 case 9:if(FSettings.soundq>=1) DoAYSQHQ(1); else DoAYSQ(1);break;
66 case 10:if(FSettings.soundq>=1) DoAYSQHQ(2); else DoAYSQ(2);break;
69 if(FSettings.soundq>=1) DoAYSQHQ(x); else DoAYSQ(x);
72 MapperExRAM[sunindex]=V;
75 static DECLFW(Mapper69_write)
79 case 0x8000:sunselect=V;break;
83 VROM_BANK1(sunselect<<10,V);
85 switch(sunselect&0x0f)
91 if(V&0x80) // Select WRAM
92 setprg8r(0x10,0x6000,0);
97 case 9:ROM_BANK8(0x8000,V);break;
98 case 0xa:ROM_BANK8(0xa000,V);break;
99 case 0xb:ROM_BANK8(0xc000,V);break;
103 case 0:MIRROR_SET2(1);break;
104 case 1:MIRROR_SET2(0);break;
105 case 2:onemir(0);break;
106 case 3:onemir(1);break;
109 case 0xd:IRQa=V;X6502_IRQEnd(FCEU_IQEXT);break;
110 case 0xe:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break;
111 case 0xf:IRQCount&=0x00FF;IRQCount|=V<<8;X6502_IRQEnd(FCEU_IQEXT);break;
117 static int32 vcount[3];
118 static int32 dcount[3];
121 static void DoAYSQ(int x)
123 int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<(4+17);
124 int32 amp=(MapperExRAM[0x8+x]&15)<<2;
131 end=(SOUNDTS<<16)/soundtsinc;
132 if(end<=start) return;
136 for(V=start;V<end;V++)
140 vcount[x]-=nesincsize;
149 static void DoAYSQHQ(int x)
152 int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<4;
153 int32 amp=(MapperExRAM[0x8+x]&15)<<6;
157 if(!(MapperExRAM[0x7]&(1<<x)))
159 for(V=CAYBC[x];V<SOUNDTS;V++)
174 static void AYSound(int Count)
184 static void AYSoundHQ(void)
191 static void AYHiSync(int32 ts)
199 static void FP_FASTAPASS(1) SunIRQHook(int a)
205 {X6502_IRQBegin(FCEU_IQEXT);IRQa=0;IRQCount=0xFFFF;}
209 void Mapper69_StateRestore(int version)
213 if(mapbyte1[1]&0x80) // Select WRAM
214 setprg8r(0x10,0x6000,0);
217 setprg8(0x6000,mapbyte1[1]);
220 void Mapper69_ESI(void)
222 GameExpSound.RChange=Mapper69_ESI;
223 GameExpSound.HiSync=AYHiSync;
224 memset(dcount,0,sizeof(dcount));
225 memset(vcount,0,sizeof(vcount));
226 memset(CAYBC,0,sizeof(CAYBC));
229 void NSFAY_Init(void)
232 SetWriteHandler(0xc000,0xdfff,Mapper69_SWL);
233 SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
237 void Mapper69_init(void)
241 SetupCartPRGMapping(0x10,WRAM,8192,1);
243 SetWriteHandler(0x8000,0xbfff,Mapper69_write);
244 SetWriteHandler(0xc000,0xdfff,Mapper69_SWL);
245 SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
246 SetWriteHandler(0x6000,0x7fff,SUN5BWRAM);
247 SetReadHandler(0x6000,0x7fff,SUN5AWRAM);
249 MapIRQHook=SunIRQHook;
250 MapStateRestore=Mapper69_StateRestore;