blob: 788ce6ccd6bf1a38d9aac6c96b17b30b7b51d152 (
plain) (
blame)
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
|
#include <stdint.h>
#include <stdbool.h>
#define VGA_COM_MIRROR
#ifdef VGA_COM_MIRROR
#include "serial.h"
#endif
#define VGA_COLUMNS 80
#define VGA_LINES 25
#define VGA_START (uint16_t *)0x000b8000
#define VGA_END (VGA_START + VGA_COLUMNS * VGA_LINES)
uint16_t *cursor = VGA_START;
uint16_t color = 0x1f00;
void vga_set_color(uint8_t new_color) {
color = new_color << 8;
}
void vga_scroll() {
cursor = VGA_START;
}
void vga_blank() {
#ifdef VGA_COM_MIRROR
soutsz("\r\n\r\n<CLEAR>\r\n\r\n");
#endif
uint32_t f = (color << 16) | color | 0x00200020;
uint32_t *p = (uint32_t *)VGA_START;
while (p < (uint32_t *)VGA_END)
*(p++) = f;
cursor = VGA_START;
}
void vga_printch(char ch) {
if (ch == '\n') {
#ifdef VGA_COM_MIRROR
soutsz("\r\n");
#endif
if ((cursor = cursor - (cursor - VGA_START) % VGA_COLUMNS + VGA_COLUMNS) == VGA_END)
vga_scroll();
return;
}
#ifdef VGA_COM_MIRROR
sout(ch);
#endif
*(cursor++) = color | (uint8_t)ch;
if (cursor == VGA_END)
vga_scroll();
}
void vga_printsz(char *sz) {
while (*sz)
vga_printch(*(sz++));
}
void vga_printsn(char *sn, uint8_t n) {
while (n--)
vga_printch(*(sn++));
}
|