diff --git a/src/system/boot/platform/u-boot/console.cpp b/src/system/boot/platform/u-boot/console.cpp index 9c665a65cf..62293e464c 100644 --- a/src/system/boot/platform/u-boot/console.cpp +++ b/src/system/boot/platform/u-boot/console.cpp @@ -6,6 +6,7 @@ #include "console.h" #include "keyboard.h" +#include "serial.h" #include #include @@ -22,9 +23,25 @@ class Console : public ConsoleNode { virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); }; +class VTConsole : public ConsoleNode { + public: + VTConsole(); + void ClearScreen(); + void SetCursor(int32 x, int32 y); + void SetColor(int32 foreground, int32 background); +}; + +class SerialConsole : public VTConsole { + public: + SerialConsole(); + + virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); + virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); +}; static Console sInput, sOutput; +static SerialConsole sSerial; FILE *stdin, *stdout, *stderr; @@ -62,10 +79,82 @@ Console::WriteAt(void *cookie, off_t /*pos*/, const void *buffer, size_t bufferS // #pragma mark - +VTConsole::VTConsole() + : ConsoleNode() +{ +} + +void +VTConsole::ClearScreen() +{ + WriteAt(NULL, 0LL, "\033E", 2); +} + + +void +VTConsole::SetCursor(int32 x, int32 y) +{ + char buff[] = "\033Y "; + x = MIN(79,MAX(0,x)); + y = MIN(24,MAX(0,y)); + buff[3] += (char)x; + buff[2] += (char)y; + WriteAt(NULL, 0LL, buff, 4); +} + + +void +VTConsole::SetColor(int32 foreground, int32 background) +{ + static const char cmap[] = { + 15, 4, 2, 6, 1, 5, 3, 7, + 8, 12, 10, 14, 9, 13, 11, 0 }; + char buff[] = "\033b \033c "; + + if (foreground < 0 && foreground >= 16) + return; + if (background < 0 && background >= 16) + return; + + buff[2] += cmap[foreground]; + buff[5] += cmap[background]; + WriteAt(NULL, 0LL, buff, 6); +} + + +// #pragma mark - + + +SerialConsole::SerialConsole() + : VTConsole() +{ +} + + +ssize_t +SerialConsole::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) +{ + // don't seek in character devices + // not implemented (and not yet? needed) + return B_ERROR; +} + + +ssize_t +SerialConsole::WriteAt(void *cookie, off_t /*pos*/, const void *buffer, size_t bufferSize) +{ + serial_puts((const char *)buffer, bufferSize); + return bufferSize; +} + + +// #pragma mark - + + void console_clear_screen(void) { - + sSerial.ClearScreen(); } @@ -86,7 +175,7 @@ console_height(void) void console_set_cursor(int32 x, int32 y) { - + sSerial.SetCursor(x, y); } @@ -105,7 +194,7 @@ console_hide_cursor(void) void console_set_color(int32 foreground, int32 background) { - + sSerial.SetColor(foreground, background); } @@ -119,6 +208,8 @@ console_wait_for_key(void) status_t console_init(void) { + stdin = (FILE *)&sSerial; + stdout = stderr = (FILE *)&sSerial; return B_OK; }