mirror of
https://github.com/Zelda64Recomp/Zelda64Recomp
synced 2026-05-23 06:54:33 -04:00
Removed use of std::exit and changed recomp runtime to exit normally, added helpers for getting recompiled args and returning values, added example of patch code calling native code
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#ifndef __RECOMP_HELPERS__
|
||||
#define __RECOMP_HELPERS__
|
||||
|
||||
#include "recomp.h"
|
||||
|
||||
template<int index, typename T>
|
||||
T _arg(uint8_t* rdram, recomp_context* ctx) {
|
||||
static_assert(index < 4, "Only args 0 through 3 supported");
|
||||
gpr raw_arg = (&ctx->r4)[index];
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
if constexpr (index < 2) {
|
||||
static_assert(index != 1, "Floats in arg 1 not supported");
|
||||
return ctx->f12.fl;
|
||||
}
|
||||
else {
|
||||
return std::bit_cast<T>(raw_arg);
|
||||
}
|
||||
}
|
||||
else if constexpr (std::is_pointer_v<T>) {
|
||||
static_assert (!std::is_pointer_v<std::remove_pointer_t<T>>, "Double pointers not supported");
|
||||
return TO_PTR(std::remove_pointer_t<T>, raw_arg);
|
||||
}
|
||||
else if constexpr (std::is_integral_v<T>) {
|
||||
static_assert(sizeof(T) <= 4, "64-bit args not supported");
|
||||
return static_cast<T>(raw_arg);
|
||||
}
|
||||
else {
|
||||
// static_assert in else workaround
|
||||
[] <bool flag = false>() {
|
||||
static_assert(flag, "Unsupported type");
|
||||
}();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void _return(recomp_context* ctx, T val) {
|
||||
static_assert(sizeof(T) <= 4 && "Only 32-bit value returns supported currently");
|
||||
if (std::is_same_v<T, float>) {
|
||||
ctx->f0.fl = val;
|
||||
}
|
||||
else if (std::is_integral_v<T> && sizeof(T) <= 4) {
|
||||
ctx->r2 = int32_t(val);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -21,5 +21,6 @@ enum class Menu {
|
||||
};
|
||||
|
||||
void set_current_menu(Menu menu);
|
||||
void destroy_ui();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,7 @@ DLLIMPORT void ProcessRDPList(void);
|
||||
DLLIMPORT void ProcessDList(void);
|
||||
DLLIMPORT void UpdateScreen(void);
|
||||
DLLIMPORT void ChangeWindow(void);
|
||||
DLLIMPORT void PluginShutdown(void);
|
||||
|
||||
void set_rt64_hooks();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user