#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; };