2014-12-04 07:56:54 +00:00
|
|
|
#include <jni.h>
|
2014-12-07 03:05:14 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <android/log.h>
|
2015-03-11 01:03:38 -04:00
|
|
|
#include <android/native_window.h>
|
|
|
|
#include <android/native_window_jni.h>
|
2014-12-07 03:05:14 +00:00
|
|
|
#include "PathUtils.h"
|
2014-12-04 07:56:54 +00:00
|
|
|
#include "../PS2VM.h"
|
2015-03-11 01:03:38 -04:00
|
|
|
#include "../GSH_Null.h"
|
|
|
|
#include "GSH_OpenGLAndroid.h"
|
2014-12-04 07:56:54 +00:00
|
|
|
|
2014-12-07 03:05:14 +00:00
|
|
|
#define LOG_NAME "Play!"
|
|
|
|
|
|
|
|
static CPS2VM* g_virtualMachine = nullptr;
|
|
|
|
|
|
|
|
void Log_Print(const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
__android_log_vprint(ANDROID_LOG_INFO, LOG_NAME, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2015-03-19 23:54:47 -04:00
|
|
|
std::string GetStringFromJstring(JNIEnv* env, jstring javaString)
|
|
|
|
{
|
|
|
|
auto nativeString = env->GetStringUTFChars(javaString, JNI_FALSE);
|
|
|
|
std::string result(nativeString);
|
|
|
|
env->ReleaseStringUTFChars(javaString, nativeString);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-12-07 03:05:14 +00:00
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_setFilesDirPath(JNIEnv* env, jobject obj, jstring dirPathString)
|
|
|
|
{
|
|
|
|
auto dirPath = env->GetStringUTFChars(dirPathString, 0);
|
|
|
|
Framework::PathUtils::SetFilesDirPath(dirPath);
|
|
|
|
env->ReleaseStringUTFChars(dirPathString, dirPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_createVirtualMachine(JNIEnv* env, jobject obj)
|
|
|
|
{
|
2015-04-05 23:29:49 -04:00
|
|
|
assert(g_virtualMachine == nullptr);
|
2014-12-07 03:05:14 +00:00
|
|
|
g_virtualMachine = new CPS2VM();
|
|
|
|
g_virtualMachine->Initialize();
|
|
|
|
}
|
|
|
|
|
2015-04-05 23:29:49 -04:00
|
|
|
extern "C" JNIEXPORT jboolean JNICALL Java_com_virtualapplications_play_NativeInterop_isVirtualMachineCreated(JNIEnv* env, jobject obj)
|
2014-12-04 07:56:54 +00:00
|
|
|
{
|
2015-04-05 23:29:49 -04:00
|
|
|
return (g_virtualMachine != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jboolean JNICALL Java_com_virtualapplications_play_NativeInterop_isVirtualMachineRunning(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
if(g_virtualMachine == nullptr) return false;
|
|
|
|
return g_virtualMachine->GetStatus() == CVirtualMachine::RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_resumeVirtualMachine(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
assert(g_virtualMachine != nullptr);
|
|
|
|
if(g_virtualMachine == nullptr) return;
|
|
|
|
g_virtualMachine->Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_pauseVirtualMachine(JNIEnv* env, jobject obj)
|
|
|
|
{
|
|
|
|
assert(g_virtualMachine != nullptr);
|
|
|
|
if(g_virtualMachine == nullptr) return;
|
|
|
|
g_virtualMachine->Pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_loadElf(JNIEnv* env, jobject obj, jstring selectedFilePath)
|
|
|
|
{
|
|
|
|
assert(g_virtualMachine != nullptr);
|
2014-12-07 03:05:14 +00:00
|
|
|
g_virtualMachine->Reset();
|
2015-03-19 23:54:47 -04:00
|
|
|
g_virtualMachine->m_ee->m_os->BootFromFile(GetStringFromJstring(env, selectedFilePath).c_str());
|
2015-04-05 23:29:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_com_virtualapplications_play_NativeInterop_setupGsHandler(JNIEnv* env, jobject obj, jobject surface)
|
|
|
|
{
|
|
|
|
auto nativeWindow = ANativeWindow_fromSurface(env, surface);
|
2015-04-06 02:34:34 -04:00
|
|
|
auto gsHandler = g_virtualMachine->GetGSHandler();
|
|
|
|
if(gsHandler == nullptr)
|
|
|
|
{
|
|
|
|
g_virtualMachine->CreateGSHandler(CGSH_OpenGLAndroid::GetFactoryFunction(nativeWindow));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static_cast<CGSH_OpenGLAndroid*>(gsHandler)->SetWindow(nativeWindow);
|
|
|
|
}
|
2014-12-04 07:56:54 +00:00
|
|
|
}
|