Page 1 of 2
Bran's kernel keyboard
Posted: Thu Aug 17, 2006 3:55 pm
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?
Re:Bran's kernel keyboard
Posted: Thu Aug 17, 2006 4:40 pm
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
and remeber to move up top every key so you dont write over other keys in the table
, now if the table fills up
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
dont do anything. now to get the keys out just read from
put it all together you get:
Re:Bran's kernel keyboard
Posted: Thu Aug 17, 2006 4:45 pm
by GLneo
[attach]
Re:Bran's kernel keyboard
Posted: Thu Aug 17, 2006 5:27 pm
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
Re:Bran's kernel keyboard
Posted: Thu Aug 17, 2006 6:55 pm
by xyjamepa
okay guys...
let us keep it simple...
i need your feedback...
where are you?
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 2:19 am
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.
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 9:30 am
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.
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 12:44 pm
by xyjamepa
thanx for your reply!!!
but... you did not help me
give me some code...
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 1:09 pm
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.
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 4:29 pm
by xyjamepa
ok
would somebody please correct my code...
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 10:21 pm
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
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 10:51 pm
by Candy
Did you clear the keyboard buffer?
Re:Bran's kernel keyboard
Posted: Fri Aug 18, 2006 11:49 pm
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
Re:Bran's kernel keyboard
Posted: Sat Aug 19, 2006 12:25 am
by xyjamepa
No i didn't clear the keyboard buffer.
how can i do that?
Re:Bran's kernel keyboard
Posted: Sat Aug 19, 2006 1:33 am
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.