2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2020-03-26 15:33:19 +01:00
|
|
|
#include <csignal>
|
|
|
|
#include <unistd.h>
|
2019-09-24 22:54:27 +02:00
|
|
|
#include "skyline/common.h"
|
|
|
|
#include "skyline/os.h"
|
2019-12-05 16:35:34 +01:00
|
|
|
#include "skyline/jvm.h"
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2019-12-05 16:35:34 +01:00
|
|
|
bool Halt;
|
2019-12-26 19:10:29 +01:00
|
|
|
jobject Surface;
|
2019-12-05 16:35:34 +01:00
|
|
|
uint FaultCount;
|
2020-03-24 21:20:28 +01:00
|
|
|
skyline::GroupMutex JniMtx;
|
2020-04-18 02:16:09 +02:00
|
|
|
skyline::u16 fps;
|
|
|
|
skyline::u32 frametime;
|
2019-12-02 18:40:53 +01:00
|
|
|
|
|
|
|
void signalHandler(int signal) {
|
|
|
|
syslog(LOG_ERR, "Halting program due to signal: %s", strsignal(signal));
|
|
|
|
if (FaultCount > 2)
|
|
|
|
exit(SIGKILL);
|
|
|
|
else
|
|
|
|
Halt = true;
|
|
|
|
FaultCount++;
|
|
|
|
}
|
|
|
|
|
2020-04-12 22:29:19 +02:00
|
|
|
extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(JNIEnv *env, jobject instance, jstring romUriJstring, jint romType, jint romFd, jint preferenceFd, jint logFd) {
|
2019-12-05 16:35:34 +01:00
|
|
|
Halt = false;
|
|
|
|
FaultCount = 0;
|
|
|
|
|
2019-12-02 18:40:53 +01:00
|
|
|
std::signal(SIGTERM, signalHandler);
|
|
|
|
std::signal(SIGSEGV, signalHandler);
|
|
|
|
std::signal(SIGINT, signalHandler);
|
|
|
|
std::signal(SIGILL, signalHandler);
|
|
|
|
std::signal(SIGABRT, signalHandler);
|
|
|
|
std::signal(SIGFPE, signalHandler);
|
2019-09-24 22:54:27 +02:00
|
|
|
|
2020-03-25 18:59:37 +01:00
|
|
|
setpriority(PRIO_PROCESS, static_cast<id_t>(getpid()), skyline::constant::AndroidPriority.second);
|
2019-12-02 18:40:53 +01:00
|
|
|
|
|
|
|
auto jvmManager = std::make_shared<skyline::JvmManager>(env, instance);
|
|
|
|
auto settings = std::make_shared<skyline::Settings>(preferenceFd);
|
|
|
|
auto logger = std::make_shared<skyline::Logger>(logFd, static_cast<skyline::Logger::LogLevel>(std::stoi(settings->GetString("log_level"))));
|
2019-09-27 18:09:48 +02:00
|
|
|
//settings->List(logger); // (Uncomment when you want to print out all settings strings)
|
2019-12-02 18:40:53 +01:00
|
|
|
|
2019-09-25 11:32:17 +02:00
|
|
|
auto start = std::chrono::steady_clock::now();
|
2019-12-02 18:40:53 +01:00
|
|
|
|
2019-09-24 22:54:27 +02:00
|
|
|
try {
|
2019-12-02 18:40:53 +01:00
|
|
|
skyline::kernel::OS os(jvmManager, logger, settings);
|
2020-04-03 13:47:32 +02:00
|
|
|
const char *romUri = env->GetStringUTFChars(romUriJstring, nullptr);
|
|
|
|
logger->Info("Launching ROM {}", romUri);
|
|
|
|
env->ReleaseStringUTFChars(romUriJstring, romUri);
|
2019-12-02 18:40:53 +01:00
|
|
|
os.Execute(romFd, static_cast<skyline::TitleFormat>(romType));
|
2019-09-24 22:54:27 +02:00
|
|
|
} catch (std::exception &e) {
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
logger->Error(e.what());
|
2019-09-24 22:54:27 +02:00
|
|
|
} catch (...) {
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
logger->Error("An unknown exception has occurred");
|
2019-09-24 22:54:27 +02:00
|
|
|
}
|
2020-02-11 07:34:22 +01:00
|
|
|
logger->Info("Emulation has ended");
|
2019-12-02 18:40:53 +01:00
|
|
|
|
2019-09-25 11:32:17 +02:00
|
|
|
auto end = std::chrono::steady_clock::now();
|
Framebuffer and NativeActivity
What was added:
* Framebuffer
* NativeActivity
* NV Services
* IOCTL Handler
* NV Devices:
* * /dev/nvmap - 0xC0080101, 0xC0080103, 0xC0200104, 0xC0180105, 0xC00C0109, 0xC008010E
* * /dev/nvhost-as-gpu
* * /dev/nvhost-channel - 0x40044801, 0xC0104809, 0xC010480B, 0xC018480C, 0x4004480D, 0xC020481A, 0x40084714
* * /dev/nvhost-ctrl
* * /dev/nvhost-ctrl-gpu - 0x80044701, 0x80284702, 0xC0184706, 0xC0B04705, 0x80084714
* SVCs:
* * SetMemoryAttribute
* * CreateTransferMemory
* * ResetSignal
* * GetSystemTick
* Addition of Compact Logger
What was fixed:
* SVCs:
* * SetHeapSize
* * SetMemoryAttribute
* * QueryMemory
* A release build would not set CMAKE_BUILD_TYPE to "RELEASE"
* The logger code was simplified
2019-11-13 21:09:31 +01:00
|
|
|
logger->Info("Done in: {} ms", (std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()));
|
2019-09-24 22:54:27 +02:00
|
|
|
}
|
2019-12-05 16:35:34 +01:00
|
|
|
|
2020-04-03 13:47:32 +02:00
|
|
|
extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_setHalt(JNIEnv *env, jobject instance, jboolean halt) {
|
2020-03-24 21:20:28 +01:00
|
|
|
JniMtx.lock(skyline::GroupMutex::Group::Group2);
|
2019-12-26 19:10:29 +01:00
|
|
|
Halt = halt;
|
2020-03-24 21:20:28 +01:00
|
|
|
JniMtx.unlock();
|
2019-12-05 16:35:34 +01:00
|
|
|
}
|
|
|
|
|
2020-04-03 13:47:32 +02:00
|
|
|
extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_setSurface(JNIEnv *env, jobject instance, jobject surface) {
|
2020-03-24 21:20:28 +01:00
|
|
|
JniMtx.lock(skyline::GroupMutex::Group::Group2);
|
2020-01-11 05:52:25 +01:00
|
|
|
if (!env->IsSameObject(Surface, nullptr))
|
2019-12-26 19:10:29 +01:00
|
|
|
env->DeleteGlobalRef(Surface);
|
2020-01-11 05:52:25 +01:00
|
|
|
if (!env->IsSameObject(surface, nullptr))
|
2019-12-26 19:10:29 +01:00
|
|
|
Surface = env->NewGlobalRef(surface);
|
|
|
|
else
|
|
|
|
Surface = surface;
|
2020-03-24 21:20:28 +01:00
|
|
|
JniMtx.unlock();
|
2019-12-05 16:35:34 +01:00
|
|
|
}
|
2020-04-18 02:16:09 +02:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT jint Java_emu_skyline_EmulationActivity_getFps(JNIEnv *env, jobject thiz) {
|
|
|
|
return fps;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT jfloat Java_emu_skyline_EmulationActivity_getFrametime(JNIEnv *env, jobject thiz) {
|
|
|
|
return static_cast<float>(frametime) / 100;
|
|
|
|
}
|