From 3ceadd4ccdb70574bc09d1a1270ab5d9341de776 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 22 Sep 2016 06:49:32 -0700 Subject: [PATCH] GB Memory: Initialize RAM pattern for GBC --- CHANGES | 1 + src/gb/memory.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGES b/CHANGES index b132c7a46..5ac343140 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ Bugfixes: Misc: - All: Only update version info if needed - FFmpeg: Encoding cleanup + - GB Memory: Initialize RAM pattern for GBC 0.5.0: (2016-09-19) Features: diff --git a/src/gb/memory.c b/src/gb/memory.c index 19564b09d..43f39ec21 100644 --- a/src/gb/memory.c +++ b/src/gb/memory.c @@ -89,6 +89,20 @@ void GBMemoryReset(struct GB* gb) { mappedMemoryFree(gb->memory.wram, GB_SIZE_WORKING_RAM); } gb->memory.wram = anonymousMemoryMap(GB_SIZE_WORKING_RAM); + if (gb->model >= GB_MODEL_CGB) { + uint32_t* base = (uint32_t*) gb->memory.wram; + size_t i; + uint32_t pattern = 0; + for (i = 0; i < GB_SIZE_WORKING_RAM / 4; i += 4) { + if ((i & 0x1FF) == 0) { + pattern = ~pattern; + } + base[i + 0] = pattern; + base[i + 1] = pattern; + base[i + 2] = ~pattern; + base[i + 3] = ~pattern; + } + } GBMemorySwitchWramBank(&gb->memory, 1); gb->memory.romBank = &gb->memory.rom[GB_SIZE_CART_BANK0]; gb->memory.currentBank = 1;