diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-09 09:27:19 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-09 09:28:34 +0100 |
| commit | f719c5e4d825b11c510408612e3bdcd0f23a76c3 (patch) | |
| tree | 89309c8061f1f53ad98148bc45560699a46553a3 /newBoot | |
| parent | fc78d2f68ab5c9d9d84734fcc1af906c02a984b8 (diff) | |
MPT: add Detail.hxx for MPT's API.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'newBoot')
| -rw-r--r-- | newBoot/Source/MPT/API.cxx | 22 | ||||
| -rw-r--r-- | newBoot/Source/MPT/Detail.hxx | 52 | ||||
| -rw-r--r-- | newBoot/Source/MPT/FileType.hxx | 8 |
3 files changed, 60 insertions, 22 deletions
diff --git a/newBoot/Source/MPT/API.cxx b/newBoot/Source/MPT/API.cxx index b76ac645..3b003cda 100644 --- a/newBoot/Source/MPT/API.cxx +++ b/newBoot/Source/MPT/API.cxx @@ -8,6 +8,7 @@ */ #include "API.hxx" +#include "Detail.hxx" struct Files32FileHdr final { @@ -45,21 +46,6 @@ struct Files32FileGroup final Files32FileGroup* fNext{ nullptr }; } kRootGroup = nullptr; -extern "C" Assert(bool expr); -extern "C" void* AllocPtr(long sz); - -namespace detail -{ - template <typename Cls> - Cls* new_class() - { - Cls* cls = (Cls*)AllocPtr(sizeof(Cls)); - *cls = Cls(); - - return cls; - } -} - /* @brief external inits */ extern "C" int init_ata_mpt(void); extern "C" int init_mpt(void); @@ -69,10 +55,10 @@ namespace mpt bool filesystem_init(void) noexcept { kRootGroup = detail::new_class<Files32FileGroup>(); - Assert(kRootGroup != nullptr); - Assert(init_ata_mpt() == 1); - Assert(init_mpt() == 1); + assert(kRootGroup != nullptr); + assert(init_ata_mpt() == detail::okay); + assert(init_mpt() == detail::okay); return true; } diff --git a/newBoot/Source/MPT/Detail.hxx b/newBoot/Source/MPT/Detail.hxx new file mode 100644 index 00000000..efde463b --- /dev/null +++ b/newBoot/Source/MPT/Detail.hxx @@ -0,0 +1,52 @@ +/* +* ======================================================== +* +* newBoot +* Copyright Mahrouss Logic, all rights reserved. +* +* ======================================================== +*/ + +#pragma once + +namespace detail +{ + inline void assert_expr(bool expr, const char* str_expr) const + { + if (!expr) + { + detail::panic("assertion failed!", str_expr); + detail::hang(); + } + } + + inline void hang() const + { + while (1) + {} + } + + extern "C" void* new_ptr(long sz); + + template <typename Cls> + inline Cls* new_class() + { + Cls* cls = (Cls*)new_ptr(sizeof(Cls)); + *cls = Cls(); + + return cls; + } + + enum + { + okay = 1, + failed = 0, + }; +} + +#ifdef assert +# undef assert +# define assert(expr) detail::assert_expr(expr, #expr) +#endif // ifdef assert + + diff --git a/newBoot/Source/MPT/FileType.hxx b/newBoot/Source/MPT/FileType.hxx index 26beb114..818d8197 100644 --- a/newBoot/Source/MPT/FileType.hxx +++ b/newBoot/Source/MPT/FileType.hxx @@ -19,10 +19,10 @@ template <typename _Manager> class FileType { public: - hCore::SizeT DiskId{ 0 }; - hCore::VoidPtr DiskSpace{ nullptr }; - hCore::SizeT DiskSize{ 0 }; - hCore::Int32 DiskError{ 0 }; + hCore::SizeT DiskId{ 0 }; // identification number of the drive. + hCore::VoidPtr DiskSpace{ nullptr }; // the pointer containing the requested disk data. + hCore::SizeT DiskSize{ 0 }; // it's size + hCore::Int32 DiskError{ 0 }; // if it's going well. FileType* Read(const char* path) { return _Manager::Read(path); } FileType* Write(FileType* path) { return _Manager::Write(path); } |
