From 6b4e953f394b896ffc81a49989f0aefc23116494 Mon Sep 17 00:00:00 2001 From: Christian Garbs Date: Fri, 12 Apr 2024 23:54:25 +0200 Subject: [PATCH] clear mapped RAM on subsong change On a subsong change the player has to reset the CPU, registers, RAM etc. Until now the mapped external cartridge RAM was not reset, which could make state from one subsong spill over into the next. Depending on the player routine and subsong sequence this could lead to playback errors. This fixes issue #124. --- HISTORY | 2 ++ gbs.c | 2 ++ mapper.c | 4 ++++ mapper.h | 1 + 4 files changed, 9 insertions(+) diff --git a/HISTORY b/HISTORY index f09a951f..c66d2a10 100644 --- a/HISTORY +++ b/HISTORY @@ -10,6 +10,8 @@ Bugfixes: - gbs core: - fix noise channel LSFR for more faithful drumtracks in most ROMs - fix generated MIDI files being ~1.5% too slow + - reset cartridge RAM on subsong change to prevent the state of a + subsong from influencing later subsongs - gbsplay - fix display of unknown version number (gbsplay -V) diff --git a/gbs.c b/gbs.c index 18ed217c..8f35d833 100644 --- a/gbs.c +++ b/gbs.c @@ -242,6 +242,8 @@ long gbs_init(struct gbs* const gbs, long subsong) struct gbcpu *gbcpu = &gbhw->gbcpu; gbhw_init(gbhw); + if (gbs->mapper) + mapper_init(gbs->mapper); if (subsong == -1) subsong = gbs->defaultsong - 1; if (subsong >= gbs->songs) { diff --git a/mapper.c b/mapper.c index 4422b7fd..baaa644a 100644 --- a/mapper.c +++ b/mapper.c @@ -254,3 +254,7 @@ struct mapper *mapper_gb(struct gbcpu *gbcpu, const uint8_t *rom, size_t size, u void mapper_free(struct mapper *m) { free(m); } + +void mapper_init(struct mapper *m) { + memset(m->ram, 0, sizeof(m->ram)); +} diff --git a/mapper.h b/mapper.h index 9b983b10..c12b1ad1 100644 --- a/mapper.h +++ b/mapper.h @@ -19,5 +19,6 @@ struct mapper *mapper_gbr(struct gbcpu *gbcpu, const uint8_t *rom, size_t size, struct mapper *mapper_gb(struct gbcpu *gbcpu, const uint8_t *rom, size_t size, uint8_t cart_type, uint8_t rom_type, uint8_t ram_type); void mapper_lockout(struct mapper *m); void mapper_free(struct mapper *m); +void mapper_init(struct mapper *m); #endif