From 403f682eb7951cba41a45c4dc618819665bfdca0 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Mon, 31 May 2021 16:55:09 +0800 Subject: [PATCH 1/6] Cleanup: Remove a few extern --- Makefile.libretro | 4 ++-- src/cart.h | 3 +++ src/drivers/libretro/libretro.c | 22 ++-------------------- src/fceu.h | 3 +++ src/input.h | 2 ++ src/ppu.h | 2 ++ 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Makefile.libretro b/Makefile.libretro index 86563b0..2387bed 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -752,8 +752,8 @@ else WARNING_DEFINES = -Wno-write-strings endif -CFLAGS += $(fpic) $(WARNING_DEFINES) $(DEFINES) $(ENDIANNESS_DEFINES) -LDFLAGS += $(LIBM) +CFLAGS += $(fpic) $(WARNING_DEFINES) $(DEFINES) $(ENDIANNESS_DEFINES) -Werror=implicit-function-declaration +LDFLAGS += $(LIBM) -Werror=implicit-function-declaration ifeq ($(platform), psp1) INCFLAGS += -I$(shell psp-config --pspsdk-path)/include diff --git a/src/cart.h b/src/cart.h index 4573403..cd05d4b 100644 --- a/src/cart.h +++ b/src/cart.h @@ -104,4 +104,7 @@ void FCEU_OpenGenie(void); void FCEU_CloseGenie(void); void FCEU_KillGenie(void); +extern CartInfo iNESCart; +extern CartInfo UNIFCart; + #endif diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 39263fc..b191dcd 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -67,8 +67,6 @@ void linearFree(void* mem); RETRO_HW_RENDER_INTEFACE_GSKIT_PS2 *ps2 = NULL; #endif -extern void FCEU_ZapperSetTolerance(int t); - static retro_video_refresh_t video_cb = NULL; static retro_input_poll_t poll_cb = NULL; static retro_input_state_t input_cb = NULL; @@ -95,7 +93,7 @@ static int aspect_ratio_par; #define MAX_BUTTONS 8 #define TURBO_BUTTONS 2 -unsigned char turbo_button_toggle[MAX_PLAYERS][TURBO_BUTTONS] = { {0} }; +unsigned turbo_button_toggle[MAX_PLAYERS][TURBO_BUTTONS] = { {0} }; typedef struct { @@ -145,8 +143,6 @@ static bool libretro_supports_bitmasks = false; const size_t PPU_BIT = 1ULL << 31ULL; -extern uint8 NTARAM[0x800], PALRAM[0x20], SPRAM[0x100], PPU[4]; - /* 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 */ @@ -158,14 +154,13 @@ 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; static unsigned opt_showAdvSystemOptions = 0; -int FCEUnetplay; - #if defined(PSP) || defined(PS2) static __attribute__((aligned(16))) uint16_t retro_palette[256]; #else @@ -181,24 +176,12 @@ static uint16_t* fceu_video_out; static unsigned sndsamplerate; static unsigned sndquality; static unsigned sndvolume; -unsigned swapDuty; static int32_t *sound = 0; static uint32_t Dummy = 0; static uint32_t current_palette = 0; static unsigned serialize_size; -int PPUViewScanline=0; -int PPUViewer=0; - -/* extern forward decls.*/ -extern FCEUGI *GameInfo; -extern uint8 *XBuf; -extern CartInfo iNESCart; -extern CartInfo UNIFCart; -extern int show_crosshair; -extern int option_ramstate; - /* emulator-specific callback functions */ void UpdatePPUView(int refreshchr) { } @@ -311,7 +294,6 @@ FILE *FCEUD_UTF8fopen(const char *n, const char *m) #define PAL_CUSTOM (PAL_TOTAL + 3) static int external_palette_exist = 0; -extern int ipalette; /* table for currently loaded palette */ static uint8_t base_palette[192]; diff --git a/src/fceu.h b/src/fceu.h index f97b425..d3ec9a6 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -23,6 +23,9 @@ 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) diff --git a/src/input.h b/src/input.h index 82061bc..1ab1e39 100644 --- a/src/input.h +++ b/src/input.h @@ -29,4 +29,6 @@ extern void (*InputScanlineHook)(uint8 *bg, uint8 *spr, uint32 linets, int final void FCEU_DoSimpleCommand(int cmd); +void FCEU_ZapperSetTolerance(int t); + #endif diff --git a/src/ppu.h b/src/ppu.h index 96338a1..d9cfcec 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -16,6 +16,8 @@ extern void FP_FASTAPASS(1) (*PPU_hook)(uint32 A); extern uint8 NTARAM[0x800], *vnapage[4]; extern uint8 PPUNTARAM; extern uint8 PPUCHRRAM; +extern uint8 PALRAM[0x20]; +extern uint8 SPRAM[0x100]; void FCEUPPU_SaveState(void); void FCEUPPU_LoadState(int version); From 46ca02a2066c058597abfadaa13401154475c58a Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Wed, 2 Jun 2021 04:18:49 +0800 Subject: [PATCH 2/6] Move settings-related vars to FSettings struct - Just some more cleanups --- src/drivers/libretro/libretro.c | 67 +++++++++++++-------------------- src/fceu.c | 26 ++++++++----- src/fceu.h | 39 +++++++++---------- src/ines.c | 3 +- src/ppu.c | 32 ++++++++-------- src/sound.c | 6 +-- src/sound.h | 1 + src/video.c | 11 +++--- src/video.h | 1 - src/x6502.c | 7 ++-- src/x6502.h | 3 +- 11 files changed, 94 insertions(+), 102 deletions(-) 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 From f6cc87a8fa0f01a13376de13659a9ee2225d81e1 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Thu, 3 Jun 2021 10:50:22 +0800 Subject: [PATCH 3/6] Move overclock-related variables to ppu instead Just makes more sense since overclocking is ppu-based. --- src/drivers/libretro/libretro.c | 30 +++++++++++++++--------------- src/fceu.c | 16 ++++++++-------- src/fceu.h | 8 -------- src/ppu.c | 24 +++++++++++++----------- src/ppu.h | 12 ++++++++++++ src/video.c | 8 ++++---- 6 files changed, 52 insertions(+), 46 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index 43a4d33..a83f842 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -1223,33 +1223,33 @@ static void check_variables(bool startup) bool do_reinit = false; if (!strcmp(var.value, "disabled") - && FSettings.overclock_enabled != 0) + && ppu.overclock_enabled != 0) { - FSettings.skip_7bit_overclocking = 1; - FSettings.extrascanlines = 0; - FSettings.vblankscanlines = 0; - FSettings.overclock_enabled = 0; + ppu.skip_7bit_overclocking = 1; + ppu.extrascanlines = 0; + ppu.vblankscanlines = 0; + ppu.overclock_enabled = 0; do_reinit = true; } else if (!strcmp(var.value, "2x-Postrender")) { - FSettings.skip_7bit_overclocking = 1; - FSettings.extrascanlines = 266; - FSettings.vblankscanlines = 0; - FSettings.overclock_enabled = 1; + ppu.skip_7bit_overclocking = 1; + ppu.extrascanlines = 266; + ppu.vblankscanlines = 0; + ppu.overclock_enabled = 1; do_reinit = true; } else if (!strcmp(var.value, "2x-VBlank")) { - FSettings.skip_7bit_overclocking = 1; - FSettings.extrascanlines = 0; - FSettings.vblankscanlines = 266; - FSettings.overclock_enabled = 1; + ppu.skip_7bit_overclocking = 1; + ppu.extrascanlines = 0; + ppu.vblankscanlines = 266; + ppu.overclock_enabled = 1; do_reinit = true; } - FSettings.normal_scanlines = FSettings.dendy ? SCANLINES_DENDY : SCANLINES_NORMAL; - FSettings.totalscanlines = FSettings.normal_scanlines + (FSettings.overclock_enabled ? FSettings.extrascanlines : 0); + ppu.normal_scanlines = FSettings.dendy ? SCANLINES_DENDY : SCANLINES_NORMAL; + ppu.totalscanlines = ppu.normal_scanlines + (ppu.overclock_enabled ? ppu.extrascanlines : 0); if (do_reinit && startup) { diff --git a/src/fceu.c b/src/fceu.c index 748e7f7..7977e5c 100644 --- a/src/fceu.c +++ b/src/fceu.c @@ -341,14 +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; + ppu.overclock_enabled = 0; + ppu.skip_7bit_overclocking = 1; + ppu.totalscanlines = 0; + ppu.normal_scanlines = SCANLINES_NORMAL; + ppu.extrascanlines = 0; + ppu.vblankscanlines = 0; FCEUPPU_Init(); X6502_Init(); return 1; @@ -482,8 +482,8 @@ void FCEU_ResetVidSys(void) if (PAL) FSettings.dendy = 0; - FSettings.normal_scanlines = FSettings.dendy ? SCANLINES_DENDY : SCANLINES_NORMAL; - FSettings.totalscanlines = FSettings.normal_scanlines + (FSettings.overclock_enabled ? FSettings.extrascanlines : 0); + ppu.normal_scanlines = FSettings.dendy ? SCANLINES_DENDY : SCANLINES_NORMAL; + ppu.totalscanlines = ppu.normal_scanlines + (ppu.overclock_enabled ? ppu.extrascanlines : 0); FCEUPPU_SetVideoSystem(w || FSettings.dendy); SetSoundVariables(); diff --git a/src/fceu.h b/src/fceu.h index 27be7a2..4756bda 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -88,14 +88,6 @@ typedef struct { 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; diff --git a/src/ppu.c b/src/ppu.c index fdf7675..ca4ea73 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -64,6 +64,8 @@ static uint32 ppulut1[256]; static uint32 ppulut2[256]; static uint32 ppulut3[128]; +FCEU_PPU ppu; + static void makeppulut(void) { int x; int y; @@ -660,7 +662,7 @@ static void DoLine(void) uint8 *target = NULL; uint8 *dtarget = NULL; - if (scanline >= 240 && scanline != FSettings.totalscanlines) + if (scanline >= 240 && scanline != ppu.totalscanlines) { X6502_Run(256 + 69); scanline++; @@ -1166,10 +1168,10 @@ int FCEUPPU_Loop(int skip) { TriggerNMI(); } X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12); - if (FSettings.overclock_enabled && FSettings.vblankscanlines) { - if (!DMC_7bit || !FSettings.skip_7bit_overclocking) { + if (ppu.overclock_enabled && ppu.vblankscanlines) { + if (!DMC_7bit || !ppu.skip_7bit_overclocking) { overclocking = 1; - X6502_Run(FSettings.vblankscanlines * (256 + 85) - 12); + X6502_Run(ppu.vblankscanlines * (256 + 85) - 12); overclocking = 0; } } @@ -1203,7 +1205,7 @@ int FCEUPPU_Loop(int skip) { kook ^= 1; } if (GameInfo->type == GIT_NSF) - X6502_Run((256 + 85) * FSettings.normal_scanlines); + X6502_Run((256 + 85) * ppu.normal_scanlines); #ifdef FRAMESKIP else if (skip) { int y; @@ -1234,19 +1236,19 @@ int FCEUPPU_Loop(int skip) { deemp = PPU[1] >> 5; /* manual samples can't play correctly with overclocking */ - if (DMC_7bit && FSettings.skip_7bit_overclocking) - FSettings.totalscanlines = FSettings.normal_scanlines; + if (DMC_7bit && ppu.skip_7bit_overclocking) + ppu.totalscanlines = ppu.normal_scanlines; else - FSettings.totalscanlines = FSettings.normal_scanlines + (FSettings.overclock_enabled ? FSettings.extrascanlines : 0); + ppu.totalscanlines = ppu.normal_scanlines + (ppu.overclock_enabled ? ppu.extrascanlines : 0); - for (scanline = 0; scanline < FSettings.totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ + for (scanline = 0; scanline < ppu.totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ deempcnt[deemp]++; /* if ((PPUViewer) && (scanline == PPUViewScanline)) UpdatePPUView(1); */ DoLine(); - if (scanline < FSettings.normal_scanlines || scanline == FSettings.totalscanlines) + if (scanline < ppu.normal_scanlines || scanline == ppu.totalscanlines) overclocking = 0; else { - if (DMC_7bit && FSettings.skip_7bit_overclocking) /* 7bit sample started after 240th line */ + if (DMC_7bit && ppu.skip_7bit_overclocking) /* 7bit sample started after 240th line */ break; overclocking = 1; } diff --git a/src/ppu.h b/src/ppu.h index d9cfcec..829de71 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -1,6 +1,18 @@ #ifndef _FCEU_PPU_H #define _FCEU_PPU_H +typedef struct { + /* 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; +} FCEU_PPU; + +extern FCEU_PPU ppu; + void FCEUPPU_Init(void); void FCEUPPU_Reset(void); void FCEUPPU_Power(void); diff --git a/src/video.c b/src/video.c index d54be19..80da854 100644 --- a/src/video.c +++ b/src/video.c @@ -52,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 + FSettings.extrascanlines + 8))); + XBuf = (uint8*)(FCEU_malloc(256 * (256 + ppu.extrascanlines + 8))); if (!XDBuf) - XDBuf = (uint8*)(FCEU_malloc(256 * (256 + FSettings.extrascanlines + 8))); + XDBuf = (uint8*)(FCEU_malloc(256 * (256 + ppu.extrascanlines + 8))); if (!XBuf || !XDBuf) return 0; - memset(XBuf, 128, 256 * (256 + FSettings.extrascanlines + 8)); - memset(XDBuf, 128, 256 * (256 + FSettings.extrascanlines + 8)); + memset(XBuf, 128, 256 * (256 + ppu.extrascanlines + 8)); + memset(XDBuf, 128, 256 * (256 + ppu.extrascanlines + 8)); return 1; } From e75d6be00be76ace1d91012157d4a30741942ee7 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Thu, 3 Jun 2021 13:30:16 +0800 Subject: [PATCH 4/6] Remove ununsed, commented code --- src/drivers/libretro/libretro.c | 2 -- src/ppu.c | 1 - src/ppuview.h | 2 -- 3 files changed, 5 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index a83f842..d14facc 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -171,8 +171,6 @@ static unsigned serialize_size; /* emulator-specific callback functions */ -void UpdatePPUView(int refreshchr) { } - const char * GetKeyboard(void) { return ""; diff --git a/src/ppu.c b/src/ppu.c index ca4ea73..abb24c3 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -1243,7 +1243,6 @@ int FCEUPPU_Loop(int skip) { for (scanline = 0; scanline < ppu.totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ deempcnt[deemp]++; - /* if ((PPUViewer) && (scanline == PPUViewScanline)) UpdatePPUView(1); */ DoLine(); if (scanline < ppu.normal_scanlines || scanline == ppu.totalscanlines) overclocking = 0; diff --git a/src/ppuview.h b/src/ppuview.h index 740a183..7a3633c 100644 --- a/src/ppuview.h +++ b/src/ppuview.h @@ -1,8 +1,6 @@ #ifndef _FCEU_PPUVIEW_H #define _FCEU_PPUVIEW_H -extern int PPUViewScanline; -extern int PPUViewer; extern int scanline; void PPUViewDoBlit(); From 6f8be4ceddc6ad3c139a780b451000cdf2435572 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sat, 5 Jun 2021 08:26:37 +0800 Subject: [PATCH 5/6] Simplify palette core options Fetch names from palette struct instead. --- src/drivers/libretro/libretro.c | 54 +++++++++++---------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/src/drivers/libretro/libretro.c b/src/drivers/libretro/libretro.c index d14facc..7ff7dcb 100644 --- a/src/drivers/libretro/libretro.c +++ b/src/drivers/libretro/libretro.c @@ -273,11 +273,6 @@ FILE *FCEUD_UTF8fopen(const char *n, const char *m) } /*palette for FCEU*/ -#define PAL_TOTAL 16 /* total no. of palettes in palettes[] */ -#define PAL_DEFAULT (PAL_TOTAL + 1) -#define PAL_RAW (PAL_TOTAL + 2) -#define PAL_CUSTOM (PAL_TOTAL + 3) - static int external_palette_exist = 0; /* table for currently loaded palette */ @@ -580,6 +575,11 @@ struct st_palettes palettes[] = { } }; +#define PAL_TOTAL (sizeof(palettes) / sizeof(palettes[0])) /* total palettes in table */ +#define PAL_DEFAULT (PAL_TOTAL + 1) +#define PAL_RAW (PAL_TOTAL + 2) +#define PAL_CUSTOM (PAL_TOTAL + 3) + #ifdef HAVE_NTSC_FILTER /* ntsc */ #include "nes_ntsc.h" @@ -1159,38 +1159,18 @@ static void check_variables(bool startup) current_palette = PAL_RAW; else if (!strcmp(var.value, "custom")) current_palette = PAL_CUSTOM; - else if (!strcmp(var.value, "asqrealc")) - current_palette = 0; - else if (!strcmp(var.value, "nintendo-vc")) - current_palette = 1; - else if (!strcmp(var.value, "rgb")) - current_palette = 2; - else if (!strcmp(var.value, "yuv-v3")) - current_palette = 3; - else if (!strcmp(var.value, "unsaturated-final")) - current_palette = 4; - else if (!strcmp(var.value, "sony-cxa2025as-us")) - current_palette = 5; - else if (!strcmp(var.value, "pal")) - current_palette = 6; - else if (!strcmp(var.value, "bmf-final2")) - current_palette = 7; - else if (!strcmp(var.value, "bmf-final3")) - current_palette = 8; - else if (!strcmp(var.value, "smooth-fbx")) - current_palette = 9; - else if (!strcmp(var.value, "composite-direct-fbx")) - current_palette = 10; - else if (!strcmp(var.value, "pvm-style-d93-fbx")) - current_palette = 11; - else if (!strcmp(var.value, "ntsc-hardware-fbx")) - current_palette = 12; - else if (!strcmp(var.value, "nes-classic-fbx-fs")) - current_palette = 13; - else if (!strcmp(var.value, "nescap")) - current_palette = 14; - else if (!strcmp(var.value, "wavebeam")) - current_palette = 15; + else + { + unsigned i; + for (i = 0; i < PAL_TOTAL; i++) + { + if (!strcmp(var.value, palettes[i].name)) + { + current_palette = i; + break; + } + } + } if (current_palette != orig_value) { From 001e3a24284484af96cd11451197dace7b295806 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sat, 5 Jun 2021 08:39:47 +0800 Subject: [PATCH 6/6] Remove this (remnants of ppuview) --- src/ppu.c | 1 - src/ppuview.h | 11 ----------- 2 files changed, 12 deletions(-) delete mode 100644 src/ppuview.h diff --git a/src/ppu.c b/src/ppu.c index abb24c3..b6ae1c5 100644 --- a/src/ppu.c +++ b/src/ppu.c @@ -32,7 +32,6 @@ #include "general.h" #include "fceu-endian.h" #include "fceu-memory.h" -#include "ppuview.h" #include "cart.h" #include "palette.h" diff --git a/src/ppuview.h b/src/ppuview.h deleted file mode 100644 index 7a3633c..0000000 --- a/src/ppuview.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _FCEU_PPUVIEW_H -#define _FCEU_PPUVIEW_H - -extern int scanline; - -void PPUViewDoBlit(); -void DoPPUView(); -void UpdatePPUView(int refreshchr); - - -#endif