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
23 #define dopol mapbyte1[0]
24 #define gorfus mapbyte1[1]
25 #define gorko mapbyte1[2]
27 static void NamcoSound(int Count);
28 static void NamcoSoundHack(void);
31 void FP_FASTAPASS(1) NamcoIRQHook(int a)
38 X6502_IRQBegin(FCEU_IQEXT);
45 DECLFR(Namco_Read4800)
47 uint8 ret=MapperExRAM[dopol&0x7f];
49 dopol=(dopol&0x80)|((dopol+1)&0x7f);
53 DECLFR(Namco_Read5000)
58 DECLFR(Namco_Read5800)
63 static void FASTAPASS(2) DoNTARAMROM(int w, uint8 V)
67 // setntamem(NTARAM+((V&1)<<10), 1, w);
68 if((V>=0xE0)) // || ((gorko>>(6+(w>>1)))&1) )
69 setntamem(NTARAM+((V&1)<<10), 1, w);
73 setntamem(VROM+(V<<10), 0, w);
76 // setntamem(NTARAM+((V&1)<<10), 1, w);
79 static void FixNTAR(void)
84 DoNTARAMROM(x,mapbyte2[x]);
87 static void FASTAPASS(2) DoCHRRAMROM(int x, uint8 V)
90 if(!((gorfus>>((x>>2)+6))&1) && (V>=0xE0))
91 VRAM_BANK1(x<<10,V&7);
96 static void FixCRR(void)
100 DoCHRRAMROM(x,mapbyte3[x]);
103 static DECLFW(Mapper19_write)
107 if(A>=0x8000 && A<=0xb800)
108 DoCHRRAMROM((A-0x8000)>>11,V);
109 else if(A>=0xC000 && A<=0xd800)
110 DoNTARAMROM((A-0xC000)>>11,V);
116 if(FSettings.SndRate)
119 GameExpSound.Fill=NamcoSound;
122 MapperExRAM[dopol&0x7f]=V;
124 dopol=(dopol&0x80)|((dopol+1)&0x7f);
127 case 0xf800: dopol=V;break;
128 case 0x5000: IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break;
129 case 0x5800: IRQCount&=0x00ff;IRQCount|=(V&0x7F)<<8;
131 X6502_IRQEnd(FCEU_IQEXT);
134 case 0xE000:gorko=V&0xC0;
138 case 0xE800:gorfus=V&0xC0;
149 static void DoNamcoSound(uint32 *Wave, int Count);
151 static void NamcoSoundHack(void)
155 z=((timestamp<<16)/soundtsinc)>>4;
158 DoNamcoSound(&Wave[dwave], a);
162 static void NamcoSound(int Count)
166 z=((timestamp<<16)/soundtsinc)>>4;
169 DoNamcoSound(&Wave[dwave], a);
173 static uint8 PlayIndex[8];
174 static int32 vcount[8];
176 static void DoNamcoSound(uint32 *Wave, int Count)
181 //FCEU_DispMessage("%d",MapperExRAM[0x7F]>>4);
182 for(P=7;P>=7-((MapperExRAM[0x7F]>>4)&7);P--)
184 if((MapperExRAM[0x44+(P<<3)]&0xE0) && (MapperExRAM[0x47+(P<<3)]&0xF))
188 uint32 duff,duff2,lengo,envelope;
192 freq=MapperExRAM[0x40+(P<<3)];
193 freq|=MapperExRAM[0x42+(P<<3)]<<8;
194 freq|=(MapperExRAM[0x44+(P<<3)]&3)<<16;
199 int c=((MapperExRAM[0x7F]>>4)&7)+1;
201 inc=(long double)(FSettings.SndRate<<15)/((long double)freq*
202 21477272/((long double)0x400000*c*45));
205 envelope=((MapperExRAM[0x47+(P<<3)]&0xF)<<18)/15;
206 duff=MapperExRAM[(((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])>>1)&0xFF)];
207 if((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&1)
210 duff2=(duff*envelope)>>14;
212 lengo=((8-((MapperExRAM[0x44+(P<<3)]>>2)&7)))<<2;
213 for(V=0;V<Count OVERSAMPLE;V++)
218 if(PlayIndex[P]>=lengo)
221 duff=MapperExRAM[(((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)];
222 if((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&1)
225 duff2=(duff*envelope)>>14;
235 static void Mapper19_StateRestore(int version)
242 static void M19SC(void)
244 if(FSettings.SndRate)
248 void Mapper19_ESI(void)
250 GameExpSound.RChange=M19SC;
251 SetWriteHandler(0xf800,0xffff,Mapper19_write);
252 SetWriteHandler(0x4800,0x4fff,Mapper19_write);
253 SetReadHandler(0x4800,0x4fff,Namco_Read4800);
256 void Mapper19_init(void)
273 SetWriteHandler(0x8000,0xffff,Mapper19_write);
274 SetWriteHandler(0x4020,0x5fff,Mapper19_write);
275 SetReadHandler(0x4800,0x4fff,Namco_Read4800);
276 SetReadHandler(0x5000,0x57ff,Namco_Read5000);
277 SetReadHandler(0x5800,0x5fff,Namco_Read5800);
279 MapIRQHook=NamcoIRQHook;
280 MapStateRestore=Mapper19_StateRestore;
281 GameExpSound.RChange=M19SC;
282 if(FSettings.SndRate)