Adding const qualifiers to the IMemory and adding error messages in the memory viewer

This commit is contained in:
Zoe Roux
2021-02-04 10:22:30 +01:00
parent 2e4e39a696
commit c9eed50289
30 changed files with 208 additions and 123 deletions
+5 -5
View File
@@ -6,7 +6,7 @@
namespace ComSquare::Memory
{
uint24_t AMemory::getRelativeAddress(uint24_t addr)
uint24_t AMemory::getRelativeAddress(uint24_t addr) const
{
return addr - this->_start;
}
@@ -17,22 +17,22 @@ namespace ComSquare::Memory
this->_end = end;
}
bool AMemory::hasMemoryAt(uint24_t addr)
bool AMemory::hasMemoryAt(uint24_t addr) const
{
return this->_start <= addr && addr <= this->_end;
}
bool AMemory::isMirror()
bool AMemory::isMirror() const
{
return false;
}
std::shared_ptr<IMemory> AMemory::getMirrored()
std::shared_ptr<IMemory> AMemory::getMirrored() const
{
return nullptr;
}
std::string AMemory::getValueName(uint24_t)
std::string AMemory::getValueName(uint24_t) const
{
return "???";
}
+5 -5
View File
@@ -26,7 +26,7 @@ namespace ComSquare::Memory
//! @param addr The absolute address (in the 24 bit bus)
//! @return The local address (0 refers to the first byte of this component).
//! @throw InvalidAddress is thrown if the address is not mapped by this component.
virtual uint24_t getRelativeAddress(uint24_t addr) override;
virtual uint24_t getRelativeAddress(uint24_t addr) const override;
//! @brief Change starting and ending points of this mapped memory.
//! @param start The first address mapped to this component.
//! @param end The last address mapped to this component.
@@ -35,16 +35,16 @@ namespace ComSquare::Memory
//! @brief Return true if this component has mapped the address.
//! @param addr The address to check.
//! @return True if this address is mapped to the component. False otherwise.
virtual bool hasMemoryAt(uint24_t addr) override;
virtual bool hasMemoryAt(uint24_t addr) const override;
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
virtual bool isMirror() override;
virtual bool isMirror() const override;
//! @brief Get the name of the data at the address
//! @param addr The address (in local space)
virtual std::string getValueName(uint24_t addr) override;
virtual std::string getValueName(uint24_t addr) const override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
virtual std::shared_ptr<IMemory> getMirrored() override;
virtual std::shared_ptr<IMemory> getMirrored() const override;
virtual ~AMemory() override = default;
};
}
+5 -6
View File
@@ -5,11 +5,10 @@
#include <iostream>
#include "ARectangleMemory.hpp"
#include "../Exceptions/InvalidAddress.hpp"
#include "../Utility/Utility.hpp"
namespace ComSquare::Memory
{
uint24_t ARectangleMemory::getRelativeAddress(uint24_t addr)
uint24_t ARectangleMemory::getRelativeAddress(uint24_t addr) const
{
uint8_t bank = addr >> 16u;
uint16_t page = addr;
@@ -24,7 +23,7 @@ namespace ComSquare::Memory
return pageCount * bankCount + page;
}
bool ARectangleMemory::hasMemoryAt(uint24_t addr)
bool ARectangleMemory::hasMemoryAt(uint24_t addr) const
{
uint8_t bank = addr >> 16u;
uint16_t page = addr;
@@ -43,17 +42,17 @@ namespace ComSquare::Memory
this->_endPage = endPage;
}
bool ARectangleMemory::isMirror()
bool ARectangleMemory::isMirror() const
{
return false;
}
std::shared_ptr<IMemory> ARectangleMemory::getMirrored()
std::shared_ptr<IMemory> ARectangleMemory::getMirrored() const
{
return nullptr;
}
std::string ARectangleMemory::getValueName(uint24_t)
std::string ARectangleMemory::getValueName(uint24_t) const
{
return "???";
}
+5 -5
View File
@@ -24,11 +24,11 @@ namespace ComSquare::Memory
//! @param addr The absolute address (in the 24 bit bus)
//! @return The local address (0 refers to the first byte of this component).
//! @throw InvalidAddress is thrown if the address is not mapped by this component.
virtual uint24_t getRelativeAddress(uint24_t addr) override;
virtual uint24_t getRelativeAddress(uint24_t addr) const override;
//! @brief Return true if this component has mapped the address.
//! @param addr The address to check.
//! @return True if this address is mapped to the component. False otherwise.
bool hasMemoryAt(uint24_t addr) override;
bool hasMemoryAt(uint24_t addr) const override;
//! @brief Change starting and ending points of this mapped memory.
//! @param startBank The first bank mapped to this component.
//! @param endBank The last bank mapped to this component.
@@ -38,13 +38,13 @@ namespace ComSquare::Memory
void setMemoryRegion(uint8_t startBank, uint8_t endBank, uint16_t startPage, uint16_t endPage);
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
virtual bool isMirror() override;
virtual bool isMirror() const override;
//! @brief Get the name of the data at the address
//! @param addr The address (in local space)
virtual std::string getValueName(uint24_t addr) override;
virtual std::string getValueName(uint24_t addr) const override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
virtual std::shared_ptr<IMemory> getMirrored() override;
virtual std::shared_ptr<IMemory> getMirrored() const override;
virtual ~ARectangleMemory() override = default;
};
}
+11 -8
View File
@@ -20,7 +20,7 @@ namespace ComSquare::Memory
//! @param addr The local address to read from (0x0 should refer to the first byte of this component).
//! @throw This function should thrown an InvalidAddress for address that are not mapped to the component.
//! @return Return the data at the address given as parameter.
virtual uint8_t read(uint24_t addr) = 0;
virtual uint8_t read(uint24_t addr) const = 0;
//! @brief Write data to this component.
//! @param addr The local address to write data (0x0 should refer to the first byte of this component).
//! @param data The new data to write.
@@ -29,25 +29,28 @@ namespace ComSquare::Memory
//! @brief Return true if this component has mapped the address.
//! @param addr The address to check.
//! @return True if this address is mapped to the component. False otherwise.
virtual bool hasMemoryAt(uint24_t addr) = 0;
virtual bool hasMemoryAt(uint24_t addr) const = 0;
//! @brief Translate an absolute address to a relative address
//! @param addr The absolute address (in the 24 bit bus)
//! @return The local address (0 refers to the first byte of this component).
//! @throw InvalidAddress is thrown if the address is not mapped by this component.
virtual uint24_t getRelativeAddress(uint24_t addr) = 0;
virtual uint24_t getRelativeAddress(uint24_t addr) const = 0;
//! @brief Get the size of the data. This size can be lower than the mapped data.
//! @return The number of bytes inside this memory.
virtual uint24_t getSize() const = 0;
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
virtual bool isMirror() = 0;
virtual bool isMirror() const = 0;
//! @brief Get the name of this accessor (used for debug purpose)
virtual std::string getName() = 0;
virtual std::string getName() const = 0;
//! @brief Get the component of this accessor (used for debug purpose)
virtual Component getComponent() = 0;
virtual Component getComponent() const = 0;
//! @brief Get the name of the data at the address
//! @param addr The address (in local space)
virtual std::string getValueName(uint24_t addr) = 0;
virtual std::string getValueName(uint24_t addr) const = 0;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
virtual std::shared_ptr<IMemory> getMirrored() = 0;
virtual std::shared_ptr<IMemory> getMirrored() const = 0;
virtual ~IMemory() = default;
};
};
+10 -5
View File
@@ -14,7 +14,7 @@ namespace ComSquare::Memory
this->setMemoryRegion(start, end);
}
uint8_t MemoryShadow::read(uint24_t addr)
uint8_t MemoryShadow::read(uint24_t addr) const
{
return this->_initial->read(addr);
}
@@ -24,22 +24,27 @@ namespace ComSquare::Memory
return this->_initial->write(addr, data);
}
bool MemoryShadow::isMirror()
uint24_t MemoryShadow::getSize() const
{
return this->_initial->getSize();
}
bool MemoryShadow::isMirror() const
{
return true;
}
std::shared_ptr<IMemory> MemoryShadow::getMirrored()
std::shared_ptr<IMemory> MemoryShadow::getMirrored() const
{
return this->_initial;
}
std::string MemoryShadow::getName()
std::string MemoryShadow::getName() const
{
return this->_initial->getName();
}
Component MemoryShadow::getComponent()
Component MemoryShadow::getComponent() const
{
return this->_initial->getComponent();
}
+8 -5
View File
@@ -24,21 +24,24 @@ namespace ComSquare::Memory
//! @param addr The address to read from. The address 0x0 should refer to the first byte of the initial AMemory.
//! @throw InvalidAddress will be thrown if the address is more than the size of the initial AMemory.
//! @return Return the data at the address.
uint8_t read(uint24_t addr) override;
uint8_t read(uint24_t addr) const override;
//! @brief Write data to the ram.
//! @param addr The address to write to. The address 0x0 should refer to the first byte of the initial AMemory.
//! @param data The data to write.
//! @throw InvalidAddress will be thrown if the address is more than the size of the initial AMemory.
void write(uint24_t addr, uint8_t data) override;
//! @brief Get the size of the data. This size can be lower than the mapped data.
//! @return The number of bytes inside this memory.
virtual uint24_t getSize() const override;
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
bool isMirror() override;
bool isMirror() const override;
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
std::string getName() const override;
//! @brief Get the component of this accessor (used for debug purpose)
Component getComponent() override;
Component getComponent() const override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
std::shared_ptr<IMemory> getMirrored() override;
std::shared_ptr<IMemory> getMirrored() const override;
};
}
+11 -6
View File
@@ -18,13 +18,13 @@ namespace ComSquare::Memory
this->setMemoryRegion(startBank, endBank, startPage, endPage);
}
uint24_t RectangleShadow::getRelativeAddress(uint24_t addr)
uint24_t RectangleShadow::getRelativeAddress(uint24_t addr) const
{
uint24_t base = ARectangleMemory::getRelativeAddress(addr);
return base + this->_bankOffset * (this->_endPage - this->_startPage);
}
uint8_t RectangleShadow::read(uint24_t addr)
uint8_t RectangleShadow::read(uint24_t addr) const
{
return this->_initial->read(addr);
}
@@ -40,22 +40,27 @@ namespace ComSquare::Memory
return this;
}
bool RectangleShadow::isMirror()
uint24_t RectangleShadow::getSize() const
{
return this->_initial->getSize();
}
bool RectangleShadow::isMirror() const
{
return true;
}
std::shared_ptr<IMemory> RectangleShadow::getMirrored()
std::shared_ptr<IMemory> RectangleShadow::getMirrored() const
{
return this->_initial;
}
std::string RectangleShadow::getName()
std::string RectangleShadow::getName() const
{
return this->_initial->getName();
}
Component RectangleShadow::getComponent()
Component RectangleShadow::getComponent() const
{
return this->_initial->getComponent();
}
+9 -6
View File
@@ -27,7 +27,7 @@ namespace ComSquare::Memory
//! @param addr The address to read from. The address 0x0 should refer to the first byte of the initial AMemory.
//! @throw InvalidAddress will be thrown if the address is more than the size of the initial AMemory.
//! @return Return the data at the address.
uint8_t read(uint24_t addr) override;
uint8_t read(uint24_t addr) const override;
//! @brief Write data to the ram.
//! @param addr The address to write to. The address 0x0 should refer to the first byte of the initial AMemory.
//! @param data The data to write.
@@ -37,17 +37,20 @@ namespace ComSquare::Memory
//! @param addr The absolute address (in the 24 bit bus)
//! @return The local address (0 refers to the first byte of this component).
//! @throw InvalidAddress is thrown if the address is not mapped by this component.
uint24_t getRelativeAddress(uint24_t addr) override;
uint24_t getRelativeAddress(uint24_t addr) const override;
//! @brief Get the size of the data. This size can be lower than the mapped data.
//! @return The number of bytes inside this memory.
virtual uint24_t getSize() const override;
//! @brief Check if this memory is a mirror or not.
//! @return True if this memory is a mirror. False otherwise.
bool isMirror() override;
bool isMirror() const override;
//! @brief Get the name of this accessor (used for debug purpose)
std::string getName() override;
std::string getName() const override;
//! @brief Get the component of this accessor (used for debug purpose)
Component getComponent() override;
Component getComponent() const override;
//! @brief Return the memory accessor this accessor mirror if any
//! @return nullptr if isMirror is false, the source otherwise.
std::shared_ptr<IMemory> getMirrored() override;
std::shared_ptr<IMemory> getMirrored() const override;
RectangleShadow *setBankOffset(uint8_t bankOffset);
};