blob: e1b59ea05652b44ebc0c6c6d0e407932b8f6e3ca (
plain) (
blame)
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
|
#include <array>
#include <cstdint>
#include <iostream>
#include <utility>
#include "io/model.h"
#include "isa/isa.h"
bool iomodel::interact(std::array<unsigned int, NUM_CTLREGS> &ctlregs) {
auto [ebegin, eend] = log.equal_range(time);
for (auto e = ebegin; e != eend; ++e) {
auto &r = ctlregs[e->second.reg];
r &= ~e->second.mask;
r |= e->second.value;
}
++time;
if (ctlregs[TT_BITS] & TTO_TX) {
// PDP-8 doesn't really have support for 8-bit output, this is Jules' contribution
std::cout << (char)(((ctlregs[TT_BITS] & TTO_DATA) >> TTO_DATA_SHIFT) ^ 0x80) << std::flush;
ctlregs[TT_BITS] &= ~TTO_TX & ~TTO_DATA;
log.emplace(time + TT_OUTPUT_DELAY, event(TT_BITS, TTO_FLAG, 0));
}
bool interrupt = false;
if (ctlregs[INT_ENABLE] & 1) {
if (ctlregs[TT_INPUT_INT_ENABLE]) {
if (ctlregs[TT_BITS] & TTI_FLAG)
interrupt = true;
}
if (ctlregs[TT_OUTPUT_INT_ENABLE]) {
if ((ctlregs[TT_BITS] & (TTO_FLAG|TTO_FLAG_OLD)) == TTO_FLAG)
interrupt = true;
}
}
if (interrupt) {
ctlregs[DATA_INSTRUCTION_FIELD_SAVED] = ctlregs[DATA_INSTRUCTION_FIELD_BUFFER];
ctlregs[DATA_INSTRUCTION_FIELD_BUFFER] = 0;
ctlregs[HALTED] = 0;
ctlregs[INT_ENABLE] = 0;
ctlregs[TT_BITS] |= (ctlregs[TT_BITS] & TTO_FLAG) ? TTO_FLAG_OLD : 0;
} else {
ctlregs[INT_ENABLE] = (ctlregs[INT_ENABLE] >> 1) * 3;
}
return interrupt;
};
|