ComSquare
Ram.hpp
Go to the documentation of this file.
1 //
2 // Created by anonymus-raccoon on 1/28/20.
3 //
4 
5 #pragma once
6 
8 #include <string>
9 #include <span>
10 #include <vector>
11 
12 namespace ComSquare::Ram
13 {
15  {
16  protected:
18  std::vector<uint8_t> _data;
22  std::string _ramName;
23  public:
25  explicit Ram(size_t size, Component, std::string ramName);
27  Ram(const Ram &) = delete;
29  Ram &operator=(Ram &) = delete;
31  ~Ram() override = default;
32 
37  uint8_t read(uint24_t addr) override;
42  void write(uint24_t addr, uint8_t data) override;
43 
47  uint8_t &operator[](uint24_t addr);
51  const uint8_t &operator[](uint24_t addr) const;
52 
54  [[nodiscard]] std::string getName() const override;
55 
57  [[nodiscard]] Component getComponent() const override;
58 
60  [[nodiscard]] uint24_t getSize() const override;
61 
64  void setSize(uint24_t size);
65 
68  [[nodiscard]] std::span<uint8_t> getData();
69 
72  [[nodiscard]] std::span<const uint8_t> getData() const;
73  };
74 }
ComSquare::Ram::Ram
Definition: Ram.hpp:14
ComSquare::Ram
Definition: Ram.cpp:10
ComSquare::Component
Component
Definition: Components.hpp:9
ComSquare::Ram::Ram::~Ram
~Ram() override=default
Destructor that free the ram.
ComSquare::Memory::ARectangleMemory
Base memory class to map non continuous rectangle to the memory. (A rectangle that spam across more t...
Definition: ARectangleMemory.hpp:13
ComSquare::Ram::Ram::getData
std::span< uint8_t > getData()
Get the raw data of the RAM.
Definition: Ram.cpp:63
uint24_t
unsigned uint24_t
Definition: Ints.hpp:10
ARectangleMemory.hpp
ComSquare::Ram::Ram::_data
std::vector< uint8_t > _data
The ram. (Can be used for WRam, SRam, VRam etc)
Definition: Ram.hpp:18
ComSquare::Ram::Ram::getName
std::string getName() const override
Get the name of this accessor (used for debug purpose)
Definition: Ram.cpp:53
ComSquare::Ram::Ram::_ramType
Component _ramType
An id identifying the type of memory this is (for the debugger)
Definition: Ram.hpp:20
ComSquare::Ram::Ram::getComponent
Component getComponent() const override
Get the component of this accessor (used for debug purpose)
Definition: Ram.cpp:58
ComSquare::Ram::Ram::setSize
void setSize(uint24_t size)
Change the size of this ram.
Definition: Ram.cpp:48
ComSquare::Ram::Ram::getSize
uint24_t getSize() const override
Get the size of the ram in bytes.
Definition: Ram.cpp:43
ComSquare::Ram::Ram::operator[]
uint8_t & operator[](uint24_t addr)
Retrieve the data at the address given. This can be used instead of read or write.
Definition: Ram.cpp:18
ComSquare::Ram::Ram::operator=
Ram & operator=(Ram &)=delete
The ram can't be assigned.
ComSquare::Ram::Ram::_ramName
std::string _ramName
The name of this ram.
Definition: Ram.hpp:22
ComSquare::Ram::Ram::write
void write(uint24_t addr, uint8_t data) override
Write data to this component.
Definition: Ram.cpp:36
ComSquare::Ram::Ram::Ram
Ram(size_t size, Component, std::string ramName)
Create a ram of a given size in bytes.
Definition: Ram.cpp:12
ComSquare::Ram::Ram::read
uint8_t read(uint24_t addr) override
Read data from the component.
Definition: Ram.cpp:28