mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-12-23 00:29:47 +00:00
Introduce the concept of a MemoryInterface to the EightBit library.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
parent
68a785ceec
commit
984626a331
@ -5,7 +5,8 @@
|
||||
#include <iomanip>
|
||||
#include <bitset>
|
||||
|
||||
#include "Memory.h"
|
||||
#include <Memory.h>
|
||||
|
||||
#include "LR35902.h"
|
||||
#include "IoRegisters.h"
|
||||
|
||||
|
20
inc/Memory.h
20
inc/Memory.h
@ -5,8 +5,10 @@
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#include "MemoryInterface.h"
|
||||
|
||||
namespace EightBit {
|
||||
class Memory {
|
||||
class Memory : public MemoryInterface {
|
||||
private:
|
||||
std::vector<uint8_t> m_bytes;
|
||||
|
||||
@ -14,7 +16,7 @@ namespace EightBit {
|
||||
const auto& BYTES() const { return m_bytes; }
|
||||
auto& BYTES() { return m_bytes; }
|
||||
|
||||
void poke(const uint16_t address, const uint8_t value) {
|
||||
virtual void poke(const uint16_t address, const uint8_t value) override {
|
||||
BYTES()[address] = value;
|
||||
}
|
||||
|
||||
@ -26,26 +28,26 @@ namespace EightBit {
|
||||
: m_bytes(size) {
|
||||
}
|
||||
|
||||
auto size() const { return m_bytes.size(); }
|
||||
virtual size_t size() const final { return m_bytes.size(); }
|
||||
|
||||
auto load(std::ifstream& file, const int writeOffset = 0, const int readOffset = 0, const int limit = -1) {
|
||||
const auto maximumSize = (int)m_bytes.size() - writeOffset;
|
||||
virtual int load(std::ifstream& file, const int writeOffset = 0, const int readOffset = 0, const int limit = -1) final {
|
||||
const auto maximumSize = (int)size() - writeOffset;
|
||||
return load(file, m_bytes, writeOffset, readOffset, limit, maximumSize);
|
||||
}
|
||||
|
||||
auto load(const std::string& path, const int writeOffset = 0, const int readOffset = 0, const int limit = -1) {
|
||||
const auto maximumSize = (int)m_bytes.size() - writeOffset;
|
||||
virtual int load(const std::string& path, const int writeOffset = 0, const int readOffset = 0, const int limit = -1) final {
|
||||
const auto maximumSize = (int)size() - writeOffset;
|
||||
return load(path, m_bytes, writeOffset, readOffset, limit, maximumSize);
|
||||
}
|
||||
|
||||
auto load(const std::vector<uint8_t>& bytes, const int writeOffset = 0, const int readOffset = 0, int limit = -1) {
|
||||
virtual int load(const std::vector<uint8_t>& bytes, const int writeOffset = 0, const int readOffset = 0, int limit = -1) final {
|
||||
if (limit < 0)
|
||||
limit = (int)bytes.size() - readOffset;
|
||||
std::copy(bytes.cbegin() + readOffset, bytes.cbegin() + limit, m_bytes.begin() + writeOffset);
|
||||
return limit;
|
||||
}
|
||||
|
||||
auto peek(const uint16_t address) const {
|
||||
virtual uint8_t peek(const uint16_t address) const final {
|
||||
return BYTES()[address];
|
||||
}
|
||||
};
|
||||
|
@ -2,14 +2,15 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "Memory.h"
|
||||
|
||||
namespace EightBit {
|
||||
|
||||
class MemoryInterface;
|
||||
|
||||
struct MemoryMapping {
|
||||
|
||||
enum AccessLevel { Unknown, ReadOnly, ReadWrite, };
|
||||
|
||||
Memory& memory;
|
||||
MemoryInterface& memory;
|
||||
uint16_t begin = 0xffff;
|
||||
uint16_t mask = 0U;
|
||||
AccessLevel access = Unknown;
|
||||
|
@ -10,11 +10,11 @@ namespace EightBit {
|
||||
: Memory(size) {
|
||||
}
|
||||
|
||||
auto& reference(const uint16_t address) {
|
||||
virtual uint8_t& reference(const uint16_t address) final {
|
||||
return BYTES()[address];
|
||||
}
|
||||
|
||||
void poke(const uint16_t address, const uint8_t value) {
|
||||
virtual void poke(const uint16_t address, const uint8_t value) final {
|
||||
Memory::poke(address, value);
|
||||
}
|
||||
};
|
||||
|
@ -149,6 +149,7 @@
|
||||
<ClInclude Include="..\inc\IntelProcessor.h" />
|
||||
<ClInclude Include="..\inc\LittleEndianProcessor.h" />
|
||||
<ClInclude Include="..\inc\Memory.h" />
|
||||
<ClInclude Include="..\inc\MemoryInterface.h" />
|
||||
<ClInclude Include="..\inc\MemoryMapping.h" />
|
||||
<ClInclude Include="..\inc\Processor.h" />
|
||||
<ClInclude Include="..\inc\Ram.h" />
|
||||
|
@ -59,6 +59,9 @@
|
||||
<ClInclude Include="..\inc\Chip.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\inc\MemoryInterface.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
Loading…
Reference in New Issue
Block a user