diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index b191dcd..43a4d33 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -143,19 +143,6 @@ static bool libretro_supports_bitmasks = false; const size_t PPU_BIT = 1ULL << 31ULL; -/* overclock the console by adding dummy scanlines to PPU loop - * disables DMC DMA and WaveHi filling for these dummies - * doesn't work with new PPU */ -unsigned overclock_enabled = -1; -unsigned overclocked = 0; -unsigned skip_7bit_overclocking = 1; /* 7-bit samples have priority over overclocking */ -unsigned totalscanlines = 0; -unsigned normal_scanlines = 240; -unsigned extrascanlines = 0; -unsigned vblankscanlines = 0; -unsigned dendy = 0; -unsigned swapDuty; - static unsigned systemRegion = 0; static unsigned opt_region = 0; static unsigned opt_showAdvSoundOptions = 0; @@ -970,7 +957,7 @@ void retro_get_system_av_info(struct retro_system_av_info *info) info->geometry.max_height = NES_HEIGHT; info->geometry.aspect_ratio = get_aspect_ratio(width, height); info->timing.sample_rate = (float)sndsamplerate; - if (FSettings.PAL || dendy) + if (FSettings.PAL || FSettings.dendy) info->timing.fps = 838977920.0/16777215.0; else info->timing.fps = 1008307711.0/16777215.0; @@ -1075,7 +1062,7 @@ static void FCEUD_RegionOverride(unsigned region) break; } - dendy = d; + FSettings.dendy = d; FCEUI_SetVidSystem(pal); ResetPalette(); } @@ -1131,11 +1118,11 @@ static void check_variables(bool startup) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { if (!strcmp(var.value, "random")) - option_ramstate = 2; + FSettings.ramstate = 2; else if (!strcmp(var.value, "fill $00")) - option_ramstate = 1; + FSettings.ramstate = 1; else - option_ramstate = 0; + FSettings.ramstate = 0; } #ifdef HAVE_NTSC_FILTER @@ -1236,33 +1223,33 @@ static void check_variables(bool startup) bool do_reinit = false; if (!strcmp(var.value, "disabled") - && overclock_enabled != 0) + && FSettings.overclock_enabled != 0) { - skip_7bit_overclocking = 1; - extrascanlines = 0; - vblankscanlines = 0; - overclock_enabled = 0; + FSettings.skip_7bit_overclocking = 1; + FSettings.extrascanlines = 0; + FSettings.vblankscanlines = 0; + FSettings.overclock_enabled = 0; do_reinit = true; } else if (!strcmp(var.value, "2x-Postrender")) { - skip_7bit_overclocking = 1; - extrascanlines = 266; - vblankscanlines = 0; - overclock_enabled = 1; + FSettings.skip_7bit_overclocking = 1; + FSettings.extrascanlines = 266; + FSettings.vblankscanlines = 0; + FSettings.overclock_enabled = 1; do_reinit = true; } else if (!strcmp(var.value, "2x-VBlank")) { - skip_7bit_overclocking = 1; - extrascanlines = 0; - vblankscanlines = 266; - overclock_enabled = 1; + FSettings.skip_7bit_overclocking = 1; + FSettings.extrascanlines = 0; + FSettings.vblankscanlines = 266; + FSettings.overclock_enabled = 1; do_reinit = true; } - normal_scanlines = dendy ? 290 : 240; - totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0); + FSettings.normal_scanlines = FSettings.dendy ? SCANLINES_DENDY : SCANLINES_NORMAL; + FSettings.totalscanlines = FSettings.normal_scanlines + (FSettings.overclock_enabled ? FSettings.extrascanlines : 0); if (do_reinit && startup) { @@ -1294,8 +1281,10 @@ static void check_variables(bool startup) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (!strcmp(var.value, "enabled")) show_crosshair = 1; - else if (!strcmp(var.value, "disabled")) show_crosshair = 0; + if (!strcmp(var.value, "enabled")) + FSettings.show_crosshair = 1; + else if (!strcmp(var.value, "disabled")) + FSettings.show_crosshair = 0; } #ifdef PSP @@ -1433,8 +1422,8 @@ static void check_variables(bool startup) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { bool newval = (!strcmp(var.value, "enabled")); - if (newval != swapDuty) - swapDuty = newval; + if (newval != FSettings.swapDuty) + FSettings.swapDuty = newval; } var.key = key; @@ -2410,8 +2399,6 @@ bool retro_load_game(const struct retro_game_info *game) #endif sndquality = 0; sndvolume = 150; - swapDuty = 0; - dendy = 0; opt_region = 0; /* Wii: initialize this or else last variable is passed through @@ -2471,7 +2458,7 @@ bool retro_load_game(const struct retro_game_info *game) FCEU_printf(" Loading custom palette: %s%cnes.pal\n", dir, slash); /* Save region and dendy mode for region-auto detect */ - systemRegion = (dendy << 1) | (retro_get_region() & 1); + systemRegion = (FSettings.dendy << 1) | (retro_get_region() & 1); current_palette = 0; diff --git a/src/fceu.c b/src/fceu.c index de3f21b..748e7f7 100644 --- a/src/fceu.c +++ b/src/fceu.c @@ -341,6 +341,14 @@ int FCEUI_Initialize(void) { FSettings.UsrLastSLine[0] = 231; FSettings.UsrLastSLine[1] = 239; FSettings.SoundVolume = 100; + FSettings.overclock_enabled = 0; + FSettings.skip_7bit_overclocking = 1; + FSettings.totalscanlines = 0; + FSettings.normal_scanlines = SCANLINES_NORMAL; + FSettings.extrascanlines = 0; + FSettings.vblankscanlines = 0; + FSettings.dendy = 0; + FSettings.swapDuty = 0; FCEUPPU_Init(); X6502_Init(); return 1; @@ -381,8 +389,6 @@ void ResetNES(void) X6502_Reset(); } -int option_ramstate = 0; - void FCEU_MemoryRand(uint8 *ptr, uint32 size) { int x = 0; @@ -397,7 +403,7 @@ void FCEU_MemoryRand(uint8 *ptr, uint32 size) /* 1942 SCORE/HISCORE is screwed... */ #endif uint8_t v = 0; - switch (option_ramstate) + switch (FSettings.ramstate) { case 0: v = 0xff; break; case 1: v = 0x00; break; @@ -466,7 +472,7 @@ void FCEU_ResetVidSys(void) else if (GameInfo->vidsys == GIV_PAL) { w = 1; - dendy = 0; + FSettings.dendy = 0; } else w = FSettings.PAL; @@ -474,12 +480,12 @@ void FCEU_ResetVidSys(void) PAL = w ? 1 : 0; if (PAL) - dendy = 0; + FSettings.dendy = 0; - normal_scanlines = dendy ? 290 : 240; - totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0); + FSettings.normal_scanlines = FSettings.dendy ? SCANLINES_DENDY : SCANLINES_NORMAL; + FSettings.totalscanlines = FSettings.normal_scanlines + (FSettings.overclock_enabled ? FSettings.extrascanlines : 0); - FCEUPPU_SetVideoSystem(w || dendy); + FCEUPPU_SetVideoSystem(w || FSettings.dendy); SetSoundVariables(); } @@ -517,7 +523,7 @@ void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) FSettings.UsrLastSLine[0] = ntscl; FSettings.UsrFirstSLine[1] = palf; FSettings.UsrLastSLine[1] = pall; - if (PAL || dendy) + if (PAL || FSettings.dendy) { FSettings.FirstSLine = FSettings.UsrFirstSLine[1]; FSettings.LastSLine = FSettings.UsrLastSLine[1]; @@ -561,7 +567,7 @@ void FCEUI_SetSnapName(int a) int32 FCEUI_GetDesiredFPS(void) { - if (PAL || dendy) + if (PAL || FSettings.dendy) return(838977920); /* ~50.007 */ else return(1008307711); /* ~60.1 */ diff --git a/src/fceu.h b/src/fceu.h index d3ec9a6..27be7a2 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -5,27 +5,6 @@ extern int fceuindbg; -/* Overclocking-related */ -extern unsigned overclock_enabled; -extern unsigned overclocked; -extern unsigned skip_7bit_overclocking; -extern unsigned DMC_7bit; -extern unsigned totalscanlines; -extern unsigned normal_scanlines; -extern unsigned extrascanlines; -extern unsigned vblankscanlines; - -/* Region selection */ -extern unsigned dendy; - -/* Audio mods*/ -extern unsigned swapDuty; /* Swap bits 6 & 7 of $4000/$4004 to mimic bug - * found on some famiclones/Dendy models. - */ - -extern int show_crosshair; -extern int option_ramstate; - void ResetGameLoaded(void); #define DECLFR(x) uint8 FP_FASTAPASS(1) x(uint32 A) @@ -82,6 +61,9 @@ extern uint8 PAL; #include "driver.h" +#define SCANLINES_NORMAL 240 +#define SCANLINES_DENDY 290 + typedef struct { int PAL; int NetworkPlay; @@ -105,6 +87,21 @@ typedef struct { uint32 SndRate; int soundq; int lowpass; + + /* PPU Overclocking */ + int overclock_enabled; /* 1 : enable, 0 : disable duh! */ + int skip_7bit_overclocking; /* 7-bit samples have priority over overclocking */ + int extrascanlines; + int vblankscanlines; + int normal_scanlines; /* 240 : normal, 290 : dendy */ + int totalscanlines; + + int show_crosshair; + int ramstate; + int dendy; + int swapDuty; /* Swap bits 6 & 7 of $4000/$4004 to mimic bug + * found on some famiclones/Dendy models. + */ } FCEUS; extern FCEUS FSettings; diff --git a/src/ines.c b/src/ines.c index 7f807d3..ba524f3 100644 --- a/src/ines.c +++ b/src/ines.c @@ -1062,7 +1062,8 @@ int iNESLoad(const char *name, FCEUFILE *fp) { * 1: RP2C07 ("Licensed PAL NES") * 2: Multiple-region * 3: UMC 6527P ("Dendy") */ - if (iNESCart.region == 3) dendy = 1; + if (iNESCart.region == 3) + FSettings.dendy = 1; FCEUI_SetVidSystem((iNESCart.region == 1) ? 1 : 0); return 1; diff --git a/src/ppu.c b/src/ppu.c index 45ccc7f..fdf7675 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -660,7 +660,7 @@ static void DoLine(void) uint8 *target = NULL; uint8 *dtarget = NULL; - if (scanline >= 240 && scanline != totalscanlines) + if (scanline >= 240 && scanline != FSettings.totalscanlines) { X6502_Run(256 + 69); scanline++; @@ -1066,7 +1066,7 @@ static void CopySprites(uint8 *target) { void FCEUPPU_SetVideoSystem(int w) { if (w) { - scanlines_per_frame = dendy ? 262 : 312; + scanlines_per_frame = FSettings.dendy ? 262 : 312; FSettings.FirstSLine = FSettings.UsrFirstSLine[1]; FSettings.LastSLine = FSettings.UsrLastSLine[1]; } else { @@ -1166,11 +1166,11 @@ int FCEUPPU_Loop(int skip) { TriggerNMI(); } X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12); - if (overclock_enabled && vblankscanlines) { - if (!DMC_7bit || !skip_7bit_overclocking) { - overclocked = 1; - X6502_Run(vblankscanlines * (256 + 85) - 12); - overclocked = 0; + if (FSettings.overclock_enabled && FSettings.vblankscanlines) { + if (!DMC_7bit || !FSettings.skip_7bit_overclocking) { + overclocking = 1; + X6502_Run(FSettings.vblankscanlines * (256 + 85) - 12); + overclocking = 0; } } PPU_status &= 0x1f; @@ -1203,7 +1203,7 @@ int FCEUPPU_Loop(int skip) { kook ^= 1; } if (GameInfo->type == GIT_NSF) - X6502_Run((256 + 85) * normal_scanlines); + X6502_Run((256 + 85) * FSettings.normal_scanlines); #ifdef FRAMESKIP else if (skip) { int y; @@ -1234,21 +1234,21 @@ int FCEUPPU_Loop(int skip) { deemp = PPU[1] >> 5; /* manual samples can't play correctly with overclocking */ - if (DMC_7bit && skip_7bit_overclocking) - totalscanlines = normal_scanlines; + if (DMC_7bit && FSettings.skip_7bit_overclocking) + FSettings.totalscanlines = FSettings.normal_scanlines; else - totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0); + FSettings.totalscanlines = FSettings.normal_scanlines + (FSettings.overclock_enabled ? FSettings.extrascanlines : 0); - for (scanline = 0; scanline < totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ + for (scanline = 0; scanline < FSettings.totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ deempcnt[deemp]++; /* if ((PPUViewer) && (scanline == PPUViewScanline)) UpdatePPUView(1); */ DoLine(); - if (scanline < normal_scanlines || scanline == totalscanlines) - overclocked = 0; + if (scanline < FSettings.normal_scanlines || scanline == FSettings.totalscanlines) + overclocking = 0; else { - if (DMC_7bit && skip_7bit_overclocking) /* 7bit sample started after 240th line */ + if (DMC_7bit && FSettings.skip_7bit_overclocking) /* 7bit sample started after 240th line */ break; - overclocked = 1; + overclocking = 1; } } diff --git a/src/sound.c b/src/sound.c index a483d16..a72f93a 100644 --- a/src/sound.c +++ b/src/sound.c @@ -61,7 +61,7 @@ typedef struct { int reloaddec; } ENVUNIT; -unsigned DMC_7bit = 0; /* used to skip overclocking */ +uint32 DMC_7bit = 0; /* used to skip overclocking */ static ENVUNIT EnvUnits[3]; static const int RectDuties[4] = { 1, 2, 4, 6 }; @@ -195,7 +195,7 @@ static DECLFW(Write_PSG) { DoSQ1(); EnvUnits[0].Mode = (V & 0x30) >> 4; EnvUnits[0].Speed = (V & 0xF); - if (swapDuty) + if (FSettings.swapDuty) V = (V & 0x3F) | ((V & 0x80) >> 1) | ((V & 0x40) << 1); break; case 0x1: @@ -216,7 +216,7 @@ static DECLFW(Write_PSG) { DoSQ2(); EnvUnits[1].Mode = (V & 0x30) >> 4; EnvUnits[1].Speed = (V & 0xF); - if (swapDuty) + if (FSettings.swapDuty) V = (V & 0x3F) | ((V & 0x80) >> 1) | ((V & 0x40) << 1); break; case 0x5: diff --git a/src/sound.h b/src/sound.h index c4413cc..d10a56a 100644 --- a/src/sound.h +++ b/src/sound.h @@ -50,6 +50,7 @@ extern int32 Wave[2048 + 512]; extern int32 WaveFinal[2048 + 512]; extern int32 WaveHi[]; extern uint32 soundtsinc; +extern uint32 DMC_7bit; extern uint32 soundtsoffs; #define SOUNDTS (sound_timestamp + soundtsoffs) diff --git a/src/video.c b/src/video.c index 0017fc1..d54be19 100644 --- a/src/video.c +++ b/src/video.c @@ -37,7 +37,6 @@ uint8 *XBuf = NULL; uint8 *XDBuf = NULL; -int show_crosshair = 0; void FCEU_KillVirtualVideo(void) { @@ -53,15 +52,15 @@ int FCEU_InitVirtualVideo(void) { /* 256 bytes per scanline, * 240 scanline maximum, +8 for alignment, */ if (!XBuf) - XBuf = (uint8*)(FCEU_malloc(256 * (256 + extrascanlines + 8))); + XBuf = (uint8*)(FCEU_malloc(256 * (256 + FSettings.extrascanlines + 8))); if (!XDBuf) - XDBuf = (uint8*)(FCEU_malloc(256 * (256 + extrascanlines + 8))); + XDBuf = (uint8*)(FCEU_malloc(256 * (256 + FSettings.extrascanlines + 8))); if (!XBuf || !XDBuf) return 0; - memset(XBuf, 128, 256 * (256 + extrascanlines + 8)); - memset(XDBuf, 128, 256 * (256 + extrascanlines + 8)); + memset(XBuf, 128, 256 * (256 + FSettings.extrascanlines + 8)); + memset(XDBuf, 128, 256 * (256 + FSettings.extrascanlines + 8)); return 1; } @@ -82,7 +81,7 @@ void FCEU_PutImage(void) FCEU_VSUniDraw(XBuf); } if (howlong) howlong--; - if (show_crosshair) + if (FSettings.show_crosshair) FCEU_DrawInput(XBuf); } diff --git a/src/video.h b/src/video.h index 9eef95b..b98a419 100644 --- a/src/video.h +++ b/src/video.h @@ -6,7 +6,6 @@ void FCEU_KillVirtualVideo(void); int SaveSnapshot(void); extern uint8 *XBuf; extern uint8 *XDBuf; -extern int show_crosshair; void FCEU_DrawNumberRow(uint8 *XBuf, int *nstatus, int cur); #endif diff --git a/src/x6502.c b/src/x6502.c index b8bf2d9..0d00377 100644 --- a/src/x6502.c +++ b/src/x6502.c @@ -34,6 +34,7 @@ void (*X6502_Run)(int32 cycles); uint32 timestamp; uint32 sound_timestamp; +uint32 overclocking = 0; void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define _PC X.PC @@ -54,7 +55,7 @@ void FP_FASTAPASS(1) (*MapIRQHook)(int a); _tcount += __x; \ _count -= __x * 48; \ timestamp += __x; \ - if (!overclocked) sound_timestamp += __x; \ + if (!overclocking) sound_timestamp += __x; \ } static INLINE uint8 RdMemNorm(uint32 A) { @@ -516,7 +517,7 @@ static void X6502_RunDebug(int32 cycles) { _tcount = 0; if (MapIRQHook) MapIRQHook(temp); - if (!overclocked) + if (!overclocking) FCEU_SoundCPUHook(temp); _PC++; @@ -613,7 +614,7 @@ void X6502_Run(int32 cycles) temp = _tcount; _tcount = 0; if (MapIRQHook) MapIRQHook(temp); - if (!overclocked) + if (!overclocking) FCEU_SoundCPUHook(temp); X.PC = pbackus; _PC++; diff --git a/src/x6502.h b/src/x6502.h index f480544..d9d8b65 100644 --- a/src/x6502.h +++ b/src/x6502.h @@ -35,6 +35,7 @@ void X6502_Run(int32 cycles); extern uint32 timestamp; extern uint32 sound_timestamp; +extern uint32 overclocking; extern X6502 X; #define N_FLAG 0x80 @@ -48,7 +49,7 @@ extern X6502 X; extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); -#define NTSC_CPU (dendy ? 1773447.467 : 1789772.7272727272727272) +#define NTSC_CPU (FSettings.dendy ? 1773447.467 : 1789772.7272727272727272) #define PAL_CPU 1662607.125 #define FCEU_IQEXT 0x001