[haiku-commits] r38304 - haiku/trunk/src/system/boot/platform/openfirmware

  • From: andreas.faerber@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 22 Aug 2010 02:06:32 +0200 (CEST)

Author: andreasf
Date: 2010-08-22 02:06:32 +0200 (Sun, 22 Aug 2010)
New Revision: 38304
Changeset: http://dev.haiku-os.org/changeset/38304
Ticket: http://dev.haiku-os.org/ticket/6140

Modified:
   haiku/trunk/src/system/boot/platform/openfirmware/console.cpp
   haiku/trunk/src/system/boot/platform/openfirmware/console.h
   haiku/trunk/src/system/boot/platform/openfirmware/start.cpp
Log:
boot_loader_openfirmware: Enable boot options by keyboard

Introduce a non-blocking function for checking keyboard input, and refactor
existing code to share the escape key translations. The comment that key-up and
key-down result in a zero char is confirmed to apply.

If the space bar is pressed, enter the boot menu. If the escape key is pressed,
disable the frame buffer and keep showing the usual debug output. Apparently
the key press must come after console/keyboard initialization but before the
"Welcome to the Haiku bootloader!" line.

Closes ticket #6140.


Modified: haiku/trunk/src/system/boot/platform/openfirmware/console.cpp
===================================================================
--- haiku/trunk/src/system/boot/platform/openfirmware/console.cpp       
2010-08-21 21:22:12 UTC (rev 38303)
+++ haiku/trunk/src/system/boot/platform/openfirmware/console.cpp       
2010-08-22 00:06:32 UTC (rev 38304)
@@ -291,6 +291,31 @@
 }
 
 
+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,33 @@
        } 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,
+       if (bytesRead == 3 && buffer[0] == 27 && buffer[1] == 91) {
+               int key = translate_key(buffer[2]);
+               if (key != 0)
+                       return key;
+       }
 
-                       default:
-                               break;
-               }
+       // put back unread chars
+       if (bytesRead > 1)
+               sInput.PutChars(buffer + 1, bytesRead - 1);
+
+       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
@@ -332,4 +364,3 @@
 
        return buffer[0];
 }
-

Modified: haiku/trunk/src/system/boot/platform/openfirmware/console.h
===================================================================
--- haiku/trunk/src/system/boot/platform/openfirmware/console.h 2010-08-21 
21:22:12 UTC (rev 38303)
+++ haiku/trunk/src/system/boot/platform/openfirmware/console.h 2010-08-22 
00:06:32 UTC (rev 38304)
@@ -12,6 +12,7 @@
 #endif
 
 extern status_t console_init(void);
+extern int console_check_for_key(void);
 
 #ifdef __cplusplus
 }

Modified: haiku/trunk/src/system/boot/platform/openfirmware/start.cpp
===================================================================
--- haiku/trunk/src/system/boot/platform/openfirmware/start.cpp 2010-08-21 
21:22:12 UTC (rev 38303)
+++ haiku/trunk/src/system/boot/platform/openfirmware/start.cpp 2010-08-22 
00:06:32 UTC (rev 38304)
@@ -32,6 +32,7 @@
 extern uint8 _end;
 
 uint32 gMachine;
+static uint32 sBootOptions;
 
 
 static void
@@ -111,8 +112,7 @@
 extern "C" uint32
 platform_boot_options(void)
 {
-       // ToDo: implement me!
-       return 0;
+       return sBootOptions;
 }
 
 
@@ -163,6 +163,17 @@
        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);


Other related posts:

  • » [haiku-commits] r38304 - haiku/trunk/src/system/boot/platform/openfirmware - andreas . faerber