Change license from GPLv3 to LGPLv3.
[seabios.git] / src / post_menu.c
index 4526e44da3e5a01bd737d9acd6bdc2896f9a312e..3182d3c9da563302b063dbf4b7a243c103fbf1c1 100644 (file)
@@ -3,12 +3,14 @@
 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
 // Copyright (C) 2002  MandrakeSoft S.A.
 //
-// This file may be distributed under the terms of the GNU GPLv3 license.
+// This file may be distributed under the terms of the GNU LGPLv3 license.
 
 #include "biosvar.h" // GET_EBDA
-#include "util.h" // usleep
+#include "util.h" // mdelay
+#include "bregs.h" // struct bregs
+#include "boot.h" // IPL
 
-static u8
+static int
 check_for_keystroke()
 {
     struct bregs br;
@@ -18,7 +20,7 @@ check_for_keystroke()
     return !(br.flags & F_ZF);
 }
 
-static u8
+static int
 get_keystroke()
 {
     struct bregs br;
@@ -28,29 +30,43 @@ get_keystroke()
 }
 
 static void
-udelay_and_check_for_keystroke(u32 usec, int count)
+usleep(u32 usec)
 {
-    int i;
-    for (i = 1; i <= count; i++) {
-        usleep(usec);
+    struct bregs br;
+    memset(&br, 0, sizeof(br));
+    br.ah = 0x86;
+    br.cx = usec >> 16;
+    br.dx = usec;
+    call16_int(0x15, &br);
+}
+
+static int
+timed_check_for_keystroke(int msec)
+{
+    while (msec > 0) {
         if (check_for_keystroke())
-            break;
+            return 1;
+        usleep(50*1000);
+        msec -= 50;
     }
+    return 0;
 }
 
 void
 interactive_bootmenu()
 {
+    if (! CONFIG_BOOTMENU)
+        return;
+
     while (check_for_keystroke())
         get_keystroke();
 
     printf("Press F12 for boot menu.\n\n");
 
-    udelay_and_check_for_keystroke(500000, 5);
-    if (! check_for_keystroke())
+    if (!timed_check_for_keystroke(2500))
         return;
-    u8 scan_code = get_keystroke();
-    if (scan_code != 0x58)
+    int scan_code = get_keystroke();
+    if (scan_code != 0x86)
         /* not F12 */
         return;
 
@@ -59,7 +75,7 @@ interactive_bootmenu()
 
     printf("Select boot device:\n\n");
 
-    int count = GET_EBDA(ipl.count);
+    int count = IPL.count;
     int i;
     for (i = 0; i < count; i++) {
         printf("%d. ", i+1);
@@ -75,8 +91,8 @@ interactive_bootmenu()
         if (scan_code <= count + 1) {
             // Add user choice to the boot order.
             u16 choice = scan_code - 1;
-            u32 bootorder = GET_EBDA(ipl.bootorder);
-            SET_EBDA(ipl.bootorder, (bootorder << 4) | choice);
+            u32 bootorder = IPL.bootorder;
+            IPL.bootorder = (bootorder << 4) | choice;
             break;
         }
     }