Add basic framebuffer support (probably not working right yet?)
Possibly (probably) calculating wrong pixel values, addresses.
This commit is contained in:
parent
12e890bb8a
commit
38f87f12c5
27
include/framebuffer.h
Normal file
27
include/framebuffer.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef FRAMEBUFFER_H
|
||||||
|
#define FRAMEBUFFER_H
|
||||||
|
|
||||||
|
// 1, 2, and 4 bit color are currently unsupported
|
||||||
|
//#define FB_COLOR_DEPTH_1 1
|
||||||
|
//#define FB_COLOR_DEPTH_2 2
|
||||||
|
//#define FB_COLOR_DEPTH_4 4
|
||||||
|
#define FB_COLOR_DEPTH_8 8
|
||||||
|
#define FB_COLOR_DEPTH_16 16
|
||||||
|
#define FB_COLOR_DEPTH_24 24
|
||||||
|
|
||||||
|
struct fbdev {
|
||||||
|
unsigned int pixelwidth, pixelheight;
|
||||||
|
unsigned int color_depth;
|
||||||
|
void *fbaddr; //start address of the frame buffer in memory
|
||||||
|
void *device_ptr; //passed into device
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fb {
|
||||||
|
unsigned int width, height;
|
||||||
|
unsigned int color_depth;
|
||||||
|
struct fbdev *device;
|
||||||
|
};
|
||||||
|
|
||||||
|
int fb_write_pixel(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b);
|
||||||
|
|
||||||
|
#endif /* FRAMEBUFFER_H */
|
31
kernel/framebuffer.c
Normal file
31
kernel/framebuffer.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <framebuffer.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
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);
|
||||||
|
((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;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fb_write_pixel(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) {
|
||||||
|
if (f->device->color_depth == FB_COLOR_DEPTH_8)
|
||||||
|
return fb_write_pixel_8bit(f, x, y, r, g, b);
|
||||||
|
else if (f->device->color_depth == FB_COLOR_DEPTH_16)
|
||||||
|
return fb_write_pixel_16bit(f, x, y, r, g, b);
|
||||||
|
else if (f->device->color_depth == FB_COLOR_DEPTH_24)
|
||||||
|
return fb_write_pixel_24bit(f, x, y, r, g, b);
|
||||||
|
return -1;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user