Does anyone know how to make a simple gets() function? I have tried, but I can't do it.

(i have a working getchar() function)
Code: Select all
int gets(char *buf)
{
int c = 0;
do
{
buf[c] = getchar();
}
while(buf[c++] != '\n');
buf[--c] = 0;
return c;
};
Code: Select all
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M/MU d- s:- a--- C++++ UL P L++ E--- W+++ N+ w++ M- V+ PS+ Y+ PE- PGP t-- 5- X R- tv b DI-- D+ G e h! r++ y+
------END GEEK CODE BLOCK------
The keyboard returns 'scan codes" which have nothing to do with the ASCII that you're expecting to see on the screen. You need to convert the scan codes (and sequences of scan codes in some cases) into something useful.piranha wrote:Well, I tested it by making it print on the screen what is typed, however it displays weird characters on the screen.
does the array kbdus convert the scan code into an ascii character?piranha wrote:oh man. I just realized that my getchar() function is weird. it worked before, but not now......
char getch
{
char ch;
while(int01flag == 0)
hlt();
ch = kbdus[ inportb(0x60) ];
int01_flag = 0;
return ch;
}
Code: Select all
char getch
{
//the ascii char we want to return
char ch;
//this holds the scan code
char scan_code;
//label that might be used later
wait_press:
while(int01flag == 0)
hlt();
int01_flag = 0;
//store the scan code
scan_code=inportb(0x60);
//if the top bit is not set then return the character
if((scan_code&0x80)==0){
ch = kbdus[ scan_code ];
return ch;
}else{
//otherwise go back to waiting.
goto wait_press;
}
}
Yes, but that's not all...Otter wrote:And that's not all. You have to notice keys like shift or alt, there are some advanced key codes following the scan code 0xE0 and so on ...
Sometimes the keyboard controller sends for example 5 scan codes for one key.