Here is a keyboard driver I'm using.
This code displays the correct scan-codes.
However displays the wrong characters.
It usually just prints "S"
If anyone can figure out whats wrong please post.
Thanks ahead of time
Code: Select all
//WalkerOS Keyboard Driver
#include "keyboard.h"
#include "isr.h"
#include "monitor.h"
char keycodes[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
//Keyboard Handler (Interrupt)
void keyboard_handler(/*struct regs *r*/registers_t regs){
unsigned char scancode;
scancode = inb(0x60); //Read from KB-buffer
if (scancode & 0x80){ //1=Released 0=Pressed
}
else{
k_text(dec(scancode));
k_text(keycodes[scancode]);
}
}
void init_keyboard(){
register_interrupt_handler(IRQ1,keyboard_handler);
}
Code: Select all
//Print Text (Decimal)
unsigned int dec(u32int n)
{
if (n == 0){
return "0";
return;
}
s32int acc = n;
char c[32];
int i = 0;
while (acc > 0){
c[i] = '0' + acc%10;
acc /= 10;
i++;
}
c[i] = 0;
char c2[32];
c2[i--] = 0;
int j = 0;
while(i >= 0){
c2[i--] = c[j++];
}
return c2;
}
Code: Select all
//Print Text
void k_text(char *message){
unsigned int i=0;
i=csr_x*2+(csr_y*80*2);
while(*message!=0){
if(*message=='\n'){ // check for a new line
csr_y++;
csr_x=0;
i=csr_x*2+(csr_y*80*2);
*message++;
k_scroll();
k_cursor();
}
else{
vidmem[i]=*message;
*message++;
i++;
vidmem[i]=font;
i++;
csr_x++;
}
}
}