-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtty_screen.mcc
155 lines (102 loc) · 4.16 KB
/
tty_screen.mcc
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
144
145
146
147
148
149
150
151
152
153
154
155
//----------------------------------------------------------
// Screen TTY Microcode (c) 2020-... zpekic@hotmail.com
// Compile with https://github.com/zpekic/MicroCodeCompiler
//----------------------------------------------------------
.code 6, 32, tty_screen_code.mif, tty_screen_code.cgf, tty:tty_screen_code.vhd, tty_screen_code.hex, tty_screen_code.bin, 4;
.mapper 7, 6, tty_screen_map.mif, tty_screen_map.cgf, tty:tty_screen_map.vhd, tty_screen_map.hex, tty_screen_map.bin, 1;
.controller tty_control_unit.vhd, 4;
ready: .valfield 2 values
no,
char_is_zero,
yes,
- default no;
seq_cond: .if 3 values
true, // hard-code to 1
char_is_zero,
cursorx_ge_maxcol,
cursory_ge_maxrow,
cursorx_is_zero,
cursory_is_zero,
memory_ready,
false // hard-code to 0
default true;
seq_then: .then 6 values next, repeat, return, fork, @ default next; // any label
seq_else: .else 6 values next, repeat, return, fork, 0x00..0x3F, @ default next; // any value as it can be a trace char
cursorx: .regfield 3 values same, zero, inc, dec, maxcol default same;
cursory: .regfield 3 values same, zero, inc, dec, maxrow default same;
data: .regfield 2 values same, char, memory, space default same;
mem: .valfield 2 values
nop, // no memory access
read, // mem(0) is RD
write, // mem(1) is WR
- // forbid read and write at same time
default nop;
xsel .valfield 1 values cursorx, altx default cursorx; // column address output mux
ysel .valfield 1 values cursory, alty default cursory; // row address output mux
altx .regfield 1 values same, cursorx default same; // column alt reg
alty .regfield 1 values same, cursory default same; // row alt reg
reserved: .valfield 1 values -, - default 0;
// useful aliases
goto: .alias if false then next else;
gosub: .alias if false then next else; // this works because "jump" pushes return address to stack (1 - 4 level deep only!)
return: .alias if false then next else return;
noop: .alias if true then next else next;
.org 0;
// First 4 microcode locations can't be used branch destinations
// ---------------------------------------------------------------------------
_reset: cursorx <= zero, cursory <= zero;
_reset1: cursorx <= zero, cursory <= zero;
_reset2: cursorx <= zero, cursory <= zero;
_reset3: cursorx <= zero, cursory <= zero;
waitChar: ready = char_is_zero, data <= char,
if char_is_zero then repeat else next;
if true then fork else fork; // interpret the ASCII code of char in data register as "instruction"
.map 0b???_????; // default to printable character handler
main: gosub printChar;
cursorx <= inc;
if cursorx_ge_maxcol then next else nextChar;
cursorx <= zero,
goto LF;
.map 0b00?_????; // special characters 00-1F are not printable, so just ignore
nextChar: ready = yes,
if char_is_zero then waitChar else repeat;
.map 0b000_0001; // 0x01 SOH == clear screen
CLS: data <= space, cursory <= zero;
nextRow: cursorx <= zero;
nextCol: gosub printChar;
cursorx <= inc;
if cursorx_ge_maxcol then next else nextCol;
cursory <= inc;
if cursory_ge_maxrow then HOME else nextRow;
.map 0b000_0010; // 0x02 STX == home
HOME: cursorx <= zero, cursory <= zero,
goto nextChar;
.map 0b000_1010; // 0x0A LF (line feed)
LF: cursory <= inc;
if cursory_ge_maxrow then next else nextChar;
scrollUp: cursory <= zero;
copyRow: if cursory_ge_maxrow then lastLine else next;
cursorx <= zero;
copyCol: if cursorx_ge_maxcol then nextY else next;
cursory <= inc,
gosub readMem;
cursory <= dec,
gosub printChar;
cursorx <= inc,
goto copyCol;
nextY: cursory <= inc,
goto copyRow;
lastLine: data <= space, cursory <= dec, cursorx <= zero;
clearCol: if cursorx_ge_maxcol then CR else next;
gosub printChar;
cursorx <= inc,
goto clearCol;
.map 0b000_1101; // 0x0D CR (carriage return)
CR: cursorx <= zero,
goto nextChar;
printChar: if memory_ready then next else repeat;
mem = write, xsel = cursorx, ysel = cursory,
return;
readMem: if memory_ready then next else repeat;
mem = read, xsel = cursorx, ysel = cursory, data <= memory,
return;