diff --git a/Common/CPUDetect.cpp b/Common/CPUDetect.cpp index 42c580135f..40c82e481d 100644 --- a/Common/CPUDetect.cpp +++ b/Common/CPUDetect.cpp @@ -62,23 +62,18 @@ void __cpuidex(int regs[4], int cpuid_leaf, int ecxval) #if defined(__i386__) "pushl %%ebx;\n\t" #endif - "movl %4, %%eax;\n\t" - "movl %5, %%ecx;\n\t" "cpuid;\n\t" - "movl %%eax, %0;\n\t" "movl %%ebx, %1;\n\t" - "movl %%ecx, %2;\n\t" - "movl %%edx, %3;\n\t" #if defined(__i386__) "popl %%ebx;\n\t" #endif - :"=m" (regs[0]), "=m" (regs[1]), "=m" (regs[2]), "=m" (regs[3]) - :"r" (cpuid_leaf), "r" (ecxval) - :"%eax", + :"=a" (regs[0]), "=m" (regs[1]), "=c" (regs[2]), "=d" (regs[3]) + :"a" (cpuid_leaf), "c" (ecxval) #if !defined(__i386__) - "%ebx", + :"%ebx"); +#else + ); #endif - "%ecx", "%edx"); #endif } void __cpuid(int regs[4], int cpuid_leaf) diff --git a/Qt/QtHost.cpp b/Qt/QtHost.cpp index 2b8dbfa922..bc03fb1ee2 100644 --- a/Qt/QtHost.cpp +++ b/Qt/QtHost.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "QtHost.h" #include "LogManager.h" @@ -313,8 +314,19 @@ void NativeInit(int argc, const char *argv[], const char *savegame_directory, co g_Config.currentDirectory = QDir::homePath().toStdString(); } - g_Config.memCardDirectory = QDir::homePath().toStdString()+"/.ppsspp/"; - g_Config.flash0Directory = g_Config.memCardDirectory+"/flash0/"; + g_Config.memCardDirectory = QDir::homePath().toStdString() + "/.ppsspp/"; + +#if defined(Q_OS_LINUX) && !defined(ARM) + std::string program_path = QCoreApplication::applicationDirPath().toStdString(); + if (File::Exists(program_path + "/flash0")) + g_Config.flash0Directory = program_path + "/flash0/"; + else if (File::Exists(program_path + "/../flash0")) + g_Config.flash0Directory = program_path + "/../flash0/"; + else + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; +#else + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; +#endif LogManager::Init(); if (fileToLog != NULL) diff --git a/UI/GamepadEmu.h b/UI/GamepadEmu.h index 7f70338c23..a07448cba6 100644 --- a/UI/GamepadEmu.h +++ b/UI/GamepadEmu.h @@ -26,7 +26,7 @@ class MultiTouchButton : public UI::View { public: MultiTouchButton(int bgImg, int img, float scale, UI::LayoutParams *layoutParams) - : UI::View(layoutParams), pointerDownMask_(0), bgImg_(bgImg), img_(img), scale_(scale), angle_(0.0f), flipImageH_(false) { + : UI::View(layoutParams), pointerDownMask_(0), scale_(scale), bgImg_(bgImg), img_(img), angle_(0.0f), flipImageH_(false) { } virtual void Key(const KeyInput &input) {} diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 4a265e9a22..222bf51a0d 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -215,6 +215,28 @@ void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, boo #endif } +const std::string NativeProgramPath() { +#if (defined(__APPLE__) && !defined(IOS)) || defined(__linux__) + char program_path[4096]; + uint32_t program_path_size = sizeof(program_path) - 1; +#if defined(__linux__) + if (readlink("/proc/self/exe", program_path, 4095) > 0) { +#elif defined(__APPLE__) && !defined(IOS) + if (_NSGetExecutablePath(program_path, &program_path_size) == 0) { +#else +#error Unmatched ifdef. +#endif + program_path[sizeof(program_path) - 1] = '\0'; + char *last_slash = strrchr(program_path, '/'); + if (last_slash != NULL) + *(last_slash + 1) = '\0'; + return program_path; + } +#endif + + return ""; +} + void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID) { bool skipLogo = false; @@ -226,13 +248,11 @@ void NativeInit(int argc, const char *argv[], #ifdef IOS user_data_path += "/"; #elif defined(__APPLE__) - char program_path[4090]; - uint32_t program_path_size = sizeof(program_path); - _NSGetExecutablePath(program_path,&program_path_size); - *(strrchr(program_path, '/')+1) = '\0'; - char assets_path[4096]; - sprintf(assets_path,"%sassets/",program_path); - VFSRegister("", new DirectoryAssetReader(assets_path)); + if (File::Exists(NativeProgramPath() + "assets")) + VFSRegister("", new DirectoryAssetReader((NativeProgramPath() + "assets/").c_str())); + // It's common to be in a build-xyz/ directory. + else + VFSRegister("", new DirectoryAssetReader((NativeProgramPath() + "../assets/").c_str())); #endif // We want this to be FIRST. @@ -259,9 +279,15 @@ void NativeInit(int argc, const char *argv[], g_Config.memCardDirectory = user_data_path; g_Config.flash0Directory = std::string(external_directory) + "/flash0/"; #elif !defined(_WIN32) - // Linux, Mac. Does this path really make sense? g_Config.memCardDirectory = std::string(getenv("HOME")) + "/.ppsspp/"; - g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; + std::string program_path = NativeProgramPath(); + if (program_path.empty()) + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; + else if (File::Exists(program_path + "flash0")) + g_Config.flash0Directory = program_path + "flash0/"; + // It's common to be in a build-xyz/ directory. + else + g_Config.flash0Directory = program_path + "../flash0/"; #endif #ifndef _WIN32 diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 71784cb441..f5223b0fd7 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -329,8 +329,9 @@ int main(int argc, const char* argv[]) #if defined(ANDROID) #elif defined(BLACKBERRY) || defined(__SYMBIAN32__) #elif !defined(_WIN32) - g_Config.memCardDirectory = std::string(getenv("HOME"))+"/.ppsspp/"; - g_Config.flash0Directory = g_Config.memCardDirectory+"/flash/"; + g_Config.memCardDirectory = std::string(getenv("HOME")) + "/.ppsspp/"; + // TODO: This isn't a great place. + g_Config.flash0Directory = g_Config.memCardDirectory + "/flash0/"; #endif if (screenshotFilename != 0)