-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdl11.cpp
139 lines (123 loc) · 2.08 KB
/
dl11.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
#include <cstdlib>
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include "kb11.h"
#include "dl11.h"
#include <stdio.h>
#include <Arduino.h>
#include "ESPTelnetStream.h"
#include <FastLED.h>
extern KB11 cpu;
extern ESPTelnetStream telnet;
static bool keypressed = false;
static int lbright = 0;
DL11::DL11() {
}
void DL11::clearterminal() {
rcsr = 0;
xcsr = 0x80;
rbuf = 0;
xbuf = 0;
count = 0;
}
static int _kbhit()
{
if (telnet.isConnected()) {
lbright = 150;
return telnet.available();
}
return 0;
}
void DL11::serial_putchar(char c)
{
telnet.write(c);
}
char DL11::serial_getchar()
{
return (telnet.read());
}
void DL11::poll() {
telnet.loop();
if (++lbright > 100)
lbright = -100;
// FastLED.setBrightness(abs(lbright));
// FastLED.show();
if (!rcvrdone()) {
// unit not busy
if (true)
if (_kbhit() || keypressed) {
char ch = serial_getchar();
count = 0;
if (ch) {
rbuf = ch & 0x7f;
rcsr |= 0x80;
if (rcsr & 0x40) {
cpu.interrupt(INTDLR, 4);
}
}
else {
keypressed = false;
}
}
}
if (xbuf) {
xcsr |= 0x80;
xbuf = 0;
if (xcsr & 0x40) {
cpu.interrupt(INTDLT, 4);
}
}
else {
if (iflag == 1) {
cpu.interrupt(INTDLT, 4);
iflag = 2;
}
}
}
uint16_t DL11::read16(uint32_t a) {
int i;
switch (a & 7) {
case 00:
return rcsr;
case 02:
rcsr &= ~0x80;
return rbuf;
case 04:
return xcsr;
case 06:
return xbuf;
default:
Serial.printf("Dl11: read from invalid address %06o\n", a);
trap(INTBUS);
}
}
void DL11::write16(uint32_t a, uint16_t v) {
switch (a & 7) {
case 00:
rcsr = ((rcsr & 0200) ^ (v & ~0200));
break;
case 02:
//rcsr &= ~0x80;
break;
case 04:
xcsr = ((xcsr & 0200) ^ (v & ~0200));
if ((xcsr & 0300) == 0300 && iflag == 0)
iflag = 1;
if (iflag == 2)
iflag = 0;
break;
case 06:
xbuf = v & 0x7f;
if (xbuf)
serial_putchar(v & 0x7f);
xbuf |= 0200; // Allow for nulls !!!!
xcsr &= ~0x80;
iflag = 0;
break;
default:
Serial.printf("Dl11: write to invalid address %06o\n", a);
trap(INTBUS);
}
}