From 9db58da40cfcb6643412bfae25aefc0cd1077f9d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 27 May 2024 20:45:46 +0200 Subject: MHR-23: Improve project structure, make it better. Signed-off-by: Amlal El Mahrouss --- SDK/Libraries/CoreSystem/Sources/App.c | 31 ++++++++++++++ SDK/Libraries/CoreSystem/Sources/CRTStartup.c | 12 ++++++ SDK/Libraries/CoreSystem/Sources/File.c | 58 +++++++++++++++++++++++++++ SDK/Libraries/CoreSystem/Sources/Heap.c | 54 +++++++++++++++++++++++++ SDK/Libraries/CoreSystem/Sources/Math.c | 14 +++++++ SDK/Libraries/CoreSystem/Sources/Thread.c | 9 +++++ 6 files changed, 178 insertions(+) create mode 100644 SDK/Libraries/CoreSystem/Sources/App.c create mode 100644 SDK/Libraries/CoreSystem/Sources/CRTStartup.c create mode 100644 SDK/Libraries/CoreSystem/Sources/File.c create mode 100644 SDK/Libraries/CoreSystem/Sources/Heap.c create mode 100644 SDK/Libraries/CoreSystem/Sources/Math.c create mode 100644 SDK/Libraries/CoreSystem/Sources/Thread.c (limited to 'SDK/Libraries/CoreSystem/Sources') diff --git a/SDK/Libraries/CoreSystem/Sources/App.c b/SDK/Libraries/CoreSystem/Sources/App.c new file mode 100644 index 00000000..42ea19c6 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/App.c @@ -0,0 +1,31 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Main Application object, retrieved from the RtGetAppPointer symbol. +ApplicationInterfaceRef kSharedApplication = NullPtr; + +/// @brief Gets the app arguments count. +/// @param void no arguments. +/// @return The number of arguments given to the application. +CS_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) +{ + CS_MUST_PASS(kSharedApplication); + + return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); +} + +/// @brief Gets the app arguments pointer. +/// @param void no arguments. +/// @return +CS_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) +{ + CS_MUST_PASS(kSharedApplication); + + return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, + kCallGetArgsPtr); +} diff --git a/SDK/Libraries/CoreSystem/Sources/CRTStartup.c b/SDK/Libraries/CoreSystem/Sources/CRTStartup.c new file mode 100644 index 00000000..1cfad65d --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/CRTStartup.c @@ -0,0 +1,12 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +VoidType __DllMainCRTStartup(VoidType) +{ + kSharedApplication = RtGetAppPointer(); +} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/File.c b/SDK/Libraries/CoreSystem/Sources/File.c new file mode 100644 index 00000000..7547e7f2 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/File.c @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include +#include + +enum FileOp +{ + kFlushFile, + kReadFork, + kWriteFork, + kOpenFork, + kCloseFork, +}; + +/// @brief Opens a new file. +/// @param path where to find it. +/// @param rest the restrict (rw, rwe, r+, w+, r, w) +/// @return FSRef the file. +CS_EXTERN_C FSRef CSOpenFile(const CharacterTypeUTF8* path, + const CharacterTypeUTF8* rest) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(path && CSIsValidPath(path) == Yes); + CS_MUST_PASS(rest); + + return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, + rest); +} + +/// @brief Closes the file and flushes it to the said file. +/// @param refCS the filesystem reference. +/// @return +CS_EXTERN_C VoidType CSCloseFile(FSRef refCS) +{ + CS_MUST_PASS(kSharedApplication); + + kSharedApplication->Invoke(kSharedApplication, refCS, kFlushFile); + kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refCS); +} + +/// @brief Check if filesystem path is valid. +/// @param path +/// @return +CS_EXTERN_C BooleanType CSIsValidPath(const CharacterTypeUTF8* path) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(path); + + return kSharedApplication->Invoke(kSharedApplication, kCallFileExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDirectoryExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallSymlinkExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDriveExists, path) || + kSharedApplication->Invoke(kSharedApplication, kCallDeviceExists, path); +} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/Heap.c b/SDK/Libraries/CoreSystem/Sources/Heap.c new file mode 100644 index 00000000..e7a77ba5 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/Heap.c @@ -0,0 +1,54 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include +#include + +/// @brief Allocate from the user's heap. +/// @param sz size of object. +/// @param flags flags. +/// @return +CS_EXTERN_C PtrVoidType CSAllocateHeap(QWordType sz, DWordType flags) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(sz); + CS_MUST_PASS(flags); + + return (PtrVoidType)kSharedApplication->Invoke(kSharedApplication, + kCallAllocPtr, sz, flags); +} + +/// @brief Free pointer from the user's heap. +/// @param ptr the pointer to free. +CS_EXTERN_C VoidType CSFreeHeap(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(ptr); + + CS_UNREFERENCED_PARAMETER( + kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); +} + +/// @brief Get pointer size. +/// @param ptr the pointer to find. +/// @return the size. +CS_EXTERN_C QWordType CSGetHeapSize(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + + CS_MUST_PASS(ptr); + return kSharedApplication->Invoke(kSharedApplication, kCallSizePtr, ptr); +} + +/// @brief Check if the pointer exists. +/// @param ptr the pointer to check. +/// @return if it exists +CS_EXTERN_C BooleanType CSIsHeapValid(PtrVoidType ptr) +{ + CS_MUST_PASS(kSharedApplication); + CS_MUST_PASS(ptr); + return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); +} diff --git a/SDK/Libraries/CoreSystem/Sources/Math.c b/SDK/Libraries/CoreSystem/Sources/Math.c new file mode 100644 index 00000000..19df42f3 --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/Math.c @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +/// @brief Number generator helper. +/// @return Random generated number. +CS_EXTERN_C SizeType MathRand(VoidType) +{ + return kSharedApplication->Invoke(kSharedApplication, kCallRandomNumberGenerator); +} \ No newline at end of file diff --git a/SDK/Libraries/CoreSystem/Sources/Thread.c b/SDK/Libraries/CoreSystem/Sources/Thread.c new file mode 100644 index 00000000..7d00bf9e --- /dev/null +++ b/SDK/Libraries/CoreSystem/Sources/Thread.c @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright SoftwareLabs + +------------------------------------------- */ + +#include + +ThreadRef kMainThread = 0; -- cgit v1.2.3