boot: Clean up editor redraw, shift-arrow input?

This commit is contained in:
K. Lange 2021-11-04 18:59:35 +09:00
parent fdbb51c55d
commit 1e7ffb7b1b
3 changed files with 51 additions and 26 deletions

View File

@ -6,26 +6,42 @@
int boot_edit = 0;
static uint16_t attribute_cache[80*25] = {0};
static void draw_text(int cursor, int len) {
int i = 0;
for (int _my_y = 0; _my_y < 25; ++_my_y) {
for (int _my_x = 0; _my_x < 80; ++_my_x) {
int ch = (i < len) ? cmdline[i] : ' ';
int attr = (i == cursor) ? 0x70 : 0x07;
uint16_t combined = (attr << 8) | (ch & 0xFF);
if (attribute_cache[i] != combined) {
move_cursor(_my_x, _my_y);
set_attr(attr);
print_((char[]){ch,'\0'});
attribute_cache[i] = combined;
}
i++;
}
}
}
int boot_editor(void) {
int len = strlen(cmdline);
int cursor = len;
int data = 0;
memset(attribute_cache, 0, sizeof(attribute_cache));
while (1) {
move_cursor(0,0);
for (int i = 0; i <= len; ++i) {
set_attr(i == cursor ? 0x70 : 0x07);
print_((char[]){cmdline[i],'\0'});
}
print_(" ");
set_attr(0x07);
do {
do {
print_(" ");
} while (x);
} while (y);
draw_text(cursor, len);
char data = 0;
int status = read_key(&data);
int status;
do {
status = read_key(&data);
} while (status == 1);
if (status == 0) {
/* Handle a few special characters */

View File

@ -58,7 +58,7 @@ int read_scancode(int timeout) {
}
}
int read_key(char * c) {
int read_key(int * c) {
EFI_INPUT_KEY Key;
unsigned long int index;
uefi_call_wrapper(ST->BootServices->WaitForEvent, 3, 1, &ST->ConIn->WaitForKey, &index);
@ -106,11 +106,28 @@ static char kbd_us_l2[128] = {
'-', 0, 0, 0, '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
int read_key(char * c) {
int read_key(int * c) {
static int shift_state = 0;
int sc = read_scancode(0);
if (sc == 0xe0) {
*c = 0xe0;
return 1;
}
if (*c == 0xe0) {
*c = 0;
switch (sc) {
/* Keft left and right */
case 0x4B:
return shift_state ? 4 : 2;
case 0x4D:
return shift_state ? 5 : 3;
}
return 1;
}
switch (sc) {
/* Shift down */
case 0x2A:
@ -122,10 +139,6 @@ int read_key(char * c) {
case 0xB6:
shift_state = 0;
return 1;
/* Keft left and right */
case 0x4B: return shift_state ? 4 : 2;
case 0x4D: return shift_state ? 5 : 3;
}
if (!(sc & 0x80)) {
@ -146,10 +159,6 @@ int read_scancode(int timeout) {
} else {
while (!(inportb(0x64) & 1));
}
int out;
while (inportb(0x64) & 1) {
out = inportb(0x60);
}
return out;
return inportb(0x60);
}
#endif

View File

@ -9,5 +9,5 @@
#define KBD_SCAN_9 10
int read_scancode(int);
int read_key(char * c);
int read_key(int * c);