From 743f3f3080fa917130ff63edab33adb348aaf317 Mon Sep 17 00:00:00 2001 From: KEKW555 <152369890+KEKW555@users.noreply.github.com> Date: Fri, 5 Jan 2024 17:57:16 +0530 Subject: [PATCH 1/7] Add Multi return syntatic sugar --- include/global.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/global.h b/include/global.h index 3cd7c1d0b..dcb2a5b8c 100644 --- a/include/global.h +++ b/include/global.h @@ -119,6 +119,21 @@ typedef struct { s8 y; } PACKED Coords8; +typedef union { + s64 DWORD; + u64 DWORD_U; + struct { + s32 LO, HI; + } HALF; + struct { + u32 LO, HI; + } HALF_U; +} SplitDWord; + +typedef u64 (*MultiReturnFunctionType)(); + +#define MULTI_RETURN_FUNCTION_CALL(func, ...) ((SplitDWord)((*(MultiReturnFunctionType)(&func))(__VA_ARGS__))) + union SplitWord { s32 WORD; u32 WORD_U; From ff469a54cfc5a1c11aac53f31b960d882c7f19da Mon Sep 17 00:00:00 2001 From: KEKW555 <152369890+KEKW555@users.noreply.github.com> Date: Sat, 6 Jan 2024 23:21:04 +0530 Subject: [PATCH 2/7] Remove generic macro for argument list safety --- include/global.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/global.h b/include/global.h index dcb2a5b8c..00db197e2 100644 --- a/include/global.h +++ b/include/global.h @@ -130,10 +130,6 @@ typedef union { } HALF_U; } SplitDWord; -typedef u64 (*MultiReturnFunctionType)(); - -#define MULTI_RETURN_FUNCTION_CALL(func, ...) ((SplitDWord)((*(MultiReturnFunctionType)(&func))(__VA_ARGS__))) - union SplitWord { s32 WORD; u32 WORD_U; From 99ef905ac3bb70a00f4e918ffeab19e3c2fb62db Mon Sep 17 00:00:00 2001 From: KEKW555 <152369890+KEKW555@users.noreply.github.com> Date: Sat, 6 Jan 2024 23:41:35 +0530 Subject: [PATCH 3/7] Add specific multi return macro for GetFuserId function --- include/asm.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/asm.h b/include/asm.h index d42458eea..490e84de8 100644 --- a/include/asm.h +++ b/include/asm.h @@ -18,6 +18,8 @@ extern void GenericConfused(struct Entity_*); extern void sub_08001290(struct Entity_*, u32); extern void GenericKnockback(struct Entity_*); extern u32 GetFuserId(struct Entity_*); +typedef u64 (*MultiReturnTypeSingleEntityArg)(struct Entity_*); +#define GetFuserIdAndFuserTextId(ent) ((union SplitDWord)(*(MultiReturnTypeSingleEntityArg)(&GetFuserId))(ent)) extern u32 CheckPlayerInRegion(u32 centerX, u32 centerY, u32 radiusX, u32 radiusY); extern u32 GravityUpdate(struct Entity_* entity, u32 gravity); enum { From f7576ba1d035da45eca4d8ecb1ac855eaad879db Mon Sep 17 00:00:00 2001 From: KEKW555 <152369890+KEKW555@users.noreply.github.com> Date: Sat, 6 Jan 2024 23:43:08 +0530 Subject: [PATCH 4/7] Make union consistent with other split union types. --- include/global.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/global.h b/include/global.h index 00db197e2..f56218066 100644 --- a/include/global.h +++ b/include/global.h @@ -119,7 +119,7 @@ typedef struct { s8 y; } PACKED Coords8; -typedef union { +union SplitDWord { s64 DWORD; u64 DWORD_U; struct { @@ -128,7 +128,7 @@ typedef union { struct { u32 LO, HI; } HALF_U; -} SplitDWord; +}; union SplitWord { s32 WORD; From cbebaa74a9d950a4833a192715c0250893f95c42 Mon Sep 17 00:00:00 2001 From: KEKW555 <152369890+KEKW555@users.noreply.github.com> Date: Sat, 6 Jan 2024 23:55:01 +0530 Subject: [PATCH 5/7] Macro for Div and Mod --- include/gba/syscall.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/gba/syscall.h b/include/gba/syscall.h index 48f35863b..aa09fd9e8 100644 --- a/include/gba/syscall.h +++ b/include/gba/syscall.h @@ -62,4 +62,6 @@ int MultiBoot(struct MultiBootParam* mp); s32 Div(s32 num, s32 denom); +#define DivAndMod(num, denom) ((union SplitDWord)(*(MultiReturnTypeTwoS32Arg)(&Div))(num, denom)) + #endif // SYSCALL_H From 973257b758554bacf71147894186261313841711 Mon Sep 17 00:00:00 2001 From: KEKW555 <152369890+KEKW555@users.noreply.github.com> Date: Sat, 6 Jan 2024 23:56:41 +0530 Subject: [PATCH 6/7] Move function cast typedef --- include/asm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/asm.h b/include/asm.h index 490e84de8..7f8d3d893 100644 --- a/include/asm.h +++ b/include/asm.h @@ -18,7 +18,6 @@ extern void GenericConfused(struct Entity_*); extern void sub_08001290(struct Entity_*, u32); extern void GenericKnockback(struct Entity_*); extern u32 GetFuserId(struct Entity_*); -typedef u64 (*MultiReturnTypeSingleEntityArg)(struct Entity_*); #define GetFuserIdAndFuserTextId(ent) ((union SplitDWord)(*(MultiReturnTypeSingleEntityArg)(&GetFuserId))(ent)) extern u32 CheckPlayerInRegion(u32 centerX, u32 centerY, u32 radiusX, u32 radiusY); extern u32 GravityUpdate(struct Entity_* entity, u32 gravity); From d7c02737e9d287a40f559b05b3c187b44c4b7624 Mon Sep 17 00:00:00 2001 From: KEKW555 <152369890+KEKW555@users.noreply.github.com> Date: Sun, 7 Jan 2024 00:01:13 +0530 Subject: [PATCH 7/7] Move function casts to typedef --- include/global.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/global.h b/include/global.h index f56218066..f62b250d6 100644 --- a/include/global.h +++ b/include/global.h @@ -163,4 +163,10 @@ struct Entity_; #define BIT(bit) (1 << (bit)) #define IS_BIT_SET(value, bit) ((value)&BIT(bit)) +/** + * Multi return function data type casts + */ +typedef u64 (*MultiReturnTypeSingleEntityArg)(struct Entity_*); +typedef s64 (*MultiReturnTypeTwoS32Arg)(s32, s32); + #endif // GLOBAL_H