Skip to content

Commit

Permalink
clear mapped RAM on subsong change
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mmitch committed Apr 16, 2024
1 parent bcba0a5 commit 6b4e953
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions gbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
1 change: 1 addition & 0 deletions mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6b4e953

Please sign in to comment.