More work on proofing C++. Will not compile without a custom toolchain.

This commit is contained in:
Curle 2021-07-05 04:17:23 +01:00
parent 6a39a82b08
commit 138c026b9a
7 changed files with 115 additions and 35 deletions

View File

@ -1,6 +1,8 @@
#project config #project config
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
SET(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)
set(CMAKE_CXX_COMPILER x86_64-elf-g++) set(CMAKE_CXX_COMPILER x86_64-elf-g++)
set(CMAKE_C_COMPILER x86_64-elf-gcc) set(CMAKE_C_COMPILER x86_64-elf-gcc)
@ -12,9 +14,9 @@ SET(CMAKE_CROSSCOMPILING 1)
project(chroma) project(chroma)
SET(src_files SET(src_files
${CMAKE_SOURCE_DIR}/src/kernel.c ${CMAKE_SOURCE_DIR}/src/kernel.cpp
${CMAKE_SOURCE_DIR}/src/video/draw.c ${CMAKE_SOURCE_DIR}/src/video/draw.c
${CMAKE_SOURCE_DIR}/src/video/print.c ${CMAKE_SOURCE_DIR}/src/video/print.cpp
${CMAKE_SOURCE_DIR}/src/system/cpu.c ${CMAKE_SOURCE_DIR}/src/system/cpu.c
${CMAKE_SOURCE_DIR}/src//system/rw.c ${CMAKE_SOURCE_DIR}/src//system/rw.c
${CMAKE_SOURCE_DIR}/src/system/serial.c ${CMAKE_SOURCE_DIR}/src/system/serial.c
@ -34,10 +36,10 @@ SET(lib_files
${CMAKE_SOURCE_DIR}/src/lainlib/compression/lzgmini.c ${CMAKE_SOURCE_DIR}/src/lainlib/compression/lzgmini.c
${CMAKE_SOURCE_DIR}/src/lainlib/string/str.c ${CMAKE_SOURCE_DIR}/src/lainlib/string/str.c
${CMAKE_SOURCE_DIR}/src/editor/EditorMain.c ${CMAKE_SOURCE_DIR}/src/editor/EditorMain.cpp
) )
include_directories("inc") include_directories("inc" "D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++" "D:/mingw/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32")
SET(src_no_sse SET(src_no_sse
${CMAKE_SOURCE_DIR}/src/system/interrupts.c ${CMAKE_SOURCE_DIR}/src/system/interrupts.c

View File

@ -73,8 +73,8 @@ void Send8042(size_t);
void WriteSerialChar(const char); void WriteSerialChar(const char);
void WriteSerialString(const char*, size_t); void WriteSerialString(const char*, size_t);
int SerialPrintf(const char* restrict format, ...); int SerialPrintf(const char* format, ...);
int Printf(const char* restrict Format, ...); int Printf(const char* Format, ...);
void* memcpy(void* dest, void const* src, size_t len); void* memcpy(void* dest, void const* src, size_t len);
void* memset(void* dst, int src, size_t len); void* memset(void* dst, int src, size_t len);

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
#include <stdatomic.h> #include <stdatomic.h>
// TODO: <atomic> for cplusplus.
/************************ /************************
*** Team Kitty, 2020 *** *** Team Kitty, 2020 ***

View File

@ -16,7 +16,7 @@ static KeyboardCallback KernelHandler;
void StartEditor(int callbackID) { void StartEditor(int callbackID) {
KernelHandler = KeyboardCallbacks[callbackID]; KernelHandler = KeyboardCallbacks[callbackID];
struct EditorLayout layout = (struct EditorLayout) {0}; struct EditorLayout layout;
layout.ScreenHeight = PrintInfo.screenHeight; layout.ScreenHeight = PrintInfo.screenHeight;
layout.ScreenWidth = PrintInfo.screenWidth; layout.ScreenWidth = PrintInfo.screenWidth;
layout.HeaderHeight = layout.ScreenHeight / 100 * 3; layout.HeaderHeight = layout.ScreenHeight / 100 * 3;

View File

@ -32,8 +32,19 @@ int InternalBufferID;
size_t BufferLength = 0; size_t BufferLength = 0;
char* InternalBuffer; char* InternalBuffer;
#ifdef __cplusplus
}
#endif
/**
* C++ code! Scary!
* This is a temporary measure to experiment with the Editor system.
*/
int Main(void) { int Main(void) {
KernelAddressSpace = (address_space_t) {0}; KernelAddressSpace.Lock.NextTicket = 0;
KernelAddressSpace.Lock.NowServing = 0;
KernelAddressSpace.PML4 = nullptr;
SerialPrintf("\r\n[ boot] Booting Chroma..\r\n"); SerialPrintf("\r\n[ boot] Booting Chroma..\r\n");
SerialPrintf("[ boot] Bootloader data structure at 0x%p\r\n", (size_t) &bootldr); SerialPrintf("[ boot] Bootloader data structure at 0x%p\r\n", (size_t) &bootldr);
@ -64,31 +75,8 @@ int Main(void) {
InternalBuffer = (char*) kmalloc(4096); InternalBuffer = (char*) kmalloc(4096);
SerialPrintf("[ Mem] Allocated a text buffer at 0x%p\r\n", (size_t) InternalBuffer); SerialPrintf("[ Mem] Allocated a text buffer at 0x%p\r\n", (size_t) InternalBuffer);
// TODO: WriteString should accept escape color codes! WriteString("\\${FF0000}C\\${<green>}h\\${<blue>}r\\${FFFF00}o\\${FF00FF}m\\${FFFF}a ");
SetForegroundColor(0x00FF0000); WriteString("\\${FFFFFF}T\\${AAAA}i\\${BBBBBB}m\\${<forgeb>}e\\${<forgey>}!\n");
WriteChar('C');
SetForegroundColor(0x0000FF00);
WriteChar('h');
SetForegroundColor(0x000000FF);
WriteChar('r');
SetForegroundColor(0x00FFFF00);
WriteChar('o');
SetForegroundColor(0x00FF00FF);
WriteChar('m');
SetForegroundColor(0x0000FFFF);
WriteChar('a');
WriteChar(' ');
SetForegroundColor(0x00FFFFFF);
WriteChar('T');
SetForegroundColor(0x0000AAAA);
WriteChar('i');
SetForegroundColor(0x00BBBBBB);
WriteChar('m');
SetForegroundColor(0x001E2D42);
WriteChar('e');
SetForegroundColor(0x00E0A969);
WriteChar('!');
WriteChar('\n');
SetForegroundColor(0x00FFFFFF); SetForegroundColor(0x00FFFFFF);
@ -101,6 +89,10 @@ int Main(void) {
return 0; return 0;
} }
#ifdef __cplusplus
extern "C" {
#endif
void PrintPressedChar(KeyboardData data) { void PrintPressedChar(KeyboardData data) {
if(!KernelLoaded) return; if(!KernelLoaded) return;

View File

@ -336,6 +336,8 @@ void DrawFilledCircleInternal(size_t centerX, size_t centerY, size_t radius, cha
/******* Public *******/ /******* Public *******/
/** TODO: Move all of this into static DrawUtils:: functions */
void DrawFilledRect(size_t x, size_t y, size_t width, size_t height) { void DrawFilledRect(size_t x, size_t y, size_t width, size_t height) {
for (size_t i = y; i < y + height; i++) for (size_t i = y; i < y + height; i++)
DrawHorizontalLine(x, i, width); DrawHorizontalLine(x, i, width);

View File

@ -1,4 +1,5 @@
#include <kernel/chroma.h> #include <kernel/chroma.h>
#include <kernel/video/draw.h>
/************************ /************************
*** Team Kitty, 2020 *** *** Team Kitty, 2020 ***
@ -35,7 +36,7 @@ static void NumToStr(char* Buffer, size_t Num, size_t Base) {
} }
int SerialPrintf(const char* restrict Format, ...) { int SerialPrintf(const char* Format, ...) {
va_list Parameters; va_list Parameters;
va_start(Parameters, Format); va_start(Parameters, Format);
@ -116,7 +117,10 @@ int SerialPrintf(const char* restrict Format, ...) {
return CharsWritten; return CharsWritten;
} }
int Printf(const char* restrict Format, ...) { size_t ParseEnglishColor(const char* Name);
size_t ParseHexColor(const char* Name, bool bgFlag);
int Printf(const char* Format, ...) {
va_list Parameters; va_list Parameters;
va_start(Parameters, Format); va_start(Parameters, Format);
@ -186,6 +190,49 @@ int Printf(const char* restrict Format, ...) {
break; break;
} }
} else if(*Format == '\\') {
Format++; // Skip backslash
switch(*Format) {
case '$':
// COLOR
Format ++; // Skip $ and {
size_t ContentLength = 0;
size_t Color = 0;
bool bgFlag = false;
switch(*Format) {
case '[':
bgFlag = true;
// bg
case '{':
// fg
Format++;
if(*Format == '<') {
Color = ParseEnglishColor(++Format);
Format++;
} else {
Color = ParseHexColor(++Format, bgFlag);
}
if(bgFlag)
SetBackgroundColor(Color);
else
SetForegroundColor(Color);
Format++;
break;
}
Format++;
break;
case 'f':
// FORMAT
break;
}
Format++;
} else { } else {
WriteChar(*Format); WriteChar(*Format);
Format++; Format++;
@ -196,6 +243,41 @@ int Printf(const char* restrict Format, ...) {
return CharsWritten; return CharsWritten;
} }
size_t ParseEnglishColor(const char* Stream) {
if(strcmp("red", Stream))
return 0xFF0000;
if(strcmp("green", Stream))
return 0xFF00;
if(strcmp("blue", Stream))
return 0xFF;
if(strcmp("yellow", Stream))
return 0xFFFF00;
if(strcmp("cyan", Stream))
return 0xFFFF;
if(strcmp("magenta", Stream))
return 0xFF00FF;
if(strcmp("beans", Stream))
return 0xAA11CC;
if(strcmp("forgeb", Stream))
return 0x1E2D42;
if(strcmp("forgey", Stream))
return 0xE0A969;
return 0xFFFFFF;
}
size_t ParseHexColor(const char* Stream, bool bgFlag) {
size_t val = 0;
char c;
while ((*Stream != bgFlag ? ']' : '}') && (c = *Stream++)) {
char v = (c & 0xF) + (c >> 6) | ((c >> 3) & 0x8);
val = (val << 4) | (size_t) v;
}
return val;
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif