-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_aggregator.cpp
70 lines (42 loc) · 1.84 KB
/
device_aggregator.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "device_aggregator.h"
DeviceAggregator::DeviceAggregator() {
this->_AggregatedDevices = new std::list<Device*>();
}
DeviceAggregator::~DeviceAggregator() {
for(auto iter = this->_AggregatedDevices->begin(); iter != this->_AggregatedDevices->end(); iter++)
delete *iter;
delete this->_AggregatedDevices;
}
bool DeviceAggregator::GetInitOk() {
if (!this->_InitOk)
return false;
for (auto iter = this->_AggregatedDevices->begin(); iter != this->_AggregatedDevices->end(); iter++)
if (!(*iter)->GetInitOk())
return false;
return true;
}
void DeviceAggregator::_InstallDevice(Device* device) {
this->_AggregatedDevices->push_back(device);
}
bool DeviceAggregator::Refresh(word32 timestamp) {
auto enter_debugger = this->_SelfRefresh(timestamp);
for(auto iter = this->_AggregatedDevices->begin(); iter != this->_AggregatedDevices->end(); iter++)
enter_debugger = enter_debugger || (*iter)->Refresh(timestamp);
return enter_debugger;
}
bool DeviceAggregator::TryReadByte(word32 address, word32 timestamp, word32 emulFlags, byte &b) {
auto read = this->Device::TryReadByte(address, timestamp, emulFlags, b);
auto out_b = b;
for(auto iter = this->_AggregatedDevices->begin(); iter != this->_AggregatedDevices->end(); iter++) {
read = (*iter)->TryReadByte(address, timestamp, emulFlags, b) || read;
out_b &= b; //Kinda-sorta simulate bus contention (failed reads default to 0xFF 'all pulled up', and devices responding on the bus pull zeroed lines to ground)
}
b = out_b;
return read;
}
bool DeviceAggregator::TryWriteByte(word32 address, word32 timestamp, byte b) {
auto written = this->Device::TryWriteByte(address, timestamp, b);
for(auto iter = this->_AggregatedDevices->begin(); iter != this->_AggregatedDevices->end(); iter++)
written = written || (*iter)->TryWriteByte(address, timestamp, b);
return written;
}