Compare commits
3 commits
1a9201b529
...
086eba4ea4
Author | SHA1 | Date | |
---|---|---|---|
086eba4ea4 | |||
fadccef0df | |||
5bfb8d9e97 |
5 changed files with 93 additions and 69 deletions
24
src/framebuffer.c
Normal file
24
src/framebuffer.c
Normal 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
7
src/framebuffer.h
Normal 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
|
106
src/kernel.c
106
src/kernel.c
|
@ -1,5 +1,5 @@
|
|||
#include "multiboot.h"
|
||||
#include "vga.h"
|
||||
#include "framebuffer.h"
|
||||
#include "serial.h"
|
||||
#include "xtoa.h"
|
||||
|
||||
|
@ -18,90 +18,58 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
|
|||
outb(0x3D4, 0x0A);
|
||||
outb(0x3D5, 0x20);
|
||||
|
||||
//cls();
|
||||
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");
|
||||
}
|
||||
vga_write("Checking multiboot loader: ");
|
||||
int serial_initialized = serial_init();
|
||||
serial_write_string("\n=== KoalemOS ===\n");
|
||||
|
||||
// Check multiboot header
|
||||
if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) {
|
||||
vga_write_color("INVALID MAGIC", VGA_COLOR_BLACK, VGA_COLOR_RED);
|
||||
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: ");
|
||||
vga_write(itoa(mbootinfo->flags, 2));
|
||||
serial_write_string("\nMultiboot flags: ");
|
||||
serial_write_string(itoa(mbootinfo->flags, 2));
|
||||
|
||||
serial_write_string("\nMultiboot flags: ");
|
||||
serial_write_string(itoa(mbootinfo->flags, 2));
|
||||
|
||||
// Check videomode
|
||||
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(itoa(mbootinfo->vbe_mode, 16));
|
||||
serial_write_string("\nVBE Mode: 0x");
|
||||
serial_write_string(itoa(mbootinfo->vbe_mode, 16));
|
||||
}
|
||||
if (mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) {
|
||||
vga_write("\nFramebuffer: ");
|
||||
serial_write_string("\nFramebuffer: ");
|
||||
vga_write("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("\n Dimensions: ");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_width, 10));
|
||||
serial_write_string("X");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_height, 10));
|
||||
serial_write_string("x");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_bpp, 10));
|
||||
serial_write_string("\n Pitch: ");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_pitch, 10));
|
||||
serial_write_string("\n RPos:");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_red_field_position, 10));
|
||||
serial_write_string("\n GPos:");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_green_field_position, 10));
|
||||
serial_write_string("\n BPos:");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_blue_field_position, 10));
|
||||
if (!(mbootinfo->flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO)) {
|
||||
serial_write_string("\nVideo info not available");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long *vmem;
|
||||
int i;
|
||||
for (i = 0; i < mbootinfo->framebuffer_height; i++) {
|
||||
vmem = mbootinfo->framebuffer_addr + i*mbootinfo->framebuffer_pitch + i*(mbootinfo->framebuffer_bpp/8);
|
||||
*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_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;
|
||||
serial_write_string("\nFramebuffer: ");
|
||||
serial_write_string("\n Address: 0x");
|
||||
serial_write_string(ultoa(mbootinfo->framebuffer_addr, 16));
|
||||
|
||||
serial_write_string("\n Dimensions: ");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_width, 10));
|
||||
serial_write_string("X");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_height, 10));
|
||||
serial_write_string("x");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_bpp, 10));
|
||||
serial_write_string("\n Pitch: ");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_pitch, 10));
|
||||
serial_write_string("\n RPos:");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_red_field_position, 10));
|
||||
serial_write_string("\n GPos:");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_green_field_position, 10));
|
||||
serial_write_string("\n BPos:");
|
||||
serial_write_string(itoa(mbootinfo->framebuffer_blue_field_position, 10));
|
||||
|
||||
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 x, y;
|
||||
for (y=0; y<mbootinfo->framebuffer_height;y++) {
|
||||
for (x=0; x<mbootinfo->framebuffer_width;x++) {
|
||||
putpixel(x, y, 0, 255*x/mbootinfo->framebuffer_width, 255*y/mbootinfo->framebuffer_height, 0xff);
|
||||
}
|
||||
|
||||
|
||||
} 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...");
|
||||
}
|
||||
|
|
24
src/xtoa.c
24
src/xtoa.c
|
@ -24,6 +24,30 @@ char* itoa(int value, int base) {
|
|||
}
|
||||
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* result;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define HEADER_XTOA
|
||||
|
||||
char* itoa(int value, int base);
|
||||
char* uitoa(unsigned int value, int base);
|
||||
char* ltoa(long value, int base);
|
||||
char* ultoa(unsigned long value, int base);
|
||||
|
||||
|
|
Loading…
Reference in a new issue