-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathArdumod.cpp
142 lines (116 loc) · 2.48 KB
/
Ardumod.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
#include "Ardumod.h"
void Ardumod::invertRect(int16_t x, int16_t y, uint8_t w, uint8_t h)
{
if(y < 0)
{
h += y;
y = 0;
}
if(x < 0)
{
w += x;
x = 0;
}
uint8_t row, page, col;
unsigned char pageY = y%8;
unsigned char fullPages = (h - (8 - pageY))/8;
unsigned char lowerPart = 0xff << pageY;
unsigned char upperPart = ~(0xff << ((y+h)%8));
row = y/8;
for(col = 0; col < w; col++)
{
int16_t address = (row*WIDTH) + (uint8_t)x+col;
if(address > sizeof(sBuffer)) continue;
if(address < 0) continue;
sBuffer[address] ^= lowerPart;
}
for(page = 1; page <= fullPages && page < 8; page++)
//for(page = 0; page < h/8; page++)
{
row = page + y/8;
for(col = 0; col < w; col++)
{
int16_t address = (row*WIDTH) + (uint8_t)x+col;
if(address > sizeof(sBuffer)) continue;
if(address < 0) continue;
sBuffer[address] ^= 0xff;
}
}
row = page + y/8;
for(col = 0; col < w; col++)
{
int16_t address = (row*WIDTH) + (uint8_t)x+col;
if(address > sizeof(sBuffer)) continue;
if(address < 0) continue;
sBuffer[address] ^= upperPart;
}
}
void Ardumod::drawPixel(int x, int y, uint8_t color)
{
#ifdef PIXEL_SAFE_MODE
if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1))
{
return;
}
#endif
uint8_t row = (uint8_t)y / 8;
if (color == 1)
{
sBuffer[(row*WIDTH) + (uint8_t)x] |= _BV((uint8_t)y % 8);
}
else if(color == 0)
{
sBuffer[(row*WIDTH) + (uint8_t)x] &= ~ _BV((uint8_t)y % 8);
}
else
{
sBuffer[(row*WIDTH) + (uint8_t)x] ^= _BV((uint8_t)y % 8);
}
}
void Ardumod::grayRect(int16_t x, int16_t y, uint8_t w, uint8_t h)
{
if(y < 0)
{
h += y;
y = 0;
}
if(x < 0)
{
w += x;
x = 0;
}
uint8_t row, page, col;
for(page = 0; page < h/8; page++)
{
row = (uint8_t)y / 8 + page;
for(col = 0; col < w; col++)
{
int16_t address = (row*WIDTH) + (uint8_t)x+col;
if(address > sizeof(sBuffer)) continue;
if(address < 0) continue;
if(col%2 == 0)
sBuffer[address] = 0b01010101;
else
sBuffer[address] = 0b10101010;
}
}
}
/* unmodified from core lib 1.1 */
void Ardumod::fillRect
(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t color)
{
drawFastHLine(x, y, w, color); // stupidest version - update in subclasses if desired!
for (int16_t i=x; i<x+w; i++)
{
drawFastVLine(i, y, h, color);
}
}
void Ardumod::drawFastVLine
(int16_t x, int16_t y, uint8_t h, uint8_t color)
{
int end = y+h;
for (int a = max(0,y); a < min(end,HEIGHT); a++)
{
drawPixel(x,a,color);
}
}