forked from fuopy/ABasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.cpp
65 lines (56 loc) · 1.44 KB
/
globals.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
#include "globals.h"
#include "data.h"
Ardumod arduboy;
bool new_a, new_b, new_up, new_left, new_down, new_right;
bool old_a, old_b, old_up, old_down, old_left, old_right;
void updateInput()
{
old_a = new_a;
old_b = new_b;
old_up = new_up;
old_down = new_down;
old_left = new_left;
old_right = new_right;
new_a = arduboy.pressed(B_BUTTON);
new_b = arduboy.pressed(A_BUTTON);
new_up = arduboy.pressed(UP_BUTTON);
new_down = arduboy.pressed(DOWN_BUTTON);
new_left = arduboy.pressed(LEFT_BUTTON);
new_right = arduboy.pressed(RIGHT_BUTTON);
}
bool modValue(unsigned char &start, short delta, short min, short max)
{
short val = start;
val += delta;
if(val < min) val = min;
if(val > max) val = max;
bool changed = (unsigned char)start != (unsigned char)val;
start = val;
return changed;
}
void printDecimal(unsigned char x, unsigned char y, unsigned char num)
{
if(num >= 100) drawChar(x, y, '0' + num/100);
if(num >= 10) drawChar(x+4, y, '0' + (num%100/10));
drawChar(x+8, y, '0' + (num%10));
}
void printHex(unsigned char x, unsigned char y, unsigned char num)
{
printHexDigit(x, y, num/16);
printHexDigit(x+4, y, num%16);
}
void printHexDigit(unsigned char x, unsigned char y, unsigned char num)
{
if(num < 0x0a)
{
drawChar(x, y, '0' + num);
}
else
{
drawChar(x, y, 'A' + (num-10));
}
}
void drawChar(unsigned char x, unsigned char y, unsigned char ch)
{
arduboy.drawBitmap(x, y, gfx_font + (unsigned short)3 * (ch - '0'), 3, 8, 1);
}