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;
|
||||
};
|
||||
}
|
||||
|
@@ -30,10 +30,10 @@ class Cpu {
|
||||
static constexpr uint8_t GPR_OLD_FIRST = 8;
|
||||
|
||||
std::shared_ptr<Bus> bus;
|
||||
std::array<uint32_t, GPR_COUNT> gpr; // general purpose registers
|
||||
std::array<uint32_t, GPR_COUNT> gpr = {}; // general purpose registers
|
||||
|
||||
Psr cpsr; // current program status register
|
||||
Psr spsr; // status program status register
|
||||
Psr cpsr = {}; // current program status register
|
||||
Psr spsr = {}; // status program status register
|
||||
|
||||
static constexpr uint8_t SP_INDEX = 13;
|
||||
static_assert(SP_INDEX < GPR_COUNT);
|
||||
@@ -56,7 +56,7 @@ class Cpu {
|
||||
|
||||
// visible registers before the mode switch
|
||||
std::array<uint32_t, GPR_COUNT - GPR_OLD_FIRST - 1> old;
|
||||
} gpr_banked; // banked general purpose registers
|
||||
} gpr_banked = {}; // banked general purpose registers
|
||||
|
||||
struct {
|
||||
Psr fiq;
|
||||
|
@@ -2,10 +2,14 @@
|
||||
#include "lcd.hh"
|
||||
#include "sound.hh"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace matar {
|
||||
class Bus;
|
||||
class IoDevices {
|
||||
public:
|
||||
IoDevices(std::weak_ptr<Bus>);
|
||||
|
||||
uint8_t read_byte(uint32_t) const;
|
||||
void write_byte(uint32_t, uint8_t);
|
||||
|
||||
@@ -28,5 +32,7 @@ class IoDevices {
|
||||
|
||||
struct lcd lcd = {};
|
||||
struct sound sound = {};
|
||||
|
||||
std::weak_ptr<Bus> bus;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user