Skip to content

Add Multi return syntatic sugar #689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern void GenericConfused(struct Entity_*);
extern void sub_08001290(struct Entity_*, u32);
extern void GenericKnockback(struct Entity_*);
extern u32 GetFuserId(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 {
Expand Down
2 changes: 2 additions & 0 deletions include/gba/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ typedef struct {
s8 y;
} PACKED Coords8;

union SplitDWord {
s64 DWORD;
u64 DWORD_U;
struct {
s32 LO, HI;
} HALF;
struct {
u32 LO, HI;
} HALF_U;
};

union SplitWord {
s32 WORD;
u32 WORD_U;
Expand Down Expand Up @@ -152,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