From c0099ab36bf9606c5503ceb0fa0d5b64f71c7203 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 17 Apr 2024 09:54:17 +0200 Subject: Unrelated: These changes are important but related to nothing. - Window now becomes Wm, as in Window manager. - Fix entrypoint for FragLib. - Remove CoreEvents to be replaced with Event Server, reworked Display Server. Signed-off-by: Amlal El Mahrouss --- Public/Developer/SystemLib/AMD64/CoreAssembly.s | 10 +- Public/Developer/SystemLib/Headers/Defines.h | 2 +- Public/Developer/SystemLib/Headers/Dialog.h | 7 +- Public/Developer/SystemLib/Headers/Draw.h | 2 +- Public/Developer/SystemLib/Headers/File.h | 13 +- Public/Developer/SystemLib/Headers/Math.h | 11 ++ Public/Developer/SystemLib/Headers/TrueType.h | 2 +- Public/Developer/SystemLib/Headers/Window.h | 164 -------------------- Public/Developer/SystemLib/Headers/Wm.h | 175 ++++++++++++++++++++++ Public/Developer/SystemLib/PowerPC/CoreAssembly.s | 5 +- Public/Developer/SystemLib/Sources/App.c | 29 ++++ Public/Developer/SystemLib/Sources/Application.c | 25 ---- Public/Developer/SystemLib/Sources/File.c | 35 ++--- Public/Developer/SystemLib/Sources/Heap.c | 7 + Public/Developer/SystemLib/Sources/Math.c | 7 + Public/Developer/SystemLib/Sources/Window.c | 76 ---------- Public/Developer/SystemLib/Sources/Wm.c | 103 +++++++++++++ Public/Developer/SystemLib/compile_flags.txt | 2 +- 18 files changed, 375 insertions(+), 300 deletions(-) create mode 100644 Public/Developer/SystemLib/Headers/Math.h delete mode 100644 Public/Developer/SystemLib/Headers/Window.h create mode 100644 Public/Developer/SystemLib/Headers/Wm.h create mode 100644 Public/Developer/SystemLib/Sources/App.c delete mode 100644 Public/Developer/SystemLib/Sources/Application.c create mode 100644 Public/Developer/SystemLib/Sources/Math.c delete mode 100644 Public/Developer/SystemLib/Sources/Window.c create mode 100644 Public/Developer/SystemLib/Sources/Wm.c (limited to 'Public/Developer/SystemLib') diff --git a/Public/Developer/SystemLib/AMD64/CoreAssembly.s b/Public/Developer/SystemLib/AMD64/CoreAssembly.s index 5c398e94..58fa3c28 100644 --- a/Public/Developer/SystemLib/AMD64/CoreAssembly.s +++ b/Public/Developer/SystemLib/AMD64/CoreAssembly.s @@ -6,23 +6,23 @@ ------------------------------------------- */ -.section .text +.text -.globl RtGetApp +.globl RtGetAppPointer .globl RtAssertTriggerInterrupt /* @brief Application getter */ /* @throws: ApptError: appartement error. */ -RtGetApp: +RtGetAppPointer: mov $0x10, %rcx /* sysGetProcessObject */ - int $0x21 + int $0x32 /* rax gets saved and returned. */ ret RtAssertTriggerInterrupt: mov $0x11, %rcx /* sysTerminateCurrentProcess */ - int $0x21 + int $0x32 ret diff --git a/Public/Developer/SystemLib/Headers/Defines.h b/Public/Developer/SystemLib/Headers/Defines.h index 7bd40c76..3be7552f 100644 --- a/Public/Developer/SystemLib/Headers/Defines.h +++ b/Public/Developer/SystemLib/Headers/Defines.h @@ -193,7 +193,7 @@ using StrType = CharacterTypeUTF8[N]; /// @brief Get app singleton. /// @param /// @return -CA_EXTERN_C ApplicationRef RtGetApp(VoidType); +CA_EXTERN_C ApplicationRef RtGetAppPointer(VoidType); /// @brief Get argument count /// @param diff --git a/Public/Developer/SystemLib/Headers/Dialog.h b/Public/Developer/SystemLib/Headers/Dialog.h index 872eae5d..800f56db 100644 --- a/Public/Developer/SystemLib/Headers/Dialog.h +++ b/Public/Developer/SystemLib/Headers/Dialog.h @@ -6,7 +6,7 @@ #pragma once -#include +#include struct _DialogPort; struct _DialogPoint; @@ -22,10 +22,11 @@ typedef struct _DialogPoint { typedef struct _DialogPort { WordType dlgPort; WordType dlgKind; - BooleanType dlgVisible; - BooleanType dlgMoving; + BooleanType dlgVisible : 1; + BooleanType dlgMoving : 1; DialogPoint dlgPosition; WmDialogFn dlgProc; + struct _WmGFX* dlgGfx; struct _WindowPort* parentPort; } DialogPort; diff --git a/Public/Developer/SystemLib/Headers/Draw.h b/Public/Developer/SystemLib/Headers/Draw.h index 3060db9d..38f99e7d 100644 --- a/Public/Developer/SystemLib/Headers/Draw.h +++ b/Public/Developer/SystemLib/Headers/Draw.h @@ -6,7 +6,7 @@ #pragma once -#include +#include /************************************************************* * diff --git a/Public/Developer/SystemLib/Headers/File.h b/Public/Developer/SystemLib/Headers/File.h index 5e58d104..234c33da 100644 --- a/Public/Developer/SystemLib/Headers/File.h +++ b/Public/Developer/SystemLib/Headers/File.h @@ -14,8 +14,8 @@ typedef QWordType FSRef; /// @brief Opens a new file. /// @param path where to find it. -/// @param r the restrict (rw, rwe, r+, w+, r, w) -/// @return +/// @param rest the restrict (rw, rwe, r+, w+, r, w) +/// @return FSRef the file. CA_EXTERN_C FSRef FsOpenFile(const CharacterTypeUTF8* path, const CharacterTypeUTF8* r); /// @brief Closes the file and flushes it to the said file. @@ -23,13 +23,15 @@ CA_EXTERN_C FSRef FsOpenFile(const CharacterTypeUTF8* path, const CharacterTypeU /// @return CA_EXTERN_C VoidType FsCloseFile(FSRef refFs); +#define kMaxForkNameLength 256 /* long fork names. */ + /// @brief A fork information header. typedef struct _Fork { PtrVoidType forkData; SizeType forkSize; Int32Type forkFlags; Int32Type forkKind; - CharacterTypeUTF8 forkName[256]; + CharacterTypeUTF8 forkName[kMaxForkNameLength]; } ForkType; typedef ForkType* FSForkRef; @@ -40,5 +42,10 @@ typedef ForkType* FSForkRef; /// @return the fork data. CA_EXTERN_C FSForkRef FsGetFork(FSRef refFs, const CharacterTypeUTF8* forkName); +/// @brief Check if the filesystem path is valid. +/// @return if not return false, or true. +CA_EXTERN_C BooleanType FsIsValidPath(const CharacterTypeUTF8* path); + +/// @note not only limited to, there is code forks, icon forks... #define FsGetDataFork(refFs) FsGetFork(refFs, "data") #define FsGetRsrcFork(refFs) FsGetFork(refFs, "rsrc") diff --git a/Public/Developer/SystemLib/Headers/Math.h b/Public/Developer/SystemLib/Headers/Math.h new file mode 100644 index 00000000..f6c8f216 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Math.h @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +CA_EXTERN_C SizeType MathRand(VoidType); diff --git a/Public/Developer/SystemLib/Headers/TrueType.h b/Public/Developer/SystemLib/Headers/TrueType.h index 7f1bed86..6387e58f 100644 --- a/Public/Developer/SystemLib/Headers/TrueType.h +++ b/Public/Developer/SystemLib/Headers/TrueType.h @@ -6,7 +6,7 @@ #pragma once -#include +#include /************************************************************* * diff --git a/Public/Developer/SystemLib/Headers/Window.h b/Public/Developer/SystemLib/Headers/Window.h deleted file mode 100644 index ca0b942e..00000000 --- a/Public/Developer/SystemLib/Headers/Window.h +++ /dev/null @@ -1,164 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include - -/************************************************************* - * - * File: Window.h - * Purpose: Window Manager API for NewOS. - * Date: 3/26/24 - * - * Copyright Mahrouss Logic, all rights reserved. - * - *************************************************************/ - -struct _WmPoint; -struct _WindowPort; - -struct _ControlPort; -struct _WmPoint; - -typedef QWordType DCRef; - -/// @brief Window procedure type. -typedef VoidType(*WmWindowFn)(struct _WindowPort* port, UInt32Type msg, UIntPtrType pParam, UIntPtrType iParam); - -/// @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; - WmWindowFn windowProc; - struct _WindowPort* windowMenuPort; ///! Attached menu to it. - struct _WindowPort* windowParentPort; -} WindowPort; - -/// @brief Control port type. -typedef struct _ControlPort { - WordType controlPort; - WordType controlKind; - BooleanType controlVisible; - BooleanType controlMoving; - WmPoint controlPosition; - WmWindowFn controlProc; - WindowPort* parentPort; -} ControlPort; - -enum { - kWmErrIncompatible = 0x74, - kWmErrOutOfMemory, - kWmErrInvalidArg, - kWmErrNotImplemented, -}; - -/// @brief Color reference. -typedef UInt32Type ColorRef; - -/***********************************************************************************/ -/// Color utils. -/***********************************************************************************/ - -CA_EXTERN_C const ColorRef kRgbRed; -CA_EXTERN_C const ColorRef kRgbGreen; -CA_EXTERN_C const ColorRef kRgbBlue; -CA_EXTERN_C const ColorRef kRgbBlack; -CA_EXTERN_C const ColorRef kRgbWhite; - -/***********************************************************************************/ -/// Color macro. -/***********************************************************************************/ - -#define WmMakeColorRef(R, G, B) (ColorRef)(0x##R##G##B) - -#define kControlKindWindow 0 -#define kControlKindDialog 1 -#define kControlKindMenu 2 -#define kControlKindButton 3 -#define kControlKindLabel 4 -#define kControlKindDropdownMenu 5 -#define kControlKindIcon 6 -#define kControlKindRadioBox 7 -#define kControlKindCheckBox 8 -#define kControlKindUserDefined 9 - -/// @brief Creates a new control -/// @param id the control rsrc fork. -/// @return -CA_EXTERN_C ControlPort* WmCreateControl(DWordType id); - -/// @brief Releases the control -/// @param id the control ref. -/// @return -CA_EXTERN_C VoidType WmReleaseControl(ControlPort* id); - -/// @brief Moves a control inside a ControlPort. -/// @param id the control ref. -/// @param where where to move at. -/// @return -CA_EXTERN_C Int32Type WmSetControlPosition(ControlPort* id, WmPoint where); - -/// @brief Enable control. -/// @param id -/// @param enabled -/// @return -CA_EXTERN_C Int32Type WmSetControlEnabled(ControlPort* id, BooleanType enabled); - -/// @brief Make control visible. -/// @param id -/// @param visible -/// @return -CA_EXTERN_C Int32Type WmSetControlVisible(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 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 CharacterTypeUTF8* 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(WindowPort* id, WmPoint where); - -/// @brief Get the NewOS about window. -/// @return The window port of it. -/// @note The reason that this is not a window is for it to run without blocking the UI. -CA_EXTERN_C WindowPort* WmGetOSDlg(void); - diff --git a/Public/Developer/SystemLib/Headers/Wm.h b/Public/Developer/SystemLib/Headers/Wm.h new file mode 100644 index 00000000..66ed96a3 --- /dev/null +++ b/Public/Developer/SystemLib/Headers/Wm.h @@ -0,0 +1,175 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/************************************************************* + * + * File: Wm.h + * Purpose: Window Manager API for NewOS. + * Date: 3/26/24 + * + * Copyright Mahrouss Logic, all rights reserved. + * + *************************************************************/ + +struct _WmPoint; +struct _WindowPort; + +struct _ControlPort; +struct _WmPoint; + +/// @brief Window Graphics type. +typedef struct _WmGFX { + UInt32Type Depth; + UInt32Type* DataFrame; + SizeType DataFrameWidth; + SizeType DataFrameHeight; +} WmGFX, *WmGFXRef; + +/// @brief Window procedure type. +typedef VoidType(*WmWindowFn)(struct _WindowPort* port, UInt32Type msg, UIntPtrType pParam, UIntPtrType iParam); + +/// @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 : 1; + BooleanType windowMaximized : 1; + BooleanType windowMinimized : 1; + BooleanType windowMoving : 1; + BooleanType windowDisableClose : 1; + BooleanType windowDisableMinimize : 1; + BooleanType windowInvalidate : 1; + WmPoint windowPosition; + WmPoint windowSize; + WmGFXRef windowGfx; + WmWindowFn windowProc; + struct _WindowPort* windowMenuPort; ///! Attached menu to it. + struct _WindowPort* windowParentPort; +} WindowPort; + +/// @brief Control port type. +typedef struct _ControlPort { + WordType controlPort; + WordType controlKind; + BooleanType controlVisible : 1; + BooleanType controlMoving : 1; + WmPoint controlPosition; + WmWindowFn controlProc; + WmGFXRef controlGfx; + WindowPort* parentPort; +} ControlPort; + +enum { + kWmErrIncompatible = 0x74, + kWmErrOutOfMemory, + kWmErrInvalidArg, + kWmErrNotImplemented, +}; + +/// @brief Color reference. +typedef UInt32Type ColorRef; + +/***********************************************************************************/ +/// Color utils. +/***********************************************************************************/ + +CA_EXTERN_C const ColorRef kRgbRed; +CA_EXTERN_C const ColorRef kRgbGreen; +CA_EXTERN_C const ColorRef kRgbBlue; +CA_EXTERN_C const ColorRef kRgbBlack; +CA_EXTERN_C const ColorRef kRgbWhite; + +/***********************************************************************************/ +/// Color macro. +/***********************************************************************************/ + +#define WmMakeColorRef(R, G, B) (ColorRef)(0x##R##G##B) + +#define kControlKindWindow 0 +#define kControlKindDialog 1 +#define kControlKindMenu 2 +#define kControlKindButton 3 +#define kControlKindLabel 4 +#define kControlKindDropdownMenu 5 +#define kControlKindIcon 6 +#define kControlKindRadioBox 7 +#define kControlKindCheckBox 8 +#define kControlKindUserDefined 9 + +/// @brief Creates a new control +/// @param id the control rsrc fork. +/// @return +CA_EXTERN_C ControlPort* WmCreateControl(DWordType id); + +/// @brief Releases the control +/// @param ctrlPort the control ref. +/// @return +CA_EXTERN_C VoidType WmReleaseControl(ControlPort* ctrlPort); + +/// @brief Moves a control inside a ControlPort. +/// @param ctrlPort the control ref. +/// @param where where to move at. +/// @return +CA_EXTERN_C Int32Type WmSetControlPosition(ControlPort* ctrlPort, WmPoint where); + +/// @brief Enable control. +/// @param ctrlPort +/// @param enabled +/// @return +CA_EXTERN_C Int32Type WmSetControlEnabled(ControlPort* ctrlPort, BooleanType enabled); + +/// @brief Make control visible. +/// @param ctrlPort +/// @param visible +/// @return +CA_EXTERN_C Int32Type WmSetControlVisible(ControlPort* ctrlPort, BooleanType visible); + +/// @brief Creates a new window. +/// @param name the window name +/// @param rsrcId the window fork rsrc ctrlPort. +/// @return the window graphics port. +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 ctrlPort. +/// @return the menu graphics port. +CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* 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 if menu is provided.) +/// @param wndPort the gfx port. +/// @param where to move. +/// @return error code. +CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* wndPort, WmPoint where); + +/// @brief Get the NewOS about window. +/// @return The window port of it. +/// @note The reason that this is not a window is for it to run without blocking the UI. +CA_EXTERN_C WindowPort* WmGetOSDlg(void); + +/// @brief Draws a blur effect on the window. +/// @param wndPort the window port. +CA_EXTERN_C VoidType WmBlur(WindowPort* wndPort); \ No newline at end of file diff --git a/Public/Developer/SystemLib/PowerPC/CoreAssembly.s b/Public/Developer/SystemLib/PowerPC/CoreAssembly.s index 98fbcca9..7078774e 100644 --- a/Public/Developer/SystemLib/PowerPC/CoreAssembly.s +++ b/Public/Developer/SystemLib/PowerPC/CoreAssembly.s @@ -2,14 +2,13 @@ ; ; Copyright Mahrouss Logic ; -; Purpose: PowerPC low level I/O +; Purpose: PowerPC Core assembly routines. ; ; ------------------------------------------- */ - /* @brief Application getter */ /* @throws: ApptError: appartement error. */ -export .code64 RtGetApp: +export .code64 RtGetAppPointer: stw 0x10, 0(r3) /* sysGetProcessObject */ sc diff --git a/Public/Developer/SystemLib/Sources/App.c b/Public/Developer/SystemLib/Sources/App.c new file mode 100644 index 00000000..9d390795 --- /dev/null +++ b/Public/Developer/SystemLib/Sources/App.c @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +/// @brief Main Application object, retrieved from the RtGetAppPointer symbol. +ApplicationRef kSharedApplication = NullPtr; + +/// @brief Gets the app arguments count. +/// @param void no arguments. +/// @return +CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) { + CA_MUST_PASS(kSharedApplication); + + return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); +} + +/// @brief Gets the app arguments pointer. +/// @param void no arguments. +/// @return +CA_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) { + CA_MUST_PASS(kSharedApplication); + + return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, + kCallGetArgsPtr); +} diff --git a/Public/Developer/SystemLib/Sources/Application.c b/Public/Developer/SystemLib/Sources/Application.c deleted file mode 100644 index 69f178af..00000000 --- a/Public/Developer/SystemLib/Sources/Application.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -/// @brief Main Application object, retrieved from the RtGetApp symbol. -ApplicationRef kSharedApplication = NullPtr; - -/// @brief Gets the app arguments count. -/// @param void no arguments. -/// @return -CA_EXTERN_C SizeType RtGetAppArgumentsCount(VoidType) { - return kSharedApplication->Invoke(kSharedApplication, kCallGetArgsCount); -} - -/// @brief Gets the app arguments pointer. -/// @param void no arguments. -/// @return -CA_EXTERN_C CharacterTypeUTF8** RtGetAppArgumentsPtr(VoidType) { - return (CharacterTypeUTF8**)kSharedApplication->Invoke(kSharedApplication, - kCallGetArgsPtr); -} diff --git a/Public/Developer/SystemLib/Sources/File.c b/Public/Developer/SystemLib/Sources/File.c index ca23d9f7..39a4aff0 100644 --- a/Public/Developer/SystemLib/Sources/File.c +++ b/Public/Developer/SystemLib/Sources/File.c @@ -8,31 +8,32 @@ #include enum FileOp { - kFlushFile, - kReadFork, - kWriteFork, - kOpenFork, - kCloseFork, + kFlushFile, + kReadFork, + kWriteFork, + kOpenFork, + kCloseFork, }; /// @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) { - CA_MUST_PASS(kSharedApplication); - CA_MUST_PASS(path); - CA_MUST_PASS(r); - - return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, r); +/// @param rest the restrict (rw, rwe, r+, w+, r, w) +/// @return FSRef the file. +CA_EXTERN_C FSRef FsOpenFile(const CharacterTypeUTF8* path, + const CharacterTypeUTF8* rest) { + CA_MUST_PASS(kSharedApplication); + CA_MUST_PASS(path && FsIsValidPath(path) == Yes); + CA_MUST_PASS(rest); + + return kSharedApplication->Invoke(kSharedApplication, kCallOpenFile, path, rest); } /// @brief Closes the file and flushes it to the said file. /// @param refFs the filesystem reference. -/// @return +/// @return CA_EXTERN_C VoidType FsCloseFile(FSRef refFs) { - CA_MUST_PASS(kSharedApplication); + CA_MUST_PASS(kSharedApplication); - kSharedApplication->Invoke(kSharedApplication, refFs, kFlushFile); - kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refFs); + kSharedApplication->Invoke(kSharedApplication, refFs, kFlushFile); + kSharedApplication->Invoke(kSharedApplication, kCallCloseFile, refFs); } diff --git a/Public/Developer/SystemLib/Sources/Heap.c b/Public/Developer/SystemLib/Sources/Heap.c index 041c5764..3db7a374 100644 --- a/Public/Developer/SystemLib/Sources/Heap.c +++ b/Public/Developer/SystemLib/Sources/Heap.c @@ -12,6 +12,7 @@ /// @param flags flags. /// @return CA_EXTERN_C PtrVoidType RtTlsAllocate(QWordType sz, DWordType flags) { + CA_MUST_PASS(kSharedApplication); CA_MUST_PASS(sz); CA_MUST_PASS(flags); @@ -22,7 +23,9 @@ CA_EXTERN_C PtrVoidType RtTlsAllocate(QWordType sz, DWordType flags) { /// @brief Free pointer from the user's heap. /// @param ptr the pointer to free. CA_EXTERN_C VoidType RtTlsFree(PtrVoidType ptr) { + CA_MUST_PASS(kSharedApplication); CA_MUST_PASS(ptr); + CA_UNREFERENCED_PARAMETER( kSharedApplication->Invoke(kSharedApplication, kCallFreePtr, ptr)); } @@ -31,6 +34,8 @@ CA_EXTERN_C VoidType RtTlsFree(PtrVoidType ptr) { /// @param ptr the pointer to find. /// @return the size. CA_EXTERN_C QWordType RtTlsGetSize(PtrVoidType ptr) { + CA_MUST_PASS(kSharedApplication); + CA_MUST_PASS(ptr); return kSharedApplication->Invoke(kSharedApplication, kCallSizePtr, ptr); } @@ -39,6 +44,8 @@ CA_EXTERN_C QWordType RtTlsGetSize(PtrVoidType ptr) { /// @param ptr the pointer to check. /// @return if it exists CA_EXTERN_C BooleanType RtTlsPtrExists(PtrVoidType ptr) { + CA_MUST_PASS(kSharedApplication); + CA_MUST_PASS(ptr); return kSharedApplication->Invoke(kSharedApplication, kCallCheckPtr, ptr); } diff --git a/Public/Developer/SystemLib/Sources/Math.c b/Public/Developer/SystemLib/Sources/Math.c new file mode 100644 index 00000000..20919711 --- /dev/null +++ b/Public/Developer/SystemLib/Sources/Math.c @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include diff --git a/Public/Developer/SystemLib/Sources/Window.c b/Public/Developer/SystemLib/Sources/Window.c deleted file mode 100644 index 196ac537..00000000 --- a/Public/Developer/SystemLib/Sources/Window.c +++ /dev/null @@ -1,76 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -/// invalid resource handle, they always start from 1. -#define kInvalidRsrc (0U) - -/// @brief Color refs. - -const ColorRef kRgbRed = 0x000000FF; -const ColorRef kRgbGreen = 0x0000FF00; -const ColorRef kRgbBlue = 0x00FF0000; -const ColorRef kRgbBlack = 0x00000000; -const ColorRef kRgbWhite = 0xFFFFFFFF; - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, - const DWordType rsrcId) { - CA_MUST_PASS(name); - CA_MUST_PASS(rsrcId != kInvalidRsrc); - - if (!name) return NullPtr; - if (rsrcId == kInvalidRsrc) return NullPtr; - - return (WindowPort*)kSharedApplication->Invoke( - kSharedApplication, kCallCreateWindow, name, rsrcId); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* winPort) { - CA_MUST_PASS(winPort); - if (!winPort) return; - - kSharedApplication->Invoke(kSharedApplication, kCallCloseWindow, winPort); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, - const DWordType rsrcId) { - CA_MUST_PASS(name); - CA_MUST_PASS(rsrcId != kInvalidRsrc); - - if (!name) return NullPtr; - if (rsrcId == kInvalidRsrc) return NullPtr; - - return (WindowPort*)kSharedApplication->Invoke(kSharedApplication, - kCallCreateMenu, name, rsrcId); -} - -///////////////////////////////////////////////////////////////////////// - -CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* winPort) { - CA_MUST_PASS(winPort); - - if (!winPort) return; - kSharedApplication->Invoke(kSharedApplication, 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; -} diff --git a/Public/Developer/SystemLib/Sources/Wm.c b/Public/Developer/SystemLib/Sources/Wm.c new file mode 100644 index 00000000..79eda22a --- /dev/null +++ b/Public/Developer/SystemLib/Sources/Wm.c @@ -0,0 +1,103 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include +#include + +/// invalid resource handle, they always start from 1. +#define kInvalidRsrc (0U) + +/// @brief Color refs. + +const ColorRef kRgbRed = 0x000000FF; +const ColorRef kRgbGreen = 0x0000FF00; +const ColorRef kRgbBlue = 0x00FF0000; +const ColorRef kRgbBlack = 0x00000000; +const ColorRef kRgbWhite = 0xFFFFFFFF; + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C WindowPort* WmCreateWindow(const CharacterTypeUTF8* name, + const DWordType rsrcId) { + CA_MUST_PASS(name); + CA_MUST_PASS(rsrcId != kInvalidRsrc); + + if (!name) return NullPtr; + if (rsrcId == kInvalidRsrc) return NullPtr; + + return (WindowPort*)kSharedApplication->Invoke( + kSharedApplication, kCallCreateWindow, name, rsrcId); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C VoidType WmReleaseWindow(WindowPort* winPort) { + CA_MUST_PASS(winPort); + if (!winPort) return; + + kSharedApplication->Invoke(kSharedApplication, kCallCloseWindow, winPort); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C WindowPort* WmCreateMenu(const CharacterTypeUTF8* name, + const DWordType rsrcId) { + CA_MUST_PASS(name); + CA_MUST_PASS(rsrcId != kInvalidRsrc); + + if (!name) return NullPtr; + if (rsrcId == kInvalidRsrc) return NullPtr; + + return (WindowPort*)kSharedApplication->Invoke(kSharedApplication, + kCallCreateMenu, name, rsrcId); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C VoidType WmReleaseMenu(WindowPort* winPort) { + CA_MUST_PASS(winPort); + + if (!winPort) return; + kSharedApplication->Invoke(kSharedApplication, kCallCloseMenu, winPort); +} + +///////////////////////////////////////////////////////////////////////// + +CA_EXTERN_C Int32Type WmMoveWindow(WindowPort* wndPort, WmPoint where) { + if (!wndPort) return kWmErrInvalidArg; + + wndPort->windowPosition.X = where.X; + wndPort->windowPosition.Y = where.Y; + wndPort->windowMoving = True; + + return 0; +} + +/// @brief Draws a blur effect on the window. +/// @param wndPort the window port. +CA_EXTERN_C VoidType WmBlur(WindowPort* wndPort) { + if (wndPort != NullPtr) { + WmGFXRef refGfx = wndPort->windowGfx; + + UInt32Type lookupTbl[4] = {0.21336, 0.41336, 0.61336, 0.81336}; + + for (SizeType width = 0; width < refGfx->DataFrameWidth; ++width) { + for (SizeType height = 0; height < refGfx->DataFrameHeight; ++height) { + refGfx->DataFrame[width * height] = + refGfx->DataFrame[width * height] * lookupTbl[MathRand() % 4]; + } + } + } +} + +/// @brief Causes the window to invalidate and redraw. +/// @param wndPort The Window port. +/// @return nothing. +CA_EXTERN_C VoidType WmInvalidateGfx(WindowPort* wndPort) { + if (wndPort) { + wndPort->windowInvalidate = Yes; + } +} \ No newline at end of file diff --git a/Public/Developer/SystemLib/compile_flags.txt b/Public/Developer/SystemLib/compile_flags.txt index 6e721e73..3be985d1 100644 --- a/Public/Developer/SystemLib/compile_flags.txt +++ b/Public/Developer/SystemLib/compile_flags.txt @@ -1,4 +1,4 @@ -I./ -I../ -I../../../Private --std=c++20 +-std=c17 -- cgit v1.2.3