From a2e9813ed69ff2456b46dc67ea4476755789fa48 Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 22 Apr 2024 19:29:08 -0400 Subject: [PATCH] Update rom and sram init --- src/app/emu/memory/memory.cc | 19 +++---------------- src/app/emu/snes.cc | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/app/emu/memory/memory.cc b/src/app/emu/memory/memory.cc index 5695b6db..c02136b0 100644 --- a/src/app/emu/memory/memory.cc +++ b/src/app/emu/memory/memory.cc @@ -23,19 +23,16 @@ void MemoryImpl::Initialize(const std::vector& romData, bool verbose) { rom_.resize(romSize); // Copy memory into rom_ - std::copy(romData.begin() + kROMStart, romData.begin() + kROMStart + kROMSize, - rom_.begin()); - - memory_.resize(0x1000000); // 16 MB - - const size_t ROM_CHUNK_SIZE = 0x8000; // 32 KB + std::copy(romData.begin(), romData.begin() + romSize, rom_.begin()); // Clear memory + memory_.resize(0x1000000); // 16 MB std::fill(memory_.begin(), memory_.end(), 0); // Load ROM data into memory based on LoROM mapping size_t romSize = romData.size(); size_t romAddress = 0; + const size_t ROM_CHUNK_SIZE = 0x8000; // 32 KB for (size_t bank = 0x00; bank <= 0x3F; ++bank) { for (size_t offset = 0x8000; offset <= 0xFFFF; offset += ROM_CHUNK_SIZE) { if (romAddress < romSize) { @@ -46,16 +43,6 @@ void MemoryImpl::Initialize(const std::vector& romData, bool verbose) { } } } - - // Copy data into rom_ vector - rom_.resize(kROMSize); - std::copy(memory_.begin() + kROMStart, memory_.begin() + kROMStart + kROMSize, - rom_.begin()); - - // Copy data into ram_ vector - ram_.resize(kRAMSize); - std::copy(memory_.begin() + kRAMStart, memory_.begin() + kRAMStart + kRAMSize, - ram_.begin()); } memory::RomInfo MemoryImpl::ReadRomHeader() { diff --git a/src/app/emu/snes.cc b/src/app/emu/snes.cc index 332eed39..dc43d5cf 100644 --- a/src/app/emu/snes.cc +++ b/src/app/emu/snes.cc @@ -22,19 +22,6 @@ namespace app { namespace emu { void SNES::Init(Rom& rom) { - // Load the ROM into memory and set up the memory mapping - rom_data = rom.vector(); - memory_.Initialize(rom_data); - - // Read the ROM header - rom_info_ = memory_.ReadRomHeader(); - Reset(); - - // Disable the emulation flag (switch to 65816 native mode) - cpu_.E = 0; - cpu_.PB = 0x00; - cpu_.PC = 0x8000; - // Initialize CPU cpu_.Init(); @@ -44,6 +31,19 @@ void SNES::Init(Rom& rom) { // Initialize APU apu_.Init(); + // Load the ROM into memory and set up the memory mapping + rom_data = rom.vector(); + memory_.Initialize(rom_data); + + // Read the ROM header + // rom_info_ = memory_.ReadRomHeader(); + Reset(true); + + // Disable the emulation flag (switch to 65816 native mode) + cpu_.E = 0; + // cpu_.PB = 0x00; + // cpu_.PC = 0x8000; + // Disable interrupts and rendering memory_.WriteByte(0x4200, 0x00); // NMITIMEN memory_.WriteByte(0x420C, 0x00); // HDMAEN @@ -90,7 +90,7 @@ void SNES::Reset(bool hard) { input1.latchedState = 0; input2.latchedState = 0; // cart_reset(); - // if(hard) memset(ram, 0, sizeof(ram)); + if (hard) memset(ram, 0, sizeof(ram)); ram_adr_ = 0; memory_.set_h_pos(0); memory_.set_v_pos(0);