diff --git a/src/system/boot/platform/openfirmware/console.cpp b/src/system/boot/platform/openfirmware/console.cpp index 45fed8a8c8..95bb65aba7 100644 --- a/src/system/boot/platform/openfirmware/console.cpp +++ b/src/system/boot/platform/openfirmware/console.cpp @@ -291,6 +291,31 @@ console_set_color(int32 foreground, int32 background) } +static int +translate_key(char escapeCode) +{ + switch (escapeCode) { + case 65: + return TEXT_CONSOLE_KEY_UP; + case 66: + return TEXT_CONSOLE_KEY_DOWN; + case 67: + return TEXT_CONSOLE_KEY_RIGHT; + case 68: + return TEXT_CONSOLE_KEY_LEFT; +// TODO: Translate the codes for the following keys. Unfortunately my OF just +// returns a '\0' character. :-/ +// TEXT_CONSOLE_KEY_PAGE_UP, +// TEXT_CONSOLE_KEY_PAGE_DOWN, +// TEXT_CONSOLE_KEY_HOME, +// TEXT_CONSOLE_KEY_END, + + default: + return 0; + } +} + + int console_wait_for_key(void) { @@ -304,26 +329,10 @@ console_wait_for_key(void) } while (bytesRead == 0); // translate the ESC sequences for cursor keys - if (bytesRead == 3 && buffer[0] == 27 && buffer [1] == 91) { - switch (buffer[2]) { - case 65: - return TEXT_CONSOLE_KEY_UP; - case 66: - return TEXT_CONSOLE_KEY_DOWN; - case 67: - return TEXT_CONSOLE_KEY_RIGHT; - case 68: - return TEXT_CONSOLE_KEY_LEFT; -// TODO: Translate the codes for the following keys. Unfortunately my OF just -// returns a '\0' character. :-/ -// TEXT_CONSOLE_KEY_PAGE_UP, -// TEXT_CONSOLE_KEY_PAGE_DOWN, -// TEXT_CONSOLE_KEY_HOME, -// TEXT_CONSOLE_KEY_END, - - default: - break; - } + if (bytesRead == 3 && buffer[0] == 27 && buffer[1] == 91) { + int key = translate_key(buffer[2]); + if (key != 0) + return key; } // put back unread chars @@ -333,3 +342,25 @@ console_wait_for_key(void) return buffer[0]; } + +int +console_check_for_key(void) +{ + char buffer[3]; + ssize_t bytesRead = sInput.ReadAt(NULL, 0, buffer, 3); + if (bytesRead <= 0) + return 0; + + // translate the ESC sequences for cursor keys + if (bytesRead == 3 && buffer[0] == 27 && buffer[1] == 91) { + int key = translate_key(buffer[2]); + if (key != 0) + return key; + } + + // put back unread chars + if (bytesRead > 1) + sInput.PutChars(buffer + 1, bytesRead - 1); + + return buffer[0]; +} diff --git a/src/system/boot/platform/openfirmware/console.h b/src/system/boot/platform/openfirmware/console.h index 487542c742..c1a16dd769 100644 --- a/src/system/boot/platform/openfirmware/console.h +++ b/src/system/boot/platform/openfirmware/console.h @@ -12,6 +12,7 @@ extern "C" { #endif extern status_t console_init(void); +extern int console_check_for_key(void); #ifdef __cplusplus } diff --git a/src/system/boot/platform/openfirmware/start.cpp b/src/system/boot/platform/openfirmware/start.cpp index 15a5ce6cba..ec674abaea 100644 --- a/src/system/boot/platform/openfirmware/start.cpp +++ b/src/system/boot/platform/openfirmware/start.cpp @@ -32,6 +32,7 @@ extern uint8 __bss_start; extern uint8 _end; uint32 gMachine; +static uint32 sBootOptions; static void @@ -111,8 +112,7 @@ platform_exit(void) extern "C" uint32 platform_boot_options(void) { - // ToDo: implement me! - return 0; + return sBootOptions; } @@ -163,6 +163,17 @@ start(void *openFirmwareEntry) if (init_real_time_clock() != B_OK) of_exit(); + // check for key presses once + sBootOptions = 0; + int key = console_check_for_key(); + if (key == 32) { + // space bar: option menu + sBootOptions |= BOOT_OPTION_MENU; + } else if (key == 27) { + // ESC: debug output + sBootOptions |= BOOT_OPTION_DEBUG_OUTPUT; + } + gKernelArgs.platform_args.openfirmware_entry = openFirmwareEntry; main(&args);