-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.c
84 lines (70 loc) · 1.4 KB
/
write.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
/* write.c */
#include "hello.h"
#include "write.h"
#include "font.h"
#include "uart.h"
#include "frame.h"
#include <string.h>
int cursor_ptr;
void write_string(const char *s)
{
for (; *s != '\0'; s++)
font_putchar(*s);
}
void write_string_large(const char *s)
{
for (; *s != '\0'; s++)
font_putchar_large(*s);
}
void write_int_string(int val, char *result)
{
bool minus = (val < 0);
if (val >= 0)
val = -val;
int i = 0;
while (val) {
result[i++] = '0' - val % 10;
val = val / 10;
}
if (i == 0)
result[i++] = '0';
if (minus)
result[i++] = '-';
result[i] = '\0';
for (int j = 0; j < i/2; j++) {
char tmp = result[j];
result[j] = result[i-j-1];
result[i-j-1] = tmp;
}
}
void write_int(int val)
{
char result[12];
write_int_string(val, result);
write_string(result);
}
void uart_write_int(int val)
{
char result[12];
write_int_string(val, result);
uart_write_string(result);
}
void uart_write_hex(uint32_t val)
{
for (int i = 0; i < 8; i++) {
uint8_t digit = val >> 28;
val = val << 4;
digit += (digit < 10)?'0':('A'-10);
uart_transmit(digit);
}
}
void uart_write_string(const char *s)
{
for (; *s != '\0'; s++)
uart_transmit(*s);
}
void clear_screen(void)
{
memset(screen_buf, 0, 1024);
cursor_ptr = 0;
}