Compare commits

...

3 commits

5 changed files with 93 additions and 69 deletions

24
src/framebuffer.c Normal file
View file

@ -0,0 +1,24 @@
#include "framebuffer.h"
static unsigned long fb_address;
static unsigned long fb_pitch;
static unsigned short fb_width, fb_height;
static unsigned char fb_bpp, fb_bytespp;
static unsigned char fb_rpos, fb_bpos, fb_gpos;
void initfb(unsigned long addr, unsigned short w, unsigned short h, unsigned char bpp, unsigned long pitch, unsigned char rpos, unsigned char gpos, unsigned char bpos) {
fb_address = addr;
fb_pitch = pitch;
fb_width = w;
fb_height = h;
fb_bpp = bpp;
fb_bytespp = bpp/8;
fb_rpos = rpos;
fb_gpos = gpos;
fb_bpos = bpos;
}
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;
*((unsigned long *)(fb_address + y*fb_pitch + x*fb_bytespp)) = r<<fb_rpos | g<<fb_gpos | b<<fb_bpos;
}

7
src/framebuffer.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef _FRAMEBUFFER_H
#define _FRAMEBUFFER_H 1
void initfb(unsigned long addr, unsigned short w, unsigned short h, unsigned char bpp, unsigned long pitch, unsigned char rpos, unsigned char gpos, unsigned char bpos);
void putpixel(unsigned short x, unsigned short y, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
#endif

View file

@ -1,5 +1,5 @@
#include "multiboot.h" #include "multiboot.h"
#include "vga.h" #include "framebuffer.h"
#include "serial.h" #include "serial.h"
#include "xtoa.h" #include "xtoa.h"
@ -18,49 +18,33 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
outb(0x3D4, 0x0A); outb(0x3D4, 0x0A);
outb(0x3D5, 0x20); outb(0x3D5, 0x20);
//cls(); int serial_initialized = serial_init();
vga_init(VGA_COLOR_BLACK, VGA_COLOR_GRAY);
vga_write_line("=== KoalemOS ===");
if (serial_init() > 0) {
vga_write_line_color("Serial initialization failed", VGA_COLOR_BLACK,
VGA_COLOR_ORANGE);
} else {
vga_write_line("\nInitialized serial.");
serial_write_string("\n=== KoalemOS ===\n"); serial_write_string("\n=== KoalemOS ===\n");
}
vga_write("Checking multiboot loader: ");
// Check multiboot header // Check multiboot header
if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) { if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) {
vga_write_color("INVALID MAGIC", VGA_COLOR_BLACK, VGA_COLOR_RED);
return; return;
} }
if (mbootinfo->flags & MULTIBOOT_INFO_BOOT_LOADER_NAME)
vga_write((char *)mbootinfo->boot_loader_name);
else
vga_write_color("Unknown", VGA_COLOR_BLACK, VGA_COLOR_ORANGE);
vga_write("\nMultiboot flags: "); serial_write_string("\nMultiboot flags: ");
vga_write(itoa(mbootinfo->flags, 2)); serial_write_string(itoa(mbootinfo->flags, 2));
serial_write_string("\nMultiboot flags: "); serial_write_string("\nMultiboot flags: ");
serial_write_string(itoa(mbootinfo->flags, 2)); serial_write_string(itoa(mbootinfo->flags, 2));
// Check videomode // Check videomode
if (mbootinfo->flags & MULTIBOOT_INFO_VBE_INFO) { if (mbootinfo->flags & MULTIBOOT_INFO_VBE_INFO) {
vga_write("\nVBE Mode: 0x");
vga_write(itoa(mbootinfo->vbe_mode, 16));
serial_write_string("\nVBE Mode: 0x"); serial_write_string("\nVBE Mode: 0x");
serial_write_string(itoa(mbootinfo->vbe_mode, 16)); serial_write_string(itoa(mbootinfo->vbe_mode, 16));
} }
if (mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
vga_write("\nFramebuffer: "); if (!(mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO)) {
serial_write_string("\nVideo info not available");
return;
}
serial_write_string("\nFramebuffer: "); serial_write_string("\nFramebuffer: ");
vga_write("address: 0x");
serial_write_string("\n Address: 0x"); serial_write_string("\n Address: 0x");
vga_write(ultoa(mbootinfo->framebuffer_addr, 16));
serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16)); serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16));
serial_write_string("\n Dimensions: "); serial_write_string("\n Dimensions: ");
@ -78,30 +62,14 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
serial_write_string("\n BPos:"); serial_write_string("\n BPos:");
serial_write_string(itoa(mbootinfo->framebuffer_blue_field_position, 10)); serial_write_string(itoa(mbootinfo->framebuffer_blue_field_position, 10));
unsigned long *vmem; initfb(mbootinfo->framebuffer_addr, mbootinfo->framebuffer_width, mbootinfo->framebuffer_height, mbootinfo->framebuffer_bpp, mbootinfo->framebuffer_pitch, mbootinfo->framebuffer_red_field_position, mbootinfo->framebuffer_green_field_position, mbootinfo->framebuffer_blue_field_position);
int i;
for (i = 0; i < mbootinfo->framebuffer_height; i++) { int x, y;
vmem = mbootinfo->framebuffer_addr + i*mbootinfo->framebuffer_pitch + i*(mbootinfo->framebuffer_bpp/8); for (y=0; y<mbootinfo->framebuffer_height;y++) {
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8; for (x=0; x<mbootinfo->framebuffer_width;x++) {
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8; putpixel(x, y, 0, 255*x/mbootinfo->framebuffer_width, 255*y/mbootinfo->framebuffer_height, 0xff);
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8; }
*vmem = 0xff<<mbootinfo->framebuffer_red_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_green_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
*vmem = 0xff<<mbootinfo->framebuffer_blue_field_position;((char *)vmem)+=mbootinfo->framebuffer_bpp/8;
} }
} else {
vga_write_color("\nVideo info not available", VGA_COLOR_BLACK, VGA_COLOR_RED);
serial_write_string("\nVideo info not available");
return;
}
vga_write_line("\nExecution finished, halting...");
serial_write_string("\nExecution finished, halting..."); serial_write_string("\nExecution finished, halting...");
} }

View file

@ -24,6 +24,30 @@ char* itoa(int value, int base) {
} }
return result; return result;
} }
char* uitoa(unsigned int value, int base) {
char* result;
// check that the base if valid
if (base < 2 || base > 36) { *result = '\0'; return result; }
char* ptr = result, *ptr1 = result, tmp_char;
int tmp_value;
do {
tmp_value = value;
value /= base;
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
} while ( value );
*ptr-- = '\0';
while(ptr1 < ptr) {
tmp_char = *ptr;
*ptr--= *ptr1;
*ptr1++ = tmp_char;
}
return result;
}
char* ltoa(long value, int base) { char* ltoa(long value, int base) {
char* result; char* result;

View file

@ -2,6 +2,7 @@
#define HEADER_XTOA #define HEADER_XTOA
char* itoa(int value, int base); char* itoa(int value, int base);
char* uitoa(unsigned int value, int base);
char* ltoa(long value, int base); char* ltoa(long value, int base);
char* ultoa(unsigned long value, int base); char* ultoa(unsigned long value, int base);