diff options
| author | 0x221E <0x221E@0xinfinity.dev> | 2026-04-12 16:59:40 +0200 |
|---|---|---|
| committer | 0x221E <0x221E@0xinfinity.dev> | 2026-04-12 16:59:40 +0200 |
| commit | a66c7433c2c11b8b6c99142277ed4e16b1a2a465 (patch) | |
| tree | e54bcfb59c303acf6118fd11f06d5c0bd5f24e5d /src/Bus.h | |
Diffstat (limited to 'src/Bus.h')
| -rw-r--r-- | src/Bus.h | 65 |
1 files changed, 65 insertions, 0 deletions
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 <iostream> +#include <cstdint> +#include <type_traits> +#include <stdexcept> +#include <cstring> +#include <memory> + +#include "RAM.h" + +#include "Exceptions.h" + +class Bus { +public: + Bus(std::shared_ptr<RAM> m_Bus); + ~Bus() = default; + +public: + template<typename T> + void WriteX(uint64_t address, T value) + { + static_assert(std::is_unsigned_v<T>, "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<typename T> + T AccessX(uint64_t address) + { + static_assert(std::is_unsigned_v<T>, "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<RAM> m_RAM; +}; |
