2017-06-04 20:38:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2017-12-26 22:46:16 +00:00
|
|
|
#include <fstream>
|
2018-11-04 16:38:57 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-11-03 22:15:17 +00:00
|
|
|
|
2017-06-04 20:38:34 +00:00
|
|
|
namespace EightBit {
|
2018-11-04 16:38:57 +00:00
|
|
|
// Memory is:
|
|
|
|
// *) Definitely has a size
|
2020-02-09 11:51:58 +00:00
|
|
|
// *) Probably 'peek'able (although you might not like the answer you get!)
|
2018-11-04 16:38:57 +00:00
|
|
|
// *) Probably 'load'able (i.e. able to be externally initialised)
|
|
|
|
// *) At the implementation level, probably 'poke'able (although may not be exposed to users)
|
|
|
|
// *) Possibly 'reference'able (Very likely if you've exposed 'poke')
|
|
|
|
class Memory {
|
2017-06-04 20:38:34 +00:00
|
|
|
public:
|
2018-11-04 16:38:57 +00:00
|
|
|
virtual ~Memory() = default;
|
2017-07-06 20:32:52 +00:00
|
|
|
|
2018-11-29 00:09:40 +00:00
|
|
|
[[nodiscard]] virtual size_t size() const = 0;
|
|
|
|
[[nodiscard]] virtual uint8_t peek(uint16_t address) const = 0;
|
2017-09-14 14:00:57 +00:00
|
|
|
|
2018-11-29 00:09:40 +00:00
|
|
|
[[nodiscard]] virtual uint8_t& reference(uint16_t);
|
2017-12-26 22:46:16 +00:00
|
|
|
|
2018-11-04 16:38:57 +00:00
|
|
|
virtual int load(std::ifstream& file, int writeOffset = 0, int readOffset = 0, int limit = -1) = 0;
|
2020-11-07 09:41:12 +00:00
|
|
|
virtual int load(std::string path, int writeOffset = 0, int readOffset = 0, int limit = -1) = 0;
|
2018-11-04 16:38:57 +00:00
|
|
|
virtual int load(const std::vector<uint8_t>& bytes, int writeOffset = 0, int readOffset = 0, int limit = -1) = 0;
|
2017-12-26 22:46:16 +00:00
|
|
|
|
2018-11-04 16:38:57 +00:00
|
|
|
protected:
|
|
|
|
virtual void poke(uint16_t address, uint8_t value) = 0;
|
2017-06-04 20:38:34 +00:00
|
|
|
};
|
2017-11-30 23:19:17 +00:00
|
|
|
}
|