From b98ce400210cc2831877c41c56063a1bb57862d5 Mon Sep 17 00:00:00 2001 From: Kawa Date: Wed, 3 Jun 2020 20:44:27 +0200 Subject: [PATCH] Update mbc.c https://github.com/LIJI32/SameBoy/commit/6a3cd371d01e5d253b0ab999da53d87ac84ab7cc --- bsnes/gb/Core/mbc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bsnes/gb/Core/mbc.c b/bsnes/gb/Core/mbc.c index d3791a18..565f801b 100644 --- a/bsnes/gb/Core/mbc.c +++ b/bsnes/gb/Core/mbc.c @@ -114,7 +114,7 @@ void GB_update_mbc_mappings(GB_gameboy_t *gb) void GB_configure_cart(GB_gameboy_t *gb) { gb->cartridge_type = &GB_cart_defs[gb->rom[0x147]]; - + if (gb->rom[0x147] == 0 && gb->rom_size > 0x8000) { GB_log(gb, "ROM header reports no MBC, but file size is over 32Kb. Assuming cartridge uses MBC3.\n"); gb->cartridge_type = &GB_cart_defs[0x11]; @@ -131,7 +131,10 @@ void GB_configure_cart(GB_gameboy_t *gb) static const int ram_sizes[256] = {0, 0x800, 0x2000, 0x8000, 0x20000, 0x10000}; gb->mbc_ram_size = ram_sizes[gb->rom[0x149]]; } - gb->mbc_ram = malloc(gb->mbc_ram_size); + + if (gb->mbc_ram_size) { + gb->mbc_ram = malloc(gb->mbc_ram_size); + } /* Todo: Some games assume unintialized MBC RAM is 0xFF. It this true for all cartridges types? */ memset(gb->mbc_ram, 0xFF, gb->mbc_ram_size); @@ -146,7 +149,7 @@ void GB_configure_cart(GB_gameboy_t *gb) gb->mbc1_wiring = GB_MBC1M_WIRING; } } - + /* Set MBC5's bank to 1 correctly */ if (gb->cartridge_type->mbc_type == GB_MBC5) { gb->mbc5.rom_bank_low = 1;