forked from kstenerud/Musashi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperipheralBase.h
50 lines (42 loc) · 1.29 KB
/
peripheralBase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#include <cstdint>
#include <cstddef>
#include <array>
#include "peripheralTypes.h"
namespace mc68k
{
void periphBaseWriteW(uint8_t* _buffer, uint32_t _addr, uint16_t _val);
uint16_t periphBaseReadW(const uint8_t* _buffer, uint32_t _addr);
template<uint32_t Base, uint32_t Size>
class PeripheralBase
{
public:
explicit PeripheralBase() : m_buffer{0} {}
virtual ~PeripheralBase() = default;
constexpr bool isInRange(PeriphAddress _addr) const
{
return static_cast<uint32_t>(_addr) >= Base && static_cast<uint32_t>(_addr) < (Base + m_buffer.size());
}
virtual uint8_t read8(PeriphAddress _addr)
{
return m_buffer[static_cast<uint32_t>(_addr) - Base];
}
virtual uint16_t read16(PeriphAddress _addr)
{
return periphBaseReadW(m_buffer.data(), static_cast<uint32_t>(_addr) - Base);
}
virtual void write8(PeriphAddress _addr, uint8_t _val)
{
m_buffer[static_cast<uint32_t>(_addr) - Base] = _val;
}
virtual void write16(PeriphAddress _addr, uint16_t _val)
{
return periphBaseWriteW(m_buffer.data(), static_cast<uint32_t>(_addr) - Base, _val);
}
virtual void exec(uint32_t _deltaCycles) {}
static constexpr uint32_t base() { return Base; }
static constexpr uint32_t size() { return Size; }
private:
std::array<uint8_t, Size> m_buffer;
};
}