ComSquare
MemoryBus.hpp
Go to the documentation of this file.
1 //
2 // Created by anonymus-raccoon on 1/23/20.
3 //
4 
5 #pragma once
6 
7 #include "AMemory.hpp"
8 #include "RectangleShadow.hpp"
9 #include "MemoryShadow.hpp"
10 #include "IMemoryBus.hpp"
11 #include <cstdint>
12 #include <memory>
13 #include <vector>
14 
15 namespace ComSquare
16 {
17  class SNES;
18 
19  namespace Memory
20  {
22  class MemoryBus : public IMemoryBus
23  {
24  private:
26  std::vector<std::reference_wrapper<IMemory>> _memoryAccessors;
27 
29  std::vector<MemoryShadow> _shadows = {};
31  std::vector<RectangleShadow> _rectangleShadows = {};
32 
36  void _mirrorComponents(SNES &console, unsigned i);
37  protected:
39  uint8_t _openBus = 0;
40  public:
42  MemoryBus() = default;
44  MemoryBus(const MemoryBus &) = default;
46  MemoryBus &operator=(const MemoryBus &) = default;
48  ~MemoryBus() override = default;
49 
54  uint8_t read(uint24_t addr) override;
55 
59  std::optional<uint8_t> peek(uint24_t addr) override;
60 
65  uint8_t peek_v(uint24_t addr) override;
66 
70  void write(uint24_t addr, uint8_t data) override;
71 
74  void mapComponents(SNES &console);
75 
79  IMemory *getAccessor(uint24_t addr) override;
80  };
81  }
82 }
ComSquare::Memory::MemoryBus::_rectangleShadows
std::vector< RectangleShadow > _rectangleShadows
The list of rectangle memory shadows that are used to map duplicated zones of memory.
Definition: MemoryBus.hpp:31
ComSquare::Memory::MemoryBus::read
uint8_t read(uint24_t addr) override
Read data at a global address. This form allow read to be silenced.
Definition: MemoryBus.cpp:25
ComSquare::Memory::MemoryBus
The memory bus is the component responsible of mapping addresses to components address and transmitti...
Definition: MemoryBus.hpp:22
ComSquare::Memory::MemoryBus::_openBus
uint8_t _openBus
The last value read via the memory bus.
Definition: MemoryBus.hpp:39
ComSquare::Memory::MemoryBus::peek
std::optional< uint8_t > peek(uint24_t addr) override
This as the same purpose as a read but it does not change the open bus and won't throw an exception.
Definition: MemoryBus.cpp:39
ComSquare::Memory::MemoryBus::_shadows
std::vector< MemoryShadow > _shadows
The list of simple memory shadows that are used to map duplicated zones of memory.
Definition: MemoryBus.hpp:29
ComSquare::Memory::MemoryBus::_memoryAccessors
std::vector< std::reference_wrapper< IMemory > > _memoryAccessors
The list of components registered inside the bus. Every components that can read/write to a public ad...
Definition: MemoryBus.hpp:26
ComSquare::Memory::MemoryBus::peek_v
uint8_t peek_v(uint24_t addr) override
This as the same purpose as a read but it does not change the open bus and won't throw an exception.
Definition: MemoryBus.cpp:52
ComSquare::Memory::MemoryBus::operator=
MemoryBus & operator=(const MemoryBus &)=default
A memory bus is assignable.
AMemory.hpp
uint24_t
unsigned uint24_t
Definition: Ints.hpp:10
ComSquare::Memory::MemoryBus::MemoryBus
MemoryBus()=default
Create a new default memory bus.
ComSquare::Memory::IMemory
Common interface implemented by all components mapping memory.
Definition: IMemory.hpp:17
ComSquare::SNES
Container of all the components of the SNES.
Definition: SNES.hpp:32
RectangleShadow.hpp
ComSquare::Memory::IMemoryBus
The memory bus is the component responsible of mapping addresses to components address and transmitti...
Definition: IMemoryBus.hpp:19
ComSquare::Memory::MemoryBus::write
void write(uint24_t addr, uint8_t data) override
Write a data to a global address.
Definition: MemoryBus.cpp:60
ComSquare::Memory::MemoryBus::mapComponents
void mapComponents(SNES &console)
Map components to the address space using the currently loaded cartridge to set the right mapping mod...
Definition: MemoryBus.cpp:79
MemoryShadow.hpp
ComSquare::Memory::MemoryBus::_mirrorComponents
void _mirrorComponents(SNES &console, unsigned i)
WRam, CPU, PPU & APU registers are mirrored to all banks of Q1 & Q3. This function is used for the mi...
Definition: MemoryBus.cpp:71
IMemoryBus.hpp
ComSquare::Memory::MemoryBus::getAccessor
IMemory * getAccessor(uint24_t addr) override
Helper function to get the components that is responsible of read/write at an address.
Definition: MemoryBus.cpp:14
ComSquare
Definition: APU.cpp:12
ComSquare::Memory::MemoryBus::~MemoryBus
~MemoryBus() override=default
A default destructor.