MIXAL
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mixal::IODevice Class Referenceabstract

#include <io.h>

Inheritance diagram for mixal::IODevice:
mixal::IODeviceStorage mixal::IODeviceDisk mixal::IODeviceSeqReader mixal::IODeviceSeqWriter mixal::IODeviceTape mixal::IODeviceCardReader mixal::IODevicePaperTape mixal::IODeviceTypewriter mixal::IODeviceCardPunch mixal::IODeviceLinePrinter

Public Member Functions

 IODevice (int32_t blockSize, bool allowRead, bool allowWrite)
 
IODeviceType type () const
 
int blockSize () const
 
bool allowRead () const
 
bool allowWrite () const
 
virtual bool ready (int32_t elapsed)
 
virtual void control (int32_t)
 
virtual void read (ComputerWord *memory, int32_t address)=0
 
virtual void write (const ComputerWord *memory, int32_t address)=0
 
virtual ComputerWordwordAt (int32_t index)=0
 

Protected Member Functions

virtual void doRead ()=0
 
virtual void doWrite ()=0
 

Protected Attributes

IODeviceType _type
 
int32_t _blockSize
 
bool _allowRead
 
bool _allowWrite
 
int32_t _timestamp
 
double _readyRate
 

Detailed Description

The IO device.

Once read or write, the device will not be ready immediately. The reading or writing operation is saved, the actual reading or writing is performed only when the device is explicitly being queried.

Definition at line 40 of file io.h.

Constructor & Destructor Documentation

◆ IODevice()

mixal::IODevice::IODevice ( int32_t  blockSize,
bool  allowRead,
bool  allowWrite 
)

Initialize an IO device.

Parameters
blockSizeThe number of bytes in one reading or writing.
allowReadWhether the device can be read.
allowWriteWhether the device can be wrote.

Definition at line 10 of file io.cpp.

10  : _type(IODeviceType::TAPE),
12  _timestamp(), _readyRate(1.0) {}

Member Function Documentation

◆ allowRead()

bool mixal::IODevice::allowRead ( ) const
inline

Whether the device can be read.

Definition at line 56 of file io.h.

56 { return _allowRead; }

References _allowRead.

◆ allowWrite()

bool mixal::IODevice::allowWrite ( ) const
inline

Whether the device can be wrote.

Definition at line 58 of file io.h.

58 { return _allowWrite; }

References _allowWrite.

◆ blockSize()

int mixal::IODevice::blockSize ( ) const
inline

The number of bytes in one reading or writing.

Definition at line 54 of file io.h.

54 { return _blockSize; }

References _blockSize.

◆ control()

virtual void mixal::IODevice::control ( int32_t  )
inlinevirtual

Special control of the device.

Reimplemented in mixal::IODevicePaperTape, mixal::IODeviceLinePrinter, mixal::IODeviceDisk, and mixal::IODeviceTape.

Definition at line 63 of file io.h.

63 {}

◆ doRead()

virtual void mixal::IODevice::doRead ( )
protectedpure virtual

Perform the actual reading.

Implemented in mixal::IODeviceStorage.

◆ doWrite()

virtual void mixal::IODevice::doWrite ( )
protectedpure virtual

Perform the actual writing.

Implemented in mixal::IODeviceStorage.

◆ read()

virtual void mixal::IODevice::read ( ComputerWord memory,
int32_t  address 
)
pure virtual

Read one block from the device.

Implemented in mixal::IODeviceStorage.

◆ ready()

bool mixal::IODevice::ready ( int32_t  elapsed)
virtual

Whether the device is ready for reading or writing.

Reimplemented in mixal::IODeviceStorage.

Definition at line 14 of file io.cpp.

14  {
15  int32_t elapsed = std::max(0, timestamp - _timestamp);
16  _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;
20 }

References _readyRate, and _timestamp.

Referenced by mixal::IODeviceStorage::ready(), and mixal::Computer::waitDevice().

◆ type()

IODeviceType mixal::IODevice::type ( ) const
inline

Get the type of the IO device.

Definition at line 52 of file io.h.

52 { return _type; }

References _type.

◆ wordAt()

virtual ComputerWord& mixal::IODevice::wordAt ( int32_t  index)
pure virtual

Get a word from the storage of the device.

Implemented in mixal::IODeviceStorage.

Referenced by mixal::Computer::getDeviceWordAt().

◆ write()

virtual void mixal::IODevice::write ( const ComputerWord memory,
int32_t  address 
)
pure virtual

Write one block to the device.

Implemented in mixal::IODeviceStorage.

Member Data Documentation

◆ _allowRead

bool mixal::IODevice::_allowRead
protected

Whether the device can be read.

Definition at line 75 of file io.h.

Referenced by allowRead().

◆ _allowWrite

bool mixal::IODevice::_allowWrite
protected

Whether the device can be wrote.

Definition at line 76 of file io.h.

Referenced by allowWrite().

◆ _blockSize

int32_t mixal::IODevice::_blockSize
protected

◆ _readyRate

double mixal::IODevice::_readyRate
protected

The rate that the device could be ready in one unit time.

Definition at line 78 of file io.h.

Referenced by ready().

◆ _timestamp

int32_t mixal::IODevice::_timestamp
protected

The latest time that the device being triggered.

Definition at line 77 of file io.h.

Referenced by mixal::IODeviceStorage::read(), and ready().

◆ _type

IODeviceType mixal::IODevice::_type
protected

The type of the IO device.

Definition at line 73 of file io.h.

Referenced by type().


The documentation for this class was generated from the following files:
mixal::IODevice::blockSize
int blockSize() const
Definition: io.h:54
mixal::IODevice::allowWrite
bool allowWrite() const
Definition: io.h:58
mixal::IODevice::_allowWrite
bool _allowWrite
Definition: io.h:76
mixal::IODevice::_blockSize
int32_t _blockSize
Definition: io.h:74
mixal::IODevice::_timestamp
int32_t _timestamp
Definition: io.h:77
mixal::IODevice::_readyRate
double _readyRate
Definition: io.h:78
mixal::IODevice::allowRead
bool allowRead() const
Definition: io.h:56
mixal::IODevice::_allowRead
bool _allowRead
Definition: io.h:75
mixal::IODevice::_type
IODeviceType _type
Definition: io.h:73