11 _blockSize(blockSize), _allowRead(allowRead), _allowWrite(allowWrite),
12 _timestamp(), _readyRate(1.0) {}
15 int32_t elapsed = std::max(0, timestamp -
_timestamp);
17 double r =
static_cast<double>(rand()) / RAND_MAX;
18 double successRate = 1.0 - pow(1.0 -
_readyRate, elapsed);
19 return r <= successRate;
22 IODeviceStorage::IODeviceStorage(int32_t storageSize) :
IODevice(100, true, true),
23 _status(
IODeviceStatus::READY), _address(0), _locator(0), _memory(nullptr),
24 _buffer(100), _storage(storageSize) {}
29 if (_status == IODeviceStatus::BUSY_READ) {
31 }
else if (_status == IODeviceStatus::BUSY_WRITE) {
39 _status = IODeviceStatus::BUSY_READ;
43 _buffer[i] = _storage[_locator + i];
49 _status = IODeviceStatus::BUSY_WRITE;
51 _buffer[i] = memory[address + i];
58 _memory[_address + i] = _buffer[i];
60 _status = IODeviceStatus::READY;
65 _storage[_locator + i] = _buffer[i];
67 _status = IODeviceStatus::READY;
70 IODeviceTape::IODeviceTape(int32_t storageSize) :
IODeviceStorage(storageSize) {
71 _type = IODeviceType::TAPE;
80 _locator = std::max(0, _locator);
84 void IODeviceTape::doRead() {
89 void IODeviceTape::doWrite() {
94 IODeviceDisk::IODeviceDisk(int32_t storageSize) : IODeviceStorage(storageSize) {
95 _type = IODeviceType::DISK;
100 _locator = operation;
103 IODeviceSeqReader::IODeviceSeqReader(int32_t storageSize) :
IODeviceStorage(storageSize) {
107 void IODeviceSeqReader::doRead() {
112 IODeviceSeqWriter::IODeviceSeqWriter(int32_t storageSize) : IODeviceStorage(storageSize) {
116 void IODeviceSeqWriter::doWrite() {
121 IODeviceCardReader::IODeviceCardReader(int32_t storageSize) : IODeviceSeqReader(storageSize) {
122 _type = IODeviceType::CARD_READER;
127 IODeviceCardPunch::IODeviceCardPunch(int32_t storageSize) : IODeviceSeqWriter(storageSize) {
128 _type = IODeviceType::CARD_PUNCH;
133 IODeviceLinePrinter::IODeviceLinePrinter(int32_t storageSize, int32_t pageSize) :
134 IODeviceSeqWriter(storageSize), _pageSize(pageSize) {
135 _type = IODeviceType::LINE_PRINTER;
150 std::ostringstream out;
152 out << _storage[offset + i].getCharacters();
157 IODeviceTypewriter::IODeviceTypewriter(int32_t storageSize) :
IODeviceSeqReader(storageSize) {
158 _type = IODeviceType::TYPEWRITER;
163 IODevicePaperTape::IODevicePaperTape(int32_t storageSize) : IODeviceSeqReader(storageSize) {
164 _type = IODeviceType::PAPER_TAPE;