Keyboard input
Keyboard input
How to make the keyboard input in my OS? All is working fine, except the keyboard input. I tried getch, getchar, scanf, but nothing of them is existing in the OS, because of freestanding. Please, help.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: Keyboard input
And you have really not seen the big banner on top of the page
Re: Keyboard input
I seen it, but i need a full code.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
-
- Member
- Posts: 119
- Joined: Tue Jan 20, 2015 9:01 am
- Libera.chat IRC: glauxosdever
Re: Keyboard input
To read a scan code from the keyboard use: Based on the scan code you got, you will need to convert it to a ascii/unicode/etc character.
Hope this helps,
glauxosdev
Code: Select all
in al, 60h
Hope this helps,
glauxosdev
Re: Keyboard input
I'm making OS in C, thank you, but give C example, please.glauxosdev wrote:To read a scan code from the keyboard use:Based on the scan code you got, you will need to convert it to a ascii/unicode/etc character.Code: Select all
in al, 60h
Hope this helps,
glauxosdev
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
-
- Member
- Posts: 119
- Joined: Tue Jan 20, 2015 9:01 am
- Libera.chat IRC: glauxosdever
Re: Keyboard input
If you don't know Assembly, where are you going? This line of code reads a byte from port 60h (which is the keyboard port) to register al. I don't think it is now hard to translate it to C.
Regards,
glauxosdev
Regards,
glauxosdev
Re: Keyboard input
You need to understand assembly. You can write some C wrappers for port I/O. An example is here.catnikita255 wrote:I'm making OS in C, thank you, but give C example, please.glauxosdev wrote:To read a scan code from the keyboard use:Based on the scan code you got, you will need to convert it to a ascii/unicode/etc character.Code: Select all
in al, 60h
Hope this helps,
glauxosdev
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: Keyboard input
You know...
Introduction
Required Knowledge
Beginner Mistakes
How To Ask Questions
You must be experienced enough in userspace in order to write a kernel. Also, you must read the manuals for the architecture you want your kernel to run on to write a good kernel.
Introduction
Required Knowledge
Beginner Mistakes
How To Ask Questions
You must be experienced enough in userspace in order to write a kernel. Also, you must read the manuals for the architecture you want your kernel to run on to write a good kernel.
Last edited by ExeTwezz on Fri Apr 24, 2015 11:43 am, edited 2 times in total.
Re: Keyboard input
Thank you, i'll check it.Roman wrote:You need to understand assembly. You can write some C wrappers for port I/O. An example is here.catnikita255 wrote:I'm making OS in C, thank you, but give C example, please.glauxosdev wrote:To read a scan code from the keyboard use:Based on the scan code you got, you will need to convert it to a ascii/unicode/etc character.Code: Select all
in al, 60h
Hope this helps,
glauxosdev
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: Keyboard input
I did the input, but it don't waits the input, it's just typing some blank character and capital S, like that (B is the blank char):
BSBSBSBSBSBSBS
Whet it reaches the bottom of the screen, OS is rebooting. How to fix it?
There's a code:
BSBSBSBSBSBSBS
Whet it reaches the bottom of the screen, OS is rebooting. How to fix it?
There's a code:
Code: Select all
char oldkey;
char key;
for(;;)
{
oldkey = key;
key = inb(60);
if(!oldkey = key)
terminal_writestring(key);
}
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing
OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
Re: Keyboard input
I'm afraid that you have been given an oversimplified explanation of how to read from a keyboard, which is worse than useless. There is more than one way of doing this, and to read directly from a USB keyboard is quite complicated, so a beginner will almost always use legacy methods (unless you ar programming a Raspberry Pi or suchlike; reading from the keyboard there is something of a stumbling block for OS development). But for a look at what is involved for a normal PC have a look at http://www.brokenthorn.com/Resources/OSDev19.html . I'd say that any serious keyboard driver is likely to be interrupt-driven, so first you need to be familiar with the interrupt mechanism and be comfortable with writing interrupt handlers. This is turn will involve an understanding of descriptor tables (unless you are staying in real mode - in which case why not just use the BIOS to read the keyboard?).
If you ever ask an OS question "How do I do such and such?" and the answer is "Just read port xx." you can be fairly sure that it is wrong. Device drivers tend to be a little more involved than that.
If you ever ask an OS question "How do I do such and such?" and the answer is "Just read port xx." you can be fairly sure that it is wrong. Device drivers tend to be a little more involved than that.
-
- Member
- Posts: 119
- Joined: Tue Jan 20, 2015 9:01 am
- Libera.chat IRC: glauxosdever
Re: Keyboard input
Removed: Plain wrong.
Last edited by glauxosdev on Sat May 02, 2015 8:59 am, edited 1 time in total.
Re: Keyboard input
Let's not put the cart before the horse. First you have to know that there is a character waiting to be read. Else you get a meaningless string of characters. Hey! there's a coincidence....I supposed he could further develop this, but I said he needs to convert those scan codes to actual characters.
Come on! Be serious. You don't write drivers this way (by just assuming that if you get the same result twice the input is invalid and if you get different results that they are valid input).You need to read from the keyboard either by interrupts, either by polling. This has to be done every some interval (eg 25 times a second). If a key is still pressed you will read the same scan code, so you will want to ignore it for another interval (eg 1 second), else your result will be like this because you can't press a key for such a short time:
-
- Member
- Posts: 119
- Joined: Tue Jan 20, 2015 9:01 am
- Libera.chat IRC: glauxosdever
Re: Keyboard input
Removed: Plain wrong.
Last edited by glauxosdev on Sat May 02, 2015 8:59 am, edited 1 time in total.
Re: Keyboard input
You don't think it's a good idea to check if there is valid data to be read before getting a character from the port?