aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-07 19:03:47 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-07 19:03:47 -0500
commit0dc446980d8ede518a356ab2c2f165cb08ce444a (patch)
treed9fc8938c1d930f8ece0dd5746601eca5b3089bc /drivers
parent2be70c3b7c3cb806614318858090c039bdfd4fc5 (diff)
downloadkappa-0dc446980d8ede518a356ab2c2f165cb08ce444a.zip
kappa-0dc446980d8ede518a356ab2c2f165cb08ce444a.tar.gz
kappa-0dc446980d8ede518a356ab2c2f165cb08ce444a.tar.bz2
kappa-0dc446980d8ede518a356ab2c2f165cb08ce444a.tar.xz
implement text in graphics mode
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gfx.c78
-rw-r--r--drivers/include/gfx.h3
-rw-r--r--drivers/include/ps2.h2
-rw-r--r--drivers/ps2.c32
4 files changed, 109 insertions, 6 deletions
diff --git a/drivers/gfx.c b/drivers/gfx.c
index 538dadb..38a6591 100644
--- a/drivers/gfx.c
+++ b/drivers/gfx.c
@@ -1,5 +1,9 @@
+#include <stdbool.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include "gfx_font.h"
#include "log.h"
#include "multiboot.h"
#include "panic.h"
@@ -8,6 +12,7 @@
static uint8_t *framebuffer = NULL;
static uint16_t fb_width;
static uint16_t fb_height;
+
/* this is BYTES per pixel */
static uint8_t fb_bpp;
@@ -30,13 +35,82 @@ void gfx_clear(uint32_t col)
}
}
-void gfx_init(struct vbe_info_t *vbe_mode_info)
+void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg)
+{
+ int stride = fb_bpp * fb_width;
+ uint8_t *line_addr = framebuffer + (x * fb_bpp) + (y * fb_width * fb_bpp);
+ for(int i = y; i < y + FONT_HEIGHT; ++i)
+ {
+ uint32_t line_buf[8] = {bg};
+ uint8_t mask = 0x80;
+ for(int j = 0; j < 8; ++j, mask >>= 1)
+ {
+ if(gfx_font[(int)c][i] & mask)
+ line_buf[j] = fg;
+ }
+ memcpy(line_addr, line_buf, sizeof(line_buf));
+ line_addr += stride;
+ }
+}
+
+static int cursor_x, cursor_y;
+static uint32_t fgcol, bgcol;
+
+void gfx_putchar(char ch)
+{
+ if(ch != '\n')
+ {
+ gfx_drawchar(cursor_x, cursor_y, ch, fgcol, bgcol);
+ cursor_x += FONT_WIDTH;
+ if(cursor_x >= fb_width)
+ {
+ cursor_x = 0;
+ cursor_y += FONT_HEIGHT;
+ if(cursor_y >= fb_height)
+ {
+ gfx_clear(bgcol);
+ cursor_y = 0;
+ }
+ }
+ }
+ else
+ {
+ cursor_x = 0;
+ cursor_y += FONT_HEIGHT;
+ if(cursor_y >= fb_height)
+ {
+ gfx_clear(bgcol);
+ cursor_y = 0;
+ }
+ }
+}
+
+void gfx_puts(const char* str)
+{
+ while(*str)
+ {
+ gfx_putchar(*str++);
+ }
+}
+
+bool gfx_init(struct vbe_info_t *vbe_mode_info)
{
framebuffer = (uint8_t*)vbe_mode_info->physbase;
fb_width = vbe_mode_info->Xres;
fb_height = vbe_mode_info->Yres;
fb_bpp = vbe_mode_info->bpp / 8;
if(fb_bpp != 4)
- panic("BPP *MUST* be 32!!!\n");
+ {
+ printf("WARNING: BPP != 32, falling back to text mode...\n");
+ return false;
+ }
gfx_clear(VGA_RGBPACK(0, 0, 0));
+ cursor_y = 0;
+ cursor_x = 0;
+ fgcol = VGA_RGBPACK(0xff, 0xff, 0xff);
+ bgcol = VGA_RGBPACK(0, 0, 0);
+ set_putchar(gfx_putchar);
+ set_puts(gfx_puts);
+
+ return true;
}
diff --git a/drivers/include/gfx.h b/drivers/include/gfx.h
index bafd7a3..19019a9 100644
--- a/drivers/include/gfx.h
+++ b/drivers/include/gfx.h
@@ -1,3 +1,4 @@
+#include <stdbool.h>
#include <stdint.h>
enum vga_color_t {
@@ -31,7 +32,7 @@ enum vga_color_t {
struct vbe_info_t;
-void gfx_init(struct vbe_info_t *vbe_mode_info);
+bool gfx_init(struct vbe_info_t *vbe_mode_info);
void gfx_drawpixel(int x, int y, uint32_t color);
diff --git a/drivers/include/ps2.h b/drivers/include/ps2.h
index 924ef24..6f2c572 100644
--- a/drivers/include/ps2.h
+++ b/drivers/include/ps2.h
@@ -1,3 +1,5 @@
+/* this is both a PS/2 keyboard AND a PS/2 MOUSE driver */
+
#include <stdint.h>
#define PS2_SCROLL_LOCK (1 << 0)
diff --git a/drivers/ps2.c b/drivers/ps2.c
index b9a9b20..742b7ad 100644
--- a/drivers/ps2.c
+++ b/drivers/ps2.c
@@ -1,3 +1,4 @@
+/* this is both a PS/2 keyboard AND a PS/2 MOUSE driver */
#include <stdint.h>
#include <stdio.h>
#include "io.h"
@@ -18,7 +19,7 @@ void ps2_set_leds(uint8_t status)
outb(0x60, status);
}
-static void ps2_handler(struct regs_t regs)
+static void key_handler(struct regs_t regs)
{
(void) regs;
uint8_t scancode = inb(0x60);
@@ -33,8 +34,33 @@ static void ps2_set_scancode_set(uint8_t set)
outb(0x60, set);
}
-void ps2_init(void)
+static void keyboard_init(void)
{
- set_interrupt_handler(IRQ(1), ps2_handler);
+ set_interrupt_handler(IRQ(1), key_handler);
ps2_set_scancode_set(1);
}
+
+static void mouse_handler(struct regs_t regs)
+{
+ printf("mouse action!\n");
+}
+
+static void mouse_init(void)
+{
+ /* enable IRQ12 */
+ set_interrupt_handler(IRQ(12), mouse_handler);
+ /* make the ps/2 controller generate IRQ12 */
+ outb(0x64, 0x20);
+ uint8_t status = inb(0x64);
+ /* set bit 1 and unset bit 5 */
+ status |= (1 << 1);
+ status &= ~(1 << 5);
+ outb(0x64, 0x60);
+ outb(0x60, status);
+}
+
+void ps2_init(void)
+{
+ keyboard_init();
+ mouse_init();
+}