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
|
#load "font.bin"
#include "std.c"
#include "screen.c"
#include "hid.c"
int drawChar(int ch, int x, int y, int color)
{
// adjust for jmp instruction
char* fontStart = 0x1FFF + 2;
int charStart = ch * 8;
for (int yOff = 0; yOff < 8; yOff++)
{
int row = fontStart[charStart + yOff];
for (int xOff = 0; xOff < 8; xOff++)
{
int bit = (row >> (7 - xOff)) & 1;
int pix = bit ? COLOR_BLACK : color;
screen_setPixel(x + xOff, y + yOff, pix);
}
}
}
int print(int* text, int len, int x, int y, int color)
{
for (int i = 0; i < len; i++)
{
int ch = text[i];
drawChar(ch, x + (i * 8), y, color);
}
}
int main()
{
int x = 0;
int y = 0;
while (true)
{
if (x >= SCREEN_WIDTH)
{
x = 0;
y += 8;
}
if (y >= SCREEN_HEIGHT)
{
x = 0;
y = 0;
screen_clear(COLOR_BLACK);
}
int sk = hid_waitForPressedKey();
while (hid_getKeyState(sk)) { }
if (sk == SK_NEWLINE)
{
y += 8;
x = 0;
continue;
}
if (sk == SK_BACKSPACE)
{
x -= 8;
if (x < 0)
x = 0;
drawChar(' ', x, y, 1);
continue;
}
if (hid_getKeyState(SK_SHIFT))
sk += ('a' - 'A');
drawChar(sk, x, y, COLOR_RED);
x += 8;
}
}
|