-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.c
103 lines (84 loc) · 1.28 KB
/
font.c
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
#ifndef FONT_C
#define FONT_C
#include "evo.h"
#include "resources.h"
static u8 text_x;
static u8 text_y;
static u8 left_pad = 0;
static u8 right_pad = 40;
static u8 strlen(u8 *s)
{
u8 c;
for (c = 0; s[c] != 0; c++)
;
return c;
}
static void swap(u8 *x, u8 *y)
{
u8 t = *x;
*x = *y;
*y = t;
}
void put_char(u8 c)
{
__asm
di
__endasm;
if (c >= ' ')
{
draw_tile_g256(text_x, text_y, c - ' ');
}
text_x++;
if (text_x == right_pad || c == '\n')
{
text_x = left_pad;
text_y++;
if (text_y == 30)
text_y = 0;
}
__asm
ei
__endasm;
}
void put_num(u16 num)
{
u8 i = 0;
u8 buffer[] = {'0', '0', '0', '0', '0', '0'};
u8 j = sizeof(buffer) - 1;
while (num)
{
u8 r = num % 10;
buffer[i++] = r + '0';
num /= 10;
}
i = 0;
while (i < j)
swap(&buffer[i++], &buffer[j--]);
for (i = 0; i < sizeof(buffer); i++)
put_char(buffer[i]);
}
void put_str(u8 *str)
{
u8 i;
while (1)
{
i = *str++;
if (!i)
break;
put_char(i);
}
}
void init_text()
{
unpack_pal256(PAL256_FONT, 0);
select_image(IMG256_FONT);
clear_screen(0);
scroll(0, 0);
swap_screen();
clear_screen(0);
swap_screen();
pal_bright(BRIGHT_MID);
text_x = 0;
text_y = 0;
}
#endif