module uefi::protocol::console; import uefi; alias InputResetFn = fn EfiStatus (SimpleTextInputProtocol*, bool); alias InputReadKeyFn = fn EfiStatus (SimpleTextInputProtocol*, EfiInputKey*); alias InputResetExFn = fn EfiStatus(SimpleTextInputExProtocol*, bool); alias InputReadKeyExFn = fn EfiStatus (SimpleTextInputExProtocol*, EfiKeyData*); alias InputSetStateFn = fn EfiStatus (SimpleTextInputExProtocol*, KeyToggleState*); alias InputRegisterKeystrokeNotifyFn = fn EfiStatus (SimpleTextInputExProtocol*, EfiKeyData*, KeyNotificationFunctionFn, void**); alias InputUnregisterKeystrokeNotifyFn = fn EfiStatus (EfiKeyData*); alias KeyNotificationFunctionFn = fn EfiStatus (EfiKeyData*); alias OutputResetFn = fn EfiStatus (SimpleTextOutputProtocol*, bool); alias OutputStringFn = fn EfiStatus (SimpleTextOutputProtocol*, EfiString); alias OutputTestStringFn = fn EfiStatus (SimpleTextOutputProtocol*, EfiString); alias OutputQueryModeFn = fn EfiStatus (SimpleTextOutputProtocol*, usz, usz*, usz*); alias OutputSetModeFn = fn EfiStatus (SimpleTextOutputProtocol*, usz); alias OutputSetAttributeFn = fn EfiStatus (SimpleTextOutputProtocol*, usz); alias OutputClearScreenFn = fn EfiStatus (SimpleTextOutputProtocol*); alias OutputSetCursorPositionFn = fn EfiStatus (SimpleTextOutputProtocol*, usz, usz); alias OutputEnableCursorFn = fn EfiStatus (SimpleTextOutputProtocol*, bool); bitstruct ConsoleColor : char @bigendian { TextColor background: 0..3; TextColor foreground: 4..6; // bit 7 is technically not used per spec } enum ScanCode : ushort (ushort raw) { NULL { 0x0000 }, UP_ARROW { 0x0001 }, DOWN_ARROW { 0x0002 }, RIGHT_ARROW { 0x0003 }, LEFT_ARROW { 0x0004 }, HOME { 0x0005 }, END { 0x0006 }, INSERT { 0x0007 }, DELETE { 0x0008 }, PAGE_UP { 0x0009 }, PAGE_DOWN { 0x000A }, F1 { 0x000B }, F2 { 0x000C }, F3 { 0x000D }, F4 { 0x000E }, F5 { 0x000F }, F6 { 0x0010 }, F7 { 0x0011 }, F8 { 0x0012 }, F9 { 0x0013 }, F10 { 0x0014 }, F11 { 0x0015 }, F12 { 0x0016 }, ESCAPE { 0x0017 }, PAUSE { 0x0048 }, F13 { 0x0068 }, F14 { 0x0069 }, F15 { 0x006A }, F16 { 0x006B }, F17 { 0x006C }, F18 { 0x006D }, F19 { 0x006E }, F20 { 0x006F }, F21 { 0x0070 }, F22 { 0x0071 }, F23 { 0x0072 }, F24 { 0x0073 }, MUTE { 0x007F }, VOLUME_UP { 0x0080 }, VOLUME_DOWN { 0x0081 }, BRIGHTNESS_UP { 0x0100 }, BRIGHTNESS_DOWN { 0x0101 }, SUSPEND { 0x0102 }, HIBERNATE { 0x0103 }, TOGGLE_DISPLAY { 0x0104 }, RECOVERY { 0x0105 }, EJECT { 0x0106 }, } struct SimpleTextInputProtocol { InputResetFn _reset; InputReadKeyFn _read_key; EfiEvent _event_wait_for_key; } struct EfiInputKey { ushort scanCode; ushort unicodeChar; } struct SimpleTextInputExProtocol { InputResetExFn reset; InputReadKeyExFn read_key; EfiEvent event_wait_for_key; InputSetStateFn set_state; InputRegisterKeystrokeNotifyFn register_keystroke_notify; InputUnregisterKeystrokeNotifyFn unregister_keystroke_notify; } enum KeyShiftState : uint (uint raw) { SHIFT_STATE_VALID { 0x8000_0000 }, RIGHT_SHIFT_PRESSED { 0x0000_0001 }, LEFT_SHIFT_PRESSED { 0x0000_0002 }, RIGHT_CONTROL_PRESSED { 0x0000_0004 }, LEFT_CONTROL_PRESSED { 0x0000_0008 }, RIGHT_ALT_PRESSED { 0x0000_0010 }, LEFT_ALT_PRESSED { 0x0000_0020 }, RIGHT_LOGO_PRESSED { 0x0000_0040 }, LEFT_LOGO_PRESSED { 0x0000_0080 }, MENU_KEY_PRESSED { 0x0000_0100 }, SYS_REQ_PRESSED { 0x0000_0200 }, } enum KeyToggleState : char (char raw) { TOGGLE_STATE_VALID { 0x80 }, KEY_STATE_EXPOSED { 0x40 }, SCROLL_LOCK_ACTIVE { 0x01 }, NUM_LOCK_ACTIVE { 0x02 }, CAPS_LOCK_ACTIVE { 0x04 }, } struct EfiKeyState { KeyShiftState keyShiftState; KeyToggleState keyToggleState; } struct EfiKeyData { EfiInputKey key; EfiKeyState keyState; } struct SimpleTextOutputProtocol { OutputResetFn _reset; OutputStringFn _output_string; OutputTestStringFn _test_string; OutputQueryModeFn _query_mode; OutputSetModeFn _set_mode; OutputSetAttributeFn _set_attribute; OutputClearScreenFn _clear_screen; OutputSetCursorPositionFn _set_cursor_position; OutputEnableCursorFn _enable_cursor; TextMode* mode; } struct TextMode { int maxMode; int currentMode; int currentAttribute; int currentCursorColumn; int currentCursorRow; bool isCursorVisible; } enum TextColor : char (char raw) { BLACK { 0x00 }, BLUE { 0x01 }, GREEN { 0x02 }, CYAN { 0x03 }, RED { 0x04 }, MAGENTA { 0x05 }, BROWN { 0x06 }, LIGHT_GRAY { 0x07 }, DARK_GRAY { 0x08 }, LIGHT_BLUE { 0x09 }, LIGHT_GREEN { 0x0A }, LIGHT_CYAN { 0x0B }, LIGHT_RED { 0x0C }, LIGHT_MAGENTA { 0x0D }, YELLOW { 0x0E }, WHITE { 0x0F }, } macro char @efi_color($fg, $bg) @builtin @public => ($fg | ((0x07 & $bg) << 4));