aboutsummaryrefslogtreecommitdiff
path: root/drivers/gfx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gfx.c')
-rw-r--r--drivers/gfx.c55
1 files changed, 39 insertions, 16 deletions
diff --git a/drivers/gfx.c b/drivers/gfx.c
index 53d6686..8dc9d74 100644
--- a/drivers/gfx.c
+++ b/drivers/gfx.c
@@ -9,25 +9,47 @@
#include "panic.h"
#include "gfx.h"
-static uint8_t *framebuffer = NULL;
-static uint16_t fb_width;
-static uint16_t fb_height;
+uint8_t *framebuffer = NULL;
+uint16_t fb_width;
+uint16_t fb_height;
/* this is BYTES per pixel */
-static uint8_t fb_bpp;
+uint8_t fb_bpp;
const uint8_t *gfx_bpp = &fb_bpp;
const uint16_t *gfx_width = &fb_width;
const uint16_t *gfx_height = &fb_height;
static int cursor_x, cursor_y;
-static uint32_t fgcol, bgcol;
+uint32_t _gfx_fgcol, _gfx_bgcol;
-void gfx_drawpixel(int x, int y, uint32_t col)
+void gfx_set_background(uint32_t col)
{
- ((uint32_t*)framebuffer)[y * fb_width + x] = col;
+ _gfx_bgcol = col;
}
+uint32_t gfx_get_background(void)
+{
+ return _gfx_bgcol;
+}
+
+void gfx_set_foreground(uint32_t col)
+{
+ _gfx_fgcol = col;
+}
+
+uint32_t gfx_get_foreground(void)
+{
+ return _gfx_fgcol;
+}
+
+void gfx_drawpixel(int x, int y)
+{
+ ((uint32_t*)framebuffer)[y * fb_width + x] = _gfx_fgcol;
+}
+
+/* implemented in assembly now */
+/*
void gfx_clear(uint32_t col)
{
uint8_t *p = framebuffer;
@@ -38,28 +60,29 @@ void gfx_clear(uint32_t col)
p += fb_bpp;
}
}
+*/
void gfx_reset(void)
{
- gfx_clear(VGA_RGBPACK(0, 0, 0));
+ _gfx_fgcol = VGA_RGBPACK(0xff, 0xff, 0xff);
+ _gfx_bgcol = VGA_RGBPACK(0, 0, 0);
+ gfx_clear();
cursor_y = 0;
cursor_x = 0;
- fgcol = VGA_RGBPACK(0xff, 0xff, 0xff);
- bgcol = VGA_RGBPACK(0, 0, 0);
}
-void gfx_drawchar(int x, int y, char c, uint32_t fg, uint32_t bg)
+void gfx_drawchar(int x, int y, char c)
{
int stride = fb_bpp * fb_width;
uint8_t *line_addr = framebuffer + (x * fb_bpp) + (y * stride);
for(int i = 0; i < FONT_HEIGHT; ++i)
{
- uint32_t line_buf[8] = {bg};
+ uint32_t line_buf[8] = {_gfx_bgcol};
uint8_t mask = 0x80;
for(int j = 0; j < 8; ++j, mask >>= 1)
{
if(gfx_font[(int)c][i] & mask)
- line_buf[j] = fg;
+ line_buf[j] = _gfx_fgcol;
}
memcpy(line_addr, line_buf, sizeof(line_buf));
line_addr += stride;
@@ -70,7 +93,7 @@ void gfx_putchar(char ch)
{
if(ch != '\n')
{
- gfx_drawchar(cursor_x, cursor_y, ch, fgcol, bgcol);
+ gfx_drawchar(cursor_x, cursor_y, ch);
cursor_x += FONT_WIDTH;
if(cursor_x >= fb_width)
{
@@ -78,7 +101,7 @@ void gfx_putchar(char ch)
cursor_y += FONT_HEIGHT;
if(cursor_y >= fb_height)
{
- gfx_clear(bgcol);
+ gfx_clear();
cursor_y = 0;
}
}
@@ -89,7 +112,7 @@ void gfx_putchar(char ch)
cursor_y += FONT_HEIGHT;
if(cursor_y >= fb_height)
{
- gfx_clear(bgcol);
+ gfx_clear();
cursor_y = 0;
}
}