2015-05-25 05:11:41 -06:00
|
|
|
// Copyright 2003 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2015-05-25 05:11:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <android/log.h>
|
|
|
|
#include <android/native_window_jni.h>
|
2015-12-07 02:13:25 -07:00
|
|
|
#include <cinttypes>
|
2014-02-18 18:56:29 -07:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <jni.h>
|
2015-12-06 21:15:51 -07:00
|
|
|
#include <memory>
|
2016-05-11 19:18:30 -06:00
|
|
|
#include <mutex>
|
2017-12-26 14:08:44 -07:00
|
|
|
#include <optional>
|
2017-05-18 17:33:44 -06:00
|
|
|
#include <string>
|
2016-05-12 03:17:17 -06:00
|
|
|
#include <thread>
|
2017-12-28 02:13:53 -07:00
|
|
|
#include <utility>
|
2015-12-07 02:13:25 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Common/CPUDetect.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Common/CommonPaths.h"
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-04-13 17:15:23 -06:00
|
|
|
#include "Common/Event.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Common/FileUtil.h"
|
2016-01-10 11:31:49 -07:00
|
|
|
#include "Common/GL/GLInterfaceBase.h"
|
2014-06-05 17:29:54 -06:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2017-05-22 02:39:36 -06:00
|
|
|
#include "Common/MsgHandler.h"
|
2017-09-09 13:52:35 -06:00
|
|
|
#include "Common/Version.h"
|
2015-12-07 02:13:25 -07:00
|
|
|
|
2017-05-27 07:43:40 -06:00
|
|
|
#include "Core/Boot/Boot.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/BootManager.h"
|
2018-02-16 11:47:52 -07:00
|
|
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2018-01-20 17:31:53 -07:00
|
|
|
#include "Core/HW/DVD/DVDInterface.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2016-02-04 17:31:36 -07:00
|
|
|
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Core/Host.h"
|
2015-05-10 19:03:34 -06:00
|
|
|
#include "Core/PowerPC/JitInterface.h"
|
2017-04-15 08:23:48 -06:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2015-05-10 19:03:34 -06:00
|
|
|
#include "Core/PowerPC/Profiler.h"
|
2016-06-24 02:43:46 -06:00
|
|
|
#include "Core/State.h"
|
2013-04-14 19:39:56 -06:00
|
|
|
|
2016-07-06 12:33:05 -06:00
|
|
|
#include "DiscIO/Enums.h"
|
2015-12-07 02:13:25 -07:00
|
|
|
#include "DiscIO/Volume.h"
|
2013-04-23 13:21:48 -06:00
|
|
|
|
2014-10-04 13:12:15 -06:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
2015-06-18 19:28:40 -06:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2018-06-01 01:36:29 -06:00
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
|
|
|
#include "jni/ButtonManager.h"
|
2015-06-07 18:13:52 -06:00
|
|
|
|
2017-05-18 17:33:44 -06:00
|
|
|
namespace
|
|
|
|
{
|
2018-06-01 01:36:29 -06:00
|
|
|
static constexpr char DOLPHIN_TAG[] = "DolphinEmuNative";
|
2017-05-18 17:33:44 -06:00
|
|
|
|
2018-06-01 01:36:29 -06:00
|
|
|
ANativeWindow* s_surf;
|
2017-05-18 17:33:44 -06:00
|
|
|
|
|
|
|
// The Core only supports using a single Host thread.
|
|
|
|
// If multiple threads want to call host functions then they need to queue
|
|
|
|
// sequentially for access.
|
|
|
|
std::mutex s_host_identity_lock;
|
|
|
|
Common::Event s_update_main_frame_event;
|
|
|
|
bool s_have_wm_user_stop = false;
|
|
|
|
} // Anonymous namespace
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void Host_NotifyMapLoaded()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2018-05-28 11:03:29 -06:00
|
|
|
void Host_Message(HostMessageID id)
|
2013-02-26 12:49:00 -07:00
|
|
|
{
|
2018-05-28 11:03:29 -06:00
|
|
|
if (id == HostMessageID::WMUserJobDispatch)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-05-18 17:33:44 -06:00
|
|
|
s_update_main_frame_event.Set();
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2018-05-28 11:03:29 -06:00
|
|
|
else if (id == HostMessageID::WMUserStop)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
s_have_wm_user_stop = true;
|
|
|
|
if (Core::IsRunning())
|
|
|
|
Core::QueueHostJob(&Core::Stop);
|
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void* Host_GetRenderHandle()
|
|
|
|
{
|
2017-05-18 17:33:44 -06:00
|
|
|
return s_surf;
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
void Host_UpdateTitle(const std::string& title)
|
2013-07-27 14:09:18 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
__android_log_write(ANDROID_LOG_INFO, DOLPHIN_TAG, title.c_str());
|
2014-03-17 17:17:12 -06:00
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void Host_UpdateDisasmDialog()
|
|
|
|
{
|
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
|
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
void Host_RequestRenderWindowSize(int width, int height)
|
|
|
|
{
|
|
|
|
}
|
2014-07-16 07:53:33 -06:00
|
|
|
|
2017-07-12 01:11:29 -06:00
|
|
|
bool Host_UINeedsControllerState()
|
2014-07-16 08:24:40 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
return true;
|
2014-07-16 08:24:40 -06:00
|
|
|
}
|
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
bool Host_RendererHasFocus()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
return true;
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
|
|
|
|
2015-01-04 09:09:56 -07:00
|
|
|
bool Host_RendererIsFullscreen()
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
return false;
|
2015-01-04 09:09:56 -07:00
|
|
|
}
|
|
|
|
|
2016-06-26 00:06:23 -06:00
|
|
|
void Host_ShowVideoConfig(void*, const std::string&)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
}
|
2014-08-02 00:21:03 -06:00
|
|
|
|
2016-11-10 09:55:21 -07:00
|
|
|
void Host_YieldToUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-25 09:35:24 -06:00
|
|
|
void Host_UpdateProgressDialog(const char* caption, int position, int total)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:17 -06:00
|
|
|
static bool MsgAlert(const char* caption, const char* text, bool yes_no, MsgType /*style*/)
|
2015-02-12 17:41:52 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "%s:%s", caption, text);
|
2015-06-07 18:13:52 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// Associate the current Thread with the Java VM.
|
|
|
|
JNIEnv* env;
|
2018-06-01 01:36:29 -06:00
|
|
|
IDCache::GetJavaVM()->AttachCurrentThread(&env, nullptr);
|
2015-06-07 18:13:52 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// Execute the Java method.
|
2018-06-01 01:36:29 -06:00
|
|
|
jboolean result = env->CallStaticBooleanMethod(
|
|
|
|
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), ToJString(env, caption),
|
|
|
|
ToJString(env, text), yes_no ? JNI_TRUE : JNI_FALSE);
|
2015-06-07 18:13:52 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
// Must be called before the current thread exits; might as well do it here.
|
2018-06-01 01:36:29 -06:00
|
|
|
IDCache::GetJavaVM()->DetachCurrentThread();
|
2015-06-07 18:13:52 -06:00
|
|
|
|
2018-01-07 15:30:28 -07:00
|
|
|
return result != JNI_FALSE;
|
2015-02-12 17:41:52 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
#ifdef __cplusplus
|
2016-06-24 02:43:46 -06:00
|
|
|
extern "C" {
|
2013-02-26 12:49:00 -07:00
|
|
|
#endif
|
2014-03-14 15:20:44 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv* env,
|
|
|
|
jobject obj);
|
2017-12-25 05:57:31 -07:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv* env,
|
|
|
|
jobject obj);
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value);
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env, jobject obj);
|
2017-09-10 00:43:12 -06:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
|
|
|
|
jobject obj);
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint api);
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jDefault);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jValue);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetFilename(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile);
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 14:22:42 -07:00
|
|
|
jint slot,
|
|
|
|
jboolean wait);
|
2017-12-25 05:50:29 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 14:22:42 -07:00
|
|
|
jstring path,
|
|
|
|
jboolean wait);
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint slot);
|
2017-12-25 05:50:29 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring path);
|
2017-09-09 03:27:24 -06:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_CreateUserDirectories(
|
|
|
|
JNIEnv* env, jobject obj);
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDirectory);
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env, jobject obj);
|
2017-06-04 18:29:56 -06:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
|
|
|
jobject obj);
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jboolean enable);
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv* env, jobject obj);
|
2017-12-26 14:08:44 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile);
|
|
|
|
JNIEXPORT void JNICALL
|
2017-12-28 02:13:53 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate);
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-05-18 17:33:44 -06:00
|
|
|
jobject surf);
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv* env,
|
|
|
|
jobject obj);
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Running);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Paused);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-03-03 23:42:35 -07:00
|
|
|
Core::SaveScreenShot("thumb", true);
|
2016-06-24 02:43:46 -06:00
|
|
|
Core::Stop();
|
2017-05-18 17:33:44 -06:00
|
|
|
s_update_main_frame_event.Set(); // Kick the waiting event
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2017-12-25 05:57:31 -07:00
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return Core::IsRunning();
|
|
|
|
}
|
|
|
|
|
2018-01-20 17:31:53 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile);
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Button, jint Action)
|
|
|
|
{
|
|
|
|
return ButtonManager::GamepadEvent(GetJString(env, jDevice), Button, Action);
|
|
|
|
}
|
2017-12-25 05:57:31 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDevice, jint Axis, jfloat Value)
|
|
|
|
{
|
|
|
|
ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
|
|
|
|
jobject obj)
|
2013-06-22 21:54:28 -06:00
|
|
|
{
|
2018-06-01 01:36:29 -06:00
|
|
|
return ToJString(env, Common::scm_rev_str.c_str());
|
2013-06-22 21:54:28 -06:00
|
|
|
}
|
2013-11-15 13:17:47 -07:00
|
|
|
|
2017-09-10 00:43:12 -06:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
2018-06-01 01:36:29 -06:00
|
|
|
return ToJString(env, Common::scm_rev_git_str.c_str());
|
2017-09-10 00:43:12 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv* env,
|
|
|
|
jobject obj)
|
2013-11-15 16:32:50 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
Core::SaveScreenShot();
|
2013-11-15 16:32:50 -07:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint api)
|
2014-02-10 23:16:21 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
eglBindAPI(api);
|
2014-02-10 23:16:21 -07:00
|
|
|
}
|
|
|
|
|
2018-02-16 11:47:52 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_InitGameIni(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jGameID)
|
|
|
|
{
|
|
|
|
// Initialize an empty INI file
|
|
|
|
IniFile ini;
|
|
|
|
std::string gameid = GetJString(env, jGameID);
|
|
|
|
|
|
|
|
__android_log_print(ANDROID_LOG_DEBUG, "InitGameIni", "Initializing base game config file");
|
|
|
|
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserSetting(
|
|
|
|
JNIEnv* env, jobject obj, jstring jGameID, jstring jSection, jstring jKey)
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
std::string gameid = GetJString(env, jGameID);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
|
|
|
|
ini = SConfig::GetInstance().LoadGameIni(gameid, 0);
|
|
|
|
std::string value;
|
|
|
|
|
|
|
|
ini.GetOrCreateSection(section)->Get(key, &value, "-1");
|
|
|
|
|
2018-06-01 01:36:29 -06:00
|
|
|
return ToJString(env, value.c_str());
|
2018-02-16 11:47:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserSetting(
|
|
|
|
JNIEnv* env, jobject obj, jstring jGameID, jstring jSection, jstring jKey, jstring jValue)
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
std::string gameid = GetJString(env, jGameID);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
std::string val = GetJString(env, jValue);
|
|
|
|
|
|
|
|
ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
|
|
|
|
|
|
if (val != "-1")
|
|
|
|
{
|
|
|
|
ini.GetOrCreateSection(section)->Set(key, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ini.GetOrCreateSection(section)->Delete(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
ini.Save(File::GetUserPath(D_GAMESETTINGS_IDX) + gameid + ".ini");
|
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jDefault)
|
2013-04-23 13:21:48 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
IniFile ini;
|
|
|
|
std::string file = GetJString(env, jFile);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
std::string defaultValue = GetJString(env, jDefault);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string(file));
|
|
|
|
std::string value;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ini.GetOrCreateSection(section)->Get(key, &value, defaultValue);
|
2013-04-23 13:21:48 -06:00
|
|
|
|
2018-06-01 01:36:29 -06:00
|
|
|
return ToJString(env, value.c_str());
|
2013-04-23 13:21:48 -06:00
|
|
|
}
|
2018-06-01 01:36:29 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetConfig(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSection, jstring jKey, jstring jValue)
|
2013-04-23 13:21:48 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
IniFile ini;
|
|
|
|
std::string file = GetJString(env, jFile);
|
|
|
|
std::string section = GetJString(env, jSection);
|
|
|
|
std::string key = GetJString(env, jKey);
|
|
|
|
std::string value = GetJString(env, jValue);
|
2013-06-18 06:09:20 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string(file));
|
2013-04-23 13:21:48 -06:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
ini.GetOrCreateSection(section)->Set(key, value);
|
|
|
|
ini.Save(File::GetUserPath(D_CONFIG_IDX) + std::string(file));
|
2013-04-23 13:21:48 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 14:22:42 -07:00
|
|
|
jint slot,
|
|
|
|
jboolean wait)
|
2013-08-29 16:47:50 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-26 14:22:42 -07:00
|
|
|
State::Save(slot, wait);
|
2013-08-29 16:47:50 -06:00
|
|
|
}
|
|
|
|
|
2017-12-25 05:50:29 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-12-26 14:22:42 -07:00
|
|
|
jstring path,
|
|
|
|
jboolean wait)
|
2017-12-25 05:50:29 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-26 14:22:42 -07:00
|
|
|
State::SaveAs(GetJString(env, path), wait);
|
2013-08-29 16:47:50 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jint slot)
|
2013-08-29 16:47:50 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
State::Load(slot);
|
2013-08-29 16:47:50 -06:00
|
|
|
}
|
|
|
|
|
2017-12-25 05:50:29 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring path)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
State::LoadAs(GetJString(env, path));
|
|
|
|
}
|
|
|
|
|
2017-09-09 03:27:24 -06:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_SetSysDirectory(
|
|
|
|
JNIEnv* env, jobject obj, jstring jPath)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jPath);
|
|
|
|
File::SetSysDirectory(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_services_DirectoryInitializationService_CreateUserDirectories(
|
|
|
|
JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
UICommon::CreateDirectories();
|
2013-08-29 17:07:32 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(
|
|
|
|
JNIEnv* env, jobject obj, jstring jDirectory)
|
2015-02-25 02:23:42 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-28 05:34:49 -07:00
|
|
|
UICommon::SetUserDirectory(GetJString(env, jDirectory));
|
2015-02-25 02:23:42 -07:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env,
|
|
|
|
jobject obj)
|
2015-02-27 22:20:33 -07:00
|
|
|
{
|
2018-06-01 01:36:29 -06:00
|
|
|
return ToJString(env, File::GetUserPath(D_USER_IDX).c_str());
|
2015-02-27 22:20:33 -07:00
|
|
|
}
|
|
|
|
|
2017-04-15 08:23:48 -06:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
return PowerPC::DefaultCPUCore();
|
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jboolean enable)
|
2015-05-10 19:03:34 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Paused);
|
2016-06-24 02:43:46 -06:00
|
|
|
JitInterface::ClearCache();
|
|
|
|
Profiler::g_ProfileBlocks = enable;
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Running);
|
2015-05-10 19:03:34 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv* env,
|
|
|
|
jobject obj)
|
2015-05-10 19:03:34 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
|
|
|
|
File::CreateFullPath(filename);
|
|
|
|
JitInterface::WriteProfileResults(filename);
|
2015-05-10 19:03:34 -06:00
|
|
|
}
|
|
|
|
|
2016-01-10 11:31:49 -07:00
|
|
|
// Surface Handling
|
2016-06-24 02:43:46 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
|
|
|
jobject obj,
|
2017-05-18 17:33:44 -06:00
|
|
|
jobject surf)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-05-18 17:33:44 -06:00
|
|
|
s_surf = ANativeWindow_fromSurface(env, surf);
|
|
|
|
if (s_surf == nullptr)
|
2016-06-24 02:43:46 -06:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "Error: Surface is null.");
|
|
|
|
|
2016-08-13 06:08:53 -06:00
|
|
|
if (g_renderer)
|
2017-05-18 17:33:44 -06:00
|
|
|
g_renderer->ChangeSurface(s_surf);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
2016-08-13 06:08:53 -06:00
|
|
|
if (g_renderer)
|
|
|
|
g_renderer->ChangeSurface(nullptr);
|
|
|
|
|
2017-05-18 17:33:44 -06:00
|
|
|
if (s_surf)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-05-18 17:33:44 -06:00
|
|
|
ANativeWindow_release(s_surf);
|
|
|
|
s_surf = nullptr;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv* env,
|
|
|
|
jobject obj)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
WiimoteReal::Refresh();
|
|
|
|
}
|
|
|
|
|
2017-12-28 02:13:53 -07:00
|
|
|
static void Run(const std::string& path, std::optional<std::string> savestate_path = {},
|
|
|
|
bool delete_savestate = false)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-08-23 14:32:23 -06:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", path.c_str());
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Install our callbacks
|
|
|
|
OSD::AddCallback(OSD::CallbackType::Initialization, ButtonManager::Init);
|
|
|
|
OSD::AddCallback(OSD::CallbackType::Shutdown, ButtonManager::Shutdown);
|
|
|
|
|
|
|
|
RegisterMsgAlertHandler(&MsgAlert);
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> guard(s_host_identity_lock);
|
|
|
|
UICommon::Init();
|
|
|
|
|
|
|
|
WiimoteReal::InitAdapterClass();
|
|
|
|
|
|
|
|
// No use running the loop when booting fails
|
|
|
|
s_have_wm_user_stop = false;
|
2017-12-28 02:13:53 -07:00
|
|
|
std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(path, savestate_path);
|
|
|
|
boot->delete_savestate = delete_savestate;
|
|
|
|
if (BootManager::BootCore(std::move(boot)))
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
|
|
|
static constexpr int TIMEOUT = 10000;
|
|
|
|
static constexpr int WAIT_STEP = 25;
|
|
|
|
int time_waited = 0;
|
|
|
|
// A Core::CORE_ERROR state would be helpful here.
|
|
|
|
while (!Core::IsRunning() && time_waited < TIMEOUT && !s_have_wm_user_stop)
|
|
|
|
{
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_STEP));
|
|
|
|
time_waited += WAIT_STEP;
|
|
|
|
}
|
|
|
|
while (Core::IsRunning())
|
|
|
|
{
|
|
|
|
guard.unlock();
|
2017-05-18 17:33:44 -06:00
|
|
|
s_update_main_frame_event.Wait();
|
2016-06-24 02:43:46 -06:00
|
|
|
guard.lock();
|
|
|
|
Core::HostDispatchJobs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::Shutdown();
|
|
|
|
UICommon::Shutdown();
|
|
|
|
guard.unlock();
|
|
|
|
|
2017-05-18 17:33:44 -06:00
|
|
|
if (s_surf)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-05-18 17:33:44 -06:00
|
|
|
ANativeWindow_release(s_surf);
|
|
|
|
s_surf = nullptr;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
2013-07-27 14:09:18 -06:00
|
|
|
|
2017-12-26 14:08:44 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile)
|
|
|
|
{
|
|
|
|
Run(GetJString(env, jFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2017-12-28 02:13:53 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run__Ljava_lang_String_2Ljava_lang_String_2Z(
|
|
|
|
JNIEnv* env, jobject obj, jstring jFile, jstring jSavestate, jboolean jDeleteSavestate)
|
2017-12-26 14:08:44 -07:00
|
|
|
{
|
2017-12-28 02:13:53 -07:00
|
|
|
Run(GetJString(env, jFile), GetJString(env, jSavestate), jDeleteSavestate);
|
2017-12-26 14:08:44 -07:00
|
|
|
}
|
|
|
|
|
2018-01-20 17:31:53 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
|
|
|
|
jobject obj,
|
|
|
|
jstring jFile)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jFile);
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str());
|
|
|
|
Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); });
|
|
|
|
}
|
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|