Half of keyboard not inputing to 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
tech2077
Posts: 4
Joined: Sun Aug 15, 2010 10:33 pm

Half of keyboard not inputing to 0x60

Post by tech2077 »

I had gone through the barebones tutorial, and implemented a printk for debugging, so i moved on to very basic input, attempting to map out to keyboard and get input, but when I would load up my image in qemu, keys q to ] and 'a' 's' along with a few other no printing chararacters would not show up, even though i had it outputting raw hex to the screen, this is the source i'm using for the reading from the keyboard, and i have tested the d_printf enough to know it isn't it, and have tried two virtual machines.

Code: Select all

	for(;;)
	{
		outb(0x20, 0x20);
		char c = inb(0x60);
		if((!(c&80)))
			d_printf("%x", c);
	}
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Half of keyboard not inputing to 0x60

Post by Brendan »

Hi,

The keyboard gives you "scancodes", which are not ASCII.

You need to convert the scancodes into ASCII. This is typically done with a set of lookup tables - one normal lookup table, one for when a shift key is held down, one for when capslock is active, etc).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
tech2077
Posts: 4
Joined: Sun Aug 15, 2010 10:33 pm

Re: Half of keyboard not inputing to 0x60

Post by tech2077 »

Brendan wrote:Hi,

The keyboard gives you "scancodes", which are not ASCII.

You need to convert the scancodes into ASCII. This is typically done with a set of lookup tables - one normal lookup table, one for when a shift key is held down, one for when capslock is active, etc).


Cheers,

Brendan
Yes, this was for debugging, as you could see, if i was to press a key, it should print out a long repeat of the hex scancode for the key, but for those fey keys it doesn't, and i have tried on 2 vms, and will soon try on another computer, is there any other method, similarly easy, to get input from the keyboard?

edit: it also doesn't work on the other computer i have tried it on.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Half of keyboard not inputing to 0x60

Post by Brendan »

Hi,
tech2077 wrote:Yes, this was for debugging, as you could see, if i was to press a key, it should print out a long repeat of the hex scancode for the key, but for those fey keys it doesn't, and i have tried on 2 vms, and will soon try on another computer, is there any other method, similarly easy, to get input from the keyboard?

edit: it also doesn't work on the other computer i have tried it on.
Doh - sorry. I thought you meant it worked for printing in hex but not when printing as characters. The only thing I can think of that might cause the problem is a broken "d_printf()".

For "similarly easy" you could try playing Quake instead. If you want to do something that's actually useful, start by forgetting about "easy"... ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
tech2077
Posts: 4
Joined: Sun Aug 15, 2010 10:33 pm

Re: Half of keyboard not inputing to 0x60

Post by tech2077 »

Brendan wrote:Hi,
tech2077 wrote:Yes, this was for debugging, as you could see, if i was to press a key, it should print out a long repeat of the hex scancode for the key, but for those fey keys it doesn't, and i have tried on 2 vms, and will soon try on another computer, is there any other method, similarly easy, to get input from the keyboard?

edit: it also doesn't work on the other computer i have tried it on.
Doh - sorry. I thought you meant it worked for printing in hex but not when printing as characters. The only thing I can think of that might cause the problem is a broken "d_printf()".

For "similarly easy" you could try playing Quake instead. If you want to do something that's actually useful, start by forgetting about "easy"... ;)


Cheers,

Brendan
Ok, i'll try dirrectly writting to vid memory without the bypass, and i never liked Quake , guess i'll just forget about easy :P, this is, as you can see, my first attempt into OS dev after a long will used to C api's and asm ontop of the kernel.

Thanks for the help anyway.

I just wrote a program to test if my keyboard has a standard setup for key scancodes, and it came back perfect, so now i have no idea whats going on, i may just boot to a cd now to test if it's the vm's fault.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Half of keyboard not inputing to 0x60

Post by gerryg400 »

Code: Select all

      if((!(c&80)))
The problem is that you're typoed 80 instead of 0x80. Because 80 is 0x50 you are ignoring any key with bit 4 set in its scan code. That includes all the keys that start with 0x1_ (q->],a,s) etc.
If a trainstation is where trains stop, what is a workstation ?
tech2077
Posts: 4
Joined: Sun Aug 15, 2010 10:33 pm

Re: Half of keyboard not inputing to 0x60

Post by tech2077 »

gerryg400 wrote:

Code: Select all

      if((!(c&80)))
The problem is that you're typoed 80 instead of 0x80. Because 80 is 0x50 you are ignoring any key with bit 4 set in its scan code. That includes all the keys that start with 0x1_ (q->],a,s) etc.
Wow, thank you, i completely forgot to declare it as hex.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Half of keyboard not inputing to 0x60

Post by Candy »

tech2077 wrote:
gerryg400 wrote:

Code: Select all

      if((!(c&80)))
The problem is that you're typoed 80 instead of 0x80. Because 80 is 0x50 you are ignoring any key with bit 4 set in its scan code. That includes all the keys that start with 0x1_ (q->],a,s) etc.
Wow, thank you, i completely forgot to declare it as hex.
Try putting stuff in an if in only one pair of brackets:

Code: Select all

if (!(c & 0x80))
instead of

Code: Select all

if ((!(c & 0x80)))
If you make an accidental assignment in the first, GCC will warn you. In the second, it won't.
Post Reply