Skip to content

Commit

Permalink
[NSF] Fixed region selection (#380).
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Mar 6, 2024
1 parent 55f6086 commit 4df298d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
27 changes: 4 additions & 23 deletions src/core/mappers/mapper_NSF.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
25 changes: 22 additions & 3 deletions src/core/nsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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];
Expand Down
16 changes: 16 additions & 0 deletions src/core/nsfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 4df298d

Please sign in to comment.