From c8a195e1eb19d346c03c1dfa6ed66c6215caefa2 Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Mon, 2 Feb 2015 21:48:38 -0500 Subject: Refactor, begin writing a PS/2 driver --- drivers/include/ps2.h | 9 +++++++++ drivers/include/tty.h | 9 +++++++++ drivers/include/vga.h | 26 ++++++++++++++++++++++++++ drivers/ps2.c | 29 +++++++++++++++++++++++++++++ drivers/tty.c | 6 ++++++ drivers/tty.h | 9 --------- drivers/vga.h | 26 -------------------------- 7 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 drivers/include/ps2.h create mode 100644 drivers/include/tty.h create mode 100644 drivers/include/vga.h create mode 100644 drivers/ps2.c delete mode 100644 drivers/tty.h delete mode 100644 drivers/vga.h (limited to 'drivers') diff --git a/drivers/include/ps2.h b/drivers/include/ps2.h new file mode 100644 index 0000000..924ef24 --- /dev/null +++ b/drivers/include/ps2.h @@ -0,0 +1,9 @@ +#include + +#define PS2_SCROLL_LOCK (1 << 0) +#define PS2_NUM_LOCK (1 << 1) +#define PS2_CAPS_LOCK (1 << 2) + +void ps2_set_leds(uint8_t status); + +void ps2_init(void); diff --git a/drivers/include/tty.h b/drivers/include/tty.h new file mode 100644 index 0000000..0e142c6 --- /dev/null +++ b/drivers/include/tty.h @@ -0,0 +1,9 @@ +#include + +void tty_init(void); +void tty_clear(void); +void tty_set_color(uint8_t); +uint8_t tty_get_color(void); +void tty_putchar_at(char ch, uint8_t color, int x, int y); +void tty_putchar(char ch); +void tty_puts(const char*); diff --git a/drivers/include/vga.h b/drivers/include/vga.h new file mode 100644 index 0000000..bf13cba --- /dev/null +++ b/drivers/include/vga.h @@ -0,0 +1,26 @@ +#include + +enum vga_color_t { + VGA_BLACK = 0, + VGA_BLUE = 1, + VGA_GREEN = 2, + VGA_CYAN = 3, + VGA_RED = 4, + VGA_MAGENTA = 5, + VGA_BROWN = 6, + VGA_LIGHT_GRAY = 7, + VGA_DARK_GRAY = 8, + VGA_LIGHT_BLUE = 9, + VGA_LIGHT_GREEN = 10, + VGA_LIGHT_CYAN = 11, + VGA_LIGHT_RED = 12, + VGA_LIGHT_MAGENTA = 13, + VGA_LIGHT_BROWN = 14, + VGA_WHITE = 15 +}; + +#define VGA_WIDTH 80 +#define VGA_HEIGHT 25 + +#define VGA_MAKE_COLOR(fg, bg) (fg | bg << 4) +#define VGA_MAKE_ENTRY(ch, col) (((uint16_t)ch)|((uint16_t)col<<8)) diff --git a/drivers/ps2.c b/drivers/ps2.c new file mode 100644 index 0000000..ff85091 --- /dev/null +++ b/drivers/ps2.c @@ -0,0 +1,29 @@ +#include +#include +#include "io.h" +#include "isr.h" +#include "ps2.h" + +void ps2_set_leds(uint8_t status) +{ + outb(0x60, 0xED); + outb(0x60, status); +} + +static void ps2_handler(struct regs_t regs) +{ + uint8_t scancode = inb(0x60); + /* TODO: handle scancode */ +} + +static void ps2_set_scancode_set(uint8_t set) +{ + outb(0x60, 0xF0); + outb(0x60, set); +} + +void ps2_init(void) +{ + set_interrupt_handler(IRQ(1), ps2_handler); + ps2_set_scancode_set(1); +} diff --git a/drivers/tty.c b/drivers/tty.c index c2be189..6668be7 100644 --- a/drivers/tty.c +++ b/drivers/tty.c @@ -65,14 +65,20 @@ void tty_putchar(char ch) { term_x = 0; if(++term_y == VGA_HEIGHT) + { + tty_clear(); term_y = 0; + } } } else { term_x = 0; if(++term_y == VGA_HEIGHT) + { + tty_clear(); term_y = 0; + } } update_cursor(); } diff --git a/drivers/tty.h b/drivers/tty.h deleted file mode 100644 index 0e142c6..0000000 --- a/drivers/tty.h +++ /dev/null @@ -1,9 +0,0 @@ -#include - -void tty_init(void); -void tty_clear(void); -void tty_set_color(uint8_t); -uint8_t tty_get_color(void); -void tty_putchar_at(char ch, uint8_t color, int x, int y); -void tty_putchar(char ch); -void tty_puts(const char*); diff --git a/drivers/vga.h b/drivers/vga.h deleted file mode 100644 index bf13cba..0000000 --- a/drivers/vga.h +++ /dev/null @@ -1,26 +0,0 @@ -#include - -enum vga_color_t { - VGA_BLACK = 0, - VGA_BLUE = 1, - VGA_GREEN = 2, - VGA_CYAN = 3, - VGA_RED = 4, - VGA_MAGENTA = 5, - VGA_BROWN = 6, - VGA_LIGHT_GRAY = 7, - VGA_DARK_GRAY = 8, - VGA_LIGHT_BLUE = 9, - VGA_LIGHT_GREEN = 10, - VGA_LIGHT_CYAN = 11, - VGA_LIGHT_RED = 12, - VGA_LIGHT_MAGENTA = 13, - VGA_LIGHT_BROWN = 14, - VGA_WHITE = 15 -}; - -#define VGA_WIDTH 80 -#define VGA_HEIGHT 25 - -#define VGA_MAKE_COLOR(fg, bg) (fg | bg << 4) -#define VGA_MAKE_ENTRY(ch, col) (((uint16_t)ch)|((uint16_t)col<<8)) -- cgit v1.1