Adding an error message on invalid instructions

This commit is contained in:
Zoe Roux
2021-02-04 12:07:26 +01:00
parent 04f9b9a8fc
commit 845a8c26f0
11 changed files with 78 additions and 17 deletions
+19 -4
View File
@@ -8,6 +8,7 @@
#include "../SNES.hpp"
#include "MemoryShadow.hpp"
#include "RectangleShadow.hpp"
#include "../Exceptions/InvalidAddress.hpp"
namespace ComSquare::Memory
{
@@ -22,20 +23,34 @@ namespace ComSquare::Memory
return *it;
}
uint8_t MemoryBus::read(uint24_t addr, bool silence)
uint8_t MemoryBus::read(uint24_t addr)
{
std::shared_ptr<IMemory> handler = this->getAccessor(addr);
if (!handler) {
if (!silence)
std::cout << "Unknown memory accessor for address $" << std::hex << addr << ". Using open bus." << std::endl;
std::cout << "Unknown memory accessor for address $" << std::hex << addr << ". Using open bus." << std::endl;
return this->_openBus;
}
uint8_t data = handler->read(handler->getRelativeAddress(addr));
uint8_t data = handler->read(handler->getRelativeAddress(addr));
this->_openBus = data;
return data;
}
uint8_t MemoryBus::read(uint24_t addr, bool silence)
{
if (!silence)
return this->read(addr);
std::shared_ptr<IMemory> handler = this->getAccessor(addr);
if (!handler)
return this->_openBus;
try {
return handler->read(handler->getRelativeAddress(addr));
} catch (const InvalidAddress &) {
return 0;
}
}
void MemoryBus::write(uint24_t addr, uint8_t data)
{
std::shared_ptr<IMemory> handler = this->getAccessor(addr);
+7 -2
View File
@@ -40,9 +40,14 @@ namespace ComSquare
//! @brief Read data at a global address.
//! @param addr The address to read from.
//! @param silence Disable login to the memory bus's debugger (if enabled). Should only be used by other debuggers.
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
virtual uint8_t read(uint24_t addr, bool silence = false);
virtual uint8_t read(uint24_t addr);
//! @brief Read data at a global address. This form allow read to be silenced.
//! @param addr The address to read from.
//! @param silence Disable login to the memory bus's debugger (if enabled). Should only be used by other debuggers. This also won't affect the open bus.
//! @return The value that the component returned for this address. If the address was mapped to ram, it simply returned the value. If the address was mapped to a register the component returned the register.
virtual uint8_t read(uint24_t addr, bool silence);
//! @brief Write a data to a global address.
//! @param addr The address to write to.