Keyboard input
Posted: Tue Oct 20, 2020 2:13 pm
I just finished the Meaty Skeleton tutorial, and i want to know, there is a way of make user interact with the os trough keyboard inputs for commands and etc.?
I recommend just polling the keyboard for data to begin with, this way you can understand how to interact with the PS/2 hardware and learn how to interpret the data which the keyboard controller sends.SuperGabry64 wrote:I just finished the Meaty Skeleton tutorial, and i want to know, there is a way of make user interact with the os trough keyboard inputs for commands and etc.?
The trickiest part is that the PS/2 device is connected to the x86 io port, which was a bit odd for me as I’m used to memory mapped io. So you need to read about the x86’s “port instructions”, this will need a bit of assembler, but I found using gcc’s inline asm intrinsics a relativity painless to wrap the required instructions in C functions.SuperGabry64 wrote:And how you do it ?
Code: Select all
// This specific snippet of code, originally written by foliagecanine, is available for use under the CC0 license
// https://creativecommons.org/publicdomain/zero/1.0/
char kbdus[] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0,
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
'\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0,
'*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9',
'-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
};
char kbdus_shift[] = {
0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0,
'\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
'\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"', '~',
0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0,
'*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9',
'-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
};
char kbdus_caps[] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0,
'\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']',
'\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`',
0, '\\', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,
'*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9',
'-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
};
Have you ever heard of something called a “Lookup Table”?SuperGabry64 wrote:Thanks for the table, but how can i implement it?
I don't mean to be rude, but how much programming experience do you have? OS development can be very difficult, and you need to know very advanced programming techniques, a lookup table is a quite elementary technique.SuperGabry64 wrote:No, i never heard of this
Code: Select all
if(shift_down)
{
return kbdus_shift[scan_code];
}
else if(caps_enable)
{
return kbdus_caps[scan_code];
}
else
{
return kbdus[scan_code];
}
Indeed, programming operating systems is generally second only to compiler writing in terms of difficulty.StudlyCaps wrote:I don't mean to be rude, but how much programming experience do you have? OS development can be very difficult, and you need to know very advanced programming techniques, a lookup table is a quite elementary technique.SuperGabry64 wrote:No, i never heard of this