Kernel: zero initialize VGA_MEMORY and fix colors

This commit is contained in:
Bananymous 2022-12-13 00:56:30 +02:00
parent 79a2bccd21
commit 5f75479861
1 changed files with 20 additions and 22 deletions

View File

@ -24,12 +24,12 @@ namespace TTY
static size_t VGA_WIDTH;
static size_t VGA_HEIGHT;
static uint16_t* VGA_MEMORY;
static uint16_t* VGA_MEMORY = nullptr;
static size_t terminal_row;
static size_t terminal_col;
static uint8_t terminal_color;
static uint16_t* terminal_buffer;
static uint16_t* terminal_buffer = nullptr;
static char s_ansi_escape_mode = '\0';
static int s_ansi_escape_index = 0;
@ -61,6 +61,8 @@ namespace TTY
VGA_WIDTH = fb.width;
VGA_HEIGHT = fb.height;
VGA_MEMORY = (uint16_t*)fb.addr;
dprintln("width: {}, height: {}, bpp: {}, pitch: {}", fb.width, fb.height, fb.bpp, fb.pitch);
}
else
{
@ -77,14 +79,7 @@ namespace TTY
if (s_multiboot_info->flags & (1 << 12))
if (s_multiboot_info->framebuffer.type != 2)
Kernel::panic("Invalid framebuffer_type in multiboot info");
for (int i = 0; i < 16; i++)
{
terminal_color = vga_entry_color((vga_color)i, VGA_COLOR_BLACK);
putchar('#');
}
putchar('\n');
dprintln("Invalid framebuffer_type in multiboot info");
}
void setcolor(uint8_t color)
@ -143,50 +138,50 @@ namespace TTY
terminal_color = vga_set_foreground(VGA_COLOR_BLACK, terminal_color);
break;
case 31:
terminal_color = vga_set_foreground(VGA_COLOR_RED, terminal_color);
terminal_color = vga_set_foreground(VGA_COLOR_LIGHT_RED, terminal_color);
break;
case 32:
terminal_color = vga_set_foreground(VGA_COLOR_GREEN, terminal_color);
terminal_color = vga_set_foreground(VGA_COLOR_LIGHT_GREEN, terminal_color);
break;
case 33:
terminal_color = vga_set_foreground(VGA_COLOR_LIGHT_BROWN, terminal_color);
break;
case 34:
terminal_color = vga_set_foreground(VGA_COLOR_BLUE, terminal_color);
terminal_color = vga_set_foreground(VGA_COLOR_LIGHT_BLUE, terminal_color);
break;
case 35:
terminal_color = vga_set_foreground(VGA_COLOR_MAGENTA, terminal_color);
terminal_color = vga_set_foreground(VGA_COLOR_LIGHT_MAGENTA, terminal_color);
break;
case 36:
terminal_color = vga_set_foreground(VGA_COLOR_CYAN, terminal_color);
terminal_color = vga_set_foreground(VGA_COLOR_LIGHT_CYAN, terminal_color);
break;
case 37:
terminal_color = vga_set_foreground(VGA_COLOR_DARK_GREY, terminal_color);
terminal_color = vga_set_foreground(VGA_COLOR_LIGHT_GREY, terminal_color);
break;
case 40:
terminal_color = vga_set_background(VGA_COLOR_BLACK, terminal_color);
break;
case 41:
terminal_color = vga_set_background(VGA_COLOR_RED, terminal_color);
terminal_color = vga_set_background(VGA_COLOR_LIGHT_RED, terminal_color);
break;
case 42:
terminal_color = vga_set_background(VGA_COLOR_GREEN, terminal_color);
terminal_color = vga_set_background(VGA_COLOR_LIGHT_GREEN, terminal_color);
break;
case 43:
terminal_color = vga_set_background(VGA_COLOR_LIGHT_BROWN, terminal_color);
break;
case 44:
terminal_color = vga_set_background(VGA_COLOR_BLUE, terminal_color);
terminal_color = vga_set_background(VGA_COLOR_LIGHT_BLUE, terminal_color);
break;
case 45:
terminal_color = vga_set_background(VGA_COLOR_MAGENTA, terminal_color);
terminal_color = vga_set_background(VGA_COLOR_LIGHT_MAGENTA, terminal_color);
break;
case 46:
terminal_color = vga_set_background(VGA_COLOR_CYAN, terminal_color);
terminal_color = vga_set_background(VGA_COLOR_LIGHT_CYAN, terminal_color);
break;
case 47:
terminal_color = vga_set_background(VGA_COLOR_DARK_GREY, terminal_color);
terminal_color = vga_set_background(VGA_COLOR_LIGHT_GREY, terminal_color);
break;
}
}
@ -310,6 +305,9 @@ namespace TTY
void putchar(char c)
{
if (VGA_MEMORY == nullptr)
return;
if (s_ansi_escape_mode)
return handle_ansi_escape(c);