forked from kstenerud/Musashi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
port.h
73 lines (59 loc) · 1.38 KB
/
port.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
#pragma once
#include <cstdint>
#include <functional>
namespace mc68k
{
class Port
{
public:
Port();
uint8_t getDirection() const
{
return m_direction;
}
void setDirection(const uint8_t _dir)
{
if(m_direction == _dir)
return;
m_direction = _dir;
m_dirChangeCallback(*this);
}
void writeTX(uint8_t _data);
void writeRX(uint8_t _data);
uint8_t read() const
{
return m_readRXCallback(*this, m_data);
}
void enablePins(uint8_t _pins)
{
m_enabledPins = _pins;
}
uint32_t getWriteCounter() const
{
return m_writeCounter;
}
uint8_t bittest(uint32_t _bit) const
{
return read() & (1<<_bit);
}
void setBitRX(uint32_t _bit)
{
writeRX(read() | static_cast<uint8_t>(1 << _bit));
}
void clearBitRX(uint32_t _bit)
{
writeRX(read() & ~(1<<_bit));
}
void setDirectionChangeCallback(const std::function<void(const Port&)>& _func);
void setWriteTXCallback(const std::function<void(const Port&)>& _func);
void setReadRXCallback(const std::function<uint8_t(const Port&, uint8_t)>& _func);
private:
uint8_t m_direction = 0; // 0 = input, 1 = output
uint8_t m_enabledPins = 0xff;
uint8_t m_data = 0;
uint32_t m_writeCounter = 0;
std::function<void(const Port&)> m_dirChangeCallback;
std::function<void(const Port&)> m_writeTXCallback;
std::function<uint8_t(const Port&, uint8_t)> m_readRXCallback;
};
}