From 332b86f520b406e1293f72b66703928b21711593 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sat, 8 Sep 2012 00:42:23 -0400 Subject: [PATCH] framebuffer: fix 16- and 24-bit color. 8-bit still doesn't work. --- kernel/framebuffer.c | 12 ++++++------ kernel/start_kernel.c | 7 +++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/kernel/framebuffer.c b/kernel/framebuffer.c index ef6f175..48cfae2 100644 --- a/kernel/framebuffer.c +++ b/kernel/framebuffer.c @@ -1,22 +1,22 @@ #include int fb_write_pixel_8bit(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) { - unsigned char pixel = (((r >> 6) << 4) & 0x30) | (((b >> 6) << 2) & 0xC) | ((g >> 6) & 0x3); - ((char*) (f->device->fbaddr))[y*f->device->pixelwidth + x] = pixel; + unsigned char pixel = (((b >> 6) << 6) & 0xC0) | (((g >> 5) << 3) & 0x38) | ((r >> 5) & 0x7); + ((char*)f->device->fbaddr)[y*f->device->pixelwidth + x] = pixel; return 0; } int fb_write_pixel_16bit(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) { - unsigned int pixel = (((r >> 3) << 10) & 0x7BF6) | (((b >> 3) << 5) & 0x3E0) | ((g >> 3) & 0x1F); + unsigned int pixel = (((b >> 3) << 11) & 0xF800) | (((g >> 2) << 6) & 0x7E0) | ((r >> 3) & 0x1F); ((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x) << 1] = (char)pixel; ((char*)f->device->fbaddr)[((y*f->device->pixelwidth + x) << 1) + 1] = (char)(pixel >> 8); return 0; } int fb_write_pixel_24bit(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) { - ((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*3] = (char)r; - ((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*3 + 1] = (char)b; - ((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*3 + 2] = (char)g; + ((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*4] = (char)r; + ((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*4 + 1] = (char)g; + ((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*4 + 2] = (char)b; return 0; } diff --git a/kernel/start_kernel.c b/kernel/start_kernel.c index 0552d9c..d74721e 100644 --- a/kernel/start_kernel.c +++ b/kernel/start_kernel.c @@ -11,10 +11,9 @@ void video(void) unsigned int x, y; pl110_init(&myfb, 16); x = 0, y = 0; - for (x=0; x<640; x++) - for (y=0; y<480; y++) - fb_write_pixel(&myfb, x, y, 0x1f, 0x1f, 0x0); - + for (y=0; y<480; y++) + for (x=0; x<640; x++) + fb_write_pixel(&myfb, x, y, 0xff, 0x00, 0x00); } int main(void)