diff --git a/OVMFbin/OVMF_VARS-pure-efi.fd b/OVMFbin/OVMF_VARS-pure-efi.fd index f681609..344dbbe 100644 Binary files a/OVMFbin/OVMF_VARS-pure-efi.fd and b/OVMFbin/OVMF_VARS-pure-efi.fd differ diff --git a/kernel/bin/CustomOS.img b/kernel/bin/CustomOS.img index d00a36b..25971e4 100644 Binary files a/kernel/bin/CustomOS.img and b/kernel/bin/CustomOS.img differ diff --git a/kernel/bin/kernel.elf b/kernel/bin/kernel.elf index 4615a03..a0de7ed 100755 Binary files a/kernel/bin/kernel.elf and b/kernel/bin/kernel.elf differ diff --git a/kernel/lib/cstr.o b/kernel/lib/cstr.o new file mode 100644 index 0000000..2e79926 Binary files /dev/null and b/kernel/lib/cstr.o differ diff --git a/kernel/lib/kernel.o b/kernel/lib/kernel.o index 8546a3b..c2b5c75 100644 Binary files a/kernel/lib/kernel.o and b/kernel/lib/kernel.o differ diff --git a/kernel/src/cstr.cpp b/kernel/src/cstr.cpp new file mode 100644 index 0000000..7916ca4 --- /dev/null +++ b/kernel/src/cstr.cpp @@ -0,0 +1,90 @@ +#include "cstr.h" + +char uintTo_StringOutput[128]; +const char* to_string(uint64_t value) { + uint8_t size = 0; + uint64_t sizeTest = value; + + while (sizeTest / 10 > 0) { + sizeTest /= 10; + size++; + } + + uint8_t index = 0; + while (value / 10 > 0) { + uint8_t remainder = value % 10; + value /= 10; + uintTo_StringOutput[size - index] = remainder + '0'; + index++; + } + + uint8_t remainder = value % 10; + uintTo_StringOutput[size - index] = remainder + '0'; + uintTo_StringOutput[size + 1] = 0; + + return uintTo_StringOutput; +} + +char intTo_StringOutput[128]; +const char* to_string(int64_t value) { + uint8_t isNegative = 0; + + if (value < 0) { + isNegative = 1; + value *= -1; + intTo_StringOutput[0] = '-'; + } + + uint8_t size = 0; + uint64_t sizeTest = value; + + while (sizeTest / 10 > 0) { + sizeTest /= 10; + size++; + } + + uint8_t index = 0; + while (value / 10 > 0) { + uint8_t remainder = value % 10; + value /= 10; + intTo_StringOutput[isNegative + size - index] = remainder + '0'; + index++; + } + + uint8_t remainder = value % 10; + intTo_StringOutput[isNegative + size - index] = remainder + '0'; + intTo_StringOutput[isNegative + size + 1] = 0; + + return intTo_StringOutput; +} + +char doubleTo_StringOutput[128]; +const char* to_string(double value, uint8_t decimalPlaces) { + char* intPtr = (char*)to_string((int64_t)value); + char* doublePtr = doubleTo_StringOutput; + + if (value < 0) { + value *= -1; + } + + while (*intPtr != 0) { + *doublePtr = *intPtr; + intPtr++; + doublePtr++; + } + + *doublePtr = '.'; + doublePtr++; + + double newValue = value - (int)value; // get only the decimal places + + for (uint8_t i = 0; i < decimalPlaces; i++) { + newValue *= 10; + *doublePtr = (int)newValue + '0'; + newValue -= (int)newValue; + doublePtr++; + } + + *doublePtr = 0; + return doubleTo_StringOutput; +} \ No newline at end of file diff --git a/kernel/src/cstr.h b/kernel/src/cstr.h new file mode 100644 index 0000000..eca6b26 --- /dev/null +++ b/kernel/src/cstr.h @@ -0,0 +1,6 @@ +#pragma once +#include + +const char* to_string(uint64_t value); +const char* to_string(int64_t value); +const char* to_string(double value, uint8_t decimalPlaces); \ No newline at end of file diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 06b55af..beb83ce 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -1,6 +1,7 @@ #include #include #include "BasicRenderer.h" +#include "cstr.h" // supposed to protect against stack smashing but we have no way to actually like @@ -11,7 +12,11 @@ extern "C" void __stack_chk_fail(void) { extern "C" void _start(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) { BasicRenderer newRenderer = BasicRenderer(framebuffer, psf1_Font); - newRenderer.Print(0xFFFFFF, "Hello, World!"); + newRenderer.Print(0xFFFFFF, to_string((uint64_t)1234976)); + newRenderer.cursorPosition = {0, 18}; + newRenderer.Print(0xFFFFFF, to_string((int64_t)-1234976)); + newRenderer.cursorPosition = {0, 36}; + newRenderer.Print(0xFFFFFF, to_string(3.141, 2)); return; } \ No newline at end of file