-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ueficon.c
142 lines (127 loc) · 3.08 KB
/
ueficon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* PROJECT: FreeLoader UEFI Support
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Console output
* COPYRIGHT: Copyright 2022 Justin Miller <justinmiller100@gmail.com>
*/
#include <uefildr.h>
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16
/* GLOBALS ********************************************************************/
extern EFI_SYSTEM_TABLE* GlobalSystemTable;
static unsigned CurrentCursorX = 0;
static unsigned CurrentCursorY = 0;
static unsigned CurrentAttr = 0x0f;
static EFI_INPUT_KEY Key;
static BOOLEAN ExtendedKey = FALSE;
static char ExtendedScanCode = 0;
/* FUNCTIONS ******************************************************************/
VOID
UefiConsPutChar(int c)
{
ULONG Width, Height, Unused;
BOOLEAN NeedScroll;
UefiVideoGetDisplaySize(&Width, &Height, &Unused);
NeedScroll = (CurrentCursorY >= Height);
if (NeedScroll)
{
UefiVideoScrollUp();
--CurrentCursorY;
}
if (c == '\r')
{
CurrentCursorX = 0;
}
else if (c == '\n')
{
CurrentCursorX = 0;
if (!NeedScroll)
++CurrentCursorY;
}
else if (c == '\t')
{
CurrentCursorX = (CurrentCursorX + 8) & ~7;
}
else
{
UefiVideoPutChar(c, CurrentAttr, CurrentCursorX, CurrentCursorY);
CurrentCursorX++;
}
if (CurrentCursorX >= Width)
{
CurrentCursorX = 0;
CurrentCursorY++;
}
}
static
UCHAR
ConvertToBiosExtValue(UCHAR KeyIn)
{
switch (KeyIn)
{
case SCAN_UP:
return KEY_UP;
case SCAN_DOWN:
return KEY_DOWN;
case SCAN_RIGHT:
return KEY_RIGHT;
case SCAN_LEFT:
return KEY_LEFT;
case SCAN_F1:
return KEY_F1;
case SCAN_F2:
return KEY_F2;
case SCAN_F3:
return KEY_F3;
case SCAN_F4:
return KEY_F4;
case SCAN_F5:
return KEY_F5;
case SCAN_F6:
return KEY_F6;
case SCAN_F7:
return KEY_F7;
case SCAN_F8:
return KEY_F8;
case SCAN_F9:
return KEY_F9;
case SCAN_F10:
return KEY_F10;
case SCAN_ESC:
return KEY_ESC;
case SCAN_DELETE:
return KEY_DELETE;
}
return 0;
}
BOOLEAN
UefiConsKbHit(VOID)
{
return (GlobalSystemTable->ConIn->ReadKeyStroke(GlobalSystemTable->ConIn, &Key) != EFI_NOT_READY);
}
int
UefiConsGetCh(VOID)
{
UCHAR KeyOutput = 0;
/* If an extended key press was detected the last time we were called
* then return the scan code of that key. */
if (ExtendedKey)
{
ExtendedKey = FALSE;
return ExtendedScanCode;
}
if (Key.UnicodeChar != 0)
{
KeyOutput = Key.UnicodeChar;
}
else
{
ExtendedKey = TRUE;
ExtendedScanCode = ConvertToBiosExtValue(Key.ScanCode);
KeyOutput = KEY_EXTENDED;
}
/* UEFI will stack input requests, we have to clear it */
Key.UnicodeChar = 0;
Key.ScanCode = 0;
return KeyOutput;
}