-
Notifications
You must be signed in to change notification settings - Fork 0
/
kl11.cpp
143 lines (132 loc) · 2.06 KB
/
kl11.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <cstdlib>
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include "kb11.h"
#include "kl11.h"
#include <stdio.h>
#include <Arduino.h>
#include "ESPTelnetStream.h"
extern KB11 cpu;
extern ESPTelnetStream telnet1;
bool keypressed = false;
KL11::KL11()
{
}
void KL11::clearterminal()
{
rcsr = 0;
xcsr = 0x80;
rbuf = 0;
xbuf = 0;
count = 0;
}
static int _kbhit()
{
if (telnet1.isConnected())
if (telnet1.available())
return true;
return Serial.available();
}
void KL11::serial_putchar(char c)
{
Serial.write(c);
telnet1.write(c);
}
char KL11::serial_getchar()
{
if (telnet1.available())
return telnet1.read();
return (Serial.read());
}
void KL11::poll()
{
telnet1.loop();
if (!rcvrdone())
{
// unit not busy
if (count++)
if (_kbhit() || keypressed)
{
char ch;
count = 0;
if (ch = KL11::serial_getchar())
{
rbuf = ch & 0x7f;
rcsr |= 0x80;
if (rcsr & 0x40)
{
cpu.interrupt(INTTTYIN, 4);
}
}
else
{
keypressed = false;
}
}
}
if (xbuf)
{
xcsr |= 0x80;
xbuf = 0;
if (xcsr & 0x40)
{
cpu.interrupt(INTTTYOUT, 4);
}
}
else {
if (iflag == 1) {
cpu.interrupt(INTTTYOUT, 4);
iflag = 2;
}
}
}
uint16_t KL11::read16(uint32_t a)
{
switch (a)
{
case 0777560:
return rcsr;
case 0777562:
rcsr &= ~0x80;
return rbuf;
case 0777564:
return xcsr;
case 0777566:
return xbuf;
default:
// Serial.printf("kl11: read from invalid address %06o\n", a);
trap(INTBUS);
}
}
void KL11::write16(uint32_t a, uint16_t v)
{
switch (a)
{
case 0777560:
rcsr = ((rcsr & 0200) ^ (v & ~0200));
break;
case 0777562:
rcsr &= ~0x80;
break;
case 0777564:
xcsr = ((xcsr & 0200) ^ (v & ~0200));
if ((xcsr & 0300) == 0300 && iflag == 0)
iflag = 1;
if (iflag == 2)
iflag = 0;
break;
case 0777566:
xbuf = v & 0x7f;
if (xbuf)
serial_putchar(xbuf);
xbuf |= 0200; // Allow for nulls !!!!
xcsr &= ~0x80;
iflag = 0;
break;
default:
// Serial.printf("kl11: write to invalid address %06o\n", a);
std::abort();
}
}