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.
Yes we could help you... but what is your problem with your k_scanf() function?
Oh, you mean whether we could implement it for you? Erm... no, this forum doesn't work that way.
Look up the FAQ. Towards the end of the HomePage you will find links to example kernels that are OpenSource. Or try some of the available OpenSource C libraries. You might find your inspiration there.
Every good solution is obvious once you've found it.
I have many problems. I rewrote that functions a lot of time, and always deleted it.
The first problem is: in which way could i cancel the keyboard buffer?
The second is: in which way could i get only one character from the keyboard buffer?
After these, the other problems are easy to resolve.
char *buf; //init this to the start of your buffer
char lc_buf;
do{
fetch char from keyboard into lc_buf;
choose according to lc_buf:
case RETURN:
*buf='\0';
break;
case (is >= 'A' AND is <= 'Z') OR (is >='0' AND is <= '9'):
*buf++=lc_buf;
end choose
}while(lc_buf!=RETURN);
This should give you a rough idea of what you'd do in a scanf like thing. Althou, I wouldna do it in kernel if I were you.
SpiglerG wrote:
Why? It would be very useful in a shell to have a scanf function.
I would also not advise you to put the shell in the kernel. It is useful in all sorts of user-level programs, so put it in a user-level library, such as the c library usually called libc (where it is, in fact, commonly found).
Yes, but programming a built-in shell in the kernel will be an interface for the programs.
For example, when a program has to be executed, the shell executes it using an exec command.
Actually this kernel will be a simple shell only. after that it will be evolved, but in this first moment the kernel has its build-it shell.
PS: in the first post i asked in which way could i delete the keyboard buffer, too. So, in which way can i?
i don't think i can write directly out(0x60,0x00);
talking about shell: I even wouldna use scanf in a shell if I were you. *gg*
Check out internet::google for Functions like readline() or getline() or gets(). readline() f. ex. - inan implementation I am aware of - also includes history management and line editing and buffer boundary checking. It's quite nifty. Have coded such a thing myself - it's based around a simple getch().
stay safe lad
PS: you mean THIS keyboard buffer in Hardware, don't you?
That's ready for the next char as soon as you're done with your in(port) function. What's in there gets overwritten with the next one the keyboard sends to the chip. As long as it is not read (i.e. the chip needs some snogging with the cpu), no new chars will be accepted.
i have a loop which always read the kbd buffer, and if the value is different from 0(the scancode), then it transform it in asciicode.
I need somethinglike fflush(), which will put 0x00 in the keyboard buffer, so reading the buffer won't return always the last character wrote.
SpiglerG wrote:
i have a loop which always read the kbd buffer, and if the value is different from 0(the scancode), then it transform it in asciicode.
I need somethinglike fflush(), which will put 0x00 in the keyboard buffer, so reading the buffer won't return always the last character wrote.
hum erhm. huhum.
- fflush() has never had the effect of removing anything from an input buffer. it only has a meaning for output buffers
- fscanf() would indeed be avoided in a shell since it will only act once the whole line is returned (so killing any attempt to suport line-edition characters such as backspace and the like)
- the keyboard notifies you of new characters on port 0x60 by the mean of IRQ1. Rather than polling the keyboard port, you should wait for IRQ1 to occur and _then_ read out the scancode.
fscanf will apply backspaces and other keys before pass the input to the kernel.
In which way could i use irq01?
is the same if i'll read the characters in the loop and see if they changed?
About using irq 1:
There is very well explained and also working code in Bran's Kernel Development tutorial on osdever.net, that teaches you about interrupts in general and keyboard and timer in special.
(maybe this tutorial should be part of the quicklinks with a special hint for total newbies who search a starting point?)