1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
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
22 static void AYSound(int Count);
23 static void DoAYSQ(int x);
24 static void DoAYNoise(void);
26 #define sunselect mapbyte1[0]
27 #define sungah mapbyte1[1]
28 #define sunindex mapbyte1[2]
35 if((sungah&0xC0)==0xC0)
41 if((sungah&0xC0)==0x40)
52 GameExpSound.Fill=AYSound;
57 case 8:DoAYSQ(0);break;
60 case 9:DoAYSQ(1);break;
63 case 10:DoAYSQ(2);break;
64 case 6:DoAYNoise();znreg=0xFFFF;break;
70 MapperExRAM[sunindex]=V;
73 DECLFW(Mapper69_write)
77 case 0x8000:sunselect=V;break;
81 VROM_BANK1(sunselect<<10,V);
83 switch(sunselect&0x0f)
89 if(V&0x80) // Select WRAM
90 setprg8r(0x10,0x6000,0);
96 case 9:ROM_BANK8(0x8000,V);
98 case 0xa:ROM_BANK8(0xa000,V);
100 case 0xb:ROM_BANK8(0xc000,V);
101 X6502_Rebase();break;
105 case 0:MIRROR_SET2(1);break;
106 case 1:MIRROR_SET2(0);break;
107 case 2:onemir(0);break;
108 case 3:onemir(1);break;
111 case 0xd:IRQa=V;break;
112 case 0xe:IRQCount&=0xFF00;IRQCount|=V;break;
113 case 0xf:IRQCount&=0x00FF;IRQCount|=V<<8;break;
119 static int32 vcount[4];
120 static int CAYBC[4]={0,0,0,0};
121 static void DoAYSQ(int x)
129 end=(timestamp<<16)/soundtsinc;
130 if(end<=start) return;
133 if(!(MapperExRAM[0x7]&(1<<x)))
136 freq=(MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1;
137 inc=(long double)((unsigned long)((FSettings.SndRate OVERSAMPLE)<<12))/
138 ((long double)PSG_base/freq);
139 amp=MapperExRAM[0x8+x]&15;
143 for(V=start;V<end;V++)
148 if(vcoo>=inc) vcoo-=inc;
153 static void DoAYNoise(void)
161 end=(timestamp<<16)/soundtsinc;
162 if(end<=start) return;
168 if(!(MapperExRAM[0x7]&(8<<V)))
170 //if(MapperExRAM[0x8+V]&0x10) amp+=MapperExRAM[0x20]&15;
172 amp+=MapperExRAM[0x8+V]&15;
179 freq=PSG_base/(MapperExRAM[0x6]+1);
181 inc=((freq<<11)/(FSettings.SndRate OVERSAMPLE))<<4;
183 inc=(freq<<15)/(FSettings.SndRate OVERSAMPLE);
185 for(V=start;V<end;V++)
191 unsigned char feedback;
193 if(znreg&1) mixer+=amp;
194 feedback=((znreg>>13)&1)^((znreg>>14)&1);
195 znreg=(znreg<<1)+(feedback);
205 static void AYSound(int Count)
216 static void FP_FASTAPASS(1) SunIRQHook(int a)
222 {TriggerIRQ();IRQa=0;IRQCount=0xFFFF;}
226 void Mapper69_StateRestore(int version)
232 if(mapbyte1[1]&0x80) // Select WRAM
233 setprg8r(0x10,0x6000,0);
236 setprg8(0x6000,mapbyte1[1]);
242 static void M69SC(void)
244 if(FSettings.SndRate)
247 SetWriteHandler(0xc000,0xffff,(writefunc)0);
250 void Mapper69_ESI(void)
252 GameExpSound.RChange=M69SC;
253 if(FSettings.SndRate)
255 SetWriteHandler(0xc000,0xdfff,Mapper69_SWL);
256 SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
260 void Mapper69_init(void)
262 SetupCartPRGMapping(0x10,WRAM,8192,1);
264 SetWriteHandler(0x8000,0xbfff,Mapper69_write);
265 SetWriteHandler(0x6000,0x7fff,SUN5BWRAM);
266 SetReadHandler(0x6000,0x7fff,SUN5AWRAM);
268 MapIRQHook=SunIRQHook;
269 MapStateRestore=Mapper69_StateRestore;