diff --git a/LR35902/src/GameBoyBus.cpp b/LR35902/src/GameBoyBus.cpp index 77d3f22..6dc6a87 100644 --- a/LR35902/src/GameBoyBus.cpp +++ b/LR35902/src/GameBoyBus.cpp @@ -2,7 +2,15 @@ #include "GameBoyBus.h" EightBit::GameBoy::Bus::Bus() -: m_disableBootRom(false), +: m_bootRom(0x100), + m_gameRomBanks(1), + m_videoRam(0x2000), + m_ramBanks(0), + m_lowInternalRam(0x2000), + m_oamRam(0xa0), + m_ioPorts(0x80), + m_highInternalRam(0x80), + m_disableBootRom(false), m_disableGameRom(false), m_rom(false), m_banked(false), @@ -32,13 +40,11 @@ void EightBit::GameBoy::Bus::loadBootRom(const std::string& path) { void EightBit::GameBoy::Bus::loadGameRom(const std::string& path) { const auto bankSize = 0x4000; m_gameRomBanks.resize(1); - const auto size = m_gameRomBanks[0].load(path, bankSize); - auto banks = size / bankSize; - if (banks > 1) { - m_gameRomBanks.resize(banks); - for (int bank = 1; bank < banks; ++banks) - m_gameRomBanks[bank].load(path, bankSize, bankSize * bank); - } + const auto size = m_gameRomBanks[0].load(path, 0, 0, bankSize); + const auto banks = size / bankSize; + m_gameRomBanks.resize(banks); + for (int bank = 1; bank < banks; ++bank) + m_gameRomBanks[bank].load(path, 0, bankSize * bank, bankSize); validateCartridgeType(); } diff --git a/src/Memory.cpp b/src/Memory.cpp index 3057297..c9b3803 100644 --- a/src/Memory.cpp +++ b/src/Memory.cpp @@ -20,15 +20,15 @@ int EightBit::Memory::loadBinary( if ((maximumSize > 0) && ((size - readOffset) > maximumSize)) throw std::runtime_error("Binary cannot fit"); - size_t extent = size + writeOffset; - if (output.size() < extent) - output.resize(extent); - file.seekg(readOffset, std::ios::beg); if ((limit < 0) || (limit > size)) limit = size; + const size_t extent = limit + writeOffset; + if (output.size() < extent) + output.resize(extent); + file.read((char*)&output[writeOffset], limit); file.close();