bus: send a weak ptr to io
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
@@ -2,41 +2,51 @@
|
||||
|
||||
#include "header.hh"
|
||||
#include "io/io.hh"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace matar {
|
||||
class Bus {
|
||||
private:
|
||||
struct Private {
|
||||
explicit Private() = default;
|
||||
};
|
||||
|
||||
public:
|
||||
static constexpr uint32_t BIOS_SIZE = 1024 * 16;
|
||||
Bus(std::array<uint8_t, BIOS_SIZE>&& bios, std::vector<uint8_t>&& rom);
|
||||
|
||||
uint8_t read_byte(uint32_t address);
|
||||
void write_byte(uint32_t address, uint8_t byte);
|
||||
Bus(Private, std::array<uint8_t, BIOS_SIZE>&&, std::vector<uint8_t>&&);
|
||||
|
||||
uint16_t read_halfword(uint32_t address);
|
||||
void write_halfword(uint32_t address, uint16_t halfword);
|
||||
static std::shared_ptr<Bus> init(std::array<uint8_t, BIOS_SIZE>&&,
|
||||
std::vector<uint8_t>&&);
|
||||
|
||||
uint32_t read_word(uint32_t address);
|
||||
void write_word(uint32_t address, uint32_t word);
|
||||
uint8_t read_byte(uint32_t);
|
||||
void write_byte(uint32_t, uint8_t);
|
||||
|
||||
uint16_t read_halfword(uint32_t);
|
||||
void write_halfword(uint32_t, uint16_t);
|
||||
|
||||
uint32_t read_word(uint32_t);
|
||||
void write_word(uint32_t, uint32_t);
|
||||
|
||||
private:
|
||||
template<unsigned int N>
|
||||
std::optional<std::span<const uint8_t>> read(uint32_t address) const;
|
||||
template<unsigned int>
|
||||
std::optional<std::span<const uint8_t>> read(uint32_t) const;
|
||||
|
||||
template<unsigned int N>
|
||||
std::optional<std::span<uint8_t>> write(uint32_t address);
|
||||
template<unsigned int>
|
||||
std::optional<std::span<uint8_t>> write(uint32_t);
|
||||
|
||||
#define MEMORY_REGION(name, start) \
|
||||
static constexpr uint32_t name##_START = start;
|
||||
|
||||
#define DECL_MEMORY(name, ident, start, end) \
|
||||
MEMORY_REGION(name, start) \
|
||||
std::array<uint8_t, end - start + 1> ident;
|
||||
std::array<uint8_t, end - start + 1> ident = {};
|
||||
|
||||
MEMORY_REGION(BIOS, 0x00000000)
|
||||
std::array<uint8_t, BIOS_SIZE> bios;
|
||||
std::array<uint8_t, BIOS_SIZE> bios = {};
|
||||
|
||||
// board working RAM
|
||||
DECL_MEMORY(BOARD_WRAM, board_wram, 0x02000000, 0x0203FFFF)
|
||||
@@ -61,9 +71,10 @@ class Bus {
|
||||
|
||||
#undef MEMORY_REGION
|
||||
std::vector<uint8_t> rom;
|
||||
|
||||
std::unique_ptr<IoDevices> io;
|
||||
|
||||
Header header;
|
||||
void parse_header();
|
||||
|
||||
IoDevices io;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user