37 std::function<void(
bool waiting)>
idle;
51 virtual uint8_t
ReadByte(uint32_t address)
const = 0;
52 virtual uint16_t
ReadWord(uint32_t address)
const = 0;
55 uint16_t length)
const = 0;
57 virtual void WriteByte(uint32_t address, uint8_t value) = 0;
58 virtual void WriteWord(uint32_t address, uint16_t value) = 0;
59 virtual void WriteLong(uint32_t address, uint32_t value) = 0;
68 virtual uint16_t
SP()
const = 0;
69 virtual void SetSP(uint16_t value) = 0;
74 virtual uint8_t
at(
int i)
const = 0;
90 virtual auto h_pos() const -> uint16_t = 0;
91 virtual auto
v_pos() const -> uint16_t = 0;
104 void Initialize(
const std::vector<uint8_t>& romData,
bool verbose =
false);
108 switch (memory_[(0x00 << 16) + 0xFFD5] & 0x07) {
119 throw std::invalid_argument(
120 "Unable to locate supported ROM mapping mode in the provided ROM "
121 "file. Please try another ROM file.");
127 uint8_t cart_read(uint8_t bank, uint16_t adr);
128 void cart_write(uint8_t bank, uint16_t adr, uint8_t val);
130 uint8_t cart_readLorom(uint8_t bank, uint16_t adr);
131 void cart_writeLorom(uint8_t bank, uint16_t adr, uint8_t val);
133 uint8_t cart_readHirom(uint8_t bank, uint16_t adr);
134 uint8_t cart_readExHirom(uint8_t bank, uint16_t adr);
136 void cart_writeHirom(uint8_t bank, uint16_t adr, uint8_t val);
138 uint8_t
ReadByte(uint32_t address)
const override {
139 uint32_t mapped_address = GetMappedAddress(address);
140 return memory_.at(mapped_address);
142 uint16_t
ReadWord(uint32_t address)
const override {
143 uint32_t mapped_address = GetMappedAddress(address);
144 return static_cast<uint16_t
>(memory_.at(mapped_address)) |
145 (
static_cast<uint16_t
>(memory_.at(mapped_address + 1)) << 8);
148 uint32_t mapped_address = GetMappedAddress(address);
149 return static_cast<uint32_t
>(memory_.at(mapped_address)) |
150 (
static_cast<uint32_t
>(memory_.at(mapped_address + 1)) << 8) |
151 (
static_cast<uint32_t
>(memory_.at(mapped_address + 2)) << 16);
154 uint16_t length)
const override {
155 uint32_t mapped_address = GetMappedAddress(address);
156 return std::vector<uint8_t>(memory_.begin() + mapped_address,
157 memory_.begin() + mapped_address + length);
160 void WriteByte(uint32_t address, uint8_t value)
override {
161 uint32_t mapped_address = GetMappedAddress(address);
162 memory_[mapped_address] = value;
164 void WriteWord(uint32_t address, uint16_t value)
override {
165 uint32_t mapped_address = GetMappedAddress(address);
166 memory_.at(mapped_address) = value & 0xFF;
167 memory_.at(mapped_address + 1) = (value >> 8) & 0xFF;
169 void WriteLong(uint32_t address, uint32_t value)
override {
170 uint32_t mapped_address = GetMappedAddress(address);
171 memory_.at(mapped_address) = value & 0xFF;
172 memory_.at(mapped_address + 1) = (value >> 8) & 0xFF;
173 memory_.at(mapped_address + 2) = (value >> 16) & 0xFF;
179 memory_.at(SP_--) = value;
182 std::cout <<
"Stack underflow!" << std::endl;
183 throw std::runtime_error(
"Stack underflow!");
189 return memory_.at(++SP_);
192 std::cout <<
"Stack overflow!" << std::endl;
193 throw std::runtime_error(
"Stack overflow!");
205 return (
static_cast<uint16_t
>(high) << 8) | low;
218 return (
static_cast<uint32_t
>(high) << 16) |
219 (
static_cast<uint32_t
>(mid) << 8) | low;
223 uint16_t
SP()
const override {
return SP_; }
225 void SetSP(uint16_t value)
override { SP_ = value; }
226 void ClearMemory()
override { std::fill(memory_.begin(), memory_.end(), 0); }
228 uint8_t
at(
int i)
const override {
return memory_[i]; }
230 if (i > memory_.size()) {
231 std::cout << i <<
" out of bounds \n";
237 auto size()
const {
return memory_.size(); }
238 auto begin()
const {
return memory_.begin(); }
239 auto end()
const {
return memory_.end(); }
240 auto data()
const {
return memory_.data(); }
242 auto open_bus() const -> uint8_t
override {
return open_bus_; }
244 return hdma_init_requested_;
247 return hdma_run_requested_;
252 hdma_run_requested_ = value;
255 hdma_init_requested_ = value;
258 void set_h_pos(uint16_t value)
override { h_pos_ = value; }
259 void set_v_pos(uint16_t value)
override { v_pos_ = value; }
260 auto h_pos() const -> uint16_t
override {
return h_pos_; }
261 auto v_pos() const -> uint16_t
override {
return v_pos_; }
262 auto pal_timing() const ->
bool override {
return pal_timing_; }
273 uint32_t GetMappedAddress(uint32_t address)
const;
275 bool verbose_ =
false;
278 bool hdma_run_requested_ =
false;
279 bool hdma_init_requested_ =
false;
281 bool pal_timing_ =
false;
292 uint8_t dma_state_ = 0;
295 uint8_t open_bus_ = 0;
Implementation of the Memory interface for emulating memory in a SNES system.
uint32_t ReadWordLong(uint32_t address) const override
std::vector< uint8_t > memory_
auto mutable_sp() -> uint16_t &
void WriteWord(uint32_t address, uint16_t value) override
void WriteLong(uint32_t address, uint32_t value) override
uint16_t PopWord() override
auto v_pos() const -> uint16_t override
void set_dma_state(uint8_t value)
auto dma_channels() -> DmaChannel *
void set_h_pos(uint16_t value) override
void PushWord(uint16_t value) override
std::vector< uint8_t > ReadByteVector(uint32_t address, uint16_t length) const override
void set_open_bus(uint8_t value) override
auto h_pos() const -> uint16_t override
void init_hdma_request() override
uint8_t at(int i) const override
void run_hdma_request() override
uint8_t ReadByte(uint32_t address) const override
std::vector< uint8_t > rom_
auto hdma_run_requested() const -> bool override
uint16_t SP() const override
void ClearMemory() override
void set_hdma_run_requested(bool value) override
void PushLong(uint32_t value) override
void SetSP(uint16_t value) override
void set_pal_timing(bool value) override
auto dma_state() -> uint8_t &
void WriteByte(uint32_t address, uint8_t value) override
auto open_bus() const -> uint8_t override
void set_v_pos(uint16_t value) override
std::vector< uint8_t > ram_
uint8_t PopByte() override
uint32_t PopLong() override
void set_hdma_init_requested(bool value) override
uint16_t GetHeaderOffset()
uint16_t ReadWord(uint32_t address) const override
auto pal_timing() const -> bool override
void PushByte(uint8_t value) override
auto hdma_init_requested() const -> bool override
uint8_t operator[](int i) const override
virtual std::vector< uint8_t > ReadByteVector(uint32_t address, uint16_t length) const =0
virtual void PushLong(uint32_t value)=0
virtual void WriteLong(uint32_t address, uint32_t value)=0
virtual void set_pal_timing(bool value)=0
virtual void PushByte(uint8_t value)=0
virtual uint16_t SP() const =0
virtual void set_v_pos(uint16_t value)=0
virtual void SetSP(uint16_t value)=0
virtual void PushWord(uint16_t value)=0
virtual auto v_pos() const -> uint16_t=0
virtual void WriteByte(uint32_t address, uint8_t value)=0
virtual uint8_t operator[](int i) const =0
virtual void set_hdma_run_requested(bool value)=0
virtual uint8_t at(int i) const =0
virtual uint8_t open_bus() const =0
virtual void WriteWord(uint32_t address, uint16_t value)=0
virtual void set_h_pos(uint16_t value)=0
virtual void run_hdma_request()=0
virtual bool hdma_run_requested() const =0
virtual uint8_t ReadByte(uint32_t address) const =0
virtual auto h_pos() const -> uint16_t=0
virtual void set_hdma_init_requested(bool value)=0
virtual uint32_t PopLong()=0
virtual uint16_t ReadWord(uint32_t address) const =0
virtual uint32_t ReadWordLong(uint32_t address) const =0
virtual void init_hdma_request()=0
virtual uint8_t PopByte()=0
virtual uint16_t PopWord()=0
virtual void ClearMemory()=0
virtual auto pal_timing() const -> bool=0
virtual void set_open_bus(uint8_t value)=0
virtual bool hdma_init_requested() const =0
virtual ~Memory()=default
constexpr uint32_t kROMSize
constexpr uint32_t kRAMSize
struct yaze::app::emu::memory::CpuCallbacks CpuCallbacks
constexpr uint32_t kROMStart
constexpr uint32_t kRAMStart
std::function< uint8_t(uint32_t)> read_byte
std::function< void(bool waiting)> idle
std::function< void(uint32_t, uint8_t)> write_byte