2020-04-20 00:04:05 +03:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 22:36:02 +03:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2020-03-26 17:33:19 +03:00
|
|
|
#include <csignal>
|
|
|
|
#include <unistd.h>
|
2020-09-25 17:35:10 +03:00
|
|
|
#include <sys/resource.h>
|
2020-09-29 15:46:17 +03:00
|
|
|
#include <android/log.h>
|
2020-06-19 23:18:33 +03:00
|
|
|
#include "skyline/loader/loader.h"
|
2019-09-24 23:54:27 +03:00
|
|
|
#include "skyline/common.h"
|
|
|
|
#include "skyline/os.h"
|
2019-12-05 18:35:34 +03:00
|
|
|
#include "skyline/jvm.h"
|
2020-04-26 02:34:35 +03:00
|
|
|
#include "skyline/input.h"
|
2019-09-24 23:54:27 +03:00
|
|
|
|
2019-12-05 18:35:34 +03:00
|
|
|
bool Halt;
|
2019-12-26 21:10:29 +03:00
|
|
|
jobject Surface;
|
2020-03-24 23:20:28 +03:00
|
|
|
skyline::GroupMutex JniMtx;
|
2020-04-18 03:16:09 +03:00
|
|
|
skyline::u16 fps;
|
|
|
|
skyline::u32 frametime;
|
2020-08-20 21:31:32 +03:00
|
|
|
std::weak_ptr<skyline::input::Input> inputWeak;
|
2019-12-02 20:40:53 +03:00
|
|
|
|
|
|
|
void signalHandler(int signal) {
|
2020-09-29 15:46:17 +03:00
|
|
|
__android_log_print(ANDROID_LOG_FATAL, "emu-cpp", "Halting program due to signal: %s", strsignal(signal));
|
|
|
|
exit(signal);
|
2019-12-02 20:40:53 +03:00
|
|
|
}
|
|
|
|
|
2020-08-08 22:38:51 +03:00
|
|
|
extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(JNIEnv *env, jobject instance, jstring romUriJstring, jint romType, jint romFd, jint preferenceFd, jstring appFilesPathJstring) {
|
2019-12-05 18:35:34 +03:00
|
|
|
Halt = false;
|
2020-04-23 21:37:52 +03:00
|
|
|
fps = 0;
|
|
|
|
frametime = 0;
|
2019-12-05 18:35:34 +03:00
|
|
|
|
2020-10-07 18:41:13 +03:00
|
|
|
/*
|
2019-12-02 20:40:53 +03: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);
|
2020-10-07 18:41:13 +03:00
|
|
|
*/
|
2019-09-24 23:54:27 +03:00
|
|
|
|
2020-04-22 20:02:27 +03:00
|
|
|
setpriority(PRIO_PROCESS, static_cast<id_t>(gettid()), -8); // Set the priority of this process to the highest value
|
2019-12-02 20:40:53 +03:00
|
|
|
|
2020-09-26 08:17:57 +03:00
|
|
|
auto jvmManager{std::make_shared<skyline::JvmManager>(env, instance)};
|
|
|
|
auto settings{std::make_shared<skyline::Settings>(preferenceFd)};
|
2020-09-29 15:46:17 +03:00
|
|
|
close(preferenceFd);
|
2020-08-08 22:38:51 +03:00
|
|
|
|
2020-09-26 08:17:57 +03:00
|
|
|
auto appFilesPath{env->GetStringUTFChars(appFilesPathJstring, nullptr)};
|
|
|
|
auto logger{std::make_shared<skyline::Logger>(std::string(appFilesPath) + "skyline.log", static_cast<skyline::Logger::LogLevel>(std::stoi(settings->GetString("log_level"))))};
|
2019-09-27 19:09:48 +03:00
|
|
|
//settings->List(logger); // (Uncomment when you want to print out all settings strings)
|
2019-12-02 20:40:53 +03:00
|
|
|
|
2020-09-26 08:17:57 +03:00
|
|
|
auto start{std::chrono::steady_clock::now()};
|
2019-12-02 20:40:53 +03:00
|
|
|
|
2019-09-24 23:54:27 +03:00
|
|
|
try {
|
2020-08-08 22:38:51 +03:00
|
|
|
skyline::kernel::OS os(jvmManager, logger, settings, std::string(appFilesPath));
|
2020-08-20 21:31:32 +03:00
|
|
|
inputWeak = os.state.input;
|
2020-08-21 14:14:27 +03:00
|
|
|
jvmManager->InitializeControllers();
|
2020-08-08 22:38:51 +03:00
|
|
|
env->ReleaseStringUTFChars(appFilesPathJstring, appFilesPath);
|
|
|
|
|
2020-09-26 08:17:57 +03:00
|
|
|
auto romUri{env->GetStringUTFChars(romUriJstring, nullptr)};
|
2020-04-03 14:47:32 +03:00
|
|
|
logger->Info("Launching ROM {}", romUri);
|
|
|
|
env->ReleaseStringUTFChars(romUriJstring, romUri);
|
2020-04-26 02:34:35 +03:00
|
|
|
|
2020-06-19 23:18:33 +03:00
|
|
|
os.Execute(romFd, static_cast<skyline::loader::RomFormat>(romType));
|
2019-09-24 23:54:27 +03: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 23:09:31 +03:00
|
|
|
logger->Error(e.what());
|
2019-09-24 23:54:27 +03: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 23:09:31 +03:00
|
|
|
logger->Error("An unknown exception has occurred");
|
2019-09-24 23:54:27 +03:00
|
|
|
}
|
2020-04-26 02:34:35 +03:00
|
|
|
|
2020-08-20 21:31:32 +03:00
|
|
|
inputWeak.reset();
|
|
|
|
|
2020-02-11 09:34:22 +03:00
|
|
|
logger->Info("Emulation has ended");
|
2019-12-02 20:40:53 +03:00
|
|
|
|
2020-09-26 08:17:57 +03: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 23:09:31 +03:00
|
|
|
logger->Info("Done in: {} ms", (std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()));
|
2020-09-29 15:46:17 +03:00
|
|
|
|
|
|
|
close(romFd);
|
2019-09-24 23:54:27 +03:00
|
|
|
}
|
2019-12-05 18:35:34 +03:00
|
|
|
|
2020-04-26 02:34:35 +03:00
|
|
|
extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_setHalt(JNIEnv *, jobject, jboolean halt) {
|
2020-03-24 23:20:28 +03:00
|
|
|
JniMtx.lock(skyline::GroupMutex::Group::Group2);
|
2019-12-26 21:10:29 +03:00
|
|
|
Halt = halt;
|
2020-03-24 23:20:28 +03:00
|
|
|
JniMtx.unlock();
|
2019-12-05 18:35:34 +03:00
|
|
|
}
|
|
|
|
|
2020-04-26 02:34:35 +03:00
|
|
|
extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_setSurface(JNIEnv *env, jobject, jobject surface) {
|
2020-03-24 23:20:28 +03:00
|
|
|
JniMtx.lock(skyline::GroupMutex::Group::Group2);
|
2020-01-11 07:52:25 +03:00
|
|
|
if (!env->IsSameObject(Surface, nullptr))
|
2019-12-26 21:10:29 +03:00
|
|
|
env->DeleteGlobalRef(Surface);
|
2020-01-11 07:52:25 +03:00
|
|
|
if (!env->IsSameObject(surface, nullptr))
|
2019-12-26 21:10:29 +03:00
|
|
|
Surface = env->NewGlobalRef(surface);
|
|
|
|
else
|
|
|
|
Surface = surface;
|
2020-03-24 23:20:28 +03:00
|
|
|
JniMtx.unlock();
|
2019-12-05 18:35:34 +03:00
|
|
|
}
|
2020-04-18 03:16:09 +03:00
|
|
|
|
2020-04-26 17:32:24 +03:00
|
|
|
extern "C" JNIEXPORT jint Java_emu_skyline_EmulationActivity_getFps(JNIEnv *, jobject) {
|
2020-04-18 03:16:09 +03:00
|
|
|
return fps;
|
|
|
|
}
|
|
|
|
|
2020-04-26 17:32:24 +03:00
|
|
|
extern "C" JNIEXPORT jfloat Java_emu_skyline_EmulationActivity_getFrametime(JNIEnv *, jobject) {
|
2020-04-18 03:16:09 +03:00
|
|
|
return static_cast<float>(frametime) / 100;
|
2020-08-08 22:38:51 +03:00
|
|
|
}
|
2020-04-26 02:34:35 +03:00
|
|
|
|
2020-08-15 16:51:23 +03:00
|
|
|
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setController(JNIEnv *, jobject, jint index, jint type, jint partnerIndex) {
|
2020-09-26 08:17:57 +03:00
|
|
|
auto input{inputWeak.lock()};
|
2020-08-20 21:31:32 +03:00
|
|
|
std::lock_guard guard(input->npad.mutex);
|
2020-08-15 16:51:23 +03:00
|
|
|
input->npad.controllers[index] = skyline::input::GuestController{static_cast<skyline::input::NpadControllerType>(type), static_cast<skyline::i8>(partnerIndex)};
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_updateControllers(JNIEnv *, jobject) {
|
2020-08-21 14:14:27 +03:00
|
|
|
inputWeak.lock()->npad.Update();
|
2020-08-15 16:51:23 +03:00
|
|
|
}
|
|
|
|
|
2020-08-21 14:14:27 +03:00
|
|
|
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setButtonState(JNIEnv *, jobject, jint index, jlong mask, jboolean pressed) {
|
2020-08-20 21:31:32 +03:00
|
|
|
try {
|
2020-09-26 08:17:57 +03:00
|
|
|
auto input{inputWeak.lock()};
|
|
|
|
auto device{input->npad.controllers[index].device};
|
2020-08-15 16:51:23 +03:00
|
|
|
if (device)
|
2020-08-21 14:14:27 +03:00
|
|
|
device->SetButtonState(skyline::input::NpadButton{.raw = static_cast<skyline::u64>(mask)}, pressed);
|
2020-09-05 02:06:07 +03:00
|
|
|
} catch (const std::bad_weak_ptr &) {
|
2020-08-20 21:31:32 +03:00
|
|
|
// We don't mind if we miss button updates while input hasn't been initialized
|
2020-04-26 17:32:24 +03:00
|
|
|
}
|
2020-04-26 02:34:35 +03:00
|
|
|
}
|
|
|
|
|
2020-08-15 16:51:23 +03:00
|
|
|
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setAxisValue(JNIEnv *, jobject, jint index, jint axis, jint value) {
|
2020-08-20 21:31:32 +03:00
|
|
|
try {
|
2020-09-26 08:17:57 +03:00
|
|
|
auto input{inputWeak.lock()};
|
|
|
|
auto device{input->npad.controllers[index].device};
|
2020-08-15 16:51:23 +03:00
|
|
|
if (device)
|
|
|
|
device->SetAxisValue(static_cast<skyline::input::NpadAxisId>(axis), value);
|
2020-09-05 02:06:07 +03:00
|
|
|
} catch (const std::bad_weak_ptr &) {
|
2020-08-20 21:31:32 +03:00
|
|
|
// We don't mind if we miss axis updates while input hasn't been initialized
|
2020-08-15 16:51:23 +03:00
|
|
|
}
|
2020-04-26 02:34:35 +03:00
|
|
|
}
|
2020-09-07 19:39:05 +03:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT void JNICALL Java_emu_skyline_EmulationActivity_setTouchState(JNIEnv *env, jobject, jintArray pointsJni) {
|
|
|
|
try {
|
|
|
|
using Point = skyline::input::TouchScreenPoint;
|
|
|
|
|
2020-09-26 08:17:57 +03:00
|
|
|
auto input{inputWeak.lock()};
|
2020-09-07 19:39:05 +03:00
|
|
|
jboolean isCopy{false};
|
|
|
|
|
2020-09-25 03:05:12 +03:00
|
|
|
skyline::span<Point> points(reinterpret_cast<Point *>(env->GetIntArrayElements(pointsJni, &isCopy)), env->GetArrayLength(pointsJni) / (sizeof(Point) / sizeof(jint)));
|
2020-09-07 19:39:05 +03:00
|
|
|
input->touch.SetState(points);
|
|
|
|
env->ReleaseIntArrayElements(pointsJni, reinterpret_cast<jint *>(points.data()), JNI_ABORT);
|
|
|
|
} catch (const std::bad_weak_ptr &) {
|
|
|
|
// We don't mind if we miss axis updates while input hasn't been initialized
|
|
|
|
}
|
|
|
|
}
|