blob: 78b75f29b3c1af3ceeee5596bf738238e879b42e (
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
|
#include "vga_character.h"
__asm__(".code16gcc\n");
static short CURSOR_LOC = 0;
static char* HEX_CHARS = "0123456789abcdef";
void vga_graphics_write_str(char* str) {
while(*str) {
vga_graphics_write_with_attr(*str++, 7);
}
}
void vga_graphics_write_with_attr(char value, char attr) {
vga_graphics_write_at_offset(value, CURSOR_LOC++);
vga_graphics_write_at_offset(attr, CURSOR_LOC++);
}
void vga_graphics_write(char value) {
vga_graphics_write_at_offset(value, CURSOR_LOC);
CURSOR_LOC += 2;
}
void vga_graphics_byte_hex(char value) {
char low = value & 0x0f;
char high = (value & 0xf0) >> 4;
vga_graphics_write(HEX_CHARS[high]);
vga_graphics_write(HEX_CHARS[low]);
}
void vga_graphics_short_hex(short value) {
char low = value & 0xff;
char high = (value & 0xff00) >> 8;
vga_graphics_byte_hex(high);
vga_graphics_byte_hex(low);
}
void vga_graphics_int_hex(int value) {
short low = value & 0xffff;
short high = (value & 0xffff0000) >> 16;
vga_graphics_short_hex(high);
vga_graphics_short_hex(low);
}
void vga_graphics_write_at_offset(char value, short offset) {
__asm__ volatile (
"mov %0, %%al \n"
"mov %1, %%di \n"
"mov %%al, %%gs:(%%di) \n"
: :"r"(value), "r"(offset) : "%ax", "%di");
}
void vga_graphics_clear() {
int TERM_WIDTH = 80;
int TERM_HEIGHT = 25;
int i = 0;
while(i < TERM_WIDTH * TERM_HEIGHT) {
vga_graphics_write_with_attr(' ', 7);
i++;
}
CURSOR_LOC = 0;
}
void vga_graphics_newln() {
CURSOR_LOC += 80 * 2;
}
void vga_graphics_return() {
CURSOR_LOC = CURSOR_LOC - (CURSOR_LOC % 160);
}
|