diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2015-02-08 17:32:23 -0500 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2015-02-08 17:32:23 -0500 |
| commit | 52d2b12c32ab15f4314cf5f0b27ea24709ed1cb1 (patch) | |
| tree | a092e2e798139456d5f1b2f6b320a6c60a705205 /drivers | |
| parent | 0d7cde7c4d735ebebd39b988440f50f5889bd29f (diff) | |
| download | kappa-52d2b12c32ab15f4314cf5f0b27ea24709ed1cb1.zip kappa-52d2b12c32ab15f4314cf5f0b27ea24709ed1cb1.tar.gz kappa-52d2b12c32ab15f4314cf5f0b27ea24709ed1cb1.tar.bz2 kappa-52d2b12c32ab15f4314cf5f0b27ea24709ed1cb1.tar.xz | |
lots of optimization, new features
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/gfx-as.S | 66 | ||||
| -rw-r--r-- | drivers/gfx.c | 73 | ||||
| -rw-r--r-- | drivers/include/gfx.h | 6 |
3 files changed, 134 insertions, 11 deletions
diff --git a/drivers/gfx-as.S b/drivers/gfx-as.S index 70009c1..51c1db8 100644 --- a/drivers/gfx-as.S +++ b/drivers/gfx-as.S @@ -17,11 +17,73 @@ gfx_clear: addl %eax, %edx cmpl %edx, %eax jnb .L2 -.L6: +.L1: movl %ebx, (%eax) addl %ecx, %eax cmpl %eax, %edx - ja .L6 + ja .L1 .L2: popl %ebx ret + + .global gfx_hline +gfx_hline: + pushl %ebx + movl 8(%esp), %eax + movl 12(%esp), %ecx + cmpl %eax, %ecx + jge .L3 + xchgl %eax, %ecx +.L3: + movzwl fb_stride, %edx + movzbl fb_bpp, %ebx + imull 16(%esp), %edx + addl framebuffer, %edx + imull %ebx, %ecx + imull %ebx, %eax + addl %edx, %eax + addl %ecx, %edx + movl _gfx_fgcol, %ecx + cmpl %edx, %eax + jnb .L5 +.L4: + movl %ecx, (%eax) + addl %ebx, %eax + cmpl %eax, %edx + ja .L4 +.L5: + popl %ebx + ret + + .global gfx_vline +gfx_vline: + pushl %esi + pushl %ebx + movl 12(%esp), %eax + movl 16(%esp), %edx + cmpl %eax, %edx + jge .L6 + xchgl %eax, %edx +.L6: + movzwl fb_stride, %ebx + movzbl fb_bpp, %ecx + imull 20(%esp), %ecx + movl framebuffer, %esi + imull %ebx, %edx + imull %ebx, %eax + addl %ecx, %eax + addl %edx, %ecx + leal (%esi,%ecx), %edx + addl %esi, %eax + movl _gfx_fgcol, %ecx + cmpl %edx, %eax + jnb .L8 +.L7: + movl %ecx, (%eax) + addl %ebx, %eax + cmpl %eax, %edx + ja .L7 +.L8: + popl %ebx + popl %esi + ret diff --git a/drivers/gfx.c b/drivers/gfx.c index 8dc9d74..e0c5f17 100644 --- a/drivers/gfx.c +++ b/drivers/gfx.c @@ -15,6 +15,7 @@ uint16_t fb_height; /* this is BYTES per pixel */ uint8_t fb_bpp; +uint16_t fb_stride; const uint8_t *gfx_bpp = &fb_bpp; const uint16_t *gfx_width = &fb_width; @@ -73,19 +74,18 @@ void gfx_reset(void) 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); + uint8_t *line_addr = framebuffer + (x * fb_bpp) + (y * fb_stride); + const uint32_t bg = _gfx_bgcol; + const uint32_t fg = _gfx_fgcol; for(int i = 0; i < FONT_HEIGHT; ++i) { - uint32_t line_buf[8] = {_gfx_bgcol}; - uint8_t mask = 0x80; - for(int j = 0; j < 8; ++j, mask >>= 1) + uint8_t mask_table[8] = {128, 64, 32, 16, 8, 4, 2, 1}; + for(int j = 0; j < 8; ++j) { - if(gfx_font[(int)c][i] & mask) - line_buf[j] = _gfx_fgcol; + if(gfx_font[c][i] & mask_table[j]) + ((uint32_t*)line_addr)[j] = fg; } - memcpy(line_addr, line_buf, sizeof(line_buf)); - line_addr += stride; + line_addr += fb_stride; } } @@ -126,12 +126,67 @@ void gfx_puts(const char* str) } } +/* implemented in assembly */ +#if 0 +void gfx_hline(int x1, int x2, int y) +{ + /* make sure x1 is to the left of x2 */ + if(x2 < x1) + { + int temp = x1; + x1 = x2; + x2 = temp; + } + + uint8_t *base = framebuffer + y * fb_stride; + + uint8_t *dest = base + x1 * fb_bpp; + uint8_t *stop = base + x2 * fb_bpp; + const uint32_t col = _gfx_fgcol; + while(dest < stop) + { + *(uint32_t*)dest = col; + dest += fb_bpp; + } +} + +void gfx_vline(int y1, int y2, int x) +{ + /* make sure y1 is above y2 */ + if(y2 < y1) + { + int temp = y1; + y1 = y2; + y2 = temp; + } + + 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; + while(dest < stop) + { + *(uint32_t*)dest = col; + dest += fb_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) + { + gfx_hline(x, x + w, y + i); + } +} + 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; + fb_stride = fb_bpp * fb_width; if(fb_bpp != 4) { printf("WARNING: BPP != 32, falling back to text mode...\n"); diff --git a/drivers/include/gfx.h b/drivers/include/gfx.h index 42ada32..561eb3e 100644 --- a/drivers/include/gfx.h +++ b/drivers/include/gfx.h @@ -54,6 +54,12 @@ void gfx_set_background(uint32_t); uint32_t gfx_get_background(void); +void gfx_hline(int x1, int x2, int y); + +void gfx_vline(int y1, int y2, int x); + +void gfx_fillrect(int x1, int y1, int w, int h); + extern const uint16_t *gfx_width, *gfx_height; /* this is _BYTES_ per pixel, NOT BITS per pixel! */ |