From 1ce16b83dba0326b13dfa3399c1497ac6b1af14d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 27 Mar 2024 17:38:23 +0100 Subject: Kernel && Developer: Developer: - Rework System API to use C instead of C++ - Add new calls in Thread.h - Documented code. Kernel: - Rework handover stage, separated the Processor specific code from the cross platform code. Signed-off-by: Amlal El Mahrouss --- Public/Developer/System.Core/Headers/Defines.h | 186 +++++++++++++++++++++ Public/Developer/System.Core/Headers/Defines.hxx | 186 --------------------- Public/Developer/System.Core/Headers/Dialog.h | 16 ++ Public/Developer/System.Core/Headers/Dialog.hxx | 16 -- Public/Developer/System.Core/Headers/FS.hxx | 7 - Public/Developer/System.Core/Headers/File.h | 11 ++ Public/Developer/System.Core/Headers/Heap.h | 32 ++++ Public/Developer/System.Core/Headers/Heap.hxx | 32 ---- Public/Developer/System.Core/Headers/Hint.h | 18 ++ Public/Developer/System.Core/Headers/Hint.hxx | 18 -- Public/Developer/System.Core/Headers/Thread.h | 43 +++++ Public/Developer/System.Core/Headers/Thread.hxx | 38 ----- Public/Developer/System.Core/Headers/TrueType.h | 32 ++++ Public/Developer/System.Core/Headers/TrueType.hxx | 31 ---- Public/Developer/System.Core/Headers/Window.h | 147 ++++++++++++++++ Public/Developer/System.Core/Headers/Window.hxx | 144 ---------------- Public/Developer/System.Core/Makefile | 2 +- Public/Developer/System.Core/Sources/CRT0.c | 14 ++ Public/Developer/System.Core/Sources/CRT0.cxx | 14 -- Public/Developer/System.Core/Sources/Heap.c | 46 +++++ Public/Developer/System.Core/Sources/Heap.cxx | 46 ----- .../Developer/System.Core/Sources/New+Delete.cxx | 2 +- 22 files changed, 547 insertions(+), 534 deletions(-) create mode 100644 Public/Developer/System.Core/Headers/Defines.h delete mode 100644 Public/Developer/System.Core/Headers/Defines.hxx create mode 100644 Public/Developer/System.Core/Headers/Dialog.h delete mode 100644 Public/Developer/System.Core/Headers/Dialog.hxx delete mode 100644 Public/Developer/System.Core/Headers/FS.hxx create mode 100644 Public/Developer/System.Core/Headers/File.h create mode 100644 Public/Developer/System.Core/Headers/Heap.h delete mode 100644 Public/Developer/System.Core/Headers/Heap.hxx create mode 100644 Public/Developer/System.Core/Headers/Hint.h delete mode 100644 Public/Developer/System.Core/Headers/Hint.hxx create mode 100644 Public/Developer/System.Core/Headers/Thread.h delete mode 100644 Public/Developer/System.Core/Headers/Thread.hxx create mode 100644 Public/Developer/System.Core/Headers/TrueType.h delete mode 100644 Public/Developer/System.Core/Headers/TrueType.hxx create mode 100644 Public/Developer/System.Core/Headers/Window.h delete mode 100644 Public/Developer/System.Core/Headers/Window.hxx create mode 100644 Public/Developer/System.Core/Sources/CRT0.c delete mode 100644 Public/Developer/System.Core/Sources/CRT0.cxx create mode 100644 Public/Developer/System.Core/Sources/Heap.c delete mode 100644 Public/Developer/System.Core/Sources/Heap.cxx (limited to 'Public/Developer/System.Core') diff --git a/Public/Developer/System.Core/Headers/Defines.h b/Public/Developer/System.Core/Headers/Defines.h new file mode 100644 index 00000000..612f0462 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Defines.h @@ -0,0 +1,186 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#ifdef CA_MUST_PASS +#undef CA_MUST_PASS +#endif + +#ifdef _DEBUG +#define CA_MUST_PASS(e) { if (!e) { DlgMsgBox("Sorry, an assertion failed.\nFile: %s\nLine: %i", __FILE__, __LINE__) __assert_chk_fail() } } +#else +#define CA_MUST_PASS(e) CA_UNREFERENCED_PARAMETER(e) +#endif + +#ifdef __cplusplus + +#define CA_EXTERN_C extern "C" + +#else + +#define CA_EXTERN_C extern + +#endif + +CA_EXTERN_C void __assert_chk_fail(void); + +#define CA_STDCALL __attribute__((stdcall)) +#define CA_CDECL __attribute__((cdecl)) +#define CA_MSCALL __attribute__((ms_abi)) + +#define PACKED __attribute__((packed)) + +#define CA_PASCAL CA_STDCALL + +typedef __UINT8_TYPE__ ByteType; +typedef __UINT16_TYPE__ WordType; +typedef __UINT32_TYPE__ DWordType; +typedef __UINT64_TYPE__ QWordType; +typedef __SIZE_TYPE__ SizeType; + +typedef char CharacterTypeUTF8; +typedef CharacterTypeUTF8* PtrCharacterType; + +typedef void* PtrVoidType; +typedef void VoidType; + +typedef __UINTPTR_TYPE__ UIntPtrType; +typedef __INTPTR_TYPE__ IntPtrType; +typedef __UINT64_TYPE__ UInt64Type; +typedef __INT64_TYPE__ Int64Type; +typedef __UINT32_TYPE__ UInt32Type; +typedef __INT32_TYPE__ Int32Type; + +typedef CharacterTypeUTF8 BooleanType; + +#define CA_COPY_DELETE(KLASS) \ + KLASS &operator=(const KLASS &) = delete; \ + KLASS(const KLASS &) = delete; + + +#define CA_COPY_DEFAULT(KLASS) \ + KLASS &operator=(const KLASS &) = default; \ + KLASS(const KLASS &) = default; + + +#define CA_MOVE_DELETE(KLASS) \ + KLASS &operator=(KLASS &&) = delete; \ + KLASS(KLASS &&) = delete; + + +#define CA_MOVE_DEFAULT(KLASS) \ + KLASS &operator=(KLASS &&) = default; \ + KLASS(KLASS &&) = default; + + +#define Yes 1 +#define No 0 + +#define CA_PTR * + +#define CA_FAR __far +#define CA_NEAR __near + +#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)e) + +#ifdef __x86_64__ +# define _M_AMD64 2 +#endif + +#ifdef __aarch64__ +# define _M_AARCH64 3 +#endif + +#ifdef __powerpc64__ +# define _M_PPC64 4 +#endif + +#ifdef __64x0__ +# define _M_64000 5 +#endif + +#ifdef __riscv__ +# define _M_RISCV 6 +#endif + +#define CA_STATIC static +#define CA_INLINE inline +#define CA_CONST const + +#ifdef __cplusplus +#define CA_CONSTEXPR constexpr +#else +#define CA_CONSTEXPR +#endif // __cplusplus + +enum RtProcessCall { + kProcessCallAllocPtr = 1, + kProcessCallFreePtr, + kProcessCallSizePtr, + kProcessCallCheckPtr, + kProcessCallAllocStack, + /// @brief Open a specific handle (can be used as sel to call methods related to it.) + kProcessCallOpenHandle, + kProcessCallCloseHandle, + /// @brief Number of process calls. + kProcessCallsCount = 7, +}; + +#include +#include + +enum { + kObjectTypeProcess, + kObjectTypeFile, + kObjectTypeDevice, + kObjectTypeNetwork, + kObjectTypeInvalid, + KObjectTypeUserDefined = 0xCF, + kObjectTypeCount = 5, +}; + +/** + * @brief GUID type, something you can also find in CFKit. + * @author AMlal El Mahrouss + */ +typedef struct GUID { + DWordType Data1; + WordType Data2; + WordType Data3; + ByteType Data4[8]; +} GUIDType, *PtrGUIDType; + +/// \brief Object handle. +/// \author Amlal El Mahrouss +typedef struct Object { + CharacterTypeUTF8 Name[255]; + DWordType Kind; + DWordType Flags; + + VoidType(*Release)(struct Object* Self); + IntPtrType(*Invoke)(struct Object* Self, DWordType Sel, ...); + VoidType(*Query)(struct Object* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); +} *ObjectRef; + +#ifdef __cplusplus + +#define object_cast reinterpret_cast + +template +using StrType = CharacterTypeUTF8[N]; + +#else + +#define object_cast (ObjectRef) + +#endif // ifdef C++ + +CA_EXTERN_C ObjectRef RtGetAppObject(VoidType); + +CA_INLINE ObjectRef kApplicationObject; + +typedef CharacterTypeUTF8 Str255Type[255]; diff --git a/Public/Developer/System.Core/Headers/Defines.hxx b/Public/Developer/System.Core/Headers/Defines.hxx deleted file mode 100644 index 64b1295e..00000000 --- a/Public/Developer/System.Core/Headers/Defines.hxx +++ /dev/null @@ -1,186 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#ifdef CA_MUST_PASS -#undef CA_MUST_PASS -#endif - -#ifdef _DEBUG -#define CA_MUST_PASS(e) { if (!e) { DlgMsgBox("Sorry, an assertion failed.\nFile: %s\nLine: %i", __FILE__, __LINE__) __assert_chk_fail() } } -#else -#define CA_MUST_PASS(e) CA_UNREFERENCED_PARAMETER(e) -#endif - -#ifdef __cplusplus - -#define CA_EXTERN_C extern "C" - -#else - -#define CA_EXTERN_C extern - -#endif - -CA_EXTERN_C void __assert_chk_fail(void); - -#define CA_STDCALL __attribute__((stdcall)) -#define CA_CDECL __attribute__((cdecl)) -#define CA_MSCALL __attribute__((ms_abi)) - -#define PACKED __attribute__((packed)) - -#define CA_PASCAL CA_STDCALL - -typedef __UINT8_TYPE__ ByteType; -typedef __UINT16_TYPE__ WordType; -typedef __UINT32_TYPE__ DWordType; -typedef __UINT64_TYPE__ QWordType; -typedef __SIZE_TYPE__ SizeType; - -typedef char CharacterTypeUTF8; -typedef CharacterTypeUTF8* PtrCharacterType; - -typedef void* PtrVoidType; -typedef void VoidType; - -typedef __UINTPTR_TYPE__ UIntPtrType; -typedef __INTPTR_TYPE__ IntPtrType; -typedef __UINT64_TYPE__ UInt64Type; -typedef __INT64_TYPE__ Int64Type; -typedef __UINT32_TYPE__ UInt32Type; -typedef __INT32_TYPE__ Int32Type; - -typedef CharacterTypeUTF8 BooleanType; - -#define CA_COPY_DELETE(KLASS) \ - KLASS &operator=(const KLASS &) = delete; \ - KLASS(const KLASS &) = delete; - - -#define CA_COPY_DEFAULT(KLASS) \ - KLASS &operator=(const KLASS &) = default; \ - KLASS(const KLASS &) = default; - - -#define CA_MOVE_DELETE(KLASS) \ - KLASS &operator=(KLASS &&) = delete; \ - KLASS(KLASS &&) = delete; - - -#define CA_MOVE_DEFAULT(KLASS) \ - KLASS &operator=(KLASS &&) = default; \ - KLASS(KLASS &&) = default; - - -#define Yes 1 -#define No 0 - -#define CA_PTR * - -#define CA_FAR __far -#define CA_NEAR __near - -#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)e) - -#ifdef __x86_64__ -# define _M_AMD64 2 -#endif - -#ifdef __aarch64__ -# define _M_AARCH64 3 -#endif - -#ifdef __powerpc64__ -# define _M_PPC64 4 -#endif - -#ifdef __64x0__ -# define _M_64000 5 -#endif - -#ifdef __riscv__ -# define _M_RISCV 6 -#endif - -#define CA_STATIC static -#define CA_INLINE inline -#define CA_CONST const - -#ifdef __cplusplus -#define CA_CONSTEXPR constexpr -#else -#define CA_CONSTEXPR -#endif // __cplusplus - -enum RtProcessCall { - kProcessCallAllocPtr = 1, - kProcessCallFreePtr, - kProcessCallSizePtr, - kProcessCallCheckPtr, - kProcessCallAllocStack, - /// @brief Open a specific handle (can be used as sel to call methods related to it.) - kProcessCallOpenHandle, - kProcessCallCloseHandle, - /// @brief Number of process calls. - kProcessCallsCount = 7, -}; - -#include -#include - -enum { - kObjectTypeProcess, - kObjectTypeFile, - kObjectTypeDevice, - kObjectTypeNetwork, - kObjectTypeInvalid, - KObjectTypeUserDefined = 0xCF, - kObjectTypeCount = 5, -}; - -/** - * @brief GUID type, something you can also find in CFKit. - * @author AMlal El Mahrouss - */ -typedef struct GUID { - DWordType Data1; - WordType Data2; - WordType Data3; - ByteType Data4[8]; -} GUIDType, *PtrGUIDType; - -/// \brief Object handle. -/// \author Amlal El Mahrouss -typedef struct Object { - CharacterTypeUTF8 Name[255]; - DWordType Kind; - DWordType Flags; - - VoidType(*Release)(struct Object* Self); - IntPtrType(*Invoke)(struct Object* Self, DWordType Sel, ...); - VoidType(*Query)(struct Object* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); -} *ObjectRef; - -#ifdef __cplusplus - -#define object_cast reinterpret_cast - -template -using StrType = CharacterTypeUTF8[N]; - -#else - -#define object_cast (ObjectRef) - -#endif // ifdef C++ - -CA_EXTERN_C ObjectRef RtGetAppObject(VoidType); - -CA_INLINE ObjectRef kApplicationObject; - -typedef CharacterTypeUTF8 Str255Type[255]; diff --git a/Public/Developer/System.Core/Headers/Dialog.h b/Public/Developer/System.Core/Headers/Dialog.h new file mode 100644 index 00000000..9d4521cf --- /dev/null +++ b/Public/Developer/System.Core/Headers/Dialog.h @@ -0,0 +1,16 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief Shows an message box with a formatting. +/// @param title the message box title +/// @param format the format +/// @param va_list the va args, that goes along with it. +/// @return void this function returns nothing. +CA_EXTERN_C VoidType DlgMsgBox(CharacterTypeUTF8* title, CharacterTypeUTF8* format, ...); diff --git a/Public/Developer/System.Core/Headers/Dialog.hxx b/Public/Developer/System.Core/Headers/Dialog.hxx deleted file mode 100644 index 0faaae67..00000000 --- a/Public/Developer/System.Core/Headers/Dialog.hxx +++ /dev/null @@ -1,16 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/// @brief Shows an message box with a formatting. -/// @param title the message box title -/// @param format the format -/// @param va_list the va args, that goes along with it. -/// @return void -CA_EXTERN_C VoidType DlgMsgBox(CharacterTypeUTF8* title, CharacterTypeUTF8* format, ...); diff --git a/Public/Developer/System.Core/Headers/FS.hxx b/Public/Developer/System.Core/Headers/FS.hxx deleted file mode 100644 index 62ed1255..00000000 --- a/Public/Developer/System.Core/Headers/FS.hxx +++ /dev/null @@ -1,7 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once diff --git a/Public/Developer/System.Core/Headers/File.h b/Public/Developer/System.Core/Headers/File.h new file mode 100644 index 00000000..bd1d8d3f --- /dev/null +++ b/Public/Developer/System.Core/Headers/File.h @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief Filesystem wrapper. diff --git a/Public/Developer/System.Core/Headers/Heap.h b/Public/Developer/System.Core/Headers/Heap.h new file mode 100644 index 00000000..90f15aa5 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Heap.h @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +#define kAllocationTypes 2 + +enum RtAllocationKind { + kStandardAllocation = 0xC, + kArrayAllocation = 0xD, +}; + +/// @brief Allocates a new heap from process pool. +/// @param refObj +/// @param sz +/// @param flags +/// @return +CA_EXTERN_C PtrVoidType RtAllocateProcessHeap(ObjectRef refObj, QWordType sz, + DWordType flags); + +/// @brief Check if pointer exists. +/// @param refObj +/// @param ptr +/// @return +CA_EXTERN_C BooleanType RtProcessHeapExists(ObjectRef refObj, PtrVoidType ptr); +CA_EXTERN_C QWordType RtProcessHeapSize(ObjectRef refObj, PtrVoidType ptr); +CA_EXTERN_C VoidType RtFreeProcessHeap(ObjectRef refObj, PtrVoidType ptr); diff --git a/Public/Developer/System.Core/Headers/Heap.hxx b/Public/Developer/System.Core/Headers/Heap.hxx deleted file mode 100644 index c6252c04..00000000 --- a/Public/Developer/System.Core/Headers/Heap.hxx +++ /dev/null @@ -1,32 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -#define kAllocationTypes 2 - -enum RtAllocationKind { - kStandardAllocation = 0xC, - kArrayAllocation = 0xD, -}; - -/// @brief Allocates a new heap from process pool. -/// @param refObj -/// @param sz -/// @param flags -/// @return -CA_EXTERN_C PtrVoidType RtAllocateProcessHeap(ObjectRef refObj, QWordType sz, - DWordType flags); - -/// @brief Check if pointer exists. -/// @param refObj -/// @param ptr -/// @return -CA_EXTERN_C BooleanType RtProcessHeapExists(ObjectRef refObj, PtrVoidType ptr); -CA_EXTERN_C QWordType RtProcessHeapSize(ObjectRef refObj, PtrVoidType ptr); -CA_EXTERN_C VoidType RtFreeProcessHeap(ObjectRef refObj, PtrVoidType ptr); diff --git a/Public/Developer/System.Core/Headers/Hint.h b/Public/Developer/System.Core/Headers/Hint.h new file mode 100644 index 00000000..86faf455 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Hint.h @@ -0,0 +1,18 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut diff --git a/Public/Developer/System.Core/Headers/Hint.hxx b/Public/Developer/System.Core/Headers/Hint.hxx deleted file mode 100644 index 86faf455..00000000 --- a/Public/Developer/System.Core/Headers/Hint.hxx +++ /dev/null @@ -1,18 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/Public/Developer/System.Core/Headers/Thread.h b/Public/Developer/System.Core/Headers/Thread.h new file mode 100644 index 00000000..7d2bfe3c --- /dev/null +++ b/Public/Developer/System.Core/Headers/Thread.h @@ -0,0 +1,43 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +// +// Created by Amlal on 3/18/24 +// + +#ifndef __THREAD__ +#define __THREAD__ + +#include + +#define kThreadErrorExit -33 + +/// @brief Thread Information Block, which holds information about the running +/// thread. +typedef QWordType ThreadRef; + +/// @brief Main application thread. +CA_EXTERN_C ThreadRef kMainThread; + +typedef VoidType(*ThreadEntrypointKind)(VoidType); + +/// @brief Creates a new thread, and runs the code. +/// @param threadName the thread's name. +/// @param threadStart where to start. +/// @return +CA_EXTERN_C ThreadRef TmCreateThread(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); + +/// @brief Dispoes the thread, and exits with code kThreadErrorExit +/// @param ref the thread reference. +/// @return nothing. +CA_EXTERN_C VoidType TmDisposeThread(ThreadRef ref); + +/// @brief Waits for the thread to complete. +/// @param ref the thread reference. +/// @return nothing. +CA_EXTERN_C VoidType TmWaitForCompletion(ThreadRef ref); + +#endif // __THREAD__ diff --git a/Public/Developer/System.Core/Headers/Thread.hxx b/Public/Developer/System.Core/Headers/Thread.hxx deleted file mode 100644 index 6118ea21..00000000 --- a/Public/Developer/System.Core/Headers/Thread.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -// -// Created by Amlal on 3/18/24 -// - -#ifndef __THREAD_API__ -#define __THREAD_API__ - -#include - -#define kThreadErrorExit -33 - -/// @brief Thread Information Block, which holds information about the running -/// thread. -typedef QWordType ThreadRef; - -/// @brief Main application thread. -CA_EXTERN_C ThreadRef kMainThread; - -typedef VoidType(*ThreadEntrypointKind)(VoidType); - -/// @brief Creates a new thread, and runs the code. -/// @param threadName the thread's name. -/// @param threadStart where to start. -/// @return -CA_EXTERN_C ThreadRef TmCreateThread(const CharacterTypeUTF8* threadName, ThreadEntrypointKind threadStart); - -/// @brief Dispoes the thread, and exits with code kThreadErrorExit -/// @param ref -/// @return -CA_EXTERN_C VoidType TmDisposeThread(ThreadRef ref); - -#endif // __THREAD_API__ diff --git a/Public/Developer/System.Core/Headers/TrueType.h b/Public/Developer/System.Core/Headers/TrueType.h new file mode 100644 index 00000000..5ad9d7a7 --- /dev/null +++ b/Public/Developer/System.Core/Headers/TrueType.h @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/************************************************************* + * + * File: TrueType.hxx + * Purpose: TrueType font implementation for HCore. + * Date: 3/26/24 + * + * Copyright Mahrouss Logic, all rights reserved. + * + *************************************************************/ + +typedef QWordType TTFFontRef; + +/// @brief Loads a new font into app's memory. +/// @param name +/// @return +CA_EXTERN_C TTFFontRef FnCreateFont(const char* name); + +/// @brief Dispose an allocated font. +/// @param fon +/// @return +CA_EXTERN_C VoidType FnDisposeFont(TTFFontRef fon); + diff --git a/Public/Developer/System.Core/Headers/TrueType.hxx b/Public/Developer/System.Core/Headers/TrueType.hxx deleted file mode 100644 index 185bbc78..00000000 --- a/Public/Developer/System.Core/Headers/TrueType.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/************************************************************* - * - * File: TrueType.hxx - * Purpose: TrueType font implementation for System Software. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ - -typedef QWordType TTFFontRef; - -/// @brief Loads a new font into app's memory. -/// @param name -/// @return -CA_EXTERN_C TTFFontRef FnCreateFont(const char* name); - -/// @brief Dispose an allocated font. -/// @param fon -/// @return -CA_EXTERN_C VoidType FnDisposeFont(TTFFontRef fon); \ No newline at end of file diff --git a/Public/Developer/System.Core/Headers/Window.h b/Public/Developer/System.Core/Headers/Window.h new file mode 100644 index 00000000..121ac502 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Window.h @@ -0,0 +1,147 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/************************************************************* + * + * File: Window.hxx + * Purpose: Window Manager API for HCore. + * Date: 3/26/24 + * + * Copyright Mahrouss Logic, all rights reserved. + * + *************************************************************/ + +struct _WmPoint; +struct _WindowPort; + +#ifdef __SINGLE_PRECISION__ +typedef float PositionType; +#else +typedef double PositionType; +#endif + +typedef QWordType DCRef; + +/// @brief A point, can represent the size, position of a window. +typedef struct _WmPoint { + PositionType X, Y; +} WmPoint; + +/// @brief Window port type, can be used to control the window. +typedef struct _WindowPort { + WordType windowPort; + WordType windowKind; + BooleanType windowVisible; + BooleanType windowMaximized; + BooleanType windowMinimized; + BooleanType windowMoving; + BooleanType windowDisableClose; + BooleanType windowDisableMinimize; + WmPoint windowPosition; + WmPoint windowSize; + BooleanType windowInvalidate; + DWordType windowClearColor; + WordType menuPort; + WordType parentPort; + DCRef windowDeviceContext; +} WindowPort; + +typedef UInt32Type ColorRef; + +/***********************************************************************************/ +/// Color utils. +/***********************************************************************************/ + +const ColorRef kRgbRed = 0x000000FF; +const ColorRef kRgbGreen = 0x0000FF00; +const ColorRef kRgbBlue = 0x00FF0000; +const ColorRef kRgbBlack = 0x00000000; +const ColorRef kRgbWhite = 0xFFFFFFFF; + +/***********************************************************************************/ +/// Color macro. +/***********************************************************************************/ + +#define RGB32(R, G, B) (ColorRef)(0x##R##G##B) + +#define kGraphicsKindWindow 0 +#define kGraphicsKindDialog 1 +#define kGraphicsKindMenu 2 +#define kGraphicsKindButton 3 +#define kGraphicsKindLabel 4 +#define kGraphicsKindDropdown 5 +#define kGraphicsKindIcon 6 +#define kGraphicsKindRadio 7 +#define kGraphicsKindCheck 7 + +typedef QWordType ControlRef; + +/// @brief Creates a new control +/// @param id the control rsrc fork. +/// @return +CA_EXTERN_C ControlRef WmCreateControl(const DWordType id); + +/// @brief Releases the control +/// @param id the control ref. +/// @return +CA_EXTERN_C VoidType WmReleaseControl(const ControlRef id); + +/// @brief Moves a control inside a WindowPort. +/// @param id the control ref. +/// @param where where to move at. +/// @return +CA_EXTERN_C Int32Type WmSetControlPosition(const ControlRef id, WmPoint where); + +/// @brief Enable control. +/// @param id +/// @param enabled +/// @return +CA_EXTERN_C Int32Type WmSetControlEnabled(const ControlRef id, BooleanType enabled); + +/// @brief Make control visible. +/// @param id +/// @param visible +/// @return +CA_EXTERN_C Int32Type WmMakeControlVisible(const ControlRef id, BooleanType visible); + +/// @brief Creates a new window. +/// @param name the window name +/// @param rsrcId the window fork rsrc id. +/// @return the window graphics port. +CA_EXTERN_C WindowPort* WmCreateWindow(const char* name, const DWordType rsrcId); + +/// @brief Creates a new menu +/// @param name the menu's name +/// @param rsrcId the menu fork rsrc id. +/// @return the menu graphics port. +CA_EXTERN_C WindowPort* WmCreateMenu(const char* name, const DWordType rsrcId); + +/// @brief Releases the window. +/// @param port the window port. +/// @return void +CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* port); + +/// @brief Releases the menu +/// @param port the menu port. +/// @return void +CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* port); + +/// @brief Moves a window on the desktop. (menu arent movable, will return kErrIncompatible is menu is provided.) +/// @param id the gfx port. +/// @param where to move. +/// @return error code. +CA_EXTERN_C Int32Type WmMoveWindow(const WindowPort* id, WmPoint where); + +enum { + kWmErrIncompatible = 0x74, + kWmErrOutOfMemory, + kWmErrInvalidArg, + kWmErrNotImplemented, +}; diff --git a/Public/Developer/System.Core/Headers/Window.hxx b/Public/Developer/System.Core/Headers/Window.hxx deleted file mode 100644 index 39d5eb47..00000000 --- a/Public/Developer/System.Core/Headers/Window.hxx +++ /dev/null @@ -1,144 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/************************************************************* - * - * File: Window.hxx - * Purpose: Window Manager implementation for System Software. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ - -struct _GraphicsPoint; -struct _GraphicsPort; - -#ifdef __SINGLE_PRECISION__ -typedef float PositionType; -#else -typedef double PositionType; -#endif - -/// @brief A point, can represent the size, position of a window. -typedef struct _GraphicsPoint { - PositionType X, Y; -} GraphicsPoint; - -/// @brief Tracker Graphics port. -typedef struct _GraphicsPort { - WordType windowPort; - WordType windowKind; - BooleanType windowVisible; - BooleanType windowMaximized; - BooleanType windowMinimized; - BooleanType windowMoving; - BooleanType windowDisableClose; - BooleanType windowDisableMinimize; - GraphicsPoint windowPosition; - GraphicsPoint windowSize; - BooleanType windowInvalidate; - DWordType windowClearColor; - WordType menuPort; - WordType parentPort; -} GraphicsPort; - -typedef UInt32Type ColorRef; - -/***********************************************************************************/ -/// Color utils. -/***********************************************************************************/ - -const ColorRef kRgbRed = 0x000000FF; -const ColorRef kRgbGreen = 0x0000FF00; -const ColorRef kRgbBlue = 0x00FF0000; -const ColorRef kRgbBlack = 0x00000000; -const ColorRef kRgbWhite = 0xFFFFFFFF; - -/***********************************************************************************/ -/// Color macro. -/***********************************************************************************/ - -#define RGB32(R, G, B) (ColorRef)(0x##R##G##B) - -#define kGraphicsKindWindow 0 -#define kGraphicsKindDialog 1 -#define kGraphicsKindMenu 2 -#define kGraphicsKindButton 3 -#define kGraphicsKindLabel 4 -#define kGraphicsKindDropdown 5 -#define kGraphicsKindIcon 6 -#define kGraphicsKindRadio 7 -#define kGraphicsKindCheck 7 - -typedef QWordType ControlRef; - -/// @brief Creates a new control -/// @param id the control rsrc fork. -/// @return -CA_EXTERN_C ControlRef WmCreateControl(const DWordType id); - -/// @brief Releases the control -/// @param id the control ref. -/// @return -CA_EXTERN_C VoidType WmReleaseControl(const ControlRef id); - -/// @brief Moves a control inside a GraphicsPort. -/// @param id the control ref. -/// @param where where to move at. -/// @return -CA_EXTERN_C Int32Type WmSetControlPosition(const ControlRef id, GraphicsPoint where); - -/// @brief Enable control. -/// @param id -/// @param enabled -/// @return -CA_EXTERN_C Int32Type WmSetControlEnabled(const ControlRef id, BooleanType enabled); - -/// @brief Make control visible. -/// @param id -/// @param visible -/// @return -CA_EXTERN_C Int32Type WmMakeControlVisible(const ControlRef id, BooleanType visible); - -/// @brief Creates a new window. -/// @param name the window name -/// @param rsrcId the window fork rsrc id. -/// @return the window graphics port. -CA_EXTERN_C GraphicsPort* WmCreateWindow(const char* name, const DWordType rsrcId); - -/// @brief Creates a new menu -/// @param name the menu's name -/// @param rsrcId the menu fork rsrc id. -/// @return the menu graphics port. -CA_EXTERN_C GraphicsPort* WmCreateMenu(const char* name, const DWordType rsrcId); - -/// @brief Releases the window. -/// @param port the window port. -/// @return void -CA_EXTERN_C VoidType WmReleaseWindow(GraphicsPort* port); - -/// @brief Releases the menu -/// @param port the menu port. -/// @return void -CA_EXTERN_C VoidType WmReleaseMenu(GraphicsPort* port); - -/// @brief Moves a window on the desktop. (menu arent movable, will return kErrIncompatible is menu is provided.) -/// @param id the gfx port. -/// @param where to move. -/// @return error code. -CA_EXTERN_C Int32Type WmMoveWindow(const GraphicsPort* id, GraphicsPoint where); - -enum { - kWmErrIncompatible = 0x74, - kWmErrOutOfMemory, - kWmErrInvalidArg, - kWmErrNotImplemented, -}; diff --git a/Public/Developer/System.Core/Makefile b/Public/Developer/System.Core/Makefile index 11e4760f..0f20cc72 100644 --- a/Public/Developer/System.Core/Makefile +++ b/Public/Developer/System.Core/Makefile @@ -9,7 +9,7 @@ OUTPUT=System.Core.lib .PHONY: build-core-amd64 build-core-amd64: - $(CC) -I../ -I$(HOME) -I../../../Private/ $(CCFLAGS) $(wildcard Sources/*.cxx) $(wildcard AMD64/*.s) -o $(OUTPUT) + $(CC) -I../ -I$(HOME) -I../../../Private/ $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard Sources/*.cxx) $(wildcard AMD64/*.s) -o $(OUTPUT) .PHONY: all all: build-core diff --git a/Public/Developer/System.Core/Sources/CRT0.c b/Public/Developer/System.Core/Sources/CRT0.c new file mode 100644 index 00000000..03aa62b8 --- /dev/null +++ b/Public/Developer/System.Core/Sources/CRT0.c @@ -0,0 +1,14 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#include + +/// @brief Inits the library. +/// @return if it was succesful or not. +CA_EXTERN_C DWordType __start(VoidType) { + kApplicationObject = RtGetAppObject(); + CA_MUST_PASS(kApplicationObject); + + return 0; +} \ No newline at end of file diff --git a/Public/Developer/System.Core/Sources/CRT0.cxx b/Public/Developer/System.Core/Sources/CRT0.cxx deleted file mode 100644 index 244e62d5..00000000 --- a/Public/Developer/System.Core/Sources/CRT0.cxx +++ /dev/null @@ -1,14 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#include - -/// @brief Inits the library. -/// @return if it was succesful or not. -CA_EXTERN_C DWordType __start(VoidType) { - kApplicationObject = RtGetAppObject(); - CA_MUST_PASS(kApplicationObject); - - return 0; -} \ No newline at end of file diff --git a/Public/Developer/System.Core/Sources/Heap.c b/Public/Developer/System.Core/Sources/Heap.c new file mode 100644 index 00000000..390ae072 --- /dev/null +++ b/Public/Developer/System.Core/Sources/Heap.c @@ -0,0 +1,46 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +/// @brief Allocate from the user's heap. +/// @param refObj Process object. +/// @param sz size of object. +/// @param flags flags. +/// @return +CA_EXTERN_C PtrVoidType RtAllocateProcessHeap(ObjectRef refObj, QWordType sz, + DWordType flags) { + CA_MUST_PASS(sz); + CA_MUST_PASS(flags); + + return (PtrVoidType)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags); +} + +/// @brief Free pointer from the user's heap. +/// @param refObj Process object. +/// @param ptr the pointer to free. +CA_EXTERN_C VoidType RtFreeProcessHeap(ObjectRef refObj, PtrVoidType ptr) { + CA_MUST_PASS(ptr); + CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr)); +} + +/// @brief Get pointer size. +/// @param refObj Process object. +/// @param ptr the pointer to find. +/// @return the size. +CA_EXTERN_C QWordType RtProcessHeapSize(ObjectRef refObj, PtrVoidType ptr) { + CA_MUST_PASS(ptr); + return refObj->Invoke(refObj, kProcessCallSizePtr, ptr); +} + +/// @brief Check if the pointer exists. +/// @param refObj Process object. +/// @param ptr the pointer to check. +/// @return if it exists +CA_EXTERN_C BooleanType RtProcessHeapExists(ObjectRef refObj, PtrVoidType ptr) { + CA_MUST_PASS(ptr); + return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr); +} diff --git a/Public/Developer/System.Core/Sources/Heap.cxx b/Public/Developer/System.Core/Sources/Heap.cxx deleted file mode 100644 index 991987ca..00000000 --- a/Public/Developer/System.Core/Sources/Heap.cxx +++ /dev/null @@ -1,46 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -/// @brief Allocate from the user's heap. -/// @param refObj Process object. -/// @param sz size of object. -/// @param flags flags. -/// @return -CA_EXTERN_C PtrVoidType RtAllocateProcessHeap(ObjectRef refObj, QWordType sz, - DWordType flags) { - CA_MUST_PASS(sz); - CA_MUST_PASS(flags); - - return (PtrVoidType)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags); -} - -/// @brief Free pointer from the user's heap. -/// @param refObj Process object. -/// @param ptr the pointer to free. -CA_EXTERN_C VoidType RtFreeProcessHeap(ObjectRef refObj, PtrVoidType ptr) { - CA_MUST_PASS(ptr); - CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr)); -} - -/// @brief Get pointer size. -/// @param refObj Process object. -/// @param ptr the pointer to find. -/// @return the size. -CA_EXTERN_C QWordType RtProcessHeapSize(ObjectRef refObj, PtrVoidType ptr) { - CA_MUST_PASS(ptr); - return refObj->Invoke(refObj, kProcessCallSizePtr, ptr); -} - -/// @brief Check if the pointer exists. -/// @param refObj Process object. -/// @param ptr the pointer to check. -/// @return if it exists -CA_EXTERN_C BooleanType RtProcessHeapExists(ObjectRef refObj, PtrVoidType ptr) { - CA_MUST_PASS(ptr); - return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr); -} diff --git a/Public/Developer/System.Core/Sources/New+Delete.cxx b/Public/Developer/System.Core/Sources/New+Delete.cxx index 3901aed1..3e2942c5 100644 --- a/Public/Developer/System.Core/Sources/New+Delete.cxx +++ b/Public/Developer/System.Core/Sources/New+Delete.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include typedef SizeType size_t; -- cgit v1.2.3