Now using shared_ptr

This commit is contained in:
AnonymusRaccoon
2020-01-24 10:39:45 +01:00
parent 01ad5b6f30
commit 6499646766
4 changed files with 11 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ namespace ComSquare
this->_end = end; this->_end = end;
} }
bool IMemory::hasMemorydAt(uint32_t addr) bool IMemory::hasMemoryAt(uint32_t addr)
{ {
return this->_start <= addr && addr <= this->_end; return this->_start <= addr && addr <= this->_end;
} }

View File

@@ -19,7 +19,7 @@ namespace ComSquare
virtual uint8_t read(uint32_t addr) = 0; virtual uint8_t read(uint32_t addr) = 0;
virtual void write(uint32_t addr, uint8_t data) = 0; virtual void write(uint32_t addr, uint8_t data) = 0;
void setMemoryRegion(uint32_t start, uint32_t end); void setMemoryRegion(uint32_t start, uint32_t end);
bool hasMemorydAt(uint32_t addr); bool hasMemoryAt(uint32_t addr);
uint32_t getStart(); uint32_t getStart();
}; };
}; };

View File

@@ -2,23 +2,22 @@
// Created by anonymus-raccoon on 1/23/20. // Created by anonymus-raccoon on 1/23/20.
// //
#include <ios>
#include <iostream> #include <iostream>
#include "MemoryBus.hpp" #include "MemoryBus.hpp"
namespace ComSquare namespace ComSquare
{ {
IMemory *MemoryBus::getAccessor(uint32_t addr) std::shared_ptr<IMemory> MemoryBus::getAccessor(uint32_t addr)
{ {
return std::find_if(this->_memoryAccessors.begin(), this->_memoryAccessors.end(), [addr](IMemory *accessor) return *std::find_if(this->_memoryAccessors.begin(), this->_memoryAccessors.end(), [addr](std::shared_ptr<IMemory> &accessor)
{ {
return accessor->hasMemorydAt(addr); return accessor->hasMemoryAt(addr);
}).base(); });
} }
uint8_t MemoryBus::read(uint32_t addr) uint8_t MemoryBus::read(uint32_t addr)
{ {
IMemory *handler = this->getAccessor(addr); std::shared_ptr<IMemory> handler = this->getAccessor(addr);
if (!handler) { if (!handler) {
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;
@@ -31,7 +30,7 @@ namespace ComSquare
void MemoryBus::write(uint32_t addr, uint8_t data) void MemoryBus::write(uint32_t addr, uint8_t data)
{ {
IMemory *handler = this->getAccessor(addr); std::shared_ptr<IMemory> handler = this->getAccessor(addr);
if (!handler) { if (!handler) {
std::cout << "Unknown memory accessor for address " << std::hex << addr << ". Warning, it was a write." << std::endl; std::cout << "Unknown memory accessor for address " << std::hex << addr << ". Warning, it was a write." << std::endl;

View File

@@ -7,14 +7,15 @@
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
#include <memory>
#include "IMemory.hpp" #include "IMemory.hpp"
namespace ComSquare namespace ComSquare
{ {
class MemoryBus { class MemoryBus {
private: private:
std::vector<IMemory> _memoryAccessors; std::vector<std::shared_ptr<IMemory>> _memoryAccessors;
IMemory * getAccessor(uint32_t addr); std::shared_ptr<IMemory> getAccessor(uint32_t addr);
uint8_t _openbus; uint8_t _openbus;
public: public:
uint8_t read(uint32_t addr); uint8_t read(uint32_t addr);