-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_disp.cpp
More file actions
79 lines (69 loc) · 1.36 KB
/
screen_disp.cpp
File metadata and controls
79 lines (69 loc) · 1.36 KB
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
#include <Arduino.h>
#include <machine.h>
#include <memory.h>
#include <display.h>
#include <serial_dsp.h>
#include <hardware.h>
#include <debugging.h>
#include "screen_disp.h"
#include "config.h"
#define CURSOR_BLINK 500000
void screen_disp::reset() {
display.begin(BG_COLOUR, FG_COLOUR, ORIENT);
display.setScreenChars(COLS, ROWS);
display.clear();
_machine->interval_timer(CURSOR_BLINK, [this]() {
static int tick = 0;
tick = (tick + 1) % 3;
cursor(tick < 2);
});
r = c = 0;
for (int j = 0; j < ROWS; j++)
for (int i = 0; i < COLS; i++)
screen[j][i] = ' ';
}
void screen_disp::cursor(bool on) {
draw(on? '_': ' ', c, r);
}
void screen_disp::draw(char ch, int i, int j) {
if (screen[j][i] != ch) {
screen[j][i] = ch;
display.setCursor(i * display.charWidth(), j * display.charHeight());
display.print(ch);
}
}
void screen_disp::write(uint8_t b) {
char ch = (char)b;
switch(ch) {
case '_':
draw(' ', c, r);
if (c-- == 0) {
r--;
c = COLS-1;
}
break;
case 0x0d:
draw(' ', c, r);
c = 0;
r++;
break;
default:
if (ch >= 0x20 && ch < 0x7f) {
draw(ch, c, r);
if (++c == COLS) {
c = 0;
r++;
}
}
}
if (r == ROWS) {
// scroll
r--;
for (int j = 0; j < (ROWS-1); j++)
for (int i = 0; i < COLS; i++)
draw(screen[j+1][i], i, j);
for (int i = 0; i < COLS; i++)
draw(' ', i, ROWS-1);
}
draw('_', c, r);
}