screen: implement cursorhome terminal command

This commit is contained in:
2025-08-22 17:43:41 +03:00
parent fffa4b7699
commit 9bb6d9d1a5
3 changed files with 39 additions and 17 deletions
+3
View File
@@ -58,6 +58,9 @@ iso:
test-cdrom: test-cdrom:
qemu-system-i386 -cdrom boot.iso -m 4096M -d int qemu-system-i386 -cdrom boot.iso -m 4096M -d int
cdrom:
qemu-system-i386 -cdrom boot.iso -m 4096M
debug-cdrom: debug-cdrom:
qemu-system-i386 -s -S -cdrom boot.iso -m 4096M -monitor stdio qemu-system-i386 -s -S -cdrom boot.iso -m 4096M -monitor stdio
+35 -10
View File
@@ -7,6 +7,12 @@ static size_t terminal_column;
static uint8_t terminal_color; static uint8_t terminal_color;
static uint16_t* terminal_buffer; static uint16_t* terminal_buffer;
static enum {
STATE_NORMAL,
STATE_ESCAPE,
STATE_BRACKET,
} terminal_state = STATE_NORMAL;
inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg) inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg)
{ {
return fg | bg << 4; return fg | bg << 4;
@@ -66,24 +72,43 @@ void terminal_scroll(void)
void terminal_putchar(char c) void terminal_putchar(char c)
{ {
if(c != '\n') if (terminal_state == STATE_ESCAPE) {
terminal_putentryat(c, terminal_color, terminal_column, terminal_row); if (c == '[') {
terminal_state = STATE_BRACKET;
if (++terminal_column >= VGA_WIDTH){ } else {
terminal_state = STATE_NORMAL;
}
return;
} else if (terminal_state == STATE_BRACKET) {
if (c == 'H') {
terminal_row = 0;
terminal_column = 0; terminal_column = 0;
if (++terminal_row >= VGA_HEIGHT)
terminal_scroll();
} }
if(terminal_row >= VGA_HEIGHT){ terminal_state = STATE_NORMAL;
terminal_scroll(); return;
} }
if(c == '\n') if (c == '\033') {//ESC
{ terminal_state = STATE_ESCAPE;
return;
}
if (c == '\n') {
terminal_column = 0;
terminal_row++;
} else {
terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
terminal_column++;
}
if (terminal_column > VGA_WIDTH) {
terminal_column = 0; terminal_column = 0;
terminal_row++; terminal_row++;
} }
if (terminal_row >= VGA_HEIGHT) {
terminal_scroll();
}
} }
void terminal_write(const char* data, size_t size) void terminal_write(const char* data, size_t size)
-6
View File
@@ -4,21 +4,15 @@
#include <stddef.h> #include <stddef.h>
#include "../include/string.h" #include "../include/string.h"
#ifdef __is_katauos
#include "../include/screen.h" #include "../include/screen.h"
#endif
int puts(const char* string) { int puts(const char* string) {
return printf("%s\n", string); return printf("%s\n", string);
} }
int putchar(int ic) { int putchar(int ic) {
#if defined(__is_katauos)
char c = (char) ic; char c = (char) ic;
terminal_write(&c, sizeof(c)); terminal_write(&c, sizeof(c));
#else
// TODO: Implement stdio and the write system call.
#endif
return ic; return ic;
} }