Finished implentation of devices and added Opcode class
This commit is contained in:
parent
9cc0c10e35
commit
3f39c6cb71
78 changed files with 262 additions and 90 deletions
|
|
@ -1,5 +1,58 @@
|
|||
#include "device.h"
|
||||
using namespace std;
|
||||
|
||||
Device::Device() {
|
||||
bool Device::test() { return true; }
|
||||
|
||||
unsigned char Device::read() { return 0; }
|
||||
|
||||
void Device::write(unsigned char) {}
|
||||
|
||||
|
||||
InputDevice::InputDevice(istream& in) {
|
||||
input = ∈
|
||||
}
|
||||
|
||||
unsigned char InputDevice::read() {
|
||||
char c;
|
||||
if (input->get(c)) {
|
||||
return static_cast<unsigned char>(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
OutputDevice::OutputDevice(ostream& out) {
|
||||
output = &out;
|
||||
}
|
||||
|
||||
void OutputDevice::write(unsigned char c) {
|
||||
output->put(static_cast<char>(c));
|
||||
output->flush();
|
||||
}
|
||||
|
||||
FileDevice::FileDevice(string& filename) {
|
||||
file.open(filename, ios::in | ios::out | ios::binary);
|
||||
if (!file.is_open()) {
|
||||
// ustvari datoteko
|
||||
file.clear();
|
||||
file.open(filename, ios::out | ios::binary);
|
||||
file.close();
|
||||
file.open(filename, ios::in | ios::out | ios::binary);
|
||||
}
|
||||
}
|
||||
|
||||
bool FileDevice::test() {
|
||||
return file.is_open();
|
||||
}
|
||||
|
||||
unsigned char FileDevice::read() {
|
||||
char c;
|
||||
if (file.get(c)) {
|
||||
return static_cast<unsigned char>(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FileDevice::write(unsigned char c) {
|
||||
file.put(static_cast<char>(c));
|
||||
file.flush();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue