diff options
author | Ian C <ianc@noddybox.co.uk> | 2007-03-01 00:36:54 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2007-03-01 00:36:54 +0000 |
commit | 6be2806499299bb13edde3481803f28416429902 (patch) | |
tree | ee80944e5af4f9ab002fb91c73f032ee6d385de8 /source/framebuffer.c | |
parent | b7fc2934d2cd1e593fe5d1c99678321a21d0948d (diff) |
Changed lower screen to 8-bits and added overlayed text mode. Monitor stub in place. Text mode helpers being developed.
Diffstat (limited to 'source/framebuffer.c')
-rw-r--r-- | source/framebuffer.c | 193 |
1 files changed, 139 insertions, 54 deletions
diff --git a/source/framebuffer.c b/source/framebuffer.c index 691862e..6d16529 100644 --- a/source/framebuffer.c +++ b/source/framebuffer.c @@ -25,12 +25,16 @@ #include <stdarg.h> #include <string.h> +#include "framebuffer.h" + /* ---------------------------------------- STATIC DATA */ #define WIDTH 256 +#define SCAN 128 #define HEIGHT 192 -static uint16 *buff=0; +static uint16 *buff; +static uint16 *pal; static uint8 font[]= { @@ -132,60 +136,138 @@ static uint8 font[]= 0x3c, 0x42, 0x99, 0x85, 0x85, 0x99, 0x42, 0x3c }; + +/* ---------------------------------------- PRIVATE INTERFACES +*/ +static inline void Plot(int x, int y, int col) +{ + uint16 *base; + uint16 cur; + int odd; + + if (col == -1) + return; + + odd = x&1; + x /= 2; + + base = buff+x+y*SCAN; + cur = *base; + + if (odd) + { + cur = (cur & 0xff) | (col<<8); + } + else + { + cur = (cur & 0xff00) | col; + } + + *base = cur; +} + + /* ---------------------------------------- PUBLIC INTERFACES */ -void FB_Init(uint16 *vram) +void FB_Init(uint16 *vram, uint16 *palette) { - buff=vram; + buff = vram; + pal = palette; + + pal[COL_BLACK] = RGB15(0,0,0); + pal[COL_WHITE] = RGB15(31,31,31); + pal[COL_RED] = RGB15(31,0,0); + pal[COL_GREEN] = RGB15(0,31,0); + pal[COL_BLUE] = RGB15(0,0,31); + pal[COL_GUISELECT] = RGB15(8,8,31); + pal[COL_GREY] = RGB15(15,15,15); + pal[COL_LIGHTGREY] = RGB15(22,22,22); + pal[COL_DARKGREY] = RGB15(8,8,8); + pal[COL_YELLOW] = RGB15(31,31,0); } -void FB_Print(const char *text, int x, int y, int colour, int paper) +void FB_LoadASCIITiles(uint16 *tiles) { - uint16 *base; + uint8 *src; + int c; + int row; + int val; + int mask; - base=buff+y*WIDTH+x; + src = font; - while(*text) + for(c = 32; c < 127; c++) { - int x,y; - int ch; + for(row = 0; row < 8; row++) + { + for(mask = 1; mask < 0xff; mask<<=1) + { + if (*src & mask) + { + val = COL_WHITE; + } + else + { + val = 0; + } + + mask <<= 1; + + if (*src & mask) + { + val |= COL_WHITE << 8; + } + + *tiles++ = val; + } + + src++; + } + } +} + +void FB_Print(const char *text, int x, int y, FB_Colour colour, FB_Colour paper) +{ + int cx,cy; + int ch; + + while(*text) + { ch=((*text)-32)*8; - for(y=0;y<8;y++) + for(cy=0;cy<8;cy++) { - for(x=0;x<8;x++) + for(cx=0;cx<8;cx++) { - if (font[ch]&(1<<x)) + if (font[ch]&(1<<cx)) { - *(base+x+y*WIDTH)=colour; + Plot(x+cx, y+cy, colour); } else { - if (paper!=-1) - { - *(base+x+y*WIDTH)=paper; - } + Plot(x+cx, y+cy, paper); } } ch++; } - base+=8; + x+=8; text++; } } -void FB_Centre(const char *text, int y, int colour, int paper) +void FB_Centre(const char *text, int y, FB_Colour colour, FB_Colour paper) { FB_Print(text,WIDTH/2-strlen(text)*4,y,colour,paper); } -void FB_printf(int x, int y, int colour, int paper, const char *format, ...) +void FB_printf(int x, int y, FB_Colour colour, FB_Colour paper, + const char *format, ...) { char buff[80]; va_list va; @@ -198,7 +280,7 @@ void FB_printf(int x, int y, int colour, int paper, const char *format, ...) } -void FB_HLine(int x1, int x2, int y, int colour) +void FB_HLine(int x1, int x2, int y, FB_Colour colour) { uint16 *line; @@ -206,28 +288,21 @@ void FB_HLine(int x1, int x2, int y, int colour) while(x1<=x2) { - *line++=colour; - x1++; + Plot(x1++,y,colour); } } -void FB_VLine(int x, int y1, int y2, int colour) +void FB_VLine(int x, int y1, int y2, FB_Colour colour) { - uint16 *line; - - line=buff+y1*WIDTH+x; - while(y1<=y2) { - *line=colour; - line+=WIDTH; - y1++; + Plot(x,y1++,colour); } } -void FB_Box(int x, int y, int w, int h, int colour) +void FB_Box(int x, int y, int w, int h, FB_Colour colour) { FB_HLine(x,x+w-1,y,colour); FB_HLine(x,x+w-1,y+h-1,colour); @@ -236,21 +311,11 @@ void FB_Box(int x, int y, int w, int h, int colour) } -void FB_FillBox(int x, int y, int w, int h, int colour) +void FB_FillBox(int x, int y, int w, int h, FB_Colour colour) { - int f; - uint16 *base; - - base=buff+x+y*WIDTH; - while(h--) { - for(f=0;f<w;f++) - { - *(base+f)=colour; - } - - base+=WIDTH; + FB_HLine(x,x+w-1,y++,colour); } } @@ -260,30 +325,50 @@ void FB_Clear(void) uint16 *p; int f; - f=WIDTH*HEIGHT; + f=WIDTH*HEIGHT/2; p=buff; while(f--) { - *p++=0x8000; + *p++=0; } } -void FB_Blit(sImage *img, int x, int y) +void FB_Blit(sImage *img, int x, int y, int offset) { - if (img->width==WIDTH && img->height==HEIGHT) + uint16 *dest; + uint16 *row; + uint8 *src; + uint16 pix; + int hww; + int ht; + int f; + + x /= 2; + + ht = img->height; + hww = img->width / 2; + dest = buff+x+y*SCAN; + src = img->image.data8; + + for(f=0;f<16;f++) { - dmaCopy(img->image.data8,buff,SCREEN_WIDTH*SCREEN_HEIGHT*2); + pal[offset+f] = img->palette[f]; } - else + + while(ht--) { - int f; + row = dest; - for(f=0;f<img->height;f++) + for(f=0;f<hww;f++) { - dmaCopy(img->image.data16+(f*img->width), - buff+x+(y+f)*WIDTH,img->width*2); + pix = *src++ + offset; + pix |= (*src++ + offset) << 8; + + *row++ = pix; } + + dest += SCAN; } } |