From 4df298dd076638679c5e55e565c3b100ee49e914 Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Wed, 6 Mar 2024 09:17:04 +0100 Subject: [PATCH] [NSF] Fixed region selection (#380). --- src/core/mappers/mapper_NSF.c | 27 ++++----------------------- src/core/nsf.c | 25 ++++++++++++++++++++++--- src/core/nsfe.c | 16 ++++++++++++++++ 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/core/mappers/mapper_NSF.c b/src/core/mappers/mapper_NSF.c index 84a3d7e9c..39a6f9f4f 100644 --- a/src/core/mappers/mapper_NSF.c +++ b/src/core/mappers/mapper_NSF.c @@ -63,19 +63,16 @@ void map_init_NSF(void) { nsf.state = NSF_PLAY | NSF_CHANGE_SONG; - switch (cfg->mode) { + switch (machine.type) { default: - case AUTO: - nsf.type = nsf.region.preferred; - break; case NTSC: - nsf.type = nsf.region.supported & 0x01 ? nsf.type = NSF_NTSC_MODE : nsf.region.preferred; + nsf.type = NSF_NTSC_MODE; break; case PAL: - nsf.type = nsf.region.supported & 0x02 ? nsf.type = NSF_PAL_MODE : nsf.region.preferred; + nsf.type = NSF_PAL_MODE; break; case DENDY: - nsf.type = nsf.region.supported & 0x04 ? nsf.type = NSF_DENDY_MODE : nsf.region.preferred; + nsf.type = NSF_DENDY_MODE; break; } @@ -281,22 +278,6 @@ void extcl_apu_tick_NSF(void) { INLINE static void select_region_NSF(void) { double rate = 0, nmi_rate = 0; - switch (nsf.type & 0x03) { - case NSF_NTSC_MODE: - info.machine[DATABASE] = NTSC; - break; - case NSF_PAL_MODE: - info.machine[DATABASE] = PAL; - break; - case NSF_DENDY_MODE: - info.machine[DATABASE] = DENDY; - break; - default: - nsf.type = NSF_NTSC_MODE; - info.machine[DATABASE] = NTSC; - break; - } - if (machine.type == NTSC) { rate = nsf.play_speed.ntsc; nmi_rate = 0x40FF; diff --git a/src/core/nsf.c b/src/core/nsf.c index b6d1113ca..23206cb94 100644 --- a/src/core/nsf.c +++ b/src/core/nsf.c @@ -199,12 +199,15 @@ void nsf_info(void) { log_info_box(uL("copyright;" uPs("") ""), nsf.info.copyright); log_info_box(uL("ripper;" uPs("") ""), nsf.info.ripper); log_info_box(uL("text;%s"), nsf.info.text ? "yes" : "no"); - log_info_box(uL("region;supported %s%s%s, preferred %s"), + log_info_box(uL("region;supported %s%s%s%s"), nsf.region.supported & 0x01 ? "NTSC" : "", nsf.region.supported & 0x02 ? nsf.region.supported & 0x01 ? "/PAL" : "PAL" : "", nsf.region.supported & 0x04 ? nsf.region.supported & 0x03 ? "/Dendy" : "Dendy" : "", - nsf.region.preferred == NSF_NTSC_MODE ? "NTSC" : nsf.region.preferred == NSF_PAL_MODE - ? "PAL" : nsf.region.preferred == NSF_DENDY_MODE ? "Dendy" : "unknown"); + (nsf.region.supported == 0x01) || (nsf.region.supported == 0x02) || (nsf.region.supported == 0x04) ? "" + : nsf.region.preferred == NSF_NTSC_MODE ? ", preferred NTSC" + : nsf.region.preferred == NSF_PAL_MODE ? ", preferred PAL" + : nsf.region.preferred == NSF_DENDY_MODE ? ", preferred Dendy" + : ", preferred unknown"); log_info_box(uL("irq support;%s"), nsf2.features.irq_support ? "yes" : "no"); log_info_box(uL("non-ret INIT;%s"), nsf2.features.non_returning_init ? "yes" : "no"); log_info_box(uL("disable PLAY;%s"), nsf2.features.suppressed_PLAY ? "yes" : "no"); @@ -540,6 +543,22 @@ BYTE nsf_load_rom(void) { nsf.play_speed.dendy = nsf.play_speed.pal; } + switch (nsf.region.preferred & 0x03) { + case NSF_NTSC_MODE: + info.machine[DATABASE] = NTSC; + break; + case NSF_PAL_MODE: + info.machine[DATABASE] = PAL; + break; + case NSF_DENDY_MODE: + info.machine[DATABASE] = DENDY; + break; + default: + nsf.region.preferred = NSF_NTSC_MODE; + info.machine[DATABASE] = NTSC; + break; + } + nsf.enabled = TRUE; nsf.songs.current = nsf.songs.starting - 1; nsf.routine = &nsf_routine[0]; diff --git a/src/core/nsfe.c b/src/core/nsfe.c index 363e89de0..eaffd450a 100644 --- a/src/core/nsfe.c +++ b/src/core/nsfe.c @@ -238,6 +238,22 @@ BYTE nsfe_load_rom(void) { nsf.play_speed.dendy = nsf.play_speed.pal; } + switch (nsf.region.preferred & 0x03) { + case NSF_NTSC_MODE: + info.machine[DATABASE] = NTSC; + break; + case NSF_PAL_MODE: + info.machine[DATABASE] = PAL; + break; + case NSF_DENDY_MODE: + info.machine[DATABASE] = DENDY; + break; + default: + nsf.region.preferred = NSF_NTSC_MODE; + info.machine[DATABASE] = NTSC; + break; + } + ram_set_size(0, S2K); ram_init();