screen: implement cursorhome terminal command
This commit is contained in:
@@ -58,6 +58,9 @@ iso:
|
||||
test-cdrom:
|
||||
qemu-system-i386 -cdrom boot.iso -m 4096M -d int
|
||||
|
||||
cdrom:
|
||||
qemu-system-i386 -cdrom boot.iso -m 4096M
|
||||
|
||||
debug-cdrom:
|
||||
qemu-system-i386 -s -S -cdrom boot.iso -m 4096M -monitor stdio
|
||||
|
||||
|
||||
+36
-11
@@ -7,6 +7,12 @@ static size_t terminal_column;
|
||||
static uint8_t terminal_color;
|
||||
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)
|
||||
{
|
||||
return fg | bg << 4;
|
||||
@@ -66,24 +72,43 @@ void terminal_scroll(void)
|
||||
|
||||
void terminal_putchar(char c)
|
||||
{
|
||||
if(c != '\n')
|
||||
if (terminal_state == STATE_ESCAPE) {
|
||||
if (c == '[') {
|
||||
terminal_state = STATE_BRACKET;
|
||||
} else {
|
||||
terminal_state = STATE_NORMAL;
|
||||
}
|
||||
return;
|
||||
} else if (terminal_state == STATE_BRACKET) {
|
||||
if (c == 'H') {
|
||||
terminal_row = 0;
|
||||
terminal_column = 0;
|
||||
}
|
||||
terminal_state = STATE_NORMAL;
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (++terminal_column >= VGA_WIDTH){
|
||||
terminal_column = 0;
|
||||
if (++terminal_row >= VGA_HEIGHT)
|
||||
terminal_scroll();
|
||||
}
|
||||
if(terminal_row >= VGA_HEIGHT){
|
||||
terminal_scroll();
|
||||
terminal_column++;
|
||||
}
|
||||
|
||||
if(c == '\n')
|
||||
{
|
||||
if (terminal_column > VGA_WIDTH) {
|
||||
terminal_column = 0;
|
||||
terminal_row++;
|
||||
}
|
||||
|
||||
if (terminal_row >= VGA_HEIGHT) {
|
||||
terminal_scroll();
|
||||
}
|
||||
}
|
||||
|
||||
void terminal_write(const char* data, size_t size)
|
||||
|
||||
@@ -4,21 +4,15 @@
|
||||
#include <stddef.h>
|
||||
#include "../include/string.h"
|
||||
|
||||
#ifdef __is_katauos
|
||||
#include "../include/screen.h"
|
||||
#endif
|
||||
|
||||
int puts(const char* string) {
|
||||
return printf("%s\n", string);
|
||||
}
|
||||
|
||||
int putchar(int ic) {
|
||||
#if defined(__is_katauos)
|
||||
char c = (char) ic;
|
||||
terminal_write(&c, sizeof(c));
|
||||
#else
|
||||
// TODO: Implement stdio and the write system call.
|
||||
#endif
|
||||
return ic;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user