Bran's kernel keyboard

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.
xyjamepa

Bran's kernel keyboard

Post by xyjamepa »

hi guys...
I,ve been trying to write a "getch()" to Bran's kernel tutorial but
when i print out this char using the "putch(char c)"
it is printed on the whole screen with out stop could you tell me how can i write this function?
GLneo

Re:Bran's kernel keyboard

Post by GLneo »

well the way i did it, you have an array

Code: Select all

#define STDINSZ 1024
unsigned char currentStdin[STDINSZ];
with is your key buffer, now every time you get a key (

Code: Select all

void keyboard_handler(struct regs *r)
) put the ascii key in the table, but you need to know were in the table, so make a variable (top) and do this

Code: Select all

currentStdin[top] = key;
and remeber to move up top every key so you dont write over other keys in the table

Code: Select all

top++;
, now if the table fills up

Code: Select all

if(top > STDINSZ)
reset top to zero. now you may be thinking what happens when top starts over it will overwrite keys, so make a new variable (bottom) to keep track of the start of the key string and

Code: Select all

if((Top + 1) == Bottom)
dont do anything. now to get the keys out just read from

Code: Select all

currentTop[bottom]
put it all together you get:
GLneo

Re:Bran's kernel keyboard

Post by GLneo »

[attach]
xyjamepa

Re:Bran's kernel keyboard

Post by xyjamepa »

my code:
unsigned char getch()
{
unsigned char scancode='\0';
while(scancode=='\0')
{
scancode = inportb(0x60);
}
return kbdus[scancode];

}
and now :
unsigned char c=getch();
putch(c);
where is my wrong
xyjamepa

Re:Bran's kernel keyboard

Post by xyjamepa »

okay guys...
let us keep it simple...
i need your feedback...
where are you?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Bran's kernel keyboard

Post by Pype.Clicker »

abuashraf wrote: okay guys...
let us keep it simple...
i need your feedback...
where are you?
out for lunch ... sleeping ... at work ... who knows.

btw, i'm not much surprised to see your character being painted all over the screen. I/O port 0x60 is a "whiteboard" between you and the keyboard controller. When you read it, you do not remove what was there previously, so if you poll it continuously, you'll get the same value continuously. And no, reading it doesn't turn it back to 0.

Moreover, you should make the distinction between "keypress" and "keybreak" codes you find there.

What you need to do here is to use an interrupt handler. Whenever something new has been placed on the "whiteboard", the keyboard controller rises an interrupt. Just watch that and only read the I/O port after you received an interrupt.

That and more in the FAQ.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Bran's kernel keyboard

Post by Candy »

abuashraf wrote: okay guys...
let us keep it simple...
i need your feedback...
where are you?
If you need timely response of a specified level and with a minimum of help, you should consider hiring somebody to help you. It's expensive.

We're in no way obliged to even read what you type, let alone answer your question. Realise that everybody here is doing this in their free time. You don't tell anybody what to do with their free time.
xyjamepa

Re:Bran's kernel keyboard

Post by xyjamepa »

thanx for your reply!!!
but... you did not help me
give me some code...
Kemp

Re:Bran's kernel keyboard

Post by Kemp »

If you are going to succeed at OS dev you need to be competent enough to be able take the pointers and advice given here and work with them, code isn't going to be delivered to you pre-written.
xyjamepa

Re:Bran's kernel keyboard

Post by xyjamepa »

ok
would somebody please correct my code...
xyjamepa

Re:Bran's kernel keyboard

Post by xyjamepa »

hello
I worte the "getch()" function and my problem is:
when i call this function for the first time it works normally,but
when i call it agin it prints the previous char without any
input from me so...
first time i call getch(),i press some key it prints the asciikey
second time call getch(),prints the previous asciikey without
any input from me!!!
you get it?

Code: Select all


void getch()
{
 unsigned char c='\0';
 while(c=='\0'){
 c=inportb(0x60);
 }
 switch(c)
  {
   case 0x1e:{putch('a');break;}    
   case 0x30:{putch('b');break;}
   .
   .
   .
   .
   case 0x2c:{putch('z');break;}
  }
}
please note:
I installed the keyboard handler into IRQ1
thanx
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Bran's kernel keyboard

Post by Candy »

Did you clear the keyboard buffer?
earlz

Re:Bran's kernel keyboard

Post by earlz »

omg
give me some code...
lol closely resembles "gimme teh codez!!11" lol

but on topic

iirc the keyboard keeps the keypressed in the port so that you can read it more than once hence why you have to use interrupts so try using ints
xyjamepa

Re:Bran's kernel keyboard

Post by xyjamepa »

No i didn't clear the keyboard buffer.
how can i do that?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Bran's kernel keyboard

Post by Candy »

abuashraf wrote: No i didn't clear the keyboard buffer.
how can i do that?
instead of peeking at the keyboard buffer, read the keyboard buffer.

Short answer: RTFM.
Post Reply