-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscreen.cpp
More file actions
53 lines (42 loc) · 1.03 KB
/
Copy pathscreen.cpp
File metadata and controls
53 lines (42 loc) · 1.03 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
#include <Arduino.h>
#include <machine.h>
#include <memory.h>
#include <display.h>
#include <hardware.h>
#include "config.h"
#include "screen.h"
void Screen::begin() {
Display::begin(BLACK, WHITE, ORIENTATION, DISPLAY_X, DISPLAY_Y);
clear();
}
void Screen::draw(Memory::address a, uint8_t b) {
int16_t y = DISPLAY_Y - (a % BYTES_PER_LINE) * 8;
int16_t x = (a / BYTES_PER_LINE);
uint8_t d = _buf[a] ^ b;
for (unsigned i = 0, bit = 0x01; i < 8; i++, bit *= 2)
if (d & bit) {
uint16_t fg = WHITE, yi = y - i;
if (yi > 32 && yi <= 64)
fg = RED;
else if (yi > 184 && yi <= 240)
fg = GREEN;
else if (yi > 240 && x >=16 && x < 134)
fg = GREEN;
drawPixel(x, yi, (b & bit)? fg: BLACK);
}
_buf[a] = b;
}
void Screen::checkpoint(Checkpoint &c) {
c.write(_buf, sizeof(_buf));
}
void Screen::restore(Checkpoint &c) {
c.read(_buf, sizeof(_buf));
clear();
for (unsigned i = 0; i < sizeof(_buf); i++) {
uint8_t b = _buf[i];
_buf[i] = 0;
draw(i, b);
if ((i % BYTES_PER_LINE) == 0)
_machine->yield();
}
}