Major interrupt change

This commit is contained in:
2024-10-23 14:11:22 +02:00
parent 11feab5014
commit f163659f0c
38 changed files with 498 additions and 468 deletions
+33 -33
View File
@@ -7,11 +7,11 @@
#include <stdbool.h>
#include <sys/gfx.h>
terminal_t* terminal = (terminal_t*)TERMINAL_INFO_LOC;
console_t* console = (console_t*)TERMINAL_INFO_LOC;
int32_t terminalWrite(const void* buf, uint32_t len) { // TODO fix font size
terminal->width = gfxMode->xRes / 8;//*(uint8_t*)(FONT_LOC);
terminal->height = gfxMode->yRes / 16;//*(uint8_t*)(FONT_LOC+1);
int32_t consoleWrite(const void* buf, uint32_t len) { // TODO fix font size
console->width = gfxMode->xRes / 8;//*(uint8_t*)(FONT_LOC);
console->height = gfxMode->yRes / 16;//*(uint8_t*)(FONT_LOC+1);
char* str = (char*)buf;
uint32_t i;
@@ -19,18 +19,18 @@ int32_t terminalWrite(const void* buf, uint32_t len) { // TODO fix font size
// Do we need to check for NULL? Can we just skip it/ignore it?
for (i = 0; i < len && str[i] != '\0'; i++) {
if (str[i] == '\n') {
drawChar(' ', terminal->x, terminal->y, terminal->fg, terminal->bg);
terminal->y++;
terminal->x = 0;
drawChar(' ', console->x, console->y, console->fg, console->bg);
console->y++;
console->x = 0;
} else if (str[i] == '\b') {
drawChar(' ', terminal->x, terminal->y, terminal->fg, terminal->bg);
if (terminal->x == 0) {
terminal->x = terminal->width - 1;
terminal->y--; // Y could be 0?
drawChar(' ', console->x, console->y, console->fg, console->bg);
if (console->x == 0) {
console->x = console->width - 1;
console->y--; // Y could be 0?
} else {
terminal->x--;
console->x--;
}
drawChar(' ', terminal->x, terminal->y, terminal->fg, terminal->bg);
drawChar(' ', console->x, console->y, console->fg, console->bg);
} else if (str[i] == '\x1b') { // Escape sequence
if (str[++i] != '[') { // TODO: Support more types of escape sequences
i--;
@@ -57,33 +57,33 @@ int32_t terminalWrite(const void* buf, uint32_t len) { // TODO fix font size
switch (str[i]) { // TODO: Add default values (see docs/escape.txt)
case 'A': // Cursor up
terminal->y -= args[0];
console->y -= args[0];
break;
case 'B': // Cursor down
terminal->y += args[0];
console->y += args[0];
break;
case 'C': // Cursor left
terminal->x -= args[0];
console->x -= args[0];
break;
case 'D': // Cursor right
terminal->x += args[0];
console->x += args[0];
break;
case 'E': // nth row
terminal->x = args[0];
console->x = args[0];
break;
case 'F': // nth col
terminal->y = args[0];
console->y = args[0];
break;
case 'G': // show/hide cursor
terminal->hideCursor = args[0] ? false : true;
console->hideCursor = args[0] ? false : true;
break;
case 'H': // move cursor to (x,y)
terminal->x = args[0];
terminal->y = args[1];
console->x = args[0];
console->y = args[1];
break;
case 'I': // RESERVED
case 'J': // Erase screen
clearScreen(terminal->bg);
clearScreen(console->bg);
break;
case 'K': // Erase line
break; // TODO
@@ -91,27 +91,27 @@ int32_t terminalWrite(const void* buf, uint32_t len) { // TODO fix font size
break; // TODO
case 'M': // Set FG
if (args[0] < 8) {
terminal->fg = codeToColor(args[0]);
console->fg = codeToColor(args[0]);
} else if (args[0] == 8) {
terminal->fg = FG_COLOR;
console->fg = FG_COLOR;
}
break;
case 'N': // Set BG
if (args[0] < 8) {
terminal->bg = codeToColor(args[0]);
console->bg = codeToColor(args[0]);
} else if (args[0] == 8) {
terminal->bg = BG_COLOR;
console->bg = BG_COLOR;
}
break;
default: break;
}
} else {
drawChar(str[i], terminal->x, terminal->y, terminal->fg, terminal->bg);
terminal->x++;
drawChar(str[i], console->x, console->y, console->fg, console->bg);
console->x++;
if (terminal->x >= terminal->width) { // Go to next line
terminal->y++;
terminal->x = 0;
if (console->x >= console->width) { // Go to next line
console->y++;
console->x = 0;
}
}
}
@@ -124,6 +124,6 @@ void toggleCursor() {
static bool visible = false;
visible = !visible;
drawChar(visible ? 127 : ' ', terminal->x, terminal->y, terminal->fg, terminal->bg);
drawChar(visible ? 127 : ' ', console->x, console->y, console->fg, console->bg);
}