Storing keyboard input in a variable using inb(0x60)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
MustLearn
Posts: 14
Joined: Wed Feb 04, 2015 4:08 pm

Storing keyboard input in a variable using inb(0x60)

Post by MustLearn »

Hi!
I'm trying to add a simple calculator (like the basic calculator we all made when starting out with c or c++) in a Kernel i made from following the Bare Bones tutorial. I've managed to display whatever the user is typing perfectly fine. But I can't figure out how to store the complete string of characters that the user is typing.

Can somebody like tell me how to go about storing whatever the user is typing?
I tried making an array and storing values inside it but didn't work :S
Here is what i'm using-

Code: Select all

terminal_writestring("  First Number:");
	unsigned char c = 0, a = 0;
    init_pics(0x20, 0x28);
	do
	{
		if(inb(0x60)!=c) //PORT FROM WHICH WE READ
		{
			c = inb(0x60);
			if(c>0){
				terminal_putchar(lowercase[c]); //print on screen
				a = lowercase[c];
				if(lowercase[c] == 0x08){
					break;
				}
			}
		}
	}while(c!=1);
	
	terminal_putchar(a); // print again
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: Storing keyboard input in a variable using inb(0x60)

Post by Muazzam »

Do you have required knowledge?. If you had, you would not be asking such a question.
MustLearn
Posts: 14
Joined: Wed Feb 04, 2015 4:08 pm

Re: Storing keyboard input in a variable using inb(0x60)

Post by MustLearn »

Well i tried solving it based on what i know, didn't work. Which lead me here
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: Storing keyboard input in a variable using inb(0x60)

Post by Muazzam »

You should develop proper interrupts handling and keyboard polling system. And function like getChar first. Maybe then you'll have to develop function to getString. At least, you should implement function to convert string to integer.
MustLearn
Posts: 14
Joined: Wed Feb 04, 2015 4:08 pm

Re: Storing keyboard input in a variable using inb(0x60)

Post by MustLearn »

I was hoping for a simpler way apart from writting getchar/getstring functions ( i should have specified that). Mainly if there was a way of using the scan codes that you take in from the user. Or have i misunderstood scan codes and there is no such way?
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: Storing keyboard input in a variable using inb(0x60)

Post by Muazzam »

MustLearn wrote:I was hoping for a simpler way apart from writting getchar/getstring functions ( i should have specified that). Mainly if there was a way of using the scan codes that you take in from the user. Or have i misunderstood scan codes and there is no such way?
It is not a good way but a worst way. Will you be using keyboard I/O port in an application? (As calculators are usually applications rather than part of Kernel).
Octocontrabass
Member
Member
Posts: 5590
Joined: Mon Mar 25, 2013 7:01 pm

Re: Storing keyboard input in a variable using inb(0x60)

Post by Octocontrabass »

MustLearn wrote:Can somebody like tell me how to go about storing whatever the user is typing?
This is not an OS development question: operating system kernels are not the only software that store input from the user. Are you sure you have the required knowledge for OS development?

You might be having issues because you are not communicating with the keyboard controller correctly. Good documentation exists for basic components, so you should at least make an attempt to communicate properly with the hardware. This may also solve your original issue, since your code was probably not prepared to handle the junk data you were reading from the keyboard controller.
MustLearn
Posts: 14
Joined: Wed Feb 04, 2015 4:08 pm

Re: Storing keyboard input in a variable using inb(0x60)

Post by MustLearn »

I...... managed to fix it......
The problem was me being blind and stupid.

I simply ran a wrong loop. That resulted in junk values. My bad. I shall go commit seppuku
freecrac
Member
Member
Posts: 69
Joined: Thu Sep 20, 2012 5:11 am
Location: germany hamburg

Re: Storing keyboard input in a variable using inb(0x60)

Post by freecrac »

Hello.
MustLearn wrote:Mainly if there was a way of using the scan codes that you take in from the user.
Here are some scancodes(make codes) from the keyboard controller and their ASCII representation (with german letters.)

Code: Select all

SCANCODE DB 02h,03h,04h,05h,06h,07h,08h,09h,0Ah,0Bh,0Ch,0Dh
	      DB 10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Eh,1Fh
	      DB 20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,2Bh,2Ch,2Dh,2Eh,2Fh
	      DB 30h,31h,32h,33h,34h,35h,39h
	      DB 56h

ASCII    DB "1234567890ß'"
	      DB "qwertzuiopü+as"
	      DB "dfghjklöä^#yxcv"
 	      DB "bnm,.- "
	      DB "<"

;---------------------------------------------------------------------------
;    Tab,shift left.,shift right,HOME,UP,LEFT,RIGHT,END,DOWN
;----------
SONTAB  DB 0Fh,2Ah,36h,47h,48h,4Bh,4Dh,4Fh,50h
MustLearn
Posts: 14
Joined: Wed Feb 04, 2015 4:08 pm

Re: Storing keyboard input in a variable using inb(0x60)

Post by MustLearn »

Oh Thanks for your help but i was already properly taking in the scan codes so that they displayed the correct letter :).

I screwed up one of my loops when storing the whole length of what the user types resulting in my problem :), making me think i was going about the problem all wrong
It was an incredibly shameful mistake :(
Post Reply