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);
95 case 9:ROM_BANK8(0x8000,V);break;
96 case 0xa:ROM_BANK8(0xa000,V);break;
97 case 0xb:ROM_BANK8(0xc000,V);break;
101 case 0:MIRROR_SET2(1);break;
102 case 1:MIRROR_SET2(0);break;
103 case 2:onemir(0);break;
104 case 3:onemir(1);break;
107 case 0xd:IRQa=V;break;
108 case 0xe:IRQCount&=0xFF00;IRQCount|=V;break;
109 case 0xf:IRQCount&=0x00FF;IRQCount|=V<<8;break;
115 static int32 vcount[4];
116 static int CAYBC[4]={0,0,0,0};
117 static void DoAYSQ(int x)
125 end=(timestamp<<16)/soundtsinc;
126 if(end<=start) return;
129 if(!(MapperExRAM[0x7]&(1<<x)))
132 freq=(MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1;
133 inc=(long double)((unsigned long)((FSettings.SndRate OVERSAMPLE)<<12))/
134 ((long double)PSG_base/freq);
135 amp=MapperExRAM[0x8+x]&15;
139 for(V=start;V<end;V++)
144 if(vcoo>=inc) vcoo-=inc;
149 static void DoAYNoise(void)
157 end=(timestamp<<16)/soundtsinc;
158 if(end<=start) return;
164 if(!(MapperExRAM[0x7]&(8<<V)))
166 //if(MapperExRAM[0x8+V]&0x10) amp+=MapperExRAM[0x20]&15;
168 amp+=MapperExRAM[0x8+V]&15;
175 freq=PSG_base/(MapperExRAM[0x6]+1);
177 inc=((freq<<11)/(FSettings.SndRate OVERSAMPLE))<<4;
179 inc=(freq<<15)/(FSettings.SndRate OVERSAMPLE);
181 for(V=start;V<end;V++)
187 unsigned char feedback;
189 if(znreg&1) mixer+=amp;
190 feedback=((znreg>>13)&1)^((znreg>>14)&1);
191 znreg=(znreg<<1)+(feedback);
201 static void AYSound(int Count)
212 static void FP_FASTAPASS(1) SunIRQHook(int a)
218 {TriggerIRQ();IRQa=0;IRQCount=0xFFFF;}
222 void Mapper69_StateRestore(int version)
228 if(mapbyte1[1]&0x80) // Select WRAM
229 setprg8r(0x10,0x6000,0);
232 setprg8(0x6000,mapbyte1[1]);
238 static void M69SC(void)
240 if(FSettings.SndRate)
243 SetWriteHandler(0xc000,0xffff,(writefunc)0);
246 void Mapper69_ESI(void)
248 GameExpSound.RChange=M69SC;
249 if(FSettings.SndRate)
251 SetWriteHandler(0xc000,0xdfff,Mapper69_SWL);
252 SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
256 void Mapper69_init(void)
258 SetupCartPRGMapping(0x10,WRAM,8192,1);
260 SetWriteHandler(0x8000,0xbfff,Mapper69_write);
261 SetWriteHandler(0x6000,0x7fff,SUN5BWRAM);
262 SetReadHandler(0x6000,0x7fff,SUN5AWRAM);
264 MapIRQHook=SunIRQHook;
265 MapStateRestore=Mapper69_StateRestore;