Octocontrabass wrote:
The address is the address of the Multiboot information structure, not the address of the framebuffer. You need to parse the multiboot information structure to find the framebuffer address.
For example:
Code:
void example( uintptr_t addr )
{
multiboot_info_t * mbi = (multiboot_info_t *)addr;
uint8_t * framebuffer = (uint8_t *)mbi->framebuffer_addr;
switch( mbi->framebuffer_bpp )
{
case 8:
framebuffer[mbi->framebuffer_pitch * 100 + 1 * 100] = 4;
break;
case 15:
case 16:
framebuffer[mbi->framebuffer_pitch * 100 + 2 * 100] = 0xff;
break;
case 24:
framebuffer[mbi->framebuffer_pitch * 100 + 3 * 100] = 0xff;
break;
case 32:
framebuffer[mbi->framebuffer_pitch * 100 + 4 * 100] = 0xff;
break;
default:
// error
break;
}
}
It works!! Thank you so much for your help!! One more question though, how do I change the color of the pixel? Do I change the hex values in the last few cases in the switch statement or is it something else?
Here is my code - this works:
Code:
unsigned int *framebuffer;
multiboot_info_t *mbi;
void initializeVGA(unsigned long addr) {
mbi = (multiboot_info_t *)addr; // Get the multiboot information from the address
framebuffer = (unsigned int *)mbi->framebuffer_addr; // Get the framebuffer address
}
void plotPixle(int x, int y, unsigned char color) {
switch (mbi->framebuffer_bpp) {
case 8:
framebuffer[mbi->framebuffer_pitch * y + 1 * x] = 4;
break;
case 15:
break;
case 16:
framebuffer[mbi->framebuffer_pitch * y + 2 * x] = 0xff;
break;
case 24:
framebuffer[mbi->framebuffer_pitch * y + 3 * x] = 0xff;
break;
case 32:
framebuffer[mbi->framebuffer_pitch * y + 4 * x] = 0xff;
break;
default:
// error
break;
}
}