]>
git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/tty.c
8 static int cursor_x
= 0; /* keep track of where cursor is */
9 static int cursor_y
= 0;
10 static uint16_t crtc_port
;
12 static inline uint8_t vga_get_color(const enum vga_color fg
, const enum vga_color bg
)
14 return fg
&0xf | bg
<<4;
17 static inline uint16_t vga_get_char(const enum vga_color fg
, const enum vga_color bg
, char character
)
19 return character
| vga_get_color(fg
, bg
)<<8;
22 static inline char *vga_get_memory_address(int x
, int y
)
24 return (char *) 0xb8000 + (y
*VGA_WIDTH
+ x
)*2;
27 static void vga_scroll_up(void)
29 for (int y
=1; y
<VGA_HEIGHT
; y
++) {
30 for (int x
= 0; x
<VGA_WIDTH
; x
++) {
31 *vga_get_memory_address(x
, y
-1) = *vga_get_memory_address(x
, y
);
35 for (int x
= 0; x
<VGA_WIDTH
; x
++) {
36 *vga_get_memory_address(x
, VGA_HEIGHT
-1) = vga_get_char(VGA_LIGHT_GRAY
, VGA_BLACK
, ' ');
38 cursor_y
= VGA_HEIGHT
- 1;
41 static void vga_set_cursor(int x
, int y
)
43 uint16_t cursor_address
= y
*VGA_WIDTH
+ x
;
46 outb(crtc_port
+1, cursor_address
>>8);
48 outb(crtc_port
+1, cursor_address
);
51 static void vga_screen_clear(void)
53 for (int y
=0; y
<VGA_HEIGHT
; y
++) {
54 for (int x
=0; x
<VGA_WIDTH
; x
++) {
55 *vga_get_memory_address(x
, y
) = vga_get_char(VGA_LIGHT_GRAY
, VGA_BLACK
, ' ');
64 void vga_print_char(const char character
, const enum vga_color fg
, const enum vga_color bg
)
66 if (character
== '\n') {
70 *vga_get_memory_address(cursor_x
, cursor_y
) = vga_get_char(fg
, bg
, character
);
74 if (cursor_x
>= VGA_WIDTH
) {
79 if (cursor_y
>= VGA_HEIGHT
)
82 vga_set_cursor(cursor_x
, cursor_y
);
87 uint8_t vga_misc
= inb(0x3cc);