From 9ebce0988063e74a25b3b597b0812435baf65cee Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Thu, 5 Dec 2019 20:33:01 +0100 Subject: [PATCH] openfirmware: alternate implementation for console If I understand the openboot specification correctly, we should not call the forth words directly. Instead, we should rely on the terminal-emulator package to parse ANSI escape sequences and manage the display for us. Unfortunately, the ANSI parser is very limited, many sequences don't work, including the ones for colors. But we can at least have inverse video, which is good enough to let the menu show. I think the PowerPC console can be modified to use the same code, at least partially. So for now I'm keeping this code in a cross-plaform file. Change-Id: Ie77b9ddcc18acb735c0d77cb574e28fbabd266e6 Reviewed-on: https://review.haiku-os.org/c/haiku/+/1989 Reviewed-by: waddlesplash --- .../boot/platform/openfirmware/console.cpp | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/system/boot/platform/openfirmware/console.cpp b/src/system/boot/platform/openfirmware/console.cpp index 41aa3bf005..016efd1db3 100644 --- a/src/system/boot/platform/openfirmware/console.cpp +++ b/src/system/boot/platform/openfirmware/console.cpp @@ -216,15 +216,23 @@ console_init(void) void console_clear_screen(void) { +#ifdef __sparc__ + sOutput.Write("\014", 1); +#else of_interpret("erase-screen", 0, 0); +#endif } int32 console_width(void) { - int columnCount; + intptr_t columnCount; +#ifdef __sparc__ + if (of_interpret("screen-#columns", 0, 1, &columnCount) == OF_FAILED) +#else if (of_interpret("#columns", 0, 1, &columnCount) == OF_FAILED) +#endif return 0; return columnCount; } @@ -233,8 +241,12 @@ console_width(void) int32 console_height(void) { - int lineCount; + intptr_t lineCount; +#ifdef __sparc__ + if (of_interpret("screen-#rows", 0, 1, &lineCount) == OF_FAILED) +#else if (of_interpret("#lines", 0, 1, &lineCount) == OF_FAILED) +#endif return 0; return lineCount; } @@ -243,6 +255,12 @@ console_height(void) void console_set_cursor(int32 x, int32 y) { +#ifdef __sparc__ + char buffer[11]; + int len = snprintf(buffer, sizeof(buffer), + "\033[%" B_PRId32 ";%" B_PRId32 "H", y, x); + sOutput.Write(buffer, len); +#else // Note: We toggle the cursor temporarily to prevent a cursor artifact at // at the old location. of_interpret("toggle-cursor" @@ -250,7 +268,7 @@ console_set_cursor(int32 x, int32 y) " to column#" " toggle-cursor", 2, 0, y, x); - +#endif } @@ -266,6 +284,7 @@ console_hide_cursor(void) } +#ifndef __sparc__ static int translate_color(int32 color) { @@ -292,11 +311,19 @@ translate_color(int32 color) return color; return 0; } +#endif void console_set_color(int32 foreground, int32 background) { +#ifdef __sparc__ + // Sadly it seems we can only get inverse video, nothing else seems to work + if (background != 0) + sOutput.Write("\033[1m", 4); + else + sOutput.Write("\033[0m", 4); +#else // Note: Toggling the cursor doesn't seem to help. We still get cursor // artifacts. of_interpret("toggle-cursor" @@ -304,6 +331,7 @@ console_set_color(int32 foreground, int32 background) " to background-color" " toggle-cursor", 2, 0, translate_color(foreground), translate_color(background)); +#endif }