From 32ab5cfa7ee64f182f5ce355afdd4afb700d648e Mon Sep 17 00:00:00 2001 From: Sour Date: Fri, 20 Dec 2024 14:25:10 +0900 Subject: [PATCH] GBA: Fixed open bus issues This fixes a freeze in Zelda Minish Cap (in the final dungeon) and fixes a test in the mGBA test suite (Misc -> DMA prefetch -> Read) --- Core/GBA/GbaMemoryManager.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Core/GBA/GbaMemoryManager.cpp b/Core/GBA/GbaMemoryManager.cpp index efcd6f93..a1abfbc0 100644 --- a/Core/GBA/GbaMemoryManager.cpp +++ b/Core/GBA/GbaMemoryManager.cpp @@ -244,11 +244,19 @@ void GbaMemoryManager::UpdateOpenBus(uint32_t addr, uint32_t value) value >>= 8; } memcpy(_state.InternalOpenBus, _state.IwramOpenBus, sizeof(_state.IwramOpenBus)); - } else { - for(int i = 0; i < width; i++) { - _state.InternalOpenBus[i] = value; - value >>= 8; - } + } else if constexpr(width == 4) { + _state.InternalOpenBus[0] = value; + _state.InternalOpenBus[1] = value >> 8; + _state.InternalOpenBus[2] = value >> 16; + _state.InternalOpenBus[3] = value >> 24; + } else if constexpr(width == 2) { + _state.InternalOpenBus[2] = _state.InternalOpenBus[0] = value; + _state.InternalOpenBus[3] = _state.InternalOpenBus[1] = value >> 8; + } else if constexpr(width == 1) { + _state.InternalOpenBus[0] = value; + _state.InternalOpenBus[1] = value; + _state.InternalOpenBus[2] = value; + _state.InternalOpenBus[3] = value; } }