diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-28 20:54:33 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-28 20:54:33 +0100 |
| commit | b2c7b8604ed3a4c209a15a9ffd718a43163dd9b4 (patch) | |
| tree | 851d79e3a9b1c676b48ec8dfcd2b989f4da45c9b /Public/Developer | |
| parent | 215518ae55a54973a1ae18f572ca5bf0ac2a499e (diff) | |
NewKernel: Add PowerPC partition type inside EPM, add Leak() FileStream method. and documentation.
SystemLib: Start implementing the API.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Public/Developer')
| -rw-r--r-- | Public/Developer/System.Core/Headers/Defines.h | 27 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Headers/File.h | 33 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Headers/Heap.h | 28 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Headers/TrueType.h | 2 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Headers/Window.h | 54 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Makefile | 2 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Sources/App.c | 20 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Sources/Heap.c | 22 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Sources/New+Delete.cxx | 13 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Sources/Start.c (renamed from Public/Developer/System.Core/Sources/CRT0.c) | 2 | ||||
| -rw-r--r-- | Public/Developer/System.Core/Sources/Window.c | 62 |
11 files changed, 198 insertions, 67 deletions
diff --git a/Public/Developer/System.Core/Headers/Defines.h b/Public/Developer/System.Core/Headers/Defines.h index cf8cbde6..36884786 100644 --- a/Public/Developer/System.Core/Headers/Defines.h +++ b/Public/Developer/System.Core/Headers/Defines.h @@ -82,7 +82,7 @@ typedef CharacterTypeUTF8 BooleanType; #define CA_PTR * -#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)e) +#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)(e)) #ifdef __x86_64__ @@ -124,16 +124,22 @@ typedef CharacterTypeUTF8 BooleanType; #endif // __cplusplus enum RtProcessCall { - kProcessCallAllocPtr = 1, - kProcessCallFreePtr, - kProcessCallSizePtr, - kProcessCallCheckPtr, - kProcessCallAllocStack, + kCallAllocPtr = 1, + kCallFreePtr, + kCallSizePtr, + kCallCheckPtr, + kCallAllocStack, /// @brief Open a specific handle (can be used as sel to call methods related to it.) - kProcessCallOpenHandle, - kProcessCallCloseHandle, + kCallOpenFile, + kCallCloseFile, + kCallCreateWindow, + kCallCloseWindow, + kCallCreateMenu, + kCallCloseMenu, + kCallGetArgsCount, + kCallGetArgsPtr, /// @brief Number of process calls. - kProcessCallsCount = 7, + kCallsCount, }; #include <System.Core/Headers/Hint.h> @@ -193,3 +199,6 @@ CA_EXTERN_C CharacterTypeUTF8* RtGetAppArgumentsPtr(VoidType); CA_INLINE ObjectRef kApplicationObject; typedef CharacterTypeUTF8 Str255Type[255]; + +#define True 1 +#define False 0 diff --git a/Public/Developer/System.Core/Headers/File.h b/Public/Developer/System.Core/Headers/File.h index bd1d8d3f..13bc7a00 100644 --- a/Public/Developer/System.Core/Headers/File.h +++ b/Public/Developer/System.Core/Headers/File.h @@ -9,3 +9,36 @@ #include <System.Core/Headers/Defines.h> /// @brief Filesystem wrapper. + +typedef QWordTyp FSRef; + +/// @brief Opens a new file. +/// @param path where to find it. +/// @param r the restrict (rw, rwe, r+, w+, r, w) +/// @return +CA_EXTERN_C FSRef FsOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); + +/// @brief Closes the file and flushes it to the said file. +/// @param refFs the filesystem reference. +/// @return +CA_EXTERN_C VoidType FsCloseFile(FSRef refFs); + +typedef QWordTyp FSForkRef; + +/// @brief A fork information header. +typedef struct _Fork { + PtrVoidType forkData; + SizeType forkSize; + Int32Type forkFlags; + Int32Type forkKind; + CharacterTypeUTF8 forkName[256]; +} ForkType; + +/// @brief Gets the fork inside a file. +/// @param refFs the filesystem ref +/// @param forkName the fork's name +/// @return the fork data. +CA_EXTERN_C FSForkRef FsGetFork(FSRef refFs, const CharacterTypeUTF8* forkName); + +#define FsGetDataFork(refFs) FsGetFork(refFs, "data") +#define FsGetRsrcFork(refFs) FsGetFork(refFs, "rsrc") diff --git a/Public/Developer/System.Core/Headers/Heap.h b/Public/Developer/System.Core/Headers/Heap.h index 90f15aa5..9f3215db 100644 --- a/Public/Developer/System.Core/Headers/Heap.h +++ b/Public/Developer/System.Core/Headers/Heap.h @@ -15,18 +15,24 @@ enum RtAllocationKind { kArrayAllocation = 0xD, }; -/// @brief Allocates a new heap from process pool. -/// @param refObj -/// @param sz -/// @param flags +/// @brief Allocates a new pointer from process pool. +/// @param sz the size +/// @param flags the allocation flags. /// @return -CA_EXTERN_C PtrVoidType RtAllocateProcessHeap(ObjectRef refObj, QWordType sz, +CA_EXTERN_C PtrVoidType RtAllocateProcessPtr(QWordType sz, DWordType flags); -/// @brief Check if pointer exists. -/// @param refObj -/// @param ptr +/// @brief Check if the pointer exists. +/// @param ptr the pointer to free. /// @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); +CA_EXTERN_C BooleanType RtProcessPtrExists(PtrVoidType ptr); + +/// @brief Gets the size of the process' pointer. +/// @param ptr the pointer to free. +/// @return +CA_EXTERN_C QWordType RtProcessPtrSize(PtrVoidType ptr); + +/// @brief Frees the process pointer. +/// @param ptr the pointer to free. +/// @return +CA_EXTERN_C VoidType RtFreeProcessPtr(PtrVoidType ptr); diff --git a/Public/Developer/System.Core/Headers/TrueType.h b/Public/Developer/System.Core/Headers/TrueType.h index 3859148f..2e8f4142 100644 --- a/Public/Developer/System.Core/Headers/TrueType.h +++ b/Public/Developer/System.Core/Headers/TrueType.h @@ -23,7 +23,7 @@ typedef QWordType TTFFontRef; /// @brief Loads a new font into app's memory. /// @param name /// @return -CA_EXTERN_C TTFFontRef FnCreateFont(const char* name); +CA_EXTERN_C TTFFontRef FnCreateFont(const CharacterTypeUTF8* name); /// @brief Dispose an allocated font. /// @param fon diff --git a/Public/Developer/System.Core/Headers/Window.h b/Public/Developer/System.Core/Headers/Window.h index 831c87bb..714ef7de 100644 --- a/Public/Developer/System.Core/Headers/Window.h +++ b/Public/Developer/System.Core/Headers/Window.h @@ -48,11 +48,19 @@ typedef struct _WindowPort { WmPoint windowSize; BooleanType windowInvalidate; DWordType windowClearColor; - WordType menuPort; - WordType parentPort; - DCRef windowDeviceContext; + struct _WindowPort* menuPort; + struct _WindowPort* parentPort; } WindowPort; +typedef struct _ControlPort { + WordType controlPort; + WordType controlKind; + BooleanType controlVisible; + BooleanType controlMoving; + WmPoint controlPosition; + WindowPort* parentPort; +} ControlPort; + typedef UInt32Type ColorRef; /***********************************************************************************/ @@ -69,59 +77,57 @@ 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 +#define WmMakeColorRef(R, G, B) (ColorRef)(0x##R##G##B) -typedef QWordType ControlRef; +#define kControlKindWindow 0 +#define kControlKindDialog 1 +#define kControlKindMenu 2 +#define kControlKindButton 3 +#define kControlKindLabel 4 +#define kControlKindDropdown 5 +#define kControlKindIcon 6 +#define kControlKindRadio 7 +#define kControlKindCheck 7 /// @brief Creates a new control /// @param id the control rsrc fork. /// @return -CA_EXTERN_C ControlRef WmCreateControl(const DWordType id); +CA_EXTERN_C ControlPort* WmCreateControl(DWordType id); /// @brief Releases the control /// @param id the control ref. /// @return -CA_EXTERN_C VoidType WmReleaseControl(const ControlRef id); +CA_EXTERN_C VoidType WmReleaseControl(ControlPort* id); -/// @brief Moves a control inside a WindowPort. +/// @brief Moves a control inside a ControlPort. /// @param id the control ref. /// @param where where to move at. /// @return -CA_EXTERN_C Int32Type WmSetControlPosition(const ControlRef id, WmPoint where); +CA_EXTERN_C Int32Type WmSetControlPosition(ControlPort* id, WmPoint where); /// @brief Enable control. /// @param id /// @param enabled /// @return -CA_EXTERN_C Int32Type WmSetControlEnabled(const ControlRef id, BooleanType enabled); +CA_EXTERN_C Int32Type WmSetControlEnabled(ControlPort* id, BooleanType enabled); /// @brief Make control visible. /// @param id /// @param visible /// @return -CA_EXTERN_C Int32Type WmMakeControlVisible(const ControlRef id, BooleanType visible); +CA_EXTERN_C Int32Type WmMakeControlVisible(ControlPort* 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); +CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* 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); +CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, const DWordType rsrcId); /// @brief Releases the window. /// @param port the window port. @@ -137,7 +143,7 @@ CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* port); /// @param id the gfx port. /// @param where to move. /// @return error code. -CA_EXTERN_C Int32Type WmMoveWindow(const WindowPort* id, WmPoint where); +CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* id, WmPoint where); enum { kWmErrIncompatible = 0x74, diff --git a/Public/Developer/System.Core/Makefile b/Public/Developer/System.Core/Makefile index 32b473f3..34851e99 100644 --- a/Public/Developer/System.Core/Makefile +++ b/Public/Developer/System.Core/Makefile @@ -10,7 +10,7 @@ OUTPUT=SystemLib.lib .PHONY: build-core-amd64 build-core-amd64: - $(CC) $(INC) $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard Sources/*.cxx) $(wildcard AMD64/*.s) -o $(OUTPUT) + $(CC) $(CCINC) $(CCFLAGS) $(wildcard Sources/*.c) $(wildcard Sources/*.cxx) $(wildcard AMD64/*.s) -o $(OUTPUT) .PHONY: all all: build-core-amd64 diff --git a/Public/Developer/System.Core/Sources/App.c b/Public/Developer/System.Core/Sources/App.c new file mode 100644 index 00000000..0bd7fd03 --- /dev/null +++ b/Public/Developer/System.Core/Sources/App.c @@ -0,0 +1,20 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#include <System.Core/Headers/Defines.h> + +/// @brief Gets the app arguments count. +/// @param +/// @return +CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) { + return kApplicationObject->Invoke(kApplicationObject, kCallGetArgsCount); +} + +/// @brief Gets the app arguments pointer. +/// @param +/// @return +CA_EXTERN_C CharacterTypeUTF8* RtGetAppArgumentsPtr(VoidType) { + return (CharacterTypeUTF8*)kApplicationObject->Invoke(kApplicationObject, + kCallGetArgsPtr); +}
\ No newline at end of file diff --git a/Public/Developer/System.Core/Sources/Heap.c b/Public/Developer/System.Core/Sources/Heap.c index 390ae072..db4a16bf 100644 --- a/Public/Developer/System.Core/Sources/Heap.c +++ b/Public/Developer/System.Core/Sources/Heap.c @@ -7,40 +7,36 @@ #include <System.Core/Headers/Heap.h> /// @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_EXTERN_C PtrVoidType RtAllocateProcessPtr(QWordType sz, + DWordType flags) { CA_MUST_PASS(sz); CA_MUST_PASS(flags); - return (PtrVoidType)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags); + return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, kCallAllocPtr, 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_EXTERN_C VoidType RtFreeProcessPtr(PtrVoidType ptr) { CA_MUST_PASS(ptr); - CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr)); + CA_UNREFERENCED_PARAMETER(kApplicationObject->Invoke(kApplicationObject, kCallFreePtr, 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_EXTERN_C QWordType RtProcessPtrSize(PtrVoidType ptr) { CA_MUST_PASS(ptr); - return refObj->Invoke(refObj, kProcessCallSizePtr, ptr); + return kApplicationObject->Invoke(kApplicationObject, kCallSizePtr, 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_EXTERN_C BooleanType RtProcessPtrExists(PtrVoidType ptr) { CA_MUST_PASS(ptr); - return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr); + return kApplicationObject->Invoke(kApplicationObject, kCallCheckPtr, ptr); } diff --git a/Public/Developer/System.Core/Sources/New+Delete.cxx b/Public/Developer/System.Core/Sources/New+Delete.cxx index 3e2942c5..0800da22 100644 --- a/Public/Developer/System.Core/Sources/New+Delete.cxx +++ b/Public/Developer/System.Core/Sources/New+Delete.cxx @@ -11,31 +11,30 @@ typedef SizeType size_t; void* operator new[](size_t sz) { if (sz == 0) ++sz; - return RtAllocateProcessHeap(kApplicationObject, sz, kStandardAllocation); + return RtAllocateProcessPtr(sz, kStandardAllocation); } void* operator new(size_t sz) { if (sz == 0) ++sz; - return RtAllocateProcessHeap(kApplicationObject, sz, kArrayAllocation); + return RtAllocateProcessPtr(sz, kArrayAllocation); } void operator delete[](void* ptr) { if (ptr == nullptr) return; - RtFreeProcessHeap(kApplicationObject, ptr); + RtFreeProcessPtr(ptr); } void operator delete(void* ptr) { if (ptr == nullptr) return; - RtFreeProcessHeap(kApplicationObject, ptr); + RtFreeProcessPtr(ptr); } void operator delete(void* ptr, size_t sz) { if (ptr == nullptr) return; + CA_UNREFERENCED_PARAMETER(sz); - (void)sz; - - RtFreeProcessHeap(kApplicationObject, ptr); + RtFreeProcessPtr(ptr); } diff --git a/Public/Developer/System.Core/Sources/CRT0.c b/Public/Developer/System.Core/Sources/Start.c index 03aa62b8..25a29e18 100644 --- a/Public/Developer/System.Core/Sources/CRT0.c +++ b/Public/Developer/System.Core/Sources/Start.c @@ -11,4 +11,4 @@ CA_EXTERN_C DWordType __start(VoidType) { CA_MUST_PASS(kApplicationObject); return 0; -}
\ No newline at end of file +} diff --git a/Public/Developer/System.Core/Sources/Window.c b/Public/Developer/System.Core/Sources/Window.c new file mode 100644 index 00000000..2b589402 --- /dev/null +++ b/Public/Developer/System.Core/Sources/Window.c @@ -0,0 +1,62 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <System.Core/Headers/Window.h> + +/// invalid resource handle, they always start from 1. +#define kInvalidRsrc 0 + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, + const DWordType rsrcId) { + CA_MUST_PASS(name); + CA_MUST_PASS(rsrcId != kInvalidRsrc); + + return (WindowPort*)kApplicationObject->Invoke( + kApplicationObject, kCallCreateWindow, name, rsrcId); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* winPort) { + CA_MUST_PASS(winPort); + + kApplicationObject->Invoke(kApplicationObject, kCallCloseWindow, winPort); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, + const DWordType rsrcId) { + CA_MUST_PASS(name); + CA_MUST_PASS(rsrcId != kInvalidRsrc); + + return (WindowPort*)kApplicationObject->Invoke(kApplicationObject, + kCallCreateMenu, name, rsrcId); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* winPort) { + CA_MUST_PASS(winPort); + + kApplicationObject->Invoke(kApplicationObject, kCallCloseMenu, winPort); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* id, WmPoint where) { + if (!id) { + return kWmErrInvalidArg; + } + + id->windowPosition.X = where.X; + id->windowPosition.Y = where.Y; + id->windowMoving = True; + + return 0; +}
\ No newline at end of file |
