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;
139 case 0xE800:gorfus=V&0xC0;
152 static void DoNamcoSound(uint32 *Wave, int Count);
154 static void NamcoSoundHack(void)
158 z=((SOUNDTS<<16)/soundtsinc)>>4;
161 DoNamcoSound(&Wave[dwave], a);
165 static void NamcoSound(int Count)
169 z=((SOUNDTS<<16)/soundtsinc)>>4;
172 DoNamcoSound(&Wave[dwave], a);
176 static uint8 PlayIndex[8];
177 static int32 vcount[8];
179 static void DoNamcoSound(uint32 *Wave, int Count)
184 //FCEU_DispMessage("%d",MapperExRAM[0x7F]>>4);
185 for(P=7;P>=7-((MapperExRAM[0x7F]>>4)&7);P--)
187 if((MapperExRAM[0x44+(P<<3)]&0xE0) && (MapperExRAM[0x47+(P<<3)]&0xF))
191 uint32 duff,duff2,lengo,envelope;
195 freq=MapperExRAM[0x40+(P<<3)];
196 freq|=MapperExRAM[0x42+(P<<3)]<<8;
197 freq|=(MapperExRAM[0x44+(P<<3)]&3)<<16;
202 int c=((MapperExRAM[0x7F]>>4)&7)+1;
204 inc=(long double)(FSettings.SndRate<<15)/((long double)freq*
205 21477272/((long double)0x400000*c*45));
208 envelope=((MapperExRAM[0x47+(P<<3)]&0xF)<<18)/15;
209 duff=MapperExRAM[(((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])>>1)&0xFF)];
210 if((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&1)
213 duff2=(duff*envelope)>>14;
215 lengo=((8-((MapperExRAM[0x44+(P<<3)]>>2)&7)))<<2;
216 for(V=0;V<Count OVERSAMPLE;V++)
221 if(PlayIndex[P]>=lengo)
224 duff=MapperExRAM[(((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)];
225 if((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&1)
228 duff2=(duff*envelope)>>14;
238 static void Mapper19_StateRestore(int version)
245 static void M19SC(void)
247 if(FSettings.SndRate)
251 void Mapper19_ESI(void)
253 GameExpSound.RChange=M19SC;
254 SetWriteHandler(0xf800,0xffff,Mapper19_write);
255 SetWriteHandler(0x4800,0x4fff,Mapper19_write);
256 SetReadHandler(0x4800,0x4fff,Namco_Read4800);
259 void Mapper19_init(void)
276 SetWriteHandler(0x8000,0xffff,Mapper19_write);
277 SetWriteHandler(0x4020,0x5fff,Mapper19_write);
278 SetReadHandler(0x4800,0x4fff,Namco_Read4800);
279 SetReadHandler(0x5000,0x57ff,Namco_Read5000);
280 SetReadHandler(0x5800,0x5fff,Namco_Read5800);
282 MapIRQHook=NamcoIRQHook;
283 MapStateRestore=Mapper19_StateRestore;
284 GameExpSound.RChange=M19SC;
285 if(FSettings.SndRate)