#ifndef GRUB_TERM_HEADER
#define GRUB_TERM_HEADER 1
+#define GRUB_TERM_NO_KEY -1
+
/* Internal codes used by GRUB to represent terminal input. */
/* Only for keys otherwise not having shifted modification. */
#define GRUB_TERM_SHIFT 0x01000000
.code16
DATA32 call real_to_prot
.code32
+#if GRUB_TERM_NO_KEY != -1
+#error Fix this asm code
+#endif
decl %eax
jmp 2b
void (*grub_xputs) (const char *str) = grub_xputs_dumb;
-static int pending_key = -1;
-
-int
-grub_getkey (void)
-{
- grub_term_input_t term;
-
- grub_refresh ();
-
- if (pending_key != -1)
- {
- pending_key = -1;
- return pending_key;
- }
-
- while (1)
- {
- if (grub_term_poll_usb)
- grub_term_poll_usb ();
-
- FOR_ACTIVE_TERM_INPUTS(term)
- {
- int key = term->getkey (term);
- if (key != -1)
- return key;
- }
-
- grub_cpu_idle ();
- }
-}
+static int pending_key = GRUB_TERM_NO_KEY;
int
grub_checkkey (void)
{
grub_term_input_t term;
- if (pending_key != -1)
+ if (pending_key != GRUB_TERM_NO_KEY)
return pending_key;
if (grub_term_poll_usb)
FOR_ACTIVE_TERM_INPUTS(term)
{
pending_key = term->getkey (term);
- if (pending_key != -1)
+ if (pending_key != GRUB_TERM_NO_KEY)
return pending_key;
}
return -1;
}
+int
+grub_getkey (void)
+{
+ grub_refresh ();
+
+ while (pending_key != GRUB_TERM_NO_KEY)
+ {
+ grub_cpu_idle ();
+ grub_checkkey ();
+ }
+ pending_key = GRUB_TERM_NO_KEY;
+ return pending_key;
+}
+
+
void
grub_refresh (void)
{
return key;
}
-/* If there is a character pending, return it; otherwise return -1. */
+/* If there is a character pending, return it;
+ otherwise return GRUB_TERM_NO_KEY. */
static int
grub_at_keyboard_getkey (struct grub_term_input *term __attribute__ ((unused)))
{
int code;
code = grub_keyboard_getkey ();
if (code == -1)
- return -1;
+ return GRUB_TERM_NO_KEY;
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "Detected key 0x%x\n", key);
#endif
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "caps_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_CAPS_LOCK));
#endif
- return -1;
+ return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_NUM_LOCK:
at_keyboard_status ^= GRUB_TERM_STATUS_NUM;
led_status ^= KEYBOARD_LED_NUM;
#ifdef DEBUG_AT_KEYBOARD
grub_dprintf ("atkeyb", "num_lock = %d\n", !!(at_keyboard_status & KEYBOARD_STATUS_NUM_LOCK));
#endif
- return -1;
+ return GRUB_TERM_NO_KEY;
case GRUB_KEYBOARD_KEY_SCROLL_LOCK:
at_keyboard_status ^= GRUB_TERM_STATUS_SCROLL;
led_status ^= KEYBOARD_LED_SCROLL;
keyboard_controller_led (led_status);
- return -1;
+ return GRUB_TERM_NO_KEY;
default:
return grub_term_map_key (code, at_keyboard_status);
}
status = efi_call_2 (i->read_key_stroke, i, &key);
if (status != GRUB_EFI_SUCCESS)
- return -1;
+ return GRUB_TERM_NO_KEY;
if (key.scan_code == 0)
return key.unicode_char;
else if (key.scan_code < ARRAY_SIZE (efi_codes))
return efi_codes[key.scan_code];
- return -1;
+ return GRUB_TERM_NO_KEY;
}
static grub_uint16_t
return data->input_buf[0];
}
- return -1;
+ return GRUB_TERM_NO_KEY;
}
grub_err_t
grub_size_t actual;
if (termdata->dead)
- return -1;
+ return GRUB_TERM_NO_KEY;
/* Poll interrupt pipe. */
err = grub_usb_check_transfer (termdata->transfer, &actual);
+ GRUB_TERM_REPEAT_INTERVAL;
return termdata->last_key;
}
- return -1;
+ return GRUB_TERM_NO_KEY;
}
grub_memcpy (data, termdata->report, sizeof (data));
data[4], data[5], data[6], data[7]);
if (err || actual < 1)
- return -1;
+ return GRUB_TERM_NO_KEY;
termdata->status = data[0];
if (actual < 3)
- return -1;
+ return GRUB_TERM_NO_KEY;
if (data[2] == KEY_NO_KEY || data[2] == KEY_ERR_BUFFER
|| data[2] == KEY_ERR_POST || data[2] == KEY_ERR_UNDEF)
- return -1;
+ return GRUB_TERM_NO_KEY;
if (data[2] == KEY_CAPS_LOCK)
{
termdata->mods ^= GRUB_TERM_STATUS_CAPS;
send_leds (termdata);
- return -1;
+ return GRUB_TERM_NO_KEY;
}
if (data[2] == KEY_NUM_LOCK)
{
termdata->mods ^= GRUB_TERM_STATUS_NUM;
send_leds (termdata);
- return -1;
+ return GRUB_TERM_NO_KEY;
}
termdata->last_key = grub_term_map_key (data[2], interpret_status (data[0])