mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-27 08:11:55 +00:00
Adding documentation and implementations for Ram, VRam, SRam
This commit is contained in:
@@ -12,15 +12,35 @@
|
||||
|
||||
namespace ComSquare
|
||||
{
|
||||
//! @brief Common interface implemented by all components mapping memory.
|
||||
class IMemory {
|
||||
private:
|
||||
//! @brief The starting address mapped to this component.
|
||||
uint24_t _start = 0;
|
||||
//! @brief The last continuous address mapped to this components. For shadows, see the MemoryShadow class.
|
||||
uint24_t _end = 0;
|
||||
public:
|
||||
//! @brief Read data from the component.
|
||||
//! @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;
|
||||
//! @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.
|
||||
//! @throw This function should thrown an InvalidAddress for address that are not mapped to the component.
|
||||
virtual void write(uint24_t addr, uint8_t data) = 0;
|
||||
//! @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.
|
||||
//! @warning The start/end address should be a continuous range. You can't map address 0x0 and 0x2 but not 0x1. To do that, use two IMemory.
|
||||
void setMemoryRegion(uint24_t start, uint24_t end);
|
||||
//! @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);
|
||||
//! @brief Get the first address mapped to this component.
|
||||
//! @return the _start value.
|
||||
uint24_t getStart();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -10,10 +10,13 @@ namespace ComSquare
|
||||
{
|
||||
std::shared_ptr<IMemory> MemoryBus::getAccessor(uint24_t addr)
|
||||
{
|
||||
return *std::find_if(this->_memoryAccessors.begin(), this->_memoryAccessors.end(), [addr](std::shared_ptr<IMemory> &accessor)
|
||||
auto it = std::find_if(this->_memoryAccessors.begin(), this->_memoryAccessors.end(), [addr](std::shared_ptr<IMemory> &accessor)
|
||||
{
|
||||
return accessor->hasMemoryAt(addr);
|
||||
});
|
||||
if (it == this->_memoryAccessors.end())
|
||||
return nullptr;
|
||||
return *it;
|
||||
}
|
||||
|
||||
uint8_t MemoryBus::read(uint24_t addr)
|
||||
|
||||
@@ -12,13 +12,25 @@
|
||||
|
||||
namespace ComSquare
|
||||
{
|
||||
//! @brief The memory bus is the component responsible of mapping addresses to components address and transmitting the data.
|
||||
class MemoryBus {
|
||||
private:
|
||||
//! @brief The list of components registered inside the bus. Every components that can read/write to a public address should be in this vector.
|
||||
std::vector<std::shared_ptr<IMemory>> _memoryAccessors;
|
||||
//! @brief Helper function to get the components that is responsible of read/write at an address.
|
||||
//! @param addr The address you want to look for.
|
||||
//! @return The components responsible for the address param or nullptr if none was found.
|
||||
std::shared_ptr<IMemory> getAccessor(uint24_t addr);
|
||||
uint8_t _openbus;
|
||||
//! @brief The last value read via the memory bus.
|
||||
uint8_t _openbus = 0;
|
||||
public:
|
||||
//! @brief Read data at a global address.
|
||||
//! @param addr The address to read from.
|
||||
//! @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.
|
||||
uint8_t read(uint24_t addr);
|
||||
//! @brief Write a data to a global address.
|
||||
//! @param addr The address to write to.
|
||||
//! @param data The data to write.
|
||||
void write(uint24_t addr, uint8_t data);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user