Skip to content

Commit 765d122

Browse files
committed
Added keyboard stuff
1 parent 6e1f10d commit 765d122

File tree

6 files changed

+92
-4
lines changed

6 files changed

+92
-4
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ ALL_OBJ := environment.o \
1616
_idt.o \
1717
irq.o \
1818
_irq.o \
19-
pit.o
19+
pit.o \
20+
kb.o
2021
ALL_DEP := $(patsubst %.o,.%.d,$(ALL_OBJ))
2122

2223
#Assembly configuration

irq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "irq.h"
33
#include "idt.h"
44
#include "io.h"
5+
#include "terminal.h"
56

67
void *irq_handlers[16] =
78
{

kb.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
#include "kb.h"
3+
#include "terminal.h"
4+
#include "irq.h"
5+
6+
void init_kb()
7+
{
8+
set_irq_handler(1, keyboard_handler);
9+
}
10+
11+
unsigned char kbdus[128] =
12+
{
13+
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
14+
'9', '0', '-', '=', '\b', /* Backspace */
15+
'\t', /* Tab */
16+
'q', 'w', 'e', 'r', /* 19 */
17+
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
18+
0, /* 29 - Control */
19+
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
20+
'\'', '`', 0, /* Left shift */
21+
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
22+
'm', ',', '.', '/', 0, /* Right shift */
23+
'*',
24+
0, /* Alt */
25+
' ', /* Space bar */
26+
0, /* Caps lock */
27+
0, /* 59 - F1 key ... > */
28+
0, 0, 0, 0, 0, 0, 0, 0,
29+
0, /* < ... F10 */
30+
0, /* 69 - Num lock*/
31+
0, /* Scroll Lock */
32+
0, /* Home key */
33+
0, /* Up Arrow */
34+
0, /* Page Up */
35+
'-',
36+
0, /* Left Arrow */
37+
0,
38+
0, /* Right Arrow */
39+
'+',
40+
0, /* 79 - End key*/
41+
0, /* Down Arrow */
42+
0, /* Page Down */
43+
0, /* Insert Key */
44+
0, /* Delete Key */
45+
0, 0, 0,
46+
0, /* F11 Key */
47+
0, /* F12 Key */
48+
0, /* All other keys are undefined */
49+
};
50+
51+
void keyboard_handler(struct regs *r)
52+
{
53+
byte scancode;
54+
scancode = inb(0x60);
55+
56+
if (scancode & 0x80)
57+
{
58+
59+
}
60+
else
61+
{
62+
terminal_write_char(kbdus[scancode]);
63+
}
64+
65+
}

kb.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef __kb_h_
2+
#define __kb_h_
3+
4+
#include "io.h"
5+
#include "types.h"
6+
7+
void init_kb();
8+
9+
void keyboard_handler(struct regs *r);
10+
11+
#endif

kernel.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ void kernel_main()
2222

2323
timer_wait(4);
2424

25-
terminal_write_str("Alright if we got all the way here!\n");
25+
terminal_write_str("Setting up KB\n");
26+
27+
init_kb();
28+
29+
terminal_write_str("Write stuff!\n");
30+
31+
for(;;);
2632

2733
return;
2834
}

pit.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#include "terminal.h"
44
#include "irq.h"
55

6-
volatile dword timer_ticks = 0; //volatile extremely important since those values changed via interrupts
6+
volatile dword timer_ticks = 0; //volatile extremely important since those values change via interrupts
77
volatile dword timer_seconds = 0;
8+
volatile byte waiting;
89

910
void pit_set_timer_phase(word hz)
1011
{
@@ -19,7 +20,7 @@ void timer_handler(struct regs *r)
1920
{
2021
timer_ticks++;
2122

22-
if (timer_ticks % 18 == 0)
23+
if (timer_ticks % 18 == 0 && waiting)
2324
{
2425
terminal_write_str("One second has passed!\n");
2526
timer_seconds++;
@@ -33,10 +34,13 @@ void init_pit()
3334

3435
void timer_wait(dword seconds)
3536
{
37+
waiting = 1;
3638
timer_seconds = 0;
3739

3840
while (timer_seconds < seconds)
3941
{
4042
asm("nop"); //making sure the loop actually runs :)
4143
}
44+
45+
waiting = 0;
4246
}

0 commit comments

Comments
 (0)