From a66c7433c2c11b8b6c99142277ed4e16b1a2a465 Mon Sep 17 00:00:00 2001 From: 0x221E <0x221E@0xinfinity.dev> Date: Sun, 12 Apr 2026 16:59:40 +0200 Subject: initial commit --- src/Bus.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/Bus.h (limited to 'src/Bus.h') diff --git a/src/Bus.h b/src/Bus.h new file mode 100644 index 0000000..d55ee4f --- /dev/null +++ b/src/Bus.h @@ -0,0 +1,65 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "RAM.h" + +#include "Exceptions.h" + +class Bus { +public: + Bus(std::shared_ptr m_Bus); + ~Bus() = default; + +public: + template + void WriteX(uint64_t address, T value) + { + static_assert(std::is_unsigned_v, "T must be an unsigned int of any size smaller than 8 bytes!"); + + // std::cout << "Bus write: " << std::hex << address << std::endl; + + switch(address) + { + case 0x00008000 ... 0x000FFFFF: + { + uint64_t offset = address - 0x00008000; + std::memcpy(&m_RAM->Data()[offset], &value, sizeof(T)); + break; + } + default: + std::string exception = "Illegal access to: " + std::to_string(address); + throw CPUException(exception); + } + } + + template + T AccessX(uint64_t address) + { + static_assert(std::is_unsigned_v, "T must be an unsigned int of any size smaller than 8 bytes!"); + + //std::cout << "Bus access: " << std::hex << address << std::endl; + + switch(address) + { + case 0x00008000 ... 0x000FFFFF: + { + uint64_t offset = address - 0x00008000; + T value; + std::memcpy(&value, &m_RAM->Data()[offset], sizeof(T)); + return value; + } + default: + std::string exception = "Illegal access to: " + std::to_string(address); + throw std::runtime_error(exception); + } + } + +private: + std::shared_ptr m_RAM; +}; -- cgit v1.2.3