-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdevice.h
80 lines (64 loc) · 1.47 KB
/
device.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
//
// device.h
//
// (C) R.P.Bellis 2021
//
//
#pragma once
#include <memory>
#include <vector>
#include <functional>
#include "typedefs.h"
/*
* an abstract device that responds to CPU cycle ticks and might be reset
*/
class ActiveDevice {
public:
virtual void reset() = 0;
virtual void tick(uint8_t cycles) = 0;
public:
using shared_ptr = std::shared_ptr<ActiveDevice>;
virtual ~ActiveDevice() {};
};
/*
* an abstract memory mapped device
*/
class MappedDevice {
public:
virtual Byte read(Word offset) = 0;
virtual void write(Word offset, Byte val) = 0;
public:
using shared_ptr = std::shared_ptr<MappedDevice>;
virtual ~MappedDevice() {};
};
/*
* an abstract class combining the above two features
*/
class ActiveMappedDevice : virtual public ActiveDevice, virtual public MappedDevice {
public:
using shared_ptr = std::shared_ptr<ActiveMappedDevice>;
virtual ~ActiveMappedDevice() {};
};
/*
* a container for mapping from memory locations to MappedDevices
*/
struct MappedDeviceEntry {
MappedDevice::shared_ptr device;
Word base;
Word mask;
};
/*
* a container for ActiveDevices {
*/
struct ActiveDeviceEntry {
ActiveDevice::shared_ptr device;
};
typedef std::vector<ActiveDeviceEntry> ActiveDevList;
typedef std::vector<MappedDeviceEntry> MappedDevList;
/*
* template to resolve smart point ambiguity issues
* see https://stackoverflow.com/questions/66032442/
*/
template<int n> struct rank : rank<n - 1> {};
template<> struct rank<0> {};