Update region overrides and overclocking

- ines.c - misc cleanups
- Fix Dendy not restored when changing overrides back to auto mode
- directly apply new scanlines and additional scanlines when changing overclock settings
- (readability) change variable name overlock_state to overclock_enabled
This commit is contained in:
negativeExponent
2020-02-07 14:53:14 +08:00
parent 85a15786ff
commit fa7b15eb61
5 changed files with 76 additions and 74 deletions

View File

@@ -92,18 +92,18 @@ extern uint8 NTARAM[0x800], PALRAM[0x20], SPRAM[0x100], PPU[4];
/* overclock the console by adding dummy scanlines to PPU loop /* overclock the console by adding dummy scanlines to PPU loop
* disables DMC DMA and WaveHi filling for these dummies * disables DMC DMA and WaveHi filling for these dummies
* doesn't work with new PPU */ * doesn't work with new PPU */
unsigned overclock_state = -1; unsigned overclock_enabled = -1;
unsigned overclocked = 0; unsigned overclocked = 0;
unsigned skip_7bit_overclocking = 1; /* 7-bit samples have priority over overclocking */ unsigned skip_7bit_overclocking = 1; /* 7-bit samples have priority over overclocking */
unsigned totalscanlines = 0; unsigned totalscanlines = 0;
unsigned normal_scanlines = 240; unsigned normal_scanlines = 240;
unsigned extrascanlines = 0; unsigned extrascanlines = 0;
unsigned vblankscanlines = 0; unsigned vblankscanlines = 0;
static unsigned is_PAL = 0;
static unsigned setregion = 0;
unsigned dendy = 0; unsigned dendy = 0;
static unsigned systemRegion = 0;
static unsigned opt_region = 0;
int FCEUnetplay; int FCEUnetplay;
#ifdef PSP #ifdef PSP
#include "pspgu.h" #include "pspgu.h"
@@ -944,34 +944,30 @@ static void retro_set_custom_palette(void)
void FCEUD_RegionOverride(unsigned region) void FCEUD_RegionOverride(unsigned region)
{ {
unsigned pal = 0; unsigned pal = 0;
unsigned d = 0;
switch (region) switch (region)
{ {
case 0: /* auto */ case 0: /* auto */
normal_scanlines = 240; d = (systemRegion >> 1) & 1;
dendy = 0; pal = systemRegion & 1;
pal = is_PAL;
break; break;
case 1: /* ntsc */ case 1: /* ntsc */
normal_scanlines = 240; FCEU_DispMessage("System: NTSC");
dendy = 0;
pal = 0;
FCEU_DispMessage("Switched to NTSC");
break; break;
case 2: /* pal */ case 2: /* pal */
normal_scanlines = 240;
dendy = 0;
pal = 1; pal = 1;
FCEU_DispMessage("Switched to PAL"); FCEU_DispMessage("System: PAL");
break; break;
case 3: /* dendy */ case 3: /* dendy */
normal_scanlines = 290; d = 1;
dendy = 1; FCEU_DispMessage("System: Dendy");
pal = 0;
FCEU_DispMessage("Switched to Dendy");
break; break;
} }
dendy = d;
normal_scanlines = dendy ? 290 : 240;
totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0);
FCEUI_SetVidSystem(pal); FCEUI_SetVidSystem(pal);
retro_set_custom_palette(); retro_set_custom_palette();
} }
@@ -1114,34 +1110,34 @@ static void check_variables(bool startup)
bool do_reinit = false; bool do_reinit = false;
if (!strcmp(var.value, "disabled") if (!strcmp(var.value, "disabled")
&& overclock_state != 0) && overclock_enabled != 0)
{ {
overclocked = 0;
skip_7bit_overclocking = 1; skip_7bit_overclocking = 1;
extrascanlines = 0; extrascanlines = 0;
vblankscanlines = 0; vblankscanlines = 0;
overclock_state = 0; overclock_enabled = 0;
do_reinit = true; do_reinit = true;
} }
else if (!strcmp(var.value, "2x-Postrender")) else if (!strcmp(var.value, "2x-Postrender"))
{ {
overclocked = 1;
skip_7bit_overclocking = 1; skip_7bit_overclocking = 1;
extrascanlines = 266; extrascanlines = 266;
vblankscanlines = 0; vblankscanlines = 0;
overclock_state = 1; overclock_enabled = 1;
do_reinit = true; do_reinit = true;
} }
else if (!strcmp(var.value, "2x-VBlank")) else if (!strcmp(var.value, "2x-VBlank"))
{ {
overclocked = 1;
skip_7bit_overclocking = 1; skip_7bit_overclocking = 1;
extrascanlines = 0; extrascanlines = 0;
vblankscanlines = 266; vblankscanlines = 266;
overclock_state = 1; overclock_enabled = 1;
do_reinit = true; do_reinit = true;
} }
normal_scanlines = dendy ? 290 : 240;
totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0);
if (do_reinit && startup) if (do_reinit && startup)
{ {
FCEU_KillVirtualVideo(); FCEU_KillVirtualVideo();
@@ -1239,17 +1235,17 @@ static void check_variables(bool startup)
var.key = "fceumm_region"; var.key = "fceumm_region";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{ {
unsigned oldval = setregion; unsigned oldval = opt_region;
if (!strcmp(var.value, "Auto")) if (!strcmp(var.value, "Auto"))
setregion = 0; opt_region = 0;
else if (!strcmp(var.value, "NTSC")) else if (!strcmp(var.value, "NTSC"))
setregion = 1; opt_region = 1;
else if (!strcmp(var.value, "PAL")) else if (!strcmp(var.value, "PAL"))
setregion = 2; opt_region = 2;
else if (!strcmp(var.value, "Dendy")) else if (!strcmp(var.value, "Dendy"))
setregion = 3; opt_region = 3;
if (setregion != oldval) if (opt_region != oldval)
FCEUD_RegionOverride(setregion); FCEUD_RegionOverride(opt_region);
} }
var.key = "fceumm_aspect"; var.key = "fceumm_aspect";
@@ -2110,6 +2106,7 @@ bool retro_load_game(const struct retro_game_info *game)
sndquality = 0; sndquality = 0;
sndvolume = 150; sndvolume = 150;
swapDuty = 0; swapDuty = 0;
dendy = 0;
/* Wii: initialize this or else last variable is passed through /* Wii: initialize this or else last variable is passed through
* when loading another rom causing save state size change. */ * when loading another rom causing save state size change. */
@@ -2158,7 +2155,8 @@ bool retro_load_game(const struct retro_game_info *game)
if (external_palette_exist) if (external_palette_exist)
FCEU_printf(" Loading custom palette: %s%cnes.pal\n", dir, slash); FCEU_printf(" Loading custom palette: %s%cnes.pal\n", dir, slash);
is_PAL = retro_get_region(); /* Save current loaded region info */ /* Save region and dendy mode for region-auto detect */
systemRegion = (dendy << 1) | retro_get_region() & 1;
retro_set_custom_palette(); retro_set_custom_palette();
FCEUD_SoundToggle(); FCEUD_SoundToggle();

View File

@@ -477,7 +477,7 @@ void FCEU_ResetVidSys(void)
dendy = 0; dendy = 0;
normal_scanlines = dendy ? 290 : 240; normal_scanlines = dendy ? 290 : 240;
totalscanlines = normal_scanlines + (overclock_state ? extrascanlines : 0); totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0);
FCEUPPU_SetVideoSystem(w || dendy); FCEUPPU_SetVideoSystem(w || dendy);
SetSoundVariables(); SetSoundVariables();

View File

@@ -6,7 +6,7 @@
extern int fceuindbg; extern int fceuindbg;
/* Overclocking-related */ /* Overclocking-related */
extern unsigned overclock_state; extern unsigned overclock_enabled;
extern unsigned overclocked; extern unsigned overclocked;
extern unsigned skip_7bit_overclocking; extern unsigned skip_7bit_overclocking;
extern unsigned DMC_7bit; extern unsigned DMC_7bit;

View File

@@ -763,10 +763,12 @@ static BMAPPINGLocal bmap[] = {
int iNESLoad(const char *name, FCEUFILE *fp) { int iNESLoad(const char *name, FCEUFILE *fp) {
struct md5_context md5; struct md5_context md5;
char* mappername = NULL; char* mappername = NULL;
uint32 filesize = fp->fp->size; uint64 filesize = FCEU_fgetsize(fp);
uint64 romSize = 0;
uint32 mappertest = 0; uint32 mappertest = 0;
uint32 prgRom = 0; uint32 prgRom = 0;
uint32 chrRom = 0; uint32 chrRom = 0;
uint32 region = 0;
if (FCEU_fread(&head, 1, 16, fp) != 16) if (FCEU_fread(&head, 1, 16, fp) != 16)
return 0; return 0;
@@ -795,46 +797,42 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
memset((char*)(&head) + 0xA, 0, 0x6); memset((char*)(&head) + 0xA, 0, 0x6);
} }
Mirroring = 0;
ROM_size = 0;
VROM_size = 0;
iNES2 = 0;
MapperNo = 0;
subMapper = 0; subMapper = 0;
MapperNo = (head.ROM_type >> 4) | (head.ROM_type2 & 0xF0); MapperNo = (head.ROM_type >> 4) | (head.ROM_type2 & 0xF0);
Mirroring = (head.ROM_type & 8) ? 2 : (head.ROM_type & 1); Mirroring = (head.ROM_type & 8) ? 2 : (head.ROM_type & 1);
prgRom = head.ROM_size; prgRom = head.ROM_size;
chrRom = head.VROM_size; chrRom = head.VROM_size;
iNES2 = ((head.ROM_type2 & 0x0C) == 0x08) ? 1 : 0;
if ((head.ROM_type2 & 0x0C) == 0x08) { if (iNES2) {
iNES2 = 1;
MapperNo |= ((uint32)head.ROM_type3 << 8) & 0xF00; MapperNo |= ((uint32)head.ROM_type3 << 8) & 0xF00;
prgRom |= ((uint32)head.upper_PRG_CHR_size << 8) & 0xF00; prgRom |= ((uint32)head.upper_PRG_CHR_size << 8) & 0xF00;
chrRom |= ((uint32)head.upper_PRG_CHR_size << 4) & 0xF00; chrRom |= ((uint32)head.upper_PRG_CHR_size << 4) & 0xF00;
subMapper = head.ROM_type3 >> 4 & 0x0F; subMapper = (head.ROM_type3 >> 4) & 0x0F;
iNESCart.prgRam = (head.PRGRAM_size & 0x0F) ? (64 << (head.PRGRAM_size & 0x0F)) : 0; iNESCart.prgRam = (head.PRGRAM_size & 0x0F) ? (64 << (head.PRGRAM_size & 0x0F)) : 0;
iNESCart.chrRam = (head.CHRRAM_size & 0x0F) ? (64 << (head.CHRRAM_size & 0x0F)) : 0; iNESCart.chrRam = (head.CHRRAM_size & 0x0F) ? (64 << (head.CHRRAM_size & 0x0F)) : 0;
iNESCart.prgRam_battery = (head.PRGRAM_size & 0xF0) ? (64 << ((head.PRGRAM_size & 0xF0) >> 4)) : 0; iNESCart.prgRam_battery = (head.PRGRAM_size & 0xF0) ? (64 << ((head.PRGRAM_size & 0xF0) >> 4)) : 0;
iNESCart.chrRam_battery = (head.CHRRAM_size & 0xF0) ? (64 << ((head.CHRRAM_size & 0xF0) >> 4)) : 0; iNESCart.chrRam_battery = (head.CHRRAM_size & 0xF0) ? (64 << ((head.CHRRAM_size & 0xF0) >> 4)) : 0;
iNESCart.region = head.Region; region = (head.Region & 3);
} else { } else {
if (!prgRom) if (!prgRom)
prgRom = 256; prgRom = 256;
} }
if (head.ROM_type & 4) { /* Trainer */ /* Trainer */
if (head.ROM_type & 4) {
trainerpoo = (uint8*)FCEU_gmalloc(512); trainerpoo = (uint8*)FCEU_gmalloc(512);
FCEU_fread(trainerpoo, 512, 1, fp); FCEU_fread(trainerpoo, 512, 1, fp);
filesize -= 512; filesize -= 512;
} }
if (((prgRom * 0x4000) + (chrRom * 0x2000)) > filesize) { romSize = (prgRom * 0x4000) + (chrRom * 0x2000);
FCEU_PrintError(" File length is too short to contain all data reported from header by %llu\n", ((prgRom * 0x4000) + (chrRom * 0x2000)) - filesize); if (romSize > filesize) {
FCEU_PrintError(" File length is too short to contain all data reported from header by %llu\n", romSize - filesize);
return 0; return 0;
} else if (((prgRom * 0x4000) + (chrRom * 0x2000)) < filesize) } else if (romSize < filesize)
FCEU_PrintError(" File contains %llu bytes of unused data\n", filesize - ((prgRom * 0x4000) + (chrRom * 0x2000))); FCEU_PrintError(" File contains %llu bytes of unused data\n", filesize - romSize);
iNESCart.prgRom = prgRom; iNESCart.prgRom = prgRom;
iNESCart.chrRom = chrRom; iNESCart.chrRom = chrRom;
@@ -945,7 +943,7 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
} }
} }
FCEU_printf(" Mirroring: %s\n", Mirroring == 2 ? "None (Four-screen)" : Mirroring ? "Vertical" : "Horizontal"); FCEU_printf(" Mirroring: %s\n", Mirroring == 2 ? "None (Four-screen)" : Mirroring ? "Vertical" : "Horizontal");
FCEU_printf(" System: %s\n", tv_region[(iNESCart.region & 3)]); FCEU_printf(" System: %s\n", tv_region[region]);
FCEU_printf(" Trained: %s\n", (head.ROM_type & 4) ? "Yes" : "No"); FCEU_printf(" Trained: %s\n", (head.ROM_type & 4) ? "Yes" : "No");
} else { } else {
FCEU_printf(" Mapper #: %3d\n", MapperNo); FCEU_printf(" Mapper #: %3d\n", MapperNo);
@@ -963,18 +961,7 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
GameInterface = iNESGI; GameInterface = iNESGI;
if (iNES2) { if (iNES2 == 0) {
switch (iNESCart.region & 0x03) {
/* 0: RP2C02 ("NTSC NES")
* 1: RP2C07 ("Licensed PAL NES")
* 2: Multiple-region
* 3: UMC 6527P ("Dendy")
*/
case 0: case 2: FCEUI_SetVidSystem(0); break;
case 1: FCEUI_SetVidSystem(1); break;
case 3: dendy = 1; FCEUI_SetVidSystem(0); break;
}
} else {
if (strstr(name, "(E)") || strstr(name, "(e)") || if (strstr(name, "(E)") || strstr(name, "(e)") ||
strstr(name, "(Europe)") || strstr(name, "(PAL)") || strstr(name, "(Europe)") || strstr(name, "(PAL)") ||
strstr(name, "(F)") || strstr(name, "(f)") || strstr(name, "(F)") || strstr(name, "(f)") ||
@@ -986,14 +973,31 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
strstr(name, "(Sweden)") || strstr(name, "(Sw)") || strstr(name, "(Sweden)") || strstr(name, "(Sw)") ||
strstr(name, "(Australia)") || strstr(name, "(A)") || strstr(name, "(Australia)") || strstr(name, "(A)") ||
strstr(name, "(a)")) { strstr(name, "(a)")) {
iNESCart.region = 1; region = 1;
FCEUI_SetVidSystem(1);
} else { } else {
iNESCart.region = 0; region = 0;
FCEUI_SetVidSystem(0);
} }
} }
iNESCart.region = region;
switch (region) {
/* 0: RP2C02 ("NTSC NES")
* 1: RP2C07 ("Licensed PAL NES")
* 2: Multiple-region
* 3: UMC 6527P ("Dendy")
*/
case 1:
FCEUI_SetVidSystem(1);
break;
case 3:
dendy = 1;
/* fallthrough */
case 0:
case 2:
FCEUI_SetVidSystem(0);
break;
}
return 1; return 1;
} }

