aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/drawer.c
blob: 542c04ceb8d9f6ac8513c6c97d00a8a86e4f3aea (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
#include "../graphics/lfb.h"
#include "../graphics/drawer.h"

#define GRAPHICS_DRAWER_C
struct Drawer g_Drawer = {.x = 0, .y = 0};

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 set_drawer(struct Drawer* d, unsigned int x, unsigned int y) {
	d->x = x % GG_MAX_X;
	d->y = y % GG_MAX_Y;
}

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";
	char* s = (char*)out+10;
	unsigned long tmp = val;
	if(tmp == 0)
		s--;
	while (tmp != 0) {
		s--;
		unsigned char rem = tmp%10;
		tmp /= 10;
		*s = rem + 0x30;
	}
	write_cstring(d, s, c);
}

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