From c462d749e2ac850dfe01637bdb1da1cf93d3eef7 Mon Sep 17 00:00:00 2001 From: scawful Date: Sat, 25 Nov 2023 22:44:27 -0500 Subject: [PATCH] Emulator housekeeping --- src/app/emu/emulator.cc | 2 ++ src/app/emu/memory/mock_memory.h | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/app/emu/emulator.cc b/src/app/emu/emulator.cc index 9e4ccf1c..464d5b12 100644 --- a/src/app/emu/emulator.cc +++ b/src/app/emu/emulator.cc @@ -131,11 +131,13 @@ using ImGui::Text; void Emulator::Run() { if (!snes_.running() && loading_) { + // Setup and initialize memory if (loading_ && !memory_setup_) { snes_.SetupMemory(*rom()); memory_setup_ = true; } + // Run the emulation if (rom()->isLoaded() && power_) { snes_.Init(*rom()); running_ = true; diff --git a/src/app/emu/memory/mock_memory.h b/src/app/emu/memory/mock_memory.h index a56b66ef..6d84b114 100644 --- a/src/app/emu/memory/mock_memory.h +++ b/src/app/emu/memory/mock_memory.h @@ -73,6 +73,29 @@ class MockMemory : public Memory { } } + void Initialize(const std::vector& romData) { + // 16 MB, simplifying the memory layout for testing + memory_.resize(0x1000000); + + // Clear memory + std::fill(memory_.begin(), memory_.end(), 0); + + // Load ROM data into mock memory + size_t romSize = romData.size(); + size_t romAddress = 0; + const size_t ROM_CHUNK_SIZE = 0x8000; // 32 KB + for (size_t bank = 0x00; bank <= 0xBF; bank += 0x80) { + for (size_t offset = 0x8000; offset <= 0xFFFF; offset += ROM_CHUNK_SIZE) { + if (romAddress < romSize) { + std::copy(romData.begin() + romAddress, + romData.begin() + romAddress + ROM_CHUNK_SIZE, + memory_.begin() + (bank << 16) + offset); + romAddress += ROM_CHUNK_SIZE; + } + } + } + } + void Init() { ON_CALL(*this, ReadByte(::testing::_)) .WillByDefault(