From 7948962d70abb04f25685ecd1bca04f2babd6a3c Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Thu, 10 Aug 2017 20:30:37 +0100 Subject: [PATCH] Because of its boot room, the LR35902 needs a custom clear mechanism. Signed-off-by: Adrian.Conlon --- LR35902/inc/Bus.h | 8 +++++++- LR35902/src/Bus.cpp | 8 +++++++- inc/Memory.h | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/LR35902/inc/Bus.h b/LR35902/inc/Bus.h index e1c956b..9646053 100644 --- a/LR35902/inc/Bus.h +++ b/LR35902/inc/Bus.h @@ -79,6 +79,8 @@ namespace EightBit { void reset(); + virtual void clear() override; + void writeRegister(int offset, uint8_t content) { return Memory::write(BASE + offset, content); } @@ -95,10 +97,13 @@ namespace EightBit { writeRegister(LY, 0); } + void disableBootRom() { m_disableBootRom = true; } + void enableBootRom() { m_disableBootRom = false; } + void loadBootRom(const std::string& path); bool isBootRom(uint16_t address) const { - return (address < m_boot.size()) && !peek(BASE + BOOT_DISABLE); + return !m_disableBootRom && (address < m_boot.size()) && !peek(BASE + BOOT_DISABLE); } virtual uint8_t peek(uint16_t address) const; @@ -107,5 +112,6 @@ namespace EightBit { private: std::array m_boot; + bool m_disableBootRom; }; } \ No newline at end of file diff --git a/LR35902/src/Bus.cpp b/LR35902/src/Bus.cpp index b56cdd2..b5cd1de 100644 --- a/LR35902/src/Bus.cpp +++ b/LR35902/src/Bus.cpp @@ -2,7 +2,8 @@ #include "Bus.h" EightBit::Bus::Bus() -: Memory(0xffff) { +: Memory(0xffff), + m_disableBootRom(false) { } void EightBit::Bus::reset() { @@ -10,6 +11,11 @@ void EightBit::Bus::reset() { writeRegister(LCDC, 0x91); } +void EightBit::Bus::clear() { + Memory::clear(); + m_boot.fill(0); +} + void EightBit::Bus::loadBootRom(const std::string& path) { auto size = loadMemory(path, 0); if (size != 0x100) diff --git a/inc/Memory.h b/inc/Memory.h index 90dd4d7..8da332b 100644 --- a/inc/Memory.h +++ b/inc/Memory.h @@ -91,7 +91,7 @@ namespace EightBit { write(value); } - void clear(); + virtual void clear(); void loadRom(const std::string& path, uint16_t offset); void loadRam(const std::string& path, uint16_t offset);