git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 7350843cca3c8a399858b557fbcf9db5967c6c62
parent c78a0037124a6215642300a39b1d7b035dac1519
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sat,  5 Mar 2022 23:05:00 +0200

Fix incorrect INFO block on MMM01 BESS states

Diffstat:
MCore/save_state.c19+++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/Core/save_state.c b/Core/save_state.c @@ -478,6 +478,14 @@ static int save_bess_mbc_block(GB_gameboy_t *gb, virtual_file_t *file) return 0; } +static const uint8_t *get_header_bank(GB_gameboy_t *gb) +{ + if (gb->cartridge_type->mbc_type == GB_MMM01) { + return gb->rom + gb->rom_size - 0x8000; + } + return gb->rom; +} + static int save_state_internal(GB_gameboy_t *gb, virtual_file_t *file, bool append_bess) { if (file->write(file, GB_GET_SECTION(gb, header), GB_SECTION_SIZE(header)) != GB_SECTION_SIZE(header)) goto error; @@ -547,11 +555,13 @@ static int save_state_internal(GB_gameboy_t *gb, virtual_file_t *file, bool appe goto error; } - if (file->write(file, gb->rom + 0x134, 0x10) != 0x10) { + const uint8_t *bank = get_header_bank(gb); + + if (file->write(file, bank + 0x134, 0x10) != 0x10) { goto error; } - if (file->write(file, gb->rom + 0x14E, 2) != 2) { + if (file->write(file, bank + 0x14E, 2) != 2) { goto error; } @@ -985,7 +995,8 @@ static int load_bess_save(GB_gameboy_t *gb, virtual_file_t *file, bool is_samebo BESS_INFO_t bess_info = {0,}; if (LE32(block.size) != sizeof(bess_info) - sizeof(block)) goto parse_error; if (file->read(file, &bess_info.header + 1, LE32(block.size)) != LE32(block.size)) goto error; - if (memcmp(bess_info.title, gb->rom + 0x134, sizeof(bess_info.title))) { + const uint8_t *bank = get_header_bank(gb); + if (memcmp(bess_info.title, bank + 0x134, sizeof(bess_info.title))) { char ascii_title[0x11] = {0,}; for (unsigned i = 0; i < 0x10; i++) { if (bess_info.title[i] < 0x20 || bess_info.title[i] > 0x7E) break; @@ -993,7 +1004,7 @@ static int load_bess_save(GB_gameboy_t *gb, virtual_file_t *file, bool is_samebo } GB_log(gb, "Save state was made on another ROM: '%s'\n", ascii_title); } - else if (memcmp(bess_info.checksum, gb->rom + 0x14E, 2)) { + else if (memcmp(bess_info.checksum, bank + 0x14E, 2)) { GB_log(gb, "Save state was potentially made on another revision of the same ROM.\n"); } break;

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.