59 lines
1.5 KiB
C
59 lines
1.5 KiB
C
#include "vga.h"
|
|
|
|
#define VGA_WIDTH 80
|
|
#define VGA_HEIGHT 25
|
|
#define VGA_ADDRESS 0xB8000
|
|
|
|
static volatile char *video_mem = (volatile char*)VGA_ADDRESS;
|
|
static int cursor_x = 0;
|
|
static int cursor_y = 0;
|
|
static char current_color = 0x07; // По умолчанию серый на черном
|
|
|
|
void vga_init(void) {
|
|
cursor_x = 0;
|
|
cursor_y = 0;
|
|
// Заполняем весь экран пробелами
|
|
for (int i = 0; i < VGA_WIDTH * VGA_HEIGHT; i++) {
|
|
video_mem[i * 2] = ' ';
|
|
video_mem[i * 2 + 1] = current_color;
|
|
}
|
|
}
|
|
|
|
void vga_set_color(char fg, char bg) {
|
|
current_color = (bg << 4) | (fg & 0x0F);
|
|
}
|
|
|
|
void vga_putchar(char c) {
|
|
// Обработка переноса строки
|
|
if (c == '\n') {
|
|
cursor_x = 0;
|
|
cursor_y++;
|
|
} else {
|
|
int index = (cursor_y * VGA_WIDTH + cursor_x) * 2;
|
|
video_mem[index] = c;
|
|
video_mem[index + 1] = current_color;
|
|
cursor_x++;
|
|
}
|
|
|
|
// Если вышли за правый край — перенос
|
|
if (cursor_x >= VGA_WIDTH) {
|
|
cursor_x = 0;
|
|
cursor_y++;
|
|
}
|
|
|
|
// Если экран кончился — просто сбрасываем наверх (примитивный скролл)
|
|
if (cursor_y >= VGA_HEIGHT) {
|
|
vga_init();
|
|
}
|
|
}
|
|
|
|
void vga_print(const char *str) {
|
|
for (int i = 0; str[i] != '\0'; i++) {
|
|
vga_putchar(str[i]);
|
|
}
|
|
}
|
|
|
|
void vga_println(const char *str) {
|
|
vga_print(str);
|
|
vga_putchar('\n');
|
|
}
|