2017-06-04 20:38:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2017-09-06 12:22:23 +00:00
|
|
|
#include <vector>
|
2017-10-22 20:24:28 +00:00
|
|
|
#include <string>
|
2017-06-04 22:37:25 +00:00
|
|
|
|
2017-06-04 20:38:34 +00:00
|
|
|
namespace EightBit {
|
|
|
|
class Memory {
|
|
|
|
public:
|
2017-09-06 23:53:22 +00:00
|
|
|
Memory(size_t size = 0)
|
2017-09-06 12:22:23 +00:00
|
|
|
: m_bytes(size) {
|
2017-07-06 20:32:52 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:00:57 +00:00
|
|
|
size_t size() const { return m_bytes.size(); }
|
|
|
|
|
2017-09-06 23:53:22 +00:00
|
|
|
int load(const std::string& path, int writeOffset = 0, int readOffset = 0, int limit = -1) {
|
|
|
|
const auto maximumSize = (int)m_bytes.size() - writeOffset;
|
|
|
|
return loadBinary(path, m_bytes, writeOffset, readOffset, limit, maximumSize);
|
2017-07-18 20:40:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-04 20:38:34 +00:00
|
|
|
protected:
|
2017-11-03 22:05:01 +00:00
|
|
|
std::vector<uint8_t>& BYTES() { return m_bytes; }
|
2017-06-04 20:38:34 +00:00
|
|
|
|
2017-09-06 12:22:23 +00:00
|
|
|
uint8_t read(uint16_t address) const {
|
|
|
|
return m_bytes[address];
|
2017-08-24 10:28:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 12:22:23 +00:00
|
|
|
void write(uint16_t address, uint8_t value) {
|
|
|
|
m_bytes[address] = value;
|
2017-08-06 16:06:48 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 12:22:23 +00:00
|
|
|
private:
|
2017-11-03 22:05:01 +00:00
|
|
|
std::vector<uint8_t> m_bytes;
|
|
|
|
|
2017-09-06 23:53:22 +00:00
|
|
|
static int loadBinary(
|
|
|
|
const std::string& path,
|
|
|
|
std::vector<uint8_t>& output,
|
|
|
|
int writeOffset,
|
|
|
|
int readOffset,
|
|
|
|
int limit,
|
|
|
|
int maximumSize);
|
2017-06-04 20:38:34 +00:00
|
|
|
};
|
|
|
|
}
|