aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-09 21:00:38 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-09 21:00:38 -0500
commit893694168d8b943505ff30bd4db57ac8aaef6fef (patch)
treec5e74fade8a3183e5b6db53e45eb58cb707dff05 /drivers
parentd894f23d893ee2fa05c34f02231e5c46563dc312 (diff)
downloadkappa-893694168d8b943505ff30bd4db57ac8aaef6fef.zip
kappa-893694168d8b943505ff30bd4db57ac8aaef6fef.tar.gz
kappa-893694168d8b943505ff30bd4db57ac8aaef6fef.tar.bz2
kappa-893694168d8b943505ff30bd4db57ac8aaef6fef.tar.xz
optimization
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gfx.c74
-rw-r--r--drivers/gfx_font.c24
-rw-r--r--drivers/include/gfx.h10
-rw-r--r--drivers/include/tty.h4
-rw-r--r--drivers/tty.c6
5 files changed, 91 insertions, 27 deletions
diff --git a/drivers/gfx.c b/drivers/gfx.c
index e0c5f17..87b2962 100644
--- a/drivers/gfx.c
+++ b/drivers/gfx.c
@@ -46,7 +46,14 @@ uint32_t gfx_get_foreground(void)
void gfx_drawpixel(int x, int y)
{
- ((uint32_t*)framebuffer)[y * fb_width + x] = _gfx_fgcol;
+ if(0 <= y && y < fb_height && 0 <= x && x < fb_width)
+ ((uint32_t*)framebuffer)[y * fb_width + x] = _gfx_fgcol;
+ else
+ {
+ printf("x: %d, y: %d\n", x, y);
+ printf("max_x: %d\nmax_y: %d\n", fb_width, fb_height);
+ panic("OOB");
+ }
}
/* implemented in assembly now */
@@ -72,11 +79,32 @@ void gfx_reset(void)
cursor_x = 0;
}
-void gfx_drawchar(int x, int y, char c)
+void gfx_drawchar(int x, int y, int c)
+{
+ uint8_t *line_addr = framebuffer + (x * fb_bpp) + (y * fb_stride);
+ const uint32_t fg = _gfx_fgcol;
+ const uint16_t stride = fb_stride;
+ if(c < 0 || c > 132)
+ return;
+ for(int i = 0; i < FONT_HEIGHT; ++i)
+ {
+ uint8_t mask_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
+ for(int j = 0; j < 8; ++j)
+ {
+ if(gfx_font[c][i] & mask_table[j])
+ ((uint32_t*)line_addr)[j] = fg;
+ }
+ line_addr += stride;
+ }
+}
+
+void gfx_drawchar_bg(int x, int y, int c)
{
uint8_t *line_addr = framebuffer + (x * fb_bpp) + (y * fb_stride);
- const uint32_t bg = _gfx_bgcol;
const uint32_t fg = _gfx_fgcol;
+ const uint16_t stride = fb_stride;
+ if(c < 0 || c > 132)
+ return;
for(int i = 0; i < FONT_HEIGHT; ++i)
{
uint8_t mask_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
@@ -84,12 +112,14 @@ void gfx_drawchar(int x, int y, char c)
{
if(gfx_font[c][i] & mask_table[j])
((uint32_t*)line_addr)[j] = fg;
+ else
+ ((uint32_t*)line_addr)[j] = _gfx_bgcol;
}
- line_addr += fb_stride;
+ line_addr += stride;
}
}
-void gfx_putchar(char ch)
+void gfx_putchar(int ch)
{
if(ch != '\n')
{
@@ -126,7 +156,7 @@ void gfx_puts(const char* str)
}
}
-/* implemented in assembly */
+/* implemented in assembly now */
#if 0
void gfx_hline(int x1, int x2, int y)
{
@@ -163,15 +193,15 @@ void gfx_vline(int y1, int y2, int x)
uint8_t *dest = framebuffer + y1 * fb_stride + x * fb_bpp;
uint8_t *stop = framebuffer + y2 * fb_stride + x * fb_bpp;
const uint32_t col = _gfx_fgcol;
+ const uint16_t stride = fb_stride;
while(dest < stop)
{
*(uint32_t*)dest = col;
- dest += fb_stride;
+ dest += stride;
}
}
#endif
-#define SWAP(x, y, tmp) (tmp=x;x=y;y=tmp;)
void gfx_fillrect(int x, int y, int w, int h)
{
for(int i = 0; i < h; ++i)
@@ -180,6 +210,34 @@ void gfx_fillrect(int x, int y, int w, int h)
}
}
+void gfx_drawline(int x1, int y1, int x2, int y2)
+{
+ int dx = abs(x2 - x1);
+ int sx = x1 < x2 ? 1 : -1;
+ int dy = -abs(y2 - y1);
+ int sy = y1 < y2 ? 1 : -1;
+ int err = dx + dy;
+ int e2; /* error value e_xy */
+
+ while(1)
+ {
+ gfx_drawpixel(x1, y1);
+ if (x1 == x2 && y1 == y2)
+ break;
+ e2 = err << 1;
+ if (e2 >= dy)
+ {
+ err += dy;
+ x1 += sx;
+ }
+ if (e2 <= dx)
+ {
+ err += dx;
+ y1 += sy;
+ }
+ }
+}
+
bool gfx_init(struct vbe_info_t *vbe_mode_info)
{
framebuffer = (uint8_t*)vbe_mode_info->physbase;
diff --git a/drivers/gfx_font.c b/drivers/gfx_font.c
index 311e86d..4515b31 100644
--- a/drivers/gfx_font.c
+++ b/drivers/gfx_font.c
@@ -1712,17 +1712,17 @@ const uint8_t gfx_font[][12] = {
b(00000000),
b(00000000) /* 12 */
},
- { b(00000000),
- b(01100110),
- b(01100110),
- b(01100110), /* 4 */
- b(01100110),
- b(00000000),
- b(00000000),
- b(00111100), /* 8 */
- b(01100110),
- b(11000011),
- b(00000000),
- b(00000000) /* 12 */
+ { b(10000000),
+ b(11000000),
+ b(11100000),
+ b(11110000), /* 4 */
+ b(11111000),
+ b(11111100),
+ b(11111110),
+ b(11111111), /* 8 */
+ b(11111000),
+ b(11011000),
+ b(10001100),
+ b(00000110) /* 12 */
},
};
diff --git a/drivers/include/gfx.h b/drivers/include/gfx.h
index 561eb3e..50b84dc 100644
--- a/drivers/include/gfx.h
+++ b/drivers/include/gfx.h
@@ -36,9 +36,13 @@ bool gfx_init(struct vbe_info_t *vbe_mode_info);
void gfx_drawpixel(int x, int y);
-void gfx_drawchar(int x, int y, char ch);
+/* transparent background */
+void gfx_drawchar(int x, int y, int ch);
-void gfx_putchar(char ch);
+/* fills the background with bgcolor */
+void gfx_drawchar_bg(int x, int y, int ch);
+
+void gfx_putchar(int ch);
void gfx_puts(const char* str);
@@ -60,6 +64,8 @@ void gfx_vline(int y1, int y2, int x);
void gfx_fillrect(int x1, int y1, int w, int h);
+void gfx_drawline(int x1, int y1, int x2, int y2);
+
extern const uint16_t *gfx_width, *gfx_height;
/* this is _BYTES_ per pixel, NOT BITS per pixel! */
diff --git a/drivers/include/tty.h b/drivers/include/tty.h
index 0e142c6..4748d81 100644
--- a/drivers/include/tty.h
+++ b/drivers/include/tty.h
@@ -4,6 +4,6 @@ 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_putchar_at(int ch, uint8_t color, int x, int y);
+void tty_putchar(int ch);
void tty_puts(const char*);
diff --git a/drivers/tty.c b/drivers/tty.c
index ae15778..e39722b 100644
--- a/drivers/tty.c
+++ b/drivers/tty.c
@@ -75,12 +75,12 @@ uint8_t tty_get_color(void)
return term_col;
}
-void tty_putchar_at(char ch, uint8_t col, int x, int y)
+void tty_putchar_at(int ch, uint8_t col, int x, int y)
{
- term_buf[y * VGA_WIDTH + x] = VGA_MAKE_ENTRY(ch, col);
+ term_buf[y * VGA_WIDTH + x] = VGA_MAKE_ENTRY((char)ch, col);
}
-void tty_putchar(char ch)
+void tty_putchar(int ch)
{
if(ch != '\n')
{