From 8c7be9d709243082bb19a1a76ed744f97c80f2b6 Mon Sep 17 00:00:00 2001 From: Frode Solheim Date: Sat, 5 Sep 2015 15:59:53 +0200 Subject: [PATCH] merged uae_dlopen_plugin implementations, unified capsimg support --- dlopen.cpp | 52 +++++++++++++++---- od-win32/caps/caps_win32.cpp | 97 +++++++++++++++++++----------------- od-win32/sysconfig.h | 4 ++ od-win32/win32.cpp | 21 -------- qemuvga/qemu.cpp | 7 ++- uaenative.cpp | 3 -- 6 files changed, 101 insertions(+), 83 deletions(-) diff --git a/dlopen.cpp b/dlopen.cpp index 870f1d1c..164cdf42 100644 --- a/dlopen.cpp +++ b/dlopen.cpp @@ -1,29 +1,37 @@ #include "sysconfig.h" #include "sysdeps.h" - +#include "uae/api.h" #include "uae/dlopen.h" -#ifdef _WIN32 +#include "uae/log.h" +#ifdef _WIN32 +#include "windows.h" #else #include #endif +#ifdef WINUAE +#include "od-win32/win32.h" +#endif UAE_DLHANDLE uae_dlopen(const TCHAR *path) { UAE_DLHANDLE result; -#ifdef WINUAE - result = uae_dlopen_plugin(path); -#elif _WIN32 + if (path == NULL || path[0] == _T('\0')) { + write_log(_T("DLOPEN: No path given\n")); + return NULL; + } +#ifdef _WIN32 result = LoadLibrary(path); #else result = dlopen(path, RTLD_NOW); const char *error = dlerror(); if (error != NULL) { - write_log("uae_dlopen failed: %s\n", error); + write_log("DLOPEN: %s\n", error); } #endif - if (result) - uae_dlopen_patch_common(result); + if (result == NULL) { + write_log("DLOPEN: Failed to open %s\n", path); + } return result; } @@ -50,7 +58,33 @@ void uae_dlclose(UAE_DLHANDLE handle) #endif } -#include "uae/log.h" +UAE_DLHANDLE uae_dlopen_plugin(const TCHAR *name) +{ +#if defined(FSUAE) + const TCHAR *path = NULL; + if (plugin_lookup) { + path = plugin_lookup(name); + } + if (path == NULL or path[0] == _T('\0')) { + write_log(_T("DLOPEN: Could not find plugin \"%s\"\n"), name); + return NULL; + } + UAE_DLHANDLE handle = uae_dlopen(path); +#else + TCHAR path[MAX_DPATH]; + _tcscpy(path, name); +#ifdef _WIN64 + _tcscat(path, _T("_x64")); +#endif + _tcscat(path, LT_MODULE_EXT); + UAE_DLHANDLE handle = uae_dlopen(path); +#endif + if (handle) { + write_log(_T("DLOPEN: Loaded plugin %s\n"), path); + uae_dlopen_patch_common(handle); + } + return handle; +} void uae_dlopen_patch_common(UAE_DLHANDLE handle) { diff --git a/od-win32/caps/caps_win32.cpp b/od-win32/caps/caps_win32.cpp index fb13fb2d..cf5ba970 100644 --- a/od-win32/caps/caps_win32.cpp +++ b/od-win32/caps/caps_win32.cpp @@ -1,18 +1,19 @@ - #include "sysconfig.h" #include "sysdeps.h" #ifdef CAPS +#ifdef _WIN32 #include +#endif #include "caps_win32.h" #include "zfile.h" #include "gui.h" -#include "win32.h" #include "uae.h" +#include "uae/dlopen.h" -#include "ComType.h" +#include "Comtype.h" #include "CapsAPI.h" #define CAPS_TRACKTIMING 1 @@ -25,78 +26,84 @@ static int caps_flags = DI_LOCK_DENVAR|DI_LOCK_DENNOISE|DI_LOCK_NOISE|DI_LOCK_UP static struct CapsVersionInfo cvi; static bool oldlib, canseed; -typedef SDWORD (__cdecl* CAPSINIT)(void); +#ifdef _WIN32 +#define CAPSCALL __cdecl +#else +#define CAPSCALL +#endif + +typedef SDWORD (CAPSCALL * CAPSINIT)(void); static CAPSINIT pCAPSInit; -typedef SDWORD (__cdecl* CAPSADDIMAGE)(void); +typedef SDWORD (CAPSCALL * CAPSADDIMAGE)(void); static CAPSADDIMAGE pCAPSAddImage; -typedef SDWORD (__cdecl* CAPSLOCKIMAGEMEMORY)(SDWORD,PUBYTE,UDWORD,UDWORD); +typedef SDWORD (CAPSCALL * CAPSLOCKIMAGEMEMORY)(SDWORD,PUBYTE,UDWORD,UDWORD); static CAPSLOCKIMAGEMEMORY pCAPSLockImageMemory; -typedef SDWORD (__cdecl* CAPSUNLOCKIMAGE)(SDWORD); +typedef SDWORD (CAPSCALL * CAPSUNLOCKIMAGE)(SDWORD); static CAPSUNLOCKIMAGE pCAPSUnlockImage; -typedef SDWORD (__cdecl* CAPSLOADIMAGE)(SDWORD,UDWORD); +typedef SDWORD (CAPSCALL * CAPSLOADIMAGE)(SDWORD,UDWORD); static CAPSLOADIMAGE pCAPSLoadImage; -typedef SDWORD (__cdecl* CAPSGETIMAGEINFO)(PCAPSIMAGEINFO,SDWORD); +typedef SDWORD (CAPSCALL * CAPSGETIMAGEINFO)(PCAPSIMAGEINFO,SDWORD); static CAPSGETIMAGEINFO pCAPSGetImageInfo; -typedef SDWORD (__cdecl* CAPSLOCKTRACK)(PCAPSTRACKINFO,SDWORD,UDWORD,UDWORD,UDWORD); +typedef SDWORD (CAPSCALL * CAPSLOCKTRACK)(PCAPSTRACKINFO,SDWORD,UDWORD,UDWORD,UDWORD); static CAPSLOCKTRACK pCAPSLockTrack; -typedef SDWORD (__cdecl* CAPSUNLOCKTRACK)(SDWORD,UDWORD); +typedef SDWORD (CAPSCALL * CAPSUNLOCKTRACK)(SDWORD,UDWORD); static CAPSUNLOCKTRACK pCAPSUnlockTrack; -typedef SDWORD (__cdecl* CAPSUNLOCKALLTRACKS)(SDWORD); +typedef SDWORD (CAPSCALL * CAPSUNLOCKALLTRACKS)(SDWORD); static CAPSUNLOCKALLTRACKS pCAPSUnlockAllTracks; -typedef SDWORD (__cdecl* CAPSGETVERSIONINFO)(PCAPSVERSIONINFO,UDWORD); +typedef SDWORD (CAPSCALL * CAPSGETVERSIONINFO)(PCAPSVERSIONINFO,UDWORD); static CAPSGETVERSIONINFO pCAPSGetVersionInfo; -typedef SDWORD (__cdecl* CAPSGETINFO)(PVOID pinfo, SDWORD id, UDWORD cylinder, UDWORD head, UDWORD inftype, UDWORD infid); +typedef SDWORD (CAPSCALL * CAPSGETINFO)(PVOID pinfo, SDWORD id, UDWORD cylinder, UDWORD head, UDWORD inftype, UDWORD infid); static CAPSGETINFO pCAPSGetInfo; -typedef SDWORD (__cdecl* CAPSSETREVOLUTION)(SDWORD id, UDWORD value); +typedef SDWORD (CAPSCALL * CAPSSETREVOLUTION)(SDWORD id, UDWORD value); static CAPSSETREVOLUTION pCAPSSetRevolution; -typedef SDWORD (__cdecl* CAPSGETIMAGETYPEMEMORY)(PUBYTE buffer, UDWORD length); +typedef SDWORD (CAPSCALL * CAPSGETIMAGETYPEMEMORY)(PUBYTE buffer, UDWORD length); static CAPSGETIMAGETYPEMEMORY pCAPSGetImageTypeMemory; int caps_init (void) { static int init, noticed; int i; - HMODULE h; - TCHAR *dllname = _T("CAPSImg.dll"); if (init) return 1; - h = WIN32_LoadLibrary (dllname); + UAE_DLHANDLE h = uae_dlopen_plugin(_T("CAPSImg")); if (!h) { TCHAR tmp[MAX_DPATH]; if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, tmp))) { _tcscat (tmp, _T("\\Software Preservation Society\\")); - _tcscat (tmp, dllname); - h = LoadLibrary (tmp); - if (!h) { - if (noticed) - return 0; - notify_user (NUMSG_NOCAPS); - noticed = 1; - return 0; - } + _tcscat (tmp, _T("CAPSImg.dll")); + h = uae_dlopen(tmp); } } - if (GetProcAddress (h, "CAPSLockImageMemory") == 0 || GetProcAddress (h, "CAPSGetVersionInfo") == 0) { + if (!h) { + if (noticed) + return 0; + notify_user (NUMSG_NOCAPS); + noticed = 1; + return 0; + } + + if (uae_dlsym(h, "CAPSLockImageMemory") == 0 || uae_dlsym(h, "CAPSGetVersionInfo") == 0) { if (noticed) return 0; notify_user (NUMSG_OLDCAPS); noticed = 1; return 0; } - pCAPSInit = (CAPSINIT)GetProcAddress (h, "CAPSInit"); - pCAPSAddImage = (CAPSADDIMAGE)GetProcAddress (h, "CAPSAddImage"); - pCAPSLockImageMemory = (CAPSLOCKIMAGEMEMORY)GetProcAddress (h, "CAPSLockImageMemory"); - pCAPSUnlockImage = (CAPSUNLOCKIMAGE)GetProcAddress (h, "CAPSUnlockImage"); - pCAPSLoadImage = (CAPSLOADIMAGE)GetProcAddress (h, "CAPSLoadImage"); - pCAPSGetImageInfo = (CAPSGETIMAGEINFO)GetProcAddress (h, "CAPSGetImageInfo"); - pCAPSLockTrack = (CAPSLOCKTRACK)GetProcAddress (h, "CAPSLockTrack"); - pCAPSUnlockTrack = (CAPSUNLOCKTRACK)GetProcAddress (h, "CAPSUnlockTrack"); - pCAPSUnlockAllTracks = (CAPSUNLOCKALLTRACKS)GetProcAddress (h, "CAPSUnlockAllTracks"); - pCAPSGetVersionInfo = (CAPSGETVERSIONINFO)GetProcAddress (h, "CAPSGetVersionInfo"); - pCAPSGetInfo = (CAPSGETINFO)GetProcAddress (h, "CAPSGetInfo"); - pCAPSSetRevolution = (CAPSSETREVOLUTION)GetProcAddress(h, "CAPSSetRevolution"); - pCAPSGetImageTypeMemory = (CAPSGETIMAGETYPEMEMORY)GetProcAddress(h, "CAPSGetImageTypeMemory"); + + pCAPSInit = (CAPSINIT) uae_dlsym(h, "CAPSInit"); + pCAPSAddImage = (CAPSADDIMAGE) uae_dlsym(h, "CAPSAddImage"); + pCAPSLockImageMemory = (CAPSLOCKIMAGEMEMORY) uae_dlsym(h, "CAPSLockImageMemory"); + pCAPSUnlockImage = (CAPSUNLOCKIMAGE) uae_dlsym(h, "CAPSUnlockImage"); + pCAPSLoadImage = (CAPSLOADIMAGE) uae_dlsym(h, "CAPSLoadImage"); + pCAPSGetImageInfo = (CAPSGETIMAGEINFO) uae_dlsym(h, "CAPSGetImageInfo"); + pCAPSLockTrack = (CAPSLOCKTRACK) uae_dlsym(h, "CAPSLockTrack"); + pCAPSUnlockTrack = (CAPSUNLOCKTRACK) uae_dlsym(h, "CAPSUnlockTrack"); + pCAPSUnlockAllTracks = (CAPSUNLOCKALLTRACKS) uae_dlsym(h, "CAPSUnlockAllTracks"); + pCAPSGetVersionInfo = (CAPSGETVERSIONINFO) uae_dlsym(h, "CAPSGetVersionInfo"); + pCAPSGetInfo = (CAPSGETINFO) uae_dlsym(h, "CAPSGetInfo"); + pCAPSSetRevolution = (CAPSSETREVOLUTION) uae_dlsym(h, "CAPSSetRevolution"); + pCAPSGetImageTypeMemory = (CAPSGETIMAGETYPEMEMORY) uae_dlsym(h, "CAPSGetImageTypeMemory"); init = 1; cvi.type = 1; @@ -227,9 +234,7 @@ static void mfmcopy (uae_u16 *mfm, uae_u8 *data, int len) static int load (struct CapsTrackInfoT2 *ci, int drv, int track, bool seed, bool newtrack) { - int flags; - - flags = caps_flags; + int flags = caps_flags; if (canseed) { ci->type = 2; if (seed) { @@ -356,4 +361,4 @@ int caps_loadtrack (uae_u16 *mfmbuf, uae_u16 *tracktiming, int drv, int track, i return 1; } -#endif +#endif /* CAPS */ diff --git a/od-win32/sysconfig.h b/od-win32/sysconfig.h index 8e66204b..df0c0f61 100644 --- a/od-win32/sysconfig.h +++ b/od-win32/sysconfig.h @@ -329,6 +329,10 @@ #undef HAVE_ISINF #define isnan _isnan +#ifndef LT_MODULE_EXT +#define LT_MODULE_EXT _T(".dll") +#endif + /* Define if you have the bcopy function. */ /* #undef HAVE_BCOPY */ diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 1cb6eeab..1846f56b 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -6495,27 +6495,6 @@ HMODULE WIN32_LoadLibrary2 (const TCHAR *name) return m; } -HMODULE uae_dlopen_plugin(const TCHAR *name) -{ - HMODULE h; - TCHAR path[MAX_DPATH]; -#ifdef WIN64 - _tcscpy(path, name); - _tcscat(path, _T("_x64.dll")); - h = WIN32_LoadLibrary(path); - if (h) - return h; - _tcscpy(path, _T("qemu\\")); - _tcscat(path, name); - _tcscat(path, _T("_x64.dll")); -#else - _tcscpy(path, name); - _tcscat(path, _T(".dll")); -#endif - h = WIN32_LoadLibrary(path); - return h; -} - int isdllversion (const TCHAR *name, int version, int revision, int subver, int subrev) { DWORD dwVersionHandle, dwFileVersionInfoSize; diff --git a/qemuvga/qemu.cpp b/qemuvga/qemu.cpp index 6045bc2a..4f99464e 100644 --- a/qemuvga/qemu.cpp +++ b/qemuvga/qemu.cpp @@ -30,7 +30,7 @@ static void init_ppc(UAE_DLHANDLE handle) } } -#ifndef WINUAE +#ifdef WITH_QEMU_SLIRP static void init_slirp(UAE_DLHANDLE handle) { UAE_IMPORT_FUNCTION(handle, qemu_uae_slirp_init); @@ -52,7 +52,7 @@ UAE_DLHANDLE uae_qemu_uae_init(void) } initialized = true; - handle = uae_dlopen(_T("qemu-uae")); + handle = uae_dlopen_plugin(_T("qemu-uae")); if (!handle) { gui_message(_T("Error loading qemu-uae plugin\n")); return handle; @@ -98,8 +98,7 @@ UAE_DLHANDLE uae_qemu_uae_init(void) } init_ppc(handle); - -#ifndef WINUAE +#ifdef WITH_QEMU_SLIRP init_slirp(handle); #endif diff --git a/uaenative.cpp b/uaenative.cpp index 2aa09873..4a731839 100644 --- a/uaenative.cpp +++ b/uaenative.cpp @@ -69,9 +69,6 @@ static int g_allocated_handles = 0; static int g_max_handle = -1; #ifdef _WIN32 -#ifndef LT_MODULE_EXT -#define LT_MODULE_EXT _T(".dll") -#endif #ifndef OS_NAME #define OS_NAME _T("windows") #endif -- 2.47.3