Hi, I got a pretty simple question, I guess:
I progged an own asm-bootloader, that loads a c-kernel, basically the same as in your tutorials here.
Now there is one problem: I have to re-code all of the high-level-c-functions. Could anyone please tell me, whether or not, and how, it is possible to include just a few very simply c-libraries?
Otherwise:
How can I handle keyboard input? I got a few inline assembler scripts, but none of them working properly.....
Thanks for your help,
Brunsbarth
Solving C-kernel-problems: inline assembler or library?
-
- Posts: 4
- Joined: Tue Jun 05, 2007 3:03 pm
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Solving C-kernel-problems: inline assembler or library?
You'd have to port a libc to do that. Try Newlib or PDClib for that.brunsbarth wrote:Now there is one problem: I have to re-code all of the high-level-c-functions. Could anyone please tell me, whether or not, and how, it is possible to include just a few very simply c-libraries?
The proper method to do so uses interrupts. Since you will need that sooner or later, you may want to do that anyway.How can I handle keyboard input? I got a few inline assembler scripts, but none of them working properly.....
wiki page on the keyboard:
http://www.osdev.org/wiki/Keyboard_Input
some code that polls instead of using interrupts (non-c):
http://dimensionalrift.homelinux.net/co ... yboard.bas
-
- Posts: 4
- Joined: Tue Jun 05, 2007 3:03 pm
-
- Posts: 4
- Joined: Tue Jun 05, 2007 3:03 pm
-
- Posts: 4
- Joined: Tue Jun 05, 2007 3:03 pm
well, this is my function:
may be better to post it, than to describe it
Brunsbarth
Code: Select all
unsigned shift_state=0;
unsigned escaped=0;
unsigned char new_char;
char KeyboardISR()
{
unsigned new_scan_code = in(0x60);
if (escaped) new_scan_code += 256;
switch(new_scan_code) {
case 0x2a: shift_state = 1; break;
case 0xaa: shift_state = 0; break;
case 0xe0: escaped = 1; break;
default:
if (new_scan_code & 0x80) {
} else {
new_char=new_scan_code;
}
break;
}
out(0x20,0x20);
return new_char;
}
Brunsbarth
Code: Select all
if (escaped) new_scan_code += 256;
Code: Select all
if (escaped)
{
escaped = 0;
new_scan_code += 256;
}
Also, new_char is still a scan code. You need to convert it to ASCII (scancode!=ASCII character). The easiest way to do this IMHO is with a lookup table, for example:
Code: Select all
unsigned char kbduk[128] =
{
/*0*/ 0, 0 /*esc*/,
/*2*/ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b' /* bksp */,
/*16*/ '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n' /* enter */,
/*29*/ 0 /* ctrl */, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
/*42*/ 0 /* LSh*/, '#', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0 /*Rsh*/,
/*55*/ '*', 0 /*Alt*/, ' '/*spc*/, 0/*caplock*/,
/*59*/ 0/*F1*/, 0, 0, 0, 0, 0, 0, 0, 0, 0/*F10*/,
/*69*/ 0/*numlock*/, 0 /*ScrollLock*/, 0/*Home*/, 0/*Up*/, 0/*PgUp*/, '-', 0/*Left*/,
/*76*/ 0, 0/*Right*/, '+', 0/*End*/, 0/*Down*/, 0/*PgDn*/,
/*82*/ 0/*Ins*/, 0/*Del*/, 0,0,'\\',0/*F11*/, 0/*F12*/,0
};
unsigned char kbduk_s[128] =
{
/*0*/ 0, 27 /*`*/,
/*2*/ '!', '"', '£', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\b' /* bksp */,
/*16*/ '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n' /* enter */,
/*29*/ 0 /* ctrl */, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '@', '~',
/*42*/ 0 /* LSh*/, '~', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0 /*RSh*/,
/*55*/ '*', 0 /*Alt*/, ' '/*spc*/, 0/*caplock*/,
/*59*/ 0/*F1*/, 0, 0, 0, 0, 0, 0, 0, 0, 0/*F10*/,
/*69*/ 0/*numlock*/, 0 /*ScrollLock*/, 0/*Home*/, 0/*Up*/, 0/*PgUp*/, '-', 0/*Left*/,
/*76*/ 0, 0/*Right*/, '+', 0/*End*/, 0/*Down*/, 0/*PgDn*/,
/*82*/ 0/*Ins*/, 0/*Del*/, 0,0,'|',0/*F11*/, 0/*F12*/,0
};
Code: Select all
char ascii_char;
if(shift_state)
ascii_char = kbduk_s[new_char];
else
ascii_char = kbduk[new_char];
Cheers,
Adam