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
31 #include "filter098.h"
36 static uint32 wlookup1[32];
37 static uint32 wlookup2[203];
40 //int32 WaveFinal[2048+512]; // TODO: use WaveFinalMono
42 static uint8 TriCount=0;
43 static uint8 TriMode=0;
45 static int32 tristep=0;
47 static int32 wlcount[4]={0,0,0,0}; /* Wave length counters. */
49 static uint8 IRQFrameMode=0; /* $4017 / xx000000 */
50 //static uint8 PSG[0x10];
51 static uint8 RawDALatch=0; /* $4011 0xxxxxxx */
53 static uint8 EnabledChannels=0; /* Byte written to $4015 */
57 uint8 Mode; /* Fixed volume(1), and loop(2) */
63 static ENVUNIT EnvUnits[3];
65 static const int RectDuties[4]={1,2,4,6};
67 static int32 RectDutyCount[2];
68 //static uint8 sweepon[2];
69 //static int32 curfreq[2];
70 //static uint8 SweepCount[2];
72 //static uint16 nreg=0;
74 //static uint8 fcnt=0;
75 //static int32 fhcnt=0;
76 //static int32 fhinc=0;
78 /* Variables exclusively for low-quality sound. */
79 static int32 sqacc[2];
80 /* LQ variables segment ends. */
82 static int32 lengthcount[4];
83 static const uint8 lengthtable[0x20]=
85 0x5*2,0x7f*2,0xA*2,0x1*2,0x14*2,0x2*2,0x28*2,0x3*2,0x50*2,0x4*2,0x1E*2,0x5*2,0x7*2,0x6*2,0x0E*2,0x7*2,
86 0x6*2,0x08*2,0xC*2,0x9*2,0x18*2,0xa*2,0x30*2,0xb*2,0x60*2,0xc*2,0x24*2,0xd*2,0x8*2,0xe*2,0x10*2,0xf*2
89 static const uint32 NoiseFreqTable[0x10]=
91 2,4,8,0x10,0x20,0x30,0x40,0x50,0x65,0x7f,0xbe,0xfe,0x17d,0x1fc,0x3f9,0x7f2
94 static const uint32 NTSCDMCTable[0x10]=
96 428,380,340,320,286,254,226,214,
97 190,160,142,128,106, 84 ,72,54
100 static const uint32 PALDMCTable[0x10]=
102 397, 353, 315, 297, 265, 235, 209, 198,
103 176, 148, 131, 118, 98, 78, 66, 50,
107 // $4011 - Actual data outputted
108 // $4012 - Address register: $c000 + V*64
109 // $4013 - Size register: Size in bytes = (V+1)*64
111 static int32 DMCacc=1;
112 static int32 DMCPeriod=0;
113 static uint8 DMCBitCount=0;
115 static uint8 DMCAddressLatch=0,DMCSizeLatch=0; /* writes to 4012 and 4013 */
116 static uint8 DMCFormat=0; /* Write to $4010 */
118 static uint32 DMCAddress=0;
119 static int32 DMCSize=0;
120 static uint8 DMCShift=0;
121 static uint8 SIRQStat=0;
123 static char DMCHaveDMA=0;
124 static uint8 DMCDMABuf=0;
125 static char DMCHaveSample=0;
127 static void Dummyfunc(void) {};
128 static void (*DoNoise)(void)=Dummyfunc;
129 static void (*DoTriangle)(void)=Dummyfunc;
130 static void (*DoPCM)(void)=Dummyfunc;
131 static void (*DoSQ1)(void)=Dummyfunc;
132 static void (*DoSQ2)(void)=Dummyfunc;
134 static uint32 ChannelBC[5];
136 static void LoadDMCPeriod(uint8 V)
139 DMCPeriod=PALDMCTable[V];
141 DMCPeriod=NTSCDMCTable[V];
144 static void PrepDPCM()
146 DMCAddress=0x4000+(DMCAddressLatch<<6);
147 DMCSize=(DMCSizeLatch<<4)+1;
150 /* Instantaneous? Maybe the new freq value is being calculated all of the time... */
152 static int FASTAPASS(2) CheckFreq(uint32 cf, uint8 sr)
164 static void SQReload(int x, uint8 V)
166 if(EnabledChannels&(1<<x))
172 lengthcount[x]=lengthtable[(V>>3)&0x1f];
175 sweepon[x]=PSG[(x<<2)|1]&0x80;
176 curfreq[x]=PSG[(x<<2)|0x2]|((V&7)<<8);
177 SweepCount[x]=((PSG[(x<<2)|0x1]>>4)&7)+1;
180 EnvUnits[x].reloaddec=1;
184 static DECLFW(Write_PSG)
190 EnvUnits[0].Mode=(V&0x30)>>4;
191 EnvUnits[0].Speed=(V&0xF);
206 EnvUnits[1].Mode=(V&0x30)>>4;
207 EnvUnits[1].Speed=(V&0xF);
219 case 0xa:DoTriangle();
223 if(EnabledChannels&0x4)
224 lengthcount[2]=lengthtable[(V>>3)&0x1f];
225 TriMode=1; // Load mode
228 EnvUnits[2].Mode=(V&0x30)>>4;
229 EnvUnits[2].Speed=(V&0xF);
235 if(EnabledChannels&0x8)
236 lengthcount[3]=lengthtable[(V>>3)&0x1f];
237 EnvUnits[2].reloaddec=1;
240 LoadDMCPeriod(V&0xF);
246 X6502_IRQEnd(FCEU_IQDPCM);
249 else X6502_IRQBegin(FCEU_IQDPCM);
256 static DECLFW(Write_DMCRegs)
263 LoadDMCPeriod(V&0xF);
269 X6502_IRQEnd(FCEU_IQDPCM);
272 else X6502_IRQBegin(FCEU_IQDPCM);
279 case 0x02:DMCAddressLatch=V;break;
280 case 0x03:DMCSizeLatch=V;break;
286 static DECLFW(StatusWrite)
296 if(!(V&(1<<x))) lengthcount[x]=0; /* Force length counters to 0. */
308 X6502_IRQEnd(FCEU_IQDPCM);
309 EnabledChannels=V&0x1F;
312 static DECLFR(StatusRead)
319 for(x=0;x<4;x++) ret|=lengthcount[x]?(1<<x):0;
320 if(DMCSize) ret|=0x10;
322 #ifdef FCEUDEF_DEBUGGER
327 X6502_IRQEnd(FCEU_IQFCOUNT);
332 static void FASTAPASS(1) FrameSoundStuff(int V)
341 if(!(V&1)) /* Envelope decay, linear counter, length counter, freq sweep */
347 if(!(PSG[0xC]&0x20)) /* Make sure loop flag is not set. */
353 if(!(PSG[P<<2]&0x20)) /* Make sure loop flag is not set. */
357 /* Frequency Sweep Code Here */
359 /* xxxx = hz. 120/(x+1)*/
364 if(SweepCount[P]>0) SweepCount[P]--;
367 SweepCount[P]=((PSG[(P<<2)+0x1]>>4)&7)+1; //+1;
368 if(PSG[(P<<2)+0x1]&0x8)
370 mod-=(P^1)+((curfreq[P])>>(PSG[(P<<2)+0x1]&7));
371 if(curfreq[P] && (PSG[(P<<2)+0x1]&7)/* && sweepon[P]&0x80*/)
378 mod=curfreq[P]>>(PSG[(P<<2)+0x1]&7);
379 if((mod+curfreq[P])&0x800)
386 if(curfreq[P] && (PSG[(P<<2)+0x1]&7)/* && sweepon[P]&0x80*/)
394 else /* Sweeping is disabled: */
396 //curfreq[P]&=0xFF00;
397 //curfreq[P]|=PSG[(P<<2)|0x2]; //|((PSG[(P<<2)|3]&7)<<8);
402 /* Now do envelope decay + linear counter. */
404 if(TriMode) // In load mode?
405 TriCount=PSG[0x8]&0x7F;
414 if(EnvUnits[P].reloaddec)
416 EnvUnits[P].decvolume=0xF;
417 EnvUnits[P].DecCountTo1=EnvUnits[P].Speed+1;
418 EnvUnits[P].reloaddec=0;
422 if(EnvUnits[P].DecCountTo1>0) EnvUnits[P].DecCountTo1--;
423 if(EnvUnits[P].DecCountTo1==0)
425 EnvUnits[P].DecCountTo1=EnvUnits[P].Speed+1;
426 if(EnvUnits[P].decvolume || (EnvUnits[P].Mode&0x2))
428 EnvUnits[P].decvolume--;
429 EnvUnits[P].decvolume&=0xF;
435 static void FrameSoundUpdate098(void)
437 // Linear counter: Bit 0-6 of $4008
438 // Length counter: Bit 4-7 of $4003, $4007, $400b, $400f
440 if(!fcnt && !(IRQFrameMode&0x3))
443 X6502_IRQBegin(FCEU_IQFCOUNT);
451 FrameSoundStuff(fcnt);
456 static INLINE void tester(void)
471 static INLINE void DMCDMA(void)
473 if(DMCSize && !DMCHaveDMA)
476 X6502_DMR(0x8000+DMCAddress);
477 X6502_DMR(0x8000+DMCAddress);
478 X6502_DMR(0x8000+DMCAddress);
479 DMCDMABuf=X6502_DMR(0x8000+DMCAddress);
481 DMCDMABuf=ARead[0x8000](0x8000);
485 DMCAddress=(DMCAddress+1)&0x7fff;
495 X6502_IRQBegin(FCEU_IQDPCM);
501 void FASTAPASS(1) FCEU_SoundCPUHook098(int cycles)
506 FrameSoundUpdate098();
517 uint8 bah=RawDALatch;
518 int t=((DMCShift&1)<<2)-2;
520 /* Unbelievably ugly hack */
521 if(FSettings.SndRate)
533 DMCBitCount=(DMCBitCount+1)&7;
540 static void RDoPCM(void)
544 for(V=ChannelBC[4];V<SOUNDTS;V++)
545 WaveHi[V]+=RawDALatch<<16;
547 ChannelBC[4]=SOUNDTS;
550 /* This has the correct phase. Don't mess with it. */
551 static INLINE void RDoSQ(int x)
561 if(curfreq[x]<8 || curfreq[x]>0x7ff)
563 if(!CheckFreq(curfreq[x],PSG[(x<<2)|0x1]))
568 if(EnvUnits[x].Mode&0x1)
569 amp=EnvUnits[x].Speed;
571 amp=EnvUnits[x].decvolume;
572 // printf("%d\n",amp);
575 rthresh=RectDuties[(PSG[(x<<2)]&0xC0)>>6];
577 D=&WaveHi[ChannelBC[x]];
578 V=SOUNDTS-ChannelBC[x];
580 currdc=RectDutyCount[x];
598 RectDutyCount[x]=currdc;
602 ChannelBC[x]=SOUNDTS;
605 static void RDoSQ1(void)
610 static void RDoSQ2(void)
616 static void RDoSQLQ(void)
630 end=(SOUNDTS<<16)/soundtsinc;
631 if(end<=start) return;
639 if(curfreq[x]<8 || curfreq[x]>0x7ff)
641 if(!CheckFreq(curfreq[x],PSG[(x<<2)|0x1]))
646 if(EnvUnits[x].Mode&0x1)
647 amp[x]=EnvUnits[x].Speed;
649 amp[x]=EnvUnits[x].decvolume;
651 if(!inie[x]) amp[x]=0; /* Correct? Buzzing in MM2, others otherwise... */
653 rthresh[x]=RectDuties[(PSG[x*4]&0xC0)>>6];
658 ttable[x][y] = amp[x];
662 freq[x]=(curfreq[x]+1)<<1;
666 totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ];
668 if(!inie[0] && !inie[1])
670 for(V=start;V<end;V++)
671 ((int32 *)Wave)[V>>4]+=totalout;
674 for(V=start;V<end;V++)
677 //if(RectDutyCount[0]<rthresh[0])
679 //if(RectDutyCount[1]<rthresh[1])
681 //tmpamp=wlookup1[tmpamp];
682 //tmpamp = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ];
684 ((int32 *)Wave)[V>>4]+=totalout; //tmpamp;
693 RectDutyCount[0]=(RectDutyCount[0]+1)&7;
694 if(sqacc[0]<=0) goto rea;
695 totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ];
702 RectDutyCount[1]=(RectDutyCount[1]+1)&7;
703 if(sqacc[1]<=0) goto rea2;
704 totalout = wlookup1[ ttable[0][RectDutyCount[0]] + ttable[1][RectDutyCount[1]] ];
710 static void RDoTriangle(void)
716 if(!(tristep&0x10)) tcout^=0xF;
717 tcout=(tcout*3) << 16; //(tcout<<1);
719 if(!lengthcount[2] || !TriCount)
720 { /* Counter is halted, but we still need to output. */
721 int32 *start = &WaveHi[ChannelBC[2]];
722 int32 count = SOUNDTS - ChannelBC[2];
728 //for(V=ChannelBC[2];V<SOUNDTS;V++)
732 for(V=ChannelBC[2];V<SOUNDTS;V++)
738 wlcount[2]=(PSG[0xa]|((PSG[0xb]&7)<<8))+1;
741 if(!(tristep&0x10)) tcout^=0xF;
742 tcout=(tcout*3) << 16;
746 ChannelBC[2]=SOUNDTS;
750 static void RDoTriangleNoisePCMLQ(void)
752 static uint32 tcout=0;
753 static int32 triacc=0;
754 static int32 noiseacc=0;
767 end=(SOUNDTS<<16)/soundtsinc;
768 if(end<=start) return;
771 inie[0]=inie[1]=nesincsize;
773 freq[0]=(((PSG[0xa]|((PSG[0xb]&7)<<8))+1));
775 if(!lengthcount[2] || !TriCount || freq[0]<=4)
779 if(EnvUnits[2].Mode&0x1)
780 amptab[0]=EnvUnits[2].Speed;
782 amptab[0]=EnvUnits[2].decvolume;
787 amptab[0]=inie[1]=0; /* Quick hack speedup, set inie[1] to 0 */
789 noiseout=amptab[(nreg>>0xe)&1];
797 totalout = wlookup2[tcout+noiseout+RawDALatch];
799 if(inie[0] && inie[1])
801 for(V=start;V<end;V++)
803 ((int32 *)Wave)[V>>4]+=totalout;
811 triacc+=freq[0]; //t;
812 tristep=(tristep+1)&0x1F;
813 if(triacc<=0) goto rea;
815 if(!(tristep&0x10)) tcout^=0xF;
817 totalout = wlookup2[tcout+noiseout+RawDALatch];
823 noiseacc+=NoiseFreqTable[PSG[0xE]&0xF]<<(16+2);
824 nreg=(nreg<<1)+(((nreg>>nshift)^(nreg>>14))&1);
826 noiseout=amptab[(nreg>>0xe)];
827 if(noiseacc<=0) goto rea2;
828 totalout = wlookup2[tcout+noiseout+RawDALatch];
834 for(V=start;V<end;V++)
836 ((int32 *)Wave)[V>>4]+=totalout;
843 triacc+=freq[0]; //t;
844 tristep=(tristep+1)&0x1F;
845 if(triacc<=0) goto area;
847 if(!(tristep&0x10)) tcout^=0xF;
849 totalout = wlookup2[tcout+noiseout+RawDALatch];
855 for(V=start;V<end;V++)
857 ((int32 *)Wave)[V>>4]+=totalout;
862 noiseacc+=NoiseFreqTable[PSG[0xE]&0xF]<<(16+2);
863 nreg=(nreg<<1)+(((nreg>>nshift)^(nreg>>14))&1);
865 noiseout=amptab[(nreg>>0xe)];
866 if(noiseacc<=0) goto area2;
867 totalout = wlookup2[tcout+noiseout+RawDALatch];
873 for(V=start;V<end;V++)
874 ((int32 *)Wave)[V>>4]+=totalout;
880 static void RDoNoise(void)
886 if(EnvUnits[2].Mode&0x1)
887 amptab[0]=EnvUnits[2].Speed;
889 amptab[0]=EnvUnits[2].decvolume;
896 outo=amptab[nreg&1]; //(nreg>>0xe)&1];
903 if(PSG[0xE]&0x80) // "short" noise
904 for(V=ChannelBC[3];V<SOUNDTS;V++)
911 wlcount[3]=NoiseFreqTable[PSG[0xE]&0xF]<<1;
912 feedback=((nreg>>8)&1)^((nreg>>14)&1);
913 nreg=(nreg<<1)+feedback;
915 outo=amptab[(nreg>>0xe)&1];
919 for(V=ChannelBC[3];V<SOUNDTS;V++)
926 wlcount[3]=NoiseFreqTable[PSG[0xE]&0xF]<<1;
927 feedback=((nreg>>13)&1)^((nreg>>14)&1);
928 nreg=(nreg<<1)+feedback;
930 outo=amptab[(nreg>>0xe)&1];
933 ChannelBC[3]=SOUNDTS;
937 static DECLFW(Write_IRQFM)
942 FrameSoundUpdate098();
945 X6502_IRQEnd(FCEU_IQFCOUNT);
950 void SetNESSoundMap098(void)
952 SetWriteHandler(0x4000,0x400F,Write_PSG);
953 SetWriteHandler(0x4010,0x4013,Write_DMCRegs);
954 SetWriteHandler(0x4017,0x4017,Write_IRQFM);
956 SetWriteHandler(0x4015,0x4015,StatusWrite);
957 SetReadHandler(0x4015,0x4015,StatusRead);
960 static int32 inbuf=0;
961 int FlushEmulateSound098(void)
966 if(!timestamp) return(0);
968 if(!FSettings.SndRate)
982 if(FSettings.soundq>=1)
984 int32 *tmpo=&WaveHi[soundtsoffs];
986 if(GameExpSound.HiFill) GameExpSound.HiFill();
988 for(x=timestamp;x;x--)
991 *tmpo=(b&65535)+wlookup2[(b>>16)&255]+wlookup1[b>>24];
994 end=NeoFilterSound(WaveHi,WaveFinal,SOUNDTS,&left);
996 memmove(WaveHi,WaveHi+SOUNDTS-left,left*sizeof(uint32));
997 memset(WaveHi+left,0,sizeof(WaveHi)-left*sizeof(uint32));
999 if(GameExpSound.HiSync) GameExpSound.HiSync(left);
1006 end=(SOUNDTS<<16)/soundtsinc;
1007 if(GameExpSound.Fill)
1008 GameExpSound.Fill(end&0xF);
1010 SexyFilter((int32 *)Wave,WaveFinalMono,end>>4);
1013 Wave[0]=Wave[(end>>4)];
1019 if(FSettings.soundq>=1)
1027 ChannelBC[x]=end&0xF;
1028 soundtsoffs = (soundtsinc*(end&0xF))>>16;
1036 /* FIXME: Find out what sound registers get reset on reset. I know $4001/$4005 don't,
1037 due to that whole MegaMan 2 Game Genie thing.
1040 void FCEUSND_Reset(void)
1052 if(nesincsize) // lq mode
1053 sqacc[x]=((uint32)2048<<17)/nesincsize;
1059 wlcount[2]=1; //2048;
1061 DMCHaveDMA=DMCHaveSample=0;
1079 // MAJOR BUG WAS HERE: DMCacc and DMCBitCount never got reset...
1080 // so, do some ridiculous hackery if a movie's about to play to keep it in sync...
1083 extern int movieSyncHackOn,resetDMCacc,movieConvertOffset1,movieConvertOffset2;
1088 // no value in movie save state
1090 // use editbox fields
1091 DMCacc=movieConvertOffset1;
1092 DMCBitCount=movieConvertOffset2;
1094 // no editbox fields, so leave the values alone
1095 // and print out a warning that says what they are
1096 FCEU_PrintError("Warning: These variables were not found in the save state and will keep their current value: DMCacc=%d, DMCBitCount=%d\n", DMCacc, DMCBitCount);
1101 // keep values loaded from movie save state or reset earlier
1107 // reset these variables like should have done in the first place
1112 // FCEU_PrintError("DMCacc=%d, DMCBitCount=%d",DMCacc,DMCBitCount);
1115 void FCEUSND_Power(void)
1119 SetNESSoundMap098();
1120 memset(PSG,0x00,sizeof(PSG));
1123 memset(Wave,0,sizeof(Wave));
1124 memset(WaveHi,0,sizeof(WaveHi));
1125 memset(&EnvUnits,0,sizeof(EnvUnits));
1130 LoadDMCPeriod(DMCFormat&0xF);
1134 void SetSoundVariables098(void)
1138 fhinc=PAL?16626:14915; // *2 CPU clock rate
1141 if(FSettings.SndRate)
1146 wlookup1[x]=(double)16*16*16*4*95.52/((double)8128/(double)x+100);
1147 // if(!FSettings.soundq) wlookup1[x]>>=4;
1152 wlookup2[x]=(double)16*16*16*4*163.67/((double)24329/(double)x+100);
1153 // if(!FSettings.soundq) wlookup2[x]>>=4;
1156 if(FSettings.soundq>=1)
1159 DoTriangle=RDoTriangle;
1167 DoNoise=DoTriangle=DoPCM=DoSQ1=DoSQ2=Dummyfunc;
1170 DoTriangle=RDoTriangleNoisePCMLQ;
1171 DoNoise=RDoTriangleNoisePCMLQ;
1172 DoPCM=RDoTriangleNoisePCMLQ;
1177 DoNoise=DoTriangle=DoPCM=DoSQ1=DoSQ2=Dummyfunc;
1181 MakeFilters(FSettings.SndRate);
1183 if(GameExpSound.RChange)
1184 GameExpSound.RChange();
1186 nesincsize=(int32)(((int64)1<<17)*(double)(PAL?PAL_CPU:NTSC_CPU)/(FSettings.SndRate * 16));
1187 memset(sqacc,0,sizeof(sqacc));
1188 memset(ChannelBC,0,sizeof(ChannelBC));
1190 LoadDMCPeriod(DMCFormat&0xF); // For changing from PAL to NTSC
1192 soundtsinc=(uint32)((uint64)(PAL?(long double)PAL_CPU*65536:(long double)NTSC_CPU*65536)/(FSettings.SndRate * 16));
1196 void FCEUI_SetLowPass(int q)
1198 FSettings.lowpass=q;
1201 void FCEUI_SetSoundQuality(int quality)
1203 FSettings.soundq=quality;
1204 SetSoundVariables098();
1209 SFORMAT FCEUSND_STATEINFO[]={
1211 { &fhcnt, 4|FCEUSTATE_RLSB,"FHCN"},
1212 { &fcnt, 1, "FCNT"},
1213 { PSG, 0x10, "PSG"},
1214 { &EnabledChannels, 1, "ENCH"},
1215 { &IRQFrameMode, 1, "IQFM"},
1216 { &nreg, 2|FCEUSTATE_RLSB, "NREG"},
1217 { &TriMode, 1, "TRIM"},
1218 { &TriCount, 1, "TRIC"},
1220 { &EnvUnits[0].Speed, 1, "E0SP"},
1221 { &EnvUnits[1].Speed, 1, "E1SP"},
1222 { &EnvUnits[2].Speed, 1, "E2SP"},
1224 { &EnvUnits[0].Mode, 1, "E0MO"},
1225 { &EnvUnits[1].Mode, 1, "E1MO"},
1226 { &EnvUnits[2].Mode, 1, "E2MO"},
1228 { &EnvUnits[0].DecCountTo1, 1, "E0D1"},
1229 { &EnvUnits[1].DecCountTo1, 1, "E1D1"},
1230 { &EnvUnits[2].DecCountTo1, 1, "E2D1"},
1232 { &EnvUnits[0].decvolume, 1, "E0DV"},
1233 { &EnvUnits[1].decvolume, 1, "E1DV"},
1234 { &EnvUnits[2].decvolume, 1, "E2DV"},
1236 { &lengthcount[0], 4|FCEUSTATE_RLSB, "LEN0"},
1237 { &lengthcount[1], 4|FCEUSTATE_RLSB, "LEN1"},
1238 { &lengthcount[2], 4|FCEUSTATE_RLSB, "LEN2"},
1239 { &lengthcount[3], 4|FCEUSTATE_RLSB, "LEN3"},
1240 { sweepon, 2, "SWEE"},
1241 { &curfreq[0], 4|FCEUSTATE_RLSB,"CRF1"},
1242 { &curfreq[1], 4|FCEUSTATE_RLSB,"CRF2"},
1243 { SweepCount, 2,"SWCT"},
1245 { &SIRQStat, 1, "SIRQ"},
1247 { &DMCacc, 4|FCEUSTATE_RLSB, "5ACC"},
1248 { &DMCBitCount, 1, "5BIT"},
1249 { &DMCAddress, 4|FCEUSTATE_RLSB, "5ADD"},
1250 { &DMCSize, 4|FCEUSTATE_RLSB, "5SIZ"},
1251 { &DMCShift, 1, "5SHF"},
1253 { &DMCHaveDMA, 1, "5HVDM"},
1254 { &DMCHaveSample, 1, "5HVSP"},
1256 { &DMCSizeLatch, 1, "5SZL"},
1257 { &DMCAddressLatch, 1, "5ADL"},
1258 { &DMCFormat, 1, "5FMT"},
1259 { &RawDALatch, 1, "RWDA"},
1263 void FCEUSND_SaveState(void)
1268 void FCEUSND_LoadState(int version)
1270 LoadDMCPeriod(DMCFormat&0xF);