Add: BMP working renderer (24b) + minor bug fixes

This commit is contained in:
xamidev
2024-09-06 21:01:31 +02:00
parent f55723c227
commit 247558669e
14 changed files with 58 additions and 22 deletions

5
debug.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
qemu-system-i386 -s -S -drive file=blankos.iso,format=raw &
sleep 1
gdb -x gdbinit

2
gdbinit Normal file
View File

@@ -0,0 +1,2 @@
target remote localhost:1234
symbol-file kernel.elf

View File

@@ -63,7 +63,7 @@ run: iso
qemu-system-i386 -drive file=blankos.iso,format=raw
debug:
qemu-system-i386 -s -S -drive file=blankos.iso,format=raw
./debug.sh
clean:
rm -rf $(OBJ_DIR) kernel.elf blankos.iso $(TOOLCHAIN_FILE)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

BIN
src/initrd/hibou.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

BIN
src/initrd/red.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
src/initrd/smiley.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@@ -118,11 +118,6 @@ void kmain(multiboot2_info *mb_info)
printf("[debug] malloc test ptr1=0x%x, ptr2=0x%x\n", ptr1, ptr2);
free(ptr1); free(ptr2);
//display_bmp(framebuffer, pitch, bpp, (uint8_t*)initrd_addr);
//putpixel(framebuffer, pitch, bpp, i, j, yellow);
timer_install();
keyboard_install();
printf("[kernel] spawning shell...\n");

View File

@@ -138,6 +138,7 @@ void shell_install()
register_command("pi", program_pi);
register_command("ls", program_ls);
register_command("cat", program_cat);
register_command("bmp", program_bmp);
for (;;)
{

View File

@@ -15,8 +15,19 @@ extern uint32_t* framebuffer;
extern uint32_t VGA_WIDTH;
extern uint32_t VGA_HEIGHT;
unsigned int VGA_X = 0, VGA_Y = 0;
extern int scanline;
int get_cursor_x()
{
return VGA_X;
}
int get_cursor_y()
{
return VGA_Y;
}
void draw_cursor(uint32_t color)
{
for (int y=12; y<CURSOR_HEIGHT; y++)

View File

@@ -87,4 +87,7 @@ enum Colors
beige = 0x00F5F5DC
};
int get_cursor_x();
int get_cursor_y();
#endif

View File

@@ -8,7 +8,9 @@
#include "../kernel/initrd.h"
#include "../drivers/framebuffer.h"
#include "../libc/stdio.h"
#include "../drivers/serial.h"
#pragma pack(push, 1)
typedef struct
{
uint16_t bfType;
@@ -32,15 +34,20 @@ typedef struct
uint32_t biClrUsed;
uint32_t biClrImportant;
} BMPInfoHeader;
#pragma pack(pop)
void display_bmp(uint32_t* fb, int pitch, int bpp, uint8_t* initrd)
void display_bmp(uint32_t* fb, int pitch, int bpp, uint8_t* initrd, const char* filename)
{
char buffer[1024*1024];
int file_status = tar_file_to_buffer(initrd, "./flower.bmp", buffer);
// Should use dynamic allocation when heap works
// Cannot go more than ~500k size for buffer
// Fail zone 450k->470k
// So right now the max should be 400kb img size
char buffer[400*1000];
int file_status = tar_file_to_buffer(initrd, filename, buffer);
if (file_status != 0)
{
puts("Error loading BMP\n");
printf("Error loading file '%s'\n", filename);
return;
}
@@ -49,7 +56,7 @@ void display_bmp(uint32_t* fb, int pitch, int bpp, uint8_t* initrd)
if (bmp_header->bfType != 0x4D42)
{
puts("Not a valid BMP\n");
printf("'%s' is not a valid BMP file\n", filename);
return;
}
@@ -57,25 +64,37 @@ void display_bmp(uint32_t* fb, int pitch, int bpp, uint8_t* initrd)
int height = bmp_info->biHeight;
int pixel_offset = bmp_header->bfOffBits;
if (bmp_info->biBitCount != 24)
{
puts("Not a 24-bit BMP\n");
return;
}
printf("%d-bit BMP, width: %d, height: %d, pixel offset: %d\n", bmp_info->biBitCount, bmp_info->biWidth, bmp_info->biHeight, bmp_header->bfOffBits);
erase_cursor();
uint8_t* pixel_data = (uint8_t*)(buffer + pixel_offset);
for (int y=0; y<height; y++)
int cursor_y = (get_cursor_y()+1)*16;
serial_printf(3, "cursor_y=%d\n", cursor_y);
for (int y=cursor_y; y<height+cursor_y; y++)
{
for (int x=0; x<width; x++)
{
int index = (x+(height-y-1)*width)*3;
int index = (x+(height-y-1+cursor_y)*width)*3;
uint8_t blue = pixel_data[index];
uint8_t green = pixel_data[index+1];
uint8_t red = pixel_data[index+2];
uint32_t color = (red << 16) | (green << 8) | blue;
uint32_t color = (0xFF << 24) | (red << 16) | (green << 8) | blue;
putpixel(fb, pitch, bpp, x, y, color);
}
}
// Update cursor pos after image drawing
move_cursor(get_cursor_x(), get_cursor_y()+(height/16)+2);
}
void program_bmp(int argc, char* argv[])
{
if (argc < 2)
{
puts("Usage: bmp <file>\n");
return;
}
display_bmp(framebuffer, pitch, bpp, (uint8_t*)initrd_addr, argv[1]);
}

View File

@@ -73,7 +73,7 @@ void program_uptime()
void program_help()
{
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\n");
printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\t uptime echo\t sysinfo\tconway\nrot13 morse\tcowsay time\t read\t reboot\npi\t ls\t cat\t bmp\n");
}
// Panic

View File

@@ -38,6 +38,6 @@ void program_reboot();
void program_ls();
void program_cat();
void display_bmp(uint32_t* fb, int pitch, int bpp, uint8_t* initrd);
void program_bmp();
#endif