View File

@@ -1156,7 +1156,7 @@ int FCEUPPU_Loop(int skip) {
TriggerNMI(); TriggerNMI();
} }
X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12); X6502_Run((scanlines_per_frame - 242) * (256 + 85) - 12);
if (overclock_state && vblankscanlines) { if (overclock_enabled && vblankscanlines) {
if (!DMC_7bit || !skip_7bit_overclocking) { if (!DMC_7bit || !skip_7bit_overclocking) {
overclocked = 1; overclocked = 1;
X6502_Run(vblankscanlines * (256 + 85) - 12); X6502_Run(vblankscanlines * (256 + 85) - 12);
@@ -1227,7 +1227,7 @@ int FCEUPPU_Loop(int skip) {
if (DMC_7bit && skip_7bit_overclocking) if (DMC_7bit && skip_7bit_overclocking)
totalscanlines = normal_scanlines; totalscanlines = normal_scanlines;
else else
totalscanlines = normal_scanlines + (overclock_state ? extrascanlines : 0); totalscanlines = normal_scanlines + (overclock_enabled ? extrascanlines : 0);
for (scanline = 0; scanline < totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */ for (scanline = 0; scanline < totalscanlines; ) { /* scanline is incremented in DoLine. Evil. :/ */
deempcnt[deemp]++; deempcnt[deemp]++;