From e822f17bb72c36ee7efed439b414e43deebd18dc Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 30 Mar 2016 23:33:32 +0300 Subject: [PATCH] =?UTF-8?q?Wrapping=20external=20RAM=20banking=20support.?= =?UTF-8?q?=20Required=20for=20Pok=C3=A9mon=20Pinball's=20saves.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Core/memory.c b/Core/memory.c index 30a366ed..459bf769 100644 --- a/Core/memory.c +++ b/Core/memory.c @@ -234,6 +234,10 @@ static void write_mbc(GB_gameboy_t *gb, unsigned short addr, unsigned char value } else { gb->mbc_ram_bank = value; + /* Some games assume banks wrap around. We can do this if RAM size is a power of two */ + if (gb->mbc_ram_bank >= gb->mbc_ram_size / 0x2000 && (gb->mbc_ram_size & (gb->mbc_ram_size - 1)) == 0 && gb->mbc_ram_size != 0) { + gb->mbc_ram_bank %= gb->mbc_ram_size / 0x2000; + } } break; case 6: