aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/drawer.c
blob: 4445919316a70141d75d7015bde2d9fd2d933d6b (plain)
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
#include <graphics/drawer.h>
#include <graphics/lfb.h>

void write_cchar(struct Drawer* d, char s, unsigned int c)
{
	d->x %= GG_MAX_X;
	d->y %= GG_MAX_Y;
	if (s == 0x0A) {
		d->y += 1;
		d->x = 0;
	} else {
		draw_cletter(d->x++, d->y, s, c);
		if (d->x >= GG_MAX_X) {
			d->y += 1;
			d->x = 0;
		}
	}
	// CHECK Y EVENTUALLY
}

void write_char(struct Drawer* d, char s)
{
	write_cchar(d, s, 0xFFFFFF);
}

void write_cstring(struct Drawer* d, char* s, unsigned int c)
{
	d->x %= GG_MAX_X;
	d->y %= GG_MAX_Y;
	unsigned int idx = 0;
	while(s[idx] != 0) {
		if (s[idx] == 0x0A) {
			d->y += 1;
			d->x = 0;
			idx++;
		} else {
			draw_cletter(d->x++, d->y, s[idx++], c);
			if (d->x >= GG_MAX_X) {
				d->y += 1;
				d->x = 0;
			}
		}
		// CHECK Y EVENTUALLY
	}
}

void write_string(struct Drawer* d, char* s)
{
	write_cstring(d, s, 0xFFFFFF);
}

void write_chex32(struct Drawer* d, unsigned long val, unsigned int c)
{
	draw_chex32(d->x, d->y, val, c);
	d->x += 8;
	if (d->x >= GG_MAX_X) {
		d->y += 1;
		d->x %= GG_MAX_X;
	}
}

void write_hex32(struct Drawer* d, unsigned long val)
{
	write_chex32(d, val, 0xFFFFFF);
}

void write_c10(struct Drawer* d, unsigned long val, unsigned int c)
{
	static char out[] = "0000000000\0";
	char* s = (char*)out+9;
	unsigned long tmp = val;
	for(int i = 0; i < 10; i++) {
		unsigned char rem = tmp%10;
		tmp /= 10;
		*s = rem + 0x30;
		if (tmp==0)
			break;
		s--;
	}
	write_cstring(d, s, c);
}

void write_10(struct Drawer* d, unsigned long val)
{
	write_c10(d, val, 0xFFFFFF);
}

void set_drawer(struct Drawer* d, unsigned int x, unsigned int y)
{
	d->x = x % GG_MAX_X;
	d->y = y % GG_MAX_Y;
}