From feed492569aedeea598f646f7e7e9839957ca814 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Thu, 24 Aug 2017 20:58:04 +0800 Subject: [PATCH] [overclock] allow choosing between postrender and vblank extra scanlines --- src/drivers/libretro/libretro.c | 17 +++++++++++++++-- src/fceu.c | 1 + src/fceu.h | 1 + src/ppu.c | 7 +++++++ src/sound.c | 4 ++-- src/sound.h | 2 +- src/x6502.c | 6 ++++-- src/x6502.h | 1 + 8 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index b0f42d8..663360f 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -56,6 +56,7 @@ unsigned overclocked = 0; unsigned skip_7bit_overclocking = 1; unsigned normal_scanlines = 240; unsigned extrascanlines = 0; +unsigned vblankscanlines = 0; unsigned overclock_state = -1; unsigned dendy = 0; @@ -693,7 +694,7 @@ void retro_set_environment(retro_environment_t cb) static const struct retro_variable vars[] = { { "fceumm_palette", "Color Palette; asqrealc|loopy|quor|chris|matt|pasofami|crashman|mess|zaphod-cv|zaphod-smb|vs-drmar|vs-cv|vs-smb|nintendo-vc|yuv-v3|unsaturated-final|sony-cxa2025as-us|pal|bmf-final2|bmf-final3|composite-direct-fbx|pvm-style-d93-fbx|ntsc-hardware-fbx|nes-classic-fbx-fs|nescap|raw" }, { "fceumm_nospritelimit", "No Sprite Limit; disabled|enabled" }, - { "fceumm_overclocking", "Overclocking; disabled|2x" }, + { "fceumm_overclocking", "Overclocking; disabled|2x-Postrender|2x-VBlank" }, { "fceumm_overscan", "Crop Overscan; enabled|disabled" }, { "fceumm_turbo_enable", "Turbo Enable; None|Player 1|Player 2|Both" }, { "fceumm_turbo_delay", "Turbo Delay (in frames); 3|5|10|15|30|60|1|2" }, @@ -968,15 +969,27 @@ static void check_variables(bool startup) overclocked = 0; skip_7bit_overclocking = 1; extrascanlines = 0; + vblankscanlines = 0; overclock_state = 0; do_reinit = true; } - else if (!strcmp(var.value, "2x") + else if (!strcmp(var.value, "2x-Postrender") && overclock_state != 1) { overclocked = 1; skip_7bit_overclocking = 1; extrascanlines = 266; + vblankscanlines = 0; + overclock_state = 1; + do_reinit = true; + } + else if (!strcmp(var.value, "2x-VBlank") + && overclock_state != 1) + { + overclocked = 1; + skip_7bit_overclocking = 1; + extrascanlines = 0; + vblankscanlines = 266; overclock_state = 1; do_reinit = true; } diff --git a/src/fceu.c b/src/fceu.c index cb3a047..effbeff 100644 --- a/src/fceu.c +++ b/src/fceu.c @@ -365,6 +365,7 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski timestampbase += timestamp; timestamp = 0; + sound_timestamp = 0; *pXBuf = skip ? 0 : XBuf; *SoundBuf = WaveFinal; diff --git a/src/fceu.h b/src/fceu.h index b3d479c..a943591 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -12,6 +12,7 @@ extern unsigned DMC_7bit; extern unsigned normal_scanlines; extern unsigned extrascanlines; +extern unsigned vblankscanlines; extern unsigned dendy; void ResetGameLoaded(void); diff --git a/src/ppu.c b/src/ppu.c index f55952b..6aece6e 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -1153,6 +1153,12 @@ int FCEUPPU_Loop(int skip) { TriggerNMI(); } X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12); + if (vblankscanlines) + { + overclocked = 1; + X6502_Run(vblankscanlines * (256 + 85) - 12); + overclocked = 0; + } PPU_status &= 0x1f; X6502_Run(256); @@ -1237,6 +1243,7 @@ int FCEUPPU_Loop(int skip) { overclock_state,DMC_7bit,skip_7bit_overclocking); FCEU_printf("SL:%d N_SL:%d, T_SL:%d Overclocked(for FCEU_SoundCPUHook):%d\n\n", scanline,normal_scanlines,totalscanlines,overclocked); + FCEU_printf("extrascanlines:%d vblankscanlines:%d\n",extrascanlines,vblankscanlines); */ DMC_7bit = 0; if (MMC5Hack && (ScreenON || SpriteON)) MMC5_hb(scanline); diff --git a/src/sound.c b/src/sound.c index b4c5472..80913ac 100644 --- a/src/sound.c +++ b/src/sound.c @@ -895,7 +895,7 @@ int FlushEmulateSound(void) { int x; int32 end, left; - if (!timestamp) return(0); + if (!sound_timestamp) return(0); if (!FSettings.SndRate) { left = 0; @@ -914,7 +914,7 @@ int FlushEmulateSound(void) { if (GameExpSound.HiFill) GameExpSound.HiFill(); - for (x = timestamp; x; x--) { + for (x = sound_timestamp; x; x--) { uint32 b = *tmpo; *tmpo = (b & 65535) + wlookup2[(b >> 16) & 255] + wlookup1[b >> 24]; tmpo++; diff --git a/src/sound.h b/src/sound.h index 3183540..c4413cc 100644 --- a/src/sound.h +++ b/src/sound.h @@ -52,7 +52,7 @@ extern int32 WaveHi[]; extern uint32 soundtsinc; extern uint32 soundtsoffs; -#define SOUNDTS (timestamp + soundtsoffs) +#define SOUNDTS (sound_timestamp + soundtsoffs) void SetNESSoundMap(void); void FrameSoundUpdate(void); diff --git a/src/x6502.c b/src/x6502.c index 2143181..ff8f16b 100644 --- a/src/x6502.c +++ b/src/x6502.c @@ -33,6 +33,7 @@ void (*X6502_Run)(int32 cycles); #endif uint32 timestamp; +uint32 sound_timestamp; void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define _PC X.PC @@ -52,7 +53,8 @@ void FP_FASTAPASS(1) (*MapIRQHook)(int a); int __x = x; \ _tcount += __x; \ _count -= __x * 48; \ - if (scanline < normal_scanlines || scanline == totalscanlines) timestamp+= __x; \ + timestamp += __x; \ + if (!overclocked) sound_timestamp += __x; \ } static INLINE uint8 RdMemNorm(uint32 A) { @@ -413,7 +415,7 @@ void X6502_Init(void) { void X6502_Power(void) { _count = _tcount = _IRQlow = _PC = _A = _X = _Y = _P = _PI = _DB = _jammed = 0; _S = 0xFD; - timestamp = 0; + timestamp = sound_timestamp = 0; X6502_Reset(); } diff --git a/src/x6502.h b/src/x6502.h index 4af9a40..00dae4b 100644 --- a/src/x6502.h +++ b/src/x6502.h @@ -38,6 +38,7 @@ void X6502_Run(int32 cycles); #endif extern uint32 timestamp; +extern uint32 sound_timestamp; extern X6502 X; #define N_FLAG 0x80