Skip to content

Commit

Permalink
Add basic keyboard support
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanhui Zhao committed Oct 28, 2019
1 parent 1bb754c commit ebef41e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OBJECTS = start.o scrn.o gdt.o idt.o isrs.o irq.o timer.o main.o
OBJECTS = start.o scrn.o gdt.o idt.o isrs.o irq.o timer.o kb.o main.o
CC = gcc
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -I./include -c
LDFLAGS = -T link.ld -melf_i386
Expand Down
2 changes: 2 additions & 0 deletions include/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ void irq_install();

void timer_install();

void keyborad_install();

#endif
63 changes: 63 additions & 0 deletions kb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <system.h>

unsigned char kbdus[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 */
};

void keyboard_handler(struct regs *r)
{
unsigned char scancode;

scancode = inportb(0x60);

if (scancode & 0x80)
{

}
else
{
putch(kbdus[scancode]);
}

}

void keyborad_install(void)
{
irq_install_handler(1, keyboard_handler);
}
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void main()
isrs_install();
irq_install();
timer_install();
keyborad_install();
init_video();
__asm__ __volatile__("sti");
puts("System Start!\n");
Expand Down

0 comments on commit ebef41e

Please sign in to comment.