about summary refs log tree commit diff stats
path: root/src/libtools/sdl2rwops.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-03-25 09:35:58 +0000
committerptitSeb <sebastien.chev@gmail.com>2023-03-25 09:35:58 +0000
commitffcfa5b2cbdae6087d1c6bf790b5e2165d9ab580 (patch)
tree0bada9207a943bc806dd4454dc614dd07e61724d /src/libtools/sdl2rwops.c
parentafae5d80c7554d6f9d19af6c1a3cc78e33313074 (diff)
downloadbox64-ffcfa5b2cbdae6087d1c6bf790b5e2165d9ab580.tar.gz
box64-ffcfa5b2cbdae6087d1c6bf790b5e2165d9ab580.zip
Added support for running native SDL2_mixer (and image/ttf too) with emulated SDL2
Diffstat (limited to 'src/libtools/sdl2rwops.c')
-rwxr-xr-xsrc/libtools/sdl2rwops.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libtools/sdl2rwops.c b/src/libtools/sdl2rwops.c
index f57dc567..9b18dd8f 100755
--- a/src/libtools/sdl2rwops.c
+++ b/src/libtools/sdl2rwops.c
@@ -13,6 +13,7 @@
 #include "librarian/library_private.h"
 #include "bridge.h"
 #include "callback.h"
+#include "librarian.h"
 
 typedef struct SDL2_RWops_s SDL2_RWops_t;
 
@@ -105,10 +106,35 @@ EXPORT int32_t my2_emulated_close(SDL2_RWops_t *context)
     return ret;
 }
 
+static uintptr_t emulated_sdl2allocrw = 0;
+EXPORT SDL2_RWops_t* my_wrapped_sdl2allocrw()
+{
+    return (SDL2_RWops_t*)RunFunction(my_context, emulated_sdl2allocrw, 0);
+}
+static uintptr_t emulated_sdl2freerw = 0;
+EXPORT void my_wrapped_sdl2freerw(SDL2_RWops_t* p)
+{
+    RunFunction(my_context, emulated_sdl2freerw, 1, p);
+}
+
+static void checkSDL2isNative()
+{
+    if(my_context->sdl2allocrw)
+        return;
+    emulated_sdl2allocrw = FindGlobalSymbol(my_context->maplib, "SDL_AllocRW", -1, NULL);
+    emulated_sdl2freerw = FindGlobalSymbol(my_context->maplib, "SDL_FreeRW", -1, NULL);
+    if(emulated_sdl2allocrw && emulated_sdl2freerw) {
+        my_context->sdl2allocrw = my_wrapped_sdl2allocrw;
+        my_context->sdl2freerw = my_wrapped_sdl2freerw;
+    } else
+        printf_log(LOG_NONE, "Warning, cannot find SDL_AllocRW and/or SDL_FreeRW function in loaded libs");
+}
+
 SDL2_RWops_t* AddNativeRW2(x64emu_t* emu, SDL2_RWops_t* ops)
 {
     if(!ops)
         return NULL;
+    checkSDL2isNative();
     uintptr_t fnc;
     bridge_t* system = emu->context->system;
 
@@ -141,6 +167,7 @@ SDL2_RWops_t* RWNativeStart2(x64emu_t* emu, SDL2_RWops_t* ops)
     if(ops->type == BOX64RW)
         return ops->hidden.my.orig;
 
+    checkSDL2isNative();
     sdl2_allocrw Alloc = (sdl2_allocrw)emu->context->sdl2allocrw;
 
     SDL2_RWops_t* newrw = Alloc();