Made the framebuffer support both 24 and 32 bpp

This commit is contained in:
Jarkko Toivanen 2023-09-21 20:01:24 +03:00
parent 2a8169e8fa
commit 5ee43c6e9f
Signed by: jt
GPG key ID: 9151B109B73ECAD5
3 changed files with 26 additions and 8 deletions

View file

@ -20,5 +20,12 @@ void initfb(unsigned long addr, unsigned short w, unsigned short h, unsigned cha
void putpixel(unsigned short x, unsigned short y, unsigned char r, unsigned char g, unsigned char b, unsigned char a) { void putpixel(unsigned short x, unsigned short y, unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
if (x>fb_width || y> fb_height) return; if (x>fb_width || y> fb_height) return;
*((unsigned long *)(fb_address + y*fb_pitch + x*fb_bytespp)) = r<<fb_rpos | g<<fb_gpos | b<<fb_bpos;
if (fb_bpp == 32) {
*((unsigned long *)(fb_address + y*fb_pitch + x*fb_bytespp)) = r<<fb_rpos | g<<fb_gpos | b<<fb_bpos;
} else {
*((unsigned char *)(fb_address + y*fb_pitch + x*fb_bytespp + fb_rpos/8)) = r;
*((unsigned char *)(fb_address + y*fb_pitch + x*fb_bytespp + fb_gpos/8)) = g;
*((unsigned char *)(fb_address + y*fb_pitch + x*fb_bytespp + fb_bpos/8)) = b;
}
} }

View file

@ -72,12 +72,24 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
int x, y, i; int x, y, i;
unsigned char c = 0; unsigned char c = 0;
for(;;) { for(;;) {
for(y=0; y < mbootinfo->framebuffer_height; y++) { //serial_write_string("\n");
for(x=0; x < mbootinfo->framebuffer_width; x++) { for (;c<255;c+=5) {
putpixel(x, y, 0, c, c, 0xff); //serial_write_string("/");
for(y=0; y < mbootinfo->framebuffer_height; y++) {
for(x=0; x < mbootinfo->framebuffer_width; x++) {
putpixel(x, y, 0, c, c, 0xff);
}
}
}
//serial_write_string("\n");
for (;c>0;c-=5) {
//serial_write_string("\\");
for(y=mbootinfo->framebuffer_height; y>=0; y--) {
for(x=mbootinfo->framebuffer_width; x>=0; x--) {
putpixel(x, y, 0, c, c, 0xff);
}
} }
} }
c+=4;
} }
serial_write_string("\nExecution finished, halting...\n"); serial_write_string("\nExecution finished, halting...\n");

View file

@ -21,8 +21,8 @@
.long 0 # bss end address .long 0 # bss end address
.long 0 # entry address .long 0 # entry address
.long 0 # video mode_type (0:fb, 1:txt) (set flags[2]!) .long 0 # video mode_type (0:fb, 1:txt) (set flags[2]!)
.long 1024 # video width .long 640 # video width
.long 768 # video height .long 480 # video height
.long 32 # video depth .long 32 # video depth
.bss .bss
@ -46,4 +46,3 @@ _start:
cli cli
1: hlt 1: hlt
jmp 1b jmp 1b
#include "lol.s"