2019-09-24 22:54:27 +02:00
|
|
|
#include <jni.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <csignal>
|
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
|
|
|
#include "skyline/common.h"
|
|
|
|
#include "skyline/os.h"
|
|
|
|
|
|
|
|
std::thread *EmuThread;
|
|
|
|
bool Halt = false;
|
|
|
|
|
|
|
|
void ThreadMain(const std::string romPath, const std::string prefPath, const std::string logPath) {
|
2019-09-25 11:32:17 +02:00
|
|
|
auto logger = std::make_shared<skyline::Logger>(logPath);
|
2019-09-24 22:54:27 +02:00
|
|
|
auto settings = std::make_shared<skyline::Settings>(prefPath);
|
2019-09-25 11:32:17 +02:00
|
|
|
//settings->List(log); // (Uncomment when you want to print out all settings strings)
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
2019-09-24 22:54:27 +02:00
|
|
|
try {
|
2019-09-25 11:32:17 +02:00
|
|
|
skyline::kernel::OS os(logger, settings);
|
|
|
|
logger->Write(skyline::Logger::Info, "Launching ROM {}", romPath);
|
2019-09-24 22:54:27 +02:00
|
|
|
os.Execute(romPath);
|
2019-09-25 11:32:17 +02:00
|
|
|
logger->Write(skyline::Logger::Info, "Emulation has ended");
|
2019-09-24 22:54:27 +02:00
|
|
|
} catch (std::exception &e) {
|
2019-09-25 11:32:17 +02:00
|
|
|
logger->Write(skyline::Logger::Error, e.what());
|
2019-09-24 22:54:27 +02:00
|
|
|
} catch (...) {
|
2019-09-25 11:32:17 +02:00
|
|
|
logger->Write(skyline::Logger::Error, "An unknown exception has occurred");
|
2019-09-24 22:54:27 +02:00
|
|
|
}
|
2019-09-25 11:32:17 +02:00
|
|
|
auto end = std::chrono::steady_clock::now();
|
|
|
|
logger->Write(skyline::Logger::Info, "Done in: {} ms", (std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()));
|
2019-09-24 22:54:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_MainActivity_loadFile(JNIEnv *env, jobject instance, jstring romPathJni, jstring prefPathJni, jstring logPathJni) {
|
|
|
|
const char *romPath = env->GetStringUTFChars(romPathJni, nullptr);
|
|
|
|
const char *prefPath = env->GetStringUTFChars(prefPathJni, nullptr);
|
|
|
|
const char *logPath = env->GetStringUTFChars(logPathJni, nullptr);
|
|
|
|
|
|
|
|
if (EmuThread) {
|
|
|
|
Halt = true; // This'll cause execution to stop after the next breakpoint
|
|
|
|
EmuThread->join();
|
|
|
|
Halt = false; // Or the current instance will halt immediately
|
|
|
|
}
|
|
|
|
|
|
|
|
// Running on UI thread is not a good idea as the UI will remain unresponsive
|
|
|
|
EmuThread = new std::thread(ThreadMain, std::string(romPath, strlen(romPath)), std::string(prefPath, strlen(prefPath)), std::string(logPath, strlen(logPath)));
|
|
|
|
|
|
|
|
env->ReleaseStringUTFChars(romPathJni, romPath);
|
|
|
|
env->ReleaseStringUTFChars(prefPathJni, prefPath);
|
|
|
|
env->ReleaseStringUTFChars(logPathJni, logPath);
|
|
|
|
}
|