Printing int/hex values, yayyyy! (videomode number)
This commit is contained in:
parent
7d576d3cd5
commit
f1b11875d7
1 changed files with 35 additions and 5 deletions
40
kernel.c
40
kernel.c
|
@ -1,9 +1,37 @@
|
||||||
#include "multiboot.h"
|
#include "multiboot.h"
|
||||||
#include "vga.h"
|
#include "vga.h"
|
||||||
|
|
||||||
// static inline void outb(unsigned int port, unsigned char val) {
|
/*
|
||||||
// asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
|
static inline void outb(unsigned int port, unsigned char val) {
|
||||||
// }
|
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
char* itoa(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 );
|
||||||
|
|
||||||
|
// Apply negative sign
|
||||||
|
if (tmp_value < 0) *ptr++ = '-';
|
||||||
|
*ptr-- = '\0';
|
||||||
|
while(ptr1 < ptr) {
|
||||||
|
tmp_char = *ptr;
|
||||||
|
*ptr--= *ptr1;
|
||||||
|
*ptr1++ = tmp_char;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
|
void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
|
||||||
|
|
||||||
|
@ -23,10 +51,12 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
|
||||||
vga_write_color("INVALID MAGIC", VGA_COLOR_BLACK, VGA_COLOR_RED);
|
vga_write_color("INVALID MAGIC", VGA_COLOR_BLACK, VGA_COLOR_RED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vga_write(mbootinfo->boot_loader_name);
|
vga_write((char *)mbootinfo->boot_loader_name);
|
||||||
|
|
||||||
// Check videomode
|
// Check videomode
|
||||||
vga_write("\nVideomode: ");
|
vga_write("\nVideomode: 0x");
|
||||||
|
vga_write(itoa(mbootinfo->vbe_mode, 16));
|
||||||
|
vga_write(": ");
|
||||||
switch (mbootinfo->vbe_mode) {
|
switch (mbootinfo->vbe_mode) {
|
||||||
case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED:
|
case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED:
|
||||||
vga_write("Indexed");
|
vga_write("Indexed");
|
||||||
|
|
Loading…
Reference in a new issue