This commit is contained in:
nub31
2025-08-31 21:27:08 +02:00
parent 68f00d12fe
commit 365ad14122
14 changed files with 232 additions and 110 deletions

View File

@@ -1,37 +1,34 @@
#include "vga.h"
#include "string.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define ROWS 25
#define COLUMNS 80
typedef struct
{
uint8_t character;
uint8_t color;
u8 character;
u8 color;
} vga_char;
vga_char* vga_buffer = (vga_char*)0xb8000;
uint8_t cursor_row = 0;
uint8_t cursor_col = 0;
u8 cursor_row = 0;
u8 cursor_col = 0;
void vga_set_char(uint8_t row, uint8_t col, vga_char character)
void vga_set_char(u8 row, u8 col, vga_char character)
{
vga_buffer[COLUMNS * row + col] = character;
}
vga_char vga_char_at(uint8_t row, uint8_t col)
vga_char vga_char_at(u8 row, u8 col)
{
return vga_buffer[COLUMNS * row + col];
}
void vga_clear(void)
{
for (uint8_t row = 0; row < ROWS; row++)
for (u8 row = 0; row < ROWS; row++)
{
for (uint8_t col = 0; col < COLUMNS; col++)
for (u8 col = 0; col < COLUMNS; col++)
{
vga_char character = {
.character = ' ',
@@ -45,7 +42,7 @@ void vga_clear(void)
cursor_col = 0;
}
void vga_set_cursor_position(uint8_t row, uint8_t col)
void vga_set_cursor_position(u8 row, u8 col)
{
if (row < ROWS && col < COLUMNS)
{
@@ -71,7 +68,7 @@ void vga_print_char_colored(char character, vga_color_t color)
}
case '\t':
{
uint8_t remainter = cursor_col % 4;
u8 remainter = cursor_col % 4;
cursor_col += remainter == 0 ? 4 : remainter;
break;
}
@@ -95,15 +92,15 @@ void vga_print_char_colored(char character, vga_color_t color)
if (cursor_row >= ROWS)
{
for (uint8_t row = 1; row < ROWS; row++)
for (u8 row = 1; row < ROWS; row++)
{
for (uint8_t col = 0; col < COLUMNS; col++)
for (u8 col = 0; col < COLUMNS; col++)
{
vga_set_char(row - 1, col, vga_char_at(row, col));
}
}
for (uint8_t col = 0; col < COLUMNS; col++)
for (u8 col = 0; col < COLUMNS; col++)
{
vga_char c = {
.character = ' ',
@@ -118,7 +115,7 @@ void vga_print_char_colored(char character, vga_color_t color)
void vga_print_colored(const char* string, vga_color_t color)
{
for (uint8_t i = 0; string[i] != '\0'; i++)
for (u8 i = 0; string[i] != '\0'; i++)
{
vga_print_char_colored(string[i], color);
}
@@ -138,14 +135,14 @@ void vga_print_error(void)
vga_print(" ]");
}
void vga_print_uint(uint32_t value)
void vga_print_uint(u32 value)
{
char buffer[11];
uitoa(value, buffer);
vga_print(buffer);
}
void vga_print_int(int32_t value)
void vga_print_int(i32 value)
{
char buffer[12];
itoa(value, buffer);