Page 1 of 1

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

Posted: Mon Feb 16, 2015 12:23 pm
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

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

Posted: Mon Feb 16, 2015 12:38 pm
by Muazzam
Do you have required knowledge?. If you had, you would not be asking such a question.

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

Posted: Mon Feb 16, 2015 12:39 pm
by MustLearn
Well i tried solving it based on what i know, didn't work. Which lead me here

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

Posted: Mon Feb 16, 2015 12:43 pm
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.

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

Posted: Mon Feb 16, 2015 12:53 pm
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?

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

Posted: Mon Feb 16, 2015 12:57 pm
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).

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

Posted: Mon Feb 16, 2015 2:07 pm
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.

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

Posted: Mon Feb 16, 2015 3:22 pm
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

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

Posted: Mon Feb 16, 2015 3:33 pm
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

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

Posted: Mon Feb 16, 2015 3:42 pm
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 :(