From 4fdfab079f3f006ae215ab453072a25588aa951d Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 29 Apr 2007 17:46:44 +0000 Subject: [PATCH] more 0.98.15-like timing, but sound glitches git-svn-id: file:///home/notaz/opt/svn/fceu@114 be3aeb3a-fb24-0410-a615-afba39da0efa --- dprintf.h | 16 ++++ drivers/common/vidblit.c | 12 +-- fce.c | 182 ++++++++++++++++++++++++++------------- fds.c | 28 +++--- input.c | 3 + mappers/19.c | 4 +- mappers/24and26.c | 6 +- mappers/69.c | 4 +- mappers/vrc7snd.c | 18 ++-- mbshare/mmc5.c | 4 +- movie.c | 2 +- ops.h | 28 +++--- sound.c | 24 +++--- sound.h | 4 + types.h | 25 ++++-- x6502.c | 4 + x6502.h | 3 + 17 files changed, 232 insertions(+), 135 deletions(-) create mode 100644 dprintf.h diff --git a/dprintf.h b/dprintf.h new file mode 100644 index 0000000..01d56d7 --- /dev/null +++ b/dprintf.h @@ -0,0 +1,16 @@ +#if 0 +#include + +extern uint32 timestamp; +extern uint32 framecount; +extern int scanline; + +#undef dprintf +#define dprintf(f,...) printf("%05u:%05u:%03i: " f "\n",timestamp,framecount,scanline,##__VA_ARGS__) + +#else + +#define dprintf(x...) + +#endif + diff --git a/drivers/common/vidblit.c b/drivers/common/vidblit.c index 75802e3..535f1ca 100644 --- a/drivers/common/vidblit.c +++ b/drivers/common/vidblit.c @@ -30,7 +30,7 @@ static int Bpp; // BYTES per pixel int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask) { Bpp=b; - + if(Bpp<=1 || Bpp>4) return(0); @@ -53,7 +53,7 @@ void KillBlitToHigh(void) } void SetPaletteBlitToHigh(uint8 *src) -{ +{ int cshiftr[3]; int cshiftl[3]; int a,x,z,y; @@ -115,7 +115,7 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in { if(efx) { - for(y=yr;y;y--,/*dest+=pinc,*/src+=272-xr) + for(y=yr;y;y--,/*dest+=pinc,*/src+=320-xr) { int doo=yscale-(yscale>>1); do @@ -141,7 +141,7 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in } else { - for(y=yr;y;y--,/*dest+=pinc,*/src+=272-xr) + for(y=yr;y;y--,/*dest+=pinc,*/src+=320-xr) { int doo=yscale; do @@ -161,11 +161,11 @@ void Blit8To8(uint8 *src, uint8 *dest, int xr, int yr, int pitch, int xscale, in src+=xr; } } - + } else { - for(y=yr;y;y--,dest+=pinc,src+=272-xr) + for(y=yr;y;y--,dest+=pinc,src+=320-xr) for(x=xr;x;x-=4,dest+=4,src+=4) *(uint32 *)dest=*(uint32 *)src; } diff --git a/fce.c b/fce.c index 3cb0632..561661a 100644 --- a/fce.c +++ b/fce.c @@ -50,6 +50,8 @@ #include "movie.h" +#include "dprintf.h" + #define Pal (PALRAM) @@ -61,6 +63,9 @@ static void PowerPPU(void); uint64 timestampbase=0; +static int ppudead=1; +static int kook=0; + int MMC5Hack; uint32 MMC5HackVROMMask; uint8 *MMC5HackExNTARAMPtr; @@ -103,9 +108,6 @@ static int RWWrap=0; #ifdef ASM_6502 static void asmcpu_update(int32 cycles) { - // timestamp.. - //timestamp += ((cycles >> 4) * 43) >> 7; // aproximating /= 48 - // some code from x6502.c fhcnt-=cycles; if(fhcnt<=0) @@ -287,6 +289,38 @@ uint8 PAL=0; #define MMC5BGVRAMADR(V) &MMC5BGVPage[(V)>>10][(V)] #define VRAMADR(V) &VPage[(V)>>10][(V)] +static int linestartts; +static int tofix=0; + +static void ResetRL(void) +{ + linestartts=timestamp*48+X6502_GetCycleCount(); + tofix=1; +} + +static INLINE void Fixit1(void); + +static void TryFixit1(void) +{ + #define TOFIXNUM (272-0x4) + int lastpixel; + + if (scanline < 240 && tofix) + { + lastpixel = (timestamp*48-linestartts)>>4; + if (PAL) lastpixel += lastpixel>>4; + + //printf("lastpixel: %i\n", lastpixel); + + if(lastpixel>=TOFIXNUM) + { + Fixit1(); + tofix=0; + } + } +} + + static DECLFW(BRAML) { RAM[A]=V; @@ -310,25 +344,38 @@ static DECLFR(ARAMH) static DECLFR(A2002) { + /* merged */ uint8 ret; + + TryFixit1(); ret = PPU_status; + ret|=PPUGenLatch&0x1F; vtoggle=0; PPU_status&=0x7F; - return ret|(PPUGenLatch&0x1F); + PPUGenLatch=ret; + dprintf("r [2002] %02x",ret); + return ret; } static DECLFR(A200x) { + /* merged */ + TryFixit1(); return PPUGenLatch; } static DECLFR(A2007) { + /* merged */ uint8 ret; uint32 tmp=RefreshAddr&0x3FFF; - PPUGenLatch=ret=VRAMBuffer; + TryFixit1(); + + ret=VRAMBuffer; + if(PPU_hook) PPU_hook(tmp); + PPUGenLatch=VRAMBuffer; if(tmp<0x2000) { VRAMBuffer=VPage[tmp>>10][tmp]; @@ -341,11 +388,14 @@ static DECLFR(A2007) if (INC32) RefreshAddr+=32; else RefreshAddr++; if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + dprintf("r [2007] %02x",ret); return ret; } static DECLFW(B2000) { + /* NMI2? */ + TryFixit1(); PPUGenLatch=V; PPU[0]=V; TempAddr&=0xF3FF; @@ -354,6 +404,8 @@ static DECLFW(B2000) static DECLFW(B2001) { + /* merged */ + TryFixit1(); PPUGenLatch=V; PPU[1]=V; if(V&0xE0) @@ -363,11 +415,13 @@ static DECLFW(B2001) static DECLFW(B2002) { + /* merged */ PPUGenLatch=V; } static DECLFW(B2003) { + /* merged */ PPUGenLatch=V; PPU[3]=V; PPUSPL=V&0x7; @@ -375,9 +429,9 @@ static DECLFW(B2003) static DECLFW(B2004) { + /* merged */ PPUGenLatch=V; - //SPRAM[PPU[3]++]=V; - if(PPUSPL&8) + if(PPUSPL>=8) { if(PPU[3]>=8) SPRAM[PPU[3]]=V; @@ -386,16 +440,17 @@ static DECLFW(B2004) { //printf("$%02x:$%02x\n",PPUSPL,V); SPRAM[PPUSPL]=V; - PPUSPL++; } PPU[3]++; + PPUSPL++; } static DECLFW(B2005) { + /* merged */ uint32 tmp=TempAddr; - + TryFixit1(); PPUGenLatch=V; if (!vtoggle) { @@ -416,6 +471,9 @@ static DECLFW(B2005) static DECLFW(B2006) { + /* merged */ + TryFixit1(); + PPUGenLatch=V; if(!vtoggle) { @@ -426,8 +484,8 @@ static DECLFW(B2006) { TempAddr&=0xFF00; TempAddr|=V; - RefreshAddr=TempAddr; + RefreshAddr=TempAddr; if(PPU_hook) PPU_hook(RefreshAddr); } @@ -436,16 +494,15 @@ static DECLFW(B2006) static DECLFW(B2007) { + /* merged */ uint32 tmp=RefreshAddr&0x3FFF; - PPUGenLatch=V; if(tmp>=0x3F00) { - // hmmm.... - if(!(tmp&0xf)) - PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]= - PALRAM[0x10]=PALRAM[0x14]=PALRAM[0x18]=PALRAM[0x1c]=V&0x3f; - else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f; + // hmmm.... + if(!(tmp&0xf)) + PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3f; + else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f; } else if(tmp<0x2000) { @@ -466,6 +523,7 @@ static DECLFW(B4014) { uint32 t=V<<8; int x; + for(x=0;x<256;x++) B2004(0x2004,X.DB=ARead[t+x](t+x)); X6502_AddCycles(512); @@ -853,7 +911,7 @@ static void SetRefreshLine(void) } } -//static INLINE +static INLINE void Fixit2(void) { if(ScreenON || SpriteON) @@ -866,7 +924,7 @@ void Fixit2(void) } } -//static INLINE +static INLINE void Fixit1(void) { if(ScreenON || SpriteON) @@ -895,32 +953,32 @@ void Fixit1(void) } } -//#define NEW_TRY /* This is called at the beginning of all h-blanks on visible lines. */ -#ifndef NEW_TRY static void DoHBlank(void) { if(ScreenON || SpriteON) FetchSpriteData(); if(GameHBIRQHook && (ScreenON || SpriteON)) { - X6502_Run(12); - GameHBIRQHook(); - X6502_Run(25-12); + X6502_Run(6); Fixit2(); - X6502_Run(85-25); + X6502_Run(4); + GameHBIRQHook(); + X6502_Run(85-16-10); } else { - X6502_Run(25); // Tried 65, caused problems with Slalom(maybe others) + X6502_Run(6); // Tried 65, caused problems with Slalom(maybe others) Fixit2(); - X6502_Run(85-25); + X6502_Run(85-6-16); } //PPU_hook(0,-1); //fprintf(stderr,"%3d: $%04x\n",scanline,RefreshAddr); + scanline++; + ResetRL(); + X6502_Run(16); } -#endif // ============================// @@ -1126,54 +1184,46 @@ int FCEUI_Initialize(void) return 1; } -#define harko 0xe //0x9 static INLINE void Thingo(void) { Loop6502(); -#ifndef NEW_TRY + // check: Battletoads & Double Dragon if(tosprite>=256) { - X6502_Run(256-harko); - Fixit1(); - X6502_Run(harko); + X6502_Run(256); } else { - if(tosprite<=240) - { + // sky glitches in SMB1 if done wrong X6502_Run(tosprite); PPU[2]|=0x40; - X6502_Run(256-tosprite-harko); - Fixit1(); - X6502_Run(harko); - } - else - { - X6502_Run(256-harko); - Fixit1(); - X6502_Run(tosprite-(256-harko)); - PPU[2]|=0x40; X6502_Run(256-tosprite); - } - tosprite=256; + tosprite = 256; } + TryFixit1(); DoHBlank(); -#else - X6502_Run_scanline(); -#endif } -#undef harko void EmLoop(void) { for(;;) { uint32 scanlines_per_frame = PAL ? 312 : 262; + UpdateInput(); + ApplyPeriodicCheats(); + + // FCEUPPU_Loop: + if(ppudead) /* Needed for Knight Rider, possibly others. */ + { + memset(XBuf, 0x80, 256*240); + X6502_Run(scanlines_per_frame*(256+85)); + ppudead--; + goto update; + } //extern int asdc; //printf("asdc: %i\n", asdc); //asdc=0; - ApplyPeriodicCheats(); X6502_Run(256+85); PPU[2]|=0x80; @@ -1204,20 +1254,23 @@ void EmLoop(void) X6502_Run(256); { - static int kook=0; if(ScreenON || SpriteON) if(GameHBIRQHook) GameHBIRQHook(); - X6502_Run(85-kook); - kook=(kook+1)&1; - } + X6502_Run(85-16); - if(ScreenON || SpriteON) - { - RefreshAddr=TempAddr; - if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + if(ScreenON || SpriteON) + { + RefreshAddr=TempAddr; + if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); + } + ResetRL(); + + X6502_Run(16-kook); + kook ^= 1; } + if(FCEUGameInfo.type==GIT_NSF) { X6502_Run((256+85)*240); @@ -1228,7 +1281,7 @@ void EmLoop(void) deemp=PPU[1]>>5; SetRefreshLine(); - for(scanline=0;scanline<240;scanline++) + for(scanline=0;scanline<240;) // scanline is incremented in DoLine. Evil. :/ { deempcnt[deemp]++; Thingo(); @@ -1247,11 +1300,15 @@ void EmLoop(void) SetNESDeemph(maxref,0); } +update: { int ssize; ssize=FlushEmulateSound(); + timestampbase += timestamp; + timestamp = 0; + #ifdef FRAMESKIP if(FSkip) { @@ -1265,7 +1322,6 @@ void EmLoop(void) FCEU_PutImage(); FCEUD_Update(XBuf+8,WaveFinalMono,ssize); } - UpdateInput(); } if(Exit) @@ -1274,7 +1330,7 @@ void EmLoop(void) break; } - } + } // for } #ifdef FPS @@ -1321,6 +1377,8 @@ static void ResetPPU(void) PPUGenLatch=0; RefreshAddr=TempAddr=0; vtoggle = 0; + ppudead = 2; + kook = 0; } static void PowerPPU(void) diff --git a/fds.c b/fds.c index 07445e7..455acc5 100644 --- a/fds.c +++ b/fds.c @@ -112,7 +112,7 @@ void FDSGI(int h) } static void FDSStateRestore(int version) -{ +{ setmirror(((mapbyte1[5]&8)>>3)^1); } @@ -141,7 +141,7 @@ static void FDSInit(void) SetReadHandler(0x4032,0x4032,FDSRead4032); SetReadHandler(0x4033,0x4033,FDSRead4033); - SetWriteHandler(0x4020,0x4020,FDSWrite4020); + SetWriteHandler(0x4020,0x4020,FDSWrite4020); SetWriteHandler(0x4021,0x4021,FDSWrite4021); SetWriteHandler(0x4022,0x4022,FDSWrite4022); SetWriteHandler(0x4023,0x4023,FDSWrite4023); @@ -206,7 +206,7 @@ static void FP_FASTAPASS(1) FDSFix(int a) X6502_IRQBegin(FCEU_IQEXT); } } - if(DiskSeekIRQ>0) + if(DiskSeekIRQ>0) { DiskSeekIRQ-=a; if(DiskSeekIRQ<=0) @@ -344,14 +344,14 @@ static DECLFW(FDSSWrite) A-=0x4080; switch(A) { - case 0x0: + case 0x0: case 0x4: if(!(V&0x80)) { // if(V&0x40) amplitude[(A&0xF)>>2]=0; // else amplitude[(A&0xF)>>2]=0x3F; } - else + else amplitude[(A&0xF)>>2]=V&0x3F; break; case 0x7: b17latch76=0;SPSG[0x5]=0;break; @@ -431,7 +431,7 @@ static INLINE void ClockRise(void) } else { - b19shiftreg60<<=1; + b19shiftreg60<<=1; b8shiftreg88>>=1; } b24adder66=(b24latch68+b19shiftreg60)&0xFFFFFF; @@ -479,7 +479,7 @@ static void RenderSound(void) int32 x; start=FBC; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; FBC=end; @@ -601,11 +601,11 @@ int FDSLoad(char *name, int fp) FCEU_fseek(fp,0,SEEK_SET); FCEU_fread(header,16,1,fp); - if(memcmp(header,"FDS\x1a",4)) + if(memcmp(header,"FDS\x1a",4)) { if(!(memcmp(header+1,"*NINTENDO-HVC*",14))) { - long t; + long t; t=FCEU_fgetsize(fp); if(t<65500) t=65500; @@ -614,15 +614,15 @@ int FDSLoad(char *name, int fp) FCEU_fseek(fp,0,SEEK_SET); } else - return 0; - } + return 0; + } if(header[4]>4) header[4]=4; if(!header[4]) header[4]|=1; for(x=0;xRead(A&1,ret); ret|=X.DB&0xC0; + dprintf("JPRead %02x", ret); return(ret); } diff --git a/mappers/19.c b/mappers/19.c index d928b4e..0258b47 100644 --- a/mappers/19.c +++ b/mappers/19.c @@ -155,7 +155,7 @@ static void NamcoSoundHack(void) { int32 z,a; - z=((timestamp<<16)/soundtsinc)>>4; + z=((SOUNDTS<<16)/soundtsinc)>>4; a=z-dwave; if(a) DoNamcoSound(&Wave[dwave], a); @@ -166,7 +166,7 @@ static void NamcoSound(int Count) { int32 z,a; - z=((timestamp<<16)/soundtsinc)>>4; + z=((SOUNDTS<<16)/soundtsinc)>>4; a=z-dwave; if(a) DoNamcoSound(&Wave[dwave], a); diff --git a/mappers/24and26.c b/mappers/24and26.c index 1981d12..50f732a 100644 --- a/mappers/24and26.c +++ b/mappers/24and26.c @@ -138,7 +138,7 @@ static void DoSQV1(void) int32 start,end; start=CVBC[0]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; CVBC[0]=end; @@ -185,7 +185,7 @@ static void DoSQV2(void) int32 start,end; start=CVBC[1]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; CVBC[1]=end; @@ -231,7 +231,7 @@ static void DoSawV(void) int32 start,end; start=CVBC[2]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; CVBC[2]=end; diff --git a/mappers/69.c b/mappers/69.c index 66e702f..3e427bb 100644 --- a/mappers/69.c +++ b/mappers/69.c @@ -126,7 +126,7 @@ static void DoAYSQ(int x) int32 start,end; start=CAYBC[x]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; CAYBC[x]=end; @@ -158,7 +158,7 @@ static void DoAYNoise(void) int32 start,end; start=CAYBC[3]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; CAYBC[3]=end; diff --git a/mappers/vrc7snd.c b/mappers/vrc7snd.c index 355143f..ea02830 100644 --- a/mappers/vrc7snd.c +++ b/mappers/vrc7snd.c @@ -32,7 +32,7 @@ static void InitOPL(void); void OPL2_setreg(uint8 A, uint8 V) { - if(fmob) + if(fmob) OPLWrite(fmob,A,V); } @@ -45,11 +45,11 @@ void LoadOPL(void) for(x=y=0;x<0x40;x++) y|=MapperExRAM[x]; if(y) - { - InitOPL(); + { + InitOPL(); for(x=0;x<6;x++) { - VRC7_LoadInstrument(x); + VRC7_LoadInstrument(x); vrc7translate(0x10+x,VRC7Chan[0][x]); } } @@ -61,7 +61,7 @@ void VRC7Update(void) { int32 z,a; - z=((timestamp<<16)/soundtsinc)>>4; + z=((SOUNDTS<<16)/soundtsinc)>>4; a=z-dwave; if(a && fmob) @@ -73,7 +73,7 @@ void UpdateOPL(int Count) { int32 z,a; - z=((timestamp<<16)/soundtsinc)>>4; + z=((SOUNDTS<<16)/soundtsinc)>>4; a=z-dwave; if(fmob && a) @@ -93,7 +93,7 @@ static void InitOPL(void) int x; if(!fmob) - { + { if(!( fmob=OPLCreate(OPL_TYPE_WAVESEL,1789772*2,FSettings.SndRate))) return; } @@ -136,13 +136,13 @@ static void VRC7_LoadInstrument(uint8 Chan) uint8 *i; uint8 x = InstTrans[Chan]; uint8 y = (VRC7Chan[2][Chan] >> 4) & 0xF; - + i=VRC7Instrument[y]; OPL2_setreg((0x20+x),i[0]); OPL2_setreg((0x23+x),i[1]); OPL2_setreg((0x40+x),i[2]); - OPL2_setreg((0x43+x),((i[3] & 0xC0) + OPL2_setreg((0x43+x),((i[3] & 0xC0) | ((VRC7Chan[2][Chan] << 2) & 0x3C))); // quiet OPL2_setreg(0xe0+x,(i[3] >> 3) & 0x01); OPL2_setreg(0xe3+x,(i[3] >> 4) & 0x01); diff --git a/mbshare/mmc5.c b/mbshare/mmc5.c index 00cdae7..219ae77 100644 --- a/mbshare/mmc5.c +++ b/mbshare/mmc5.c @@ -525,7 +525,7 @@ static void Do5PCM(void) int32 start,end; start=C5BC[2]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; C5BC[2]=end; @@ -571,7 +571,7 @@ void Do5SQ(int P) int32 freq; start=C5BC[P]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; C5BC[P]=end; diff --git a/movie.c b/movie.c index d3fc1ef..d4a6505 100644 --- a/movie.c +++ b/movie.c @@ -83,7 +83,7 @@ static uint8* moviedata = NULL; static uint32 moviedatasize = 0; static uint32 firstframeoffset = 0; static uint32 savestate_offset = 0; -static uint32 framecount = 0; +/*static*/ uint32 framecount = 0; static uint32 rerecord_count = 0; /*static*/ int movie_readonly = 1; int frame_display = 0; diff --git a/ops.h b/ops.h index cd595cd..a652a88 100644 --- a/ops.h +++ b/ops.h @@ -346,22 +346,22 @@ case 0xAB: LD_IM(_A|=0xEE;AND;_X=_A); case 0xCB: LD_IM(AXS); /* DCP */ -case 0xC7: LD_ZP(DEC;CMP); -case 0xD7: LD_ZPX(DEC;CMP); -case 0xCF: LD_AB(DEC;CMP); -case 0xDF: LD_ABX(DEC;CMP); -case 0xDB: LD_ABY(DEC;CMP); -case 0xC3: LD_IX(DEC;CMP); -case 0xD3: LD_IY(DEC;CMP); +case 0xC7: RMW_ZP(DEC;CMP); +case 0xD7: RMW_ZPX(DEC;CMP); +case 0xCF: RMW_AB(DEC;CMP); +case 0xDF: RMW_ABX(DEC;CMP); +case 0xDB: RMW_ABY(DEC;CMP); +case 0xC3: RMW_IX(DEC;CMP); +case 0xD3: RMW_IY(DEC;CMP); /* ISC */ -case 0xE7: LD_ZP(INC;SBC); -case 0xF7: LD_ZPX(INC;SBC); -case 0xEF: LD_AB(INC;SBC); -case 0xFF: LD_ABX(INC;SBC); -case 0xFB: LD_ABY(INC;SBC); -case 0xE3: LD_IX(INC;SBC); -case 0xF3: LD_IY(INC;SBC); +case 0xE7: RMW_ZP(INC;SBC); +case 0xF7: RMW_ZPX(INC;SBC); +case 0xEF: RMW_AB(INC;SBC); +case 0xFF: RMW_ABX(INC;SBC); +case 0xFB: RMW_ABY(INC;SBC); +case 0xE3: RMW_IX(INC;SBC); +case 0xF3: RMW_IY(INC;SBC); /* DOP */ diff --git a/sound.c b/sound.c index 8cdde0e..0951e6f 100644 --- a/sound.c +++ b/sound.c @@ -59,6 +59,8 @@ static int32 count[5]; static int64 sqacc[2]={0,0}; uint8 sqnon=0; +uint32 soundtsoffs=0; + #undef printf uint16 nreg; @@ -194,7 +196,7 @@ static uint8 DutyCount[2]={0,0}; static DECLFW(Write_PSG) { //if((A>=0x4004 && A<=0x4007) || A==0x4015) - //printf("$%04x:$%02x, %d\n",A,V,timestamp); + //printf("$%04x:$%02x, %d\n",A,V,SOUNDTS); A&=0x1f; switch(A) { @@ -569,7 +571,7 @@ static void RDoPCM(void) uint32 out=PSG[0x11]<<3; start=ChannelBC[4]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; ChannelBC[4]=end; @@ -649,7 +651,7 @@ static void RDoSQ1(void) CalcRectAmp(0); start=ChannelBC[0]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; ChannelBC[0]=end; @@ -692,7 +694,7 @@ static void RDoSQ2(void) CalcRectAmp(1); start=ChannelBC[1]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; ChannelBC[1]=end; @@ -737,7 +739,7 @@ static void RDoTriangle(void) int64 freq=(((PSG[0xa]|((PSG[0xb]&7)<<8))+1)); start=ChannelBC[2]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; ChannelBC[2]=end; @@ -789,7 +791,7 @@ static void RDoNoise(void) int32 start,end; start=ChannelBC[3]; - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; if(end<=start) return; ChannelBC[3]=end; @@ -917,9 +919,8 @@ static void FilterSound(uint32 *in, int32 *out, int16 *outMono, int count) int FlushEmulateSound(void) { - uint32 end; int x; - + uint32 end; if(!timestamp) return(0); @@ -929,7 +930,7 @@ int FlushEmulateSound(void) goto nosoundo; } - end=(timestamp<<16)/soundtsinc; + end=(SOUNDTS<<16)/soundtsinc; DoSQ1(); DoSQ2(); DoTriangle(); @@ -960,9 +961,7 @@ int FlushEmulateSound(void) nosoundo: for(x=0;x<5;x++) ChannelBC[x]=end&0xF; - timestampbase+=timestamp; - timestamp=(soundtsinc*(end&0xF))>>16; - timestampbase-=timestamp; + soundtsoffs=(soundtsinc*(end&0xF))>>16; return(end>>4); } @@ -984,6 +983,7 @@ void PowerSound(void) fhcnt=fhinc; fcnt=0; nreg=1; + soundtsoffs=0; } void ResetSound(void) diff --git a/sound.h b/sound.h index c5adc3e..02c6a68 100644 --- a/sound.h +++ b/sound.h @@ -69,6 +69,10 @@ extern int32 WaveFinal[2048]; extern int16 WaveFinalMono[2048]; extern uint32 soundtsinc; +extern uint32 soundtsoffs; +#define SOUNDTS (timestamp + soundtsoffs) + void SetNESSoundMap(void); void FrameSoundUpdate(void); void FixOldSaveStateSFreq(void); + diff --git a/types.h b/types.h index 05512f8..485b019 100644 --- a/types.h +++ b/types.h @@ -22,9 +22,18 @@ #ifndef __FCEU_TYPES #define __FCEU_TYPES -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned long uint32; +#include +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; + +//typedef unsigned char uint8; +//typedef unsigned short uint16; +//typedef unsigned long uint32; #ifdef __GNUC__ typedef unsigned long long uint64; @@ -42,9 +51,9 @@ typedef unsigned long uint32; other than Windows/DOS targets? */ #endif -typedef signed char int8; -typedef signed short int16; -typedef signed long int32; +//typedef signed char int8; +//typedef signed short int16; +//typedef signed long int32; #define byte uint8 #define word uint16 @@ -53,8 +62,8 @@ typedef signed long int32; #define FASTAPASS(x) __attribute__((regparm(x))) #define FP_FASTAPASS FASTAPASS #else - #define FASTAPASS(x) - #define FP_FASTAPASS(x) + #define FASTAPASS(x) + #define FP_FASTAPASS(x) #endif #else #define FP_FASTAPASS(x) diff --git a/x6502.c b/x6502.c index dc6aab0..7ec04ef 100644 --- a/x6502.c +++ b/x6502.c @@ -26,6 +26,8 @@ #include "sound.h" #include "cart.h" +#include "dprintf.h" + #ifdef DEBUG_ASM_6502 #include #include @@ -426,6 +428,7 @@ static void TriggerNMIReal(void) { if(!_jammed) { + dprintf("NMI"); ADDCYC(7); PUSH(_PC>>8); PUSH(_PC); @@ -444,6 +447,7 @@ void TriggerIRQReal(void) { if(!(_PI&I_FLAG) && !_jammed) { + dprintf("IRQ"); ADDCYC(7); PUSH(_PC>>8); PUSH(_PC); diff --git a/x6502.h b/x6502.h index 3216d50..1a44b30 100644 --- a/x6502.h +++ b/x6502.h @@ -64,6 +64,7 @@ extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define X6502_IRQBegin X6502_IRQBegin_d #define X6502_IRQEnd X6502_IRQEnd_d #define X6502_Rebase X6502_Rebase_d +#define X6502_GetCycleCount() 0 #define X6502_C #define X6502_A #define X6502_D @@ -78,6 +79,7 @@ extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define X6502_IRQBegin X6502_IRQBegin_a #define X6502_IRQEnd X6502_IRQEnd_a #define X6502_Rebase X6502_Rebase_a +#define X6502_GetCycleCount() ((int32)nes_registers[7]>>16) #define X6502_A #define X6502_Run(c) \ @@ -103,6 +105,7 @@ extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define X6502_IRQBegin X6502_IRQBegin_c #define X6502_IRQEnd X6502_IRQEnd_c #define X6502_Rebase(...) +#define X6502_GetCycleCount() X.count #define X6502_C #define X6502_Run(c) \ -- 2.39.2