forked from kstenerud/Musashi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport.cpp
51 lines (44 loc) · 1.24 KB
/
port.cpp
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
#include "port.h"
namespace mc68k
{
Port::Port()
: m_dirChangeCallback([](const Port&){})
, m_writeTXCallback([](const Port&) {})
, m_readRXCallback([](const Port& , uint8_t _c) { return _c; })
{
}
void Port::writeTX(const uint8_t _data)
{
// only write pins that are enabled and that are set to output
const auto mask = m_direction & m_enabledPins;
m_data &= ~mask;
m_data |= _data & mask;
++m_writeCounter;
m_writeTXCallback(*this);
}
void Port::writeRX(const uint8_t _data)
{
// only write pins that are enabled and that are set to input
const auto mask = (~m_direction) & m_enabledPins;
m_data &= ~mask;
m_data |= _data & mask;
}
void Port::setDirectionChangeCallback(const std::function<void(const Port&)>& _func)
{
m_dirChangeCallback = _func;
if(!m_dirChangeCallback)
m_dirChangeCallback = [](const Port&){};
}
void Port::setWriteTXCallback(const std::function<void(const Port&)>& _func)
{
m_writeTXCallback = _func;
if(!m_writeTXCallback)
m_writeTXCallback = [](const Port&){};
}
void Port::setReadRXCallback(const std::function<uint8_t(const Port&, uint8_t)>& _func)
{
m_readRXCallback = _func;
if(!m_readRXCallback)
m_readRXCallback = [](const Port&, const uint8_t _c) { return _c; };
}
}