Skip to content

Commit

Permalink
Project: Adds the latest fixes and updates the app to version 0.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
shadergz committed Jan 23, 2024
1 parent d2a31b2 commit 61f494e
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Cosmic Project

### Project Progress:
- Progression: ```13%```
- Current top priority: Add more instructions to the respective EE, IOP, and VUs interpreters
- Progression: ```14%```
- Current top priority: Add more instructions to the respective `EE`, `IOP`, and `VUs` interpreters
- Target for the first demo release: 2025

### Special thanks
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
minSdk = 31

targetSdk = 34
versionCode = 17
versionName = "0.0.17"
versionCode = 18
versionName = "0.0.18"
ndk {
abiFilters.clear()
abiFilters.add("arm64-v8a")
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-feature android:glEsVersion="0x00030000"/>

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

Expand Down
9 changes: 4 additions & 5 deletions app/src/main/cpp/cosmic/common/except.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ namespace cosmic {
jclass exceptionActivity{};
CosmicException::CosmicException(const std::string& format) :
std::runtime_error(format) {
user->error("{}", format);
user->error("An exception of type CosmicException was raised due to: {}", format);

msg = cosmicEnv->NewStringUTF(format.c_str());
title = lookupByActivity();
alertUser();
}
jstring CosmicException::lookupByActivity() {
const jclass emulation{cosmicEnv->FindClass("emu/cosmic/EmulationActivity$Companion")};
const jclass emulation{cosmicEnv->FindClass("emu/cosmic/EmulationActivity")};
if (cosmicEnv->IsSameObject(exceptionActivity, emulation)) {
return cosmicEnv->NewStringUTF("Emulation Scene");
}
return cosmicEnv->NewStringUTF("General Exception");
}

void CosmicException::alertUser() {
alert = cosmicEnv->GetMethodID(exceptionActivity,
alert = cosmicEnv->GetStaticMethodID(exceptionActivity,
"displayAlert", "(Ljava/lang/String;Ljava/lang/String;)V");

if (alert) {
cosmicEnv->CallStaticVoidMethod(exceptionActivity, alert, title, msg);
}
Expand All @@ -33,7 +32,7 @@ namespace cosmic {
void CosmicException::setExceptionClass(jobject super) {
const jclass emuClass{cosmicEnv->FindClass("emu/cosmic/EmulationActivity")};
if (cosmicEnv->IsInstanceOf(super, emuClass)) {
exceptionActivity = cosmicEnv->FindClass("emu/cosmic/EmulationActivity$Companion");
exceptionActivity = cosmicEnv->FindClass("emu/cosmic/EmulationActivity");
}
}
}
10 changes: 5 additions & 5 deletions app/src/main/cpp/cosmic/common/except.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ namespace cosmic {
}

DECLARE_EXCEPTION_TYPE(Cop0Fail, "Cop0");
DECLARE_EXCEPTION_TYPE(TimerFail, "Timer");
DECLARE_EXCEPTION_TYPE(MioFail, "Mio");
DECLARE_EXCEPTION_TYPE(IoFail, "Io");
DECLARE_EXCEPTION_TYPE(FsFail, "Fs");
DECLARE_EXCEPTION_TYPE(GpuFail, "Gpu");
DECLARE_EXCEPTION_TYPE(TimerFail, "EE.Timer");
DECLARE_EXCEPTION_TYPE(MioFail, "MIO");
DECLARE_EXCEPTION_TYPE(IoFail, "IO");
DECLARE_EXCEPTION_TYPE(FsFail, "FS");
DECLARE_EXCEPTION_TYPE(GpuFail, "GPU");
DECLARE_EXCEPTION_TYPE(AppFail, "Cosmic");
#undef DECLARE_EXCEPTION_TYPE

Expand Down
14 changes: 7 additions & 7 deletions app/src/main/cpp/cosmic/vm/watch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ namespace cosmic::vm {

void WatchStatus::markStepsDone() {
auto currentTime{std::chrono::high_resolution_clock::now()};
auto elapsedMicro{
std::chrono::duration_cast<std::chrono::microseconds>
auto elapsedMilli{
std::chrono::duration_cast<std::chrono::milliseconds>
(currentTime - starts)};
std::array<bool, 5> milestone{
elapsedMicro.count() >= std::chrono::microseconds(1).count(),
isFrameCompleted
elapsedMilli.count() >= std::chrono::milliseconds(1).count(),
isFrameCompleted
};
milestone[2] = milestone[0] || milestone[1];
executionCount++;

std::chrono::microseconds final;
std::chrono::milliseconds final;
fmt::memory_buffer elapsed{};
if (milestone[1]) {
final = std::chrono::duration_cast<std::chrono::microseconds>(finish - starts);
final = std::chrono::duration_cast<std::chrono::milliseconds>(finish - starts);
fmt::format_to(std::back_inserter(elapsed),
"Complete frame within {}µs...\n", final.count());
"Complete frame within {}ms...\n", final.count());
isFrameCompleted = false;
}
if (milestone[2]) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/cpp/emu_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Java_emu_cosmic_EmulationActivity_swtSurfaceContext(JNIEnv* env, jobject thiz, j
std::atomic<cosmic::u8> is{false};
extern "C"
JNIEXPORT void JNICALL
Java_emu_cosmic_EmulationActivity_runEmulatorVm(JNIEnv* env, [[maybe_unused]] jobject thiz) {
Java_emu_cosmic_EmulationActivity_startEmulator(JNIEnv* env, [[maybe_unused]] jobject thiz) {
cosmic::CosmicException::setExceptionClass(thiz);

cosmic::app->vm->resetVm();
Expand All @@ -24,6 +24,7 @@ Java_emu_cosmic_EmulationActivity_runEmulatorVm(JNIEnv* env, [[maybe_unused]] jo
}
extern "C"
JNIEXPORT void JNICALL
Java_emu_cosmic_EmulationActivity_stopEmulatorVm(JNIEnv* env, jobject thiz) {
is = 0;
Java_emu_cosmic_EmulationActivity_stopEmulator(JNIEnv* env, jobject thiz) {
if (is != 0)
is = 0;
}
21 changes: 21 additions & 0 deletions app/src/main/cpp/jvm_comm.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
#include <jni.h>
#include <signal.h>

#include <cosmic/common/global.h>
#include <cosmic/java/device_handler.h>
#include <cosmic/java/jclasses.h>
static std::array<struct sigaction, 3> signals;
void catchSystemSignals(cosmic::i32 sig, siginfo_t* ino, void* context) {
cosmic::u8 sid{};
if (sig == SIGABRT || sig == SIGTRAP) {
if (sig == SIGTRAP)
sid = 1;
}
if (sig == SIGSEGV) {
sid = 2;
}
sigaction(sig, &signals[sid], nullptr);
}
static struct sigaction trap {
.sa_flags = SA_SIGINFO,
.sa_sigaction = catchSystemSignals,
};

// JNI_OnLoad function is called when the JVM has loaded our native code in the heap, this process
// is started by Java Runtime using System.loadLibrary("cosmic")
Expand All @@ -11,6 +28,10 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
cosmic::user = std::make_shared<cosmic::GlobalLogger>();
cosmic::device = std::make_unique<cosmic::java::JvmManager>(vm);

sigaction(SIGABRT, &trap, &signals[0]);
sigaction(SIGTRAP, &trap, &signals[1]);
sigaction(SIGSEGV, &trap, &signals[2]);

cosmic::app = std::make_shared<cosmic::CoreApplication>();
return JNI_VERSION_1_6;
}
Expand Down
38 changes: 27 additions & 11 deletions app/src/main/java/emu/cosmic/EmulationActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import android.view.SurfaceHolder
import android.view.WindowInsets
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import emu.cosmic.databinding.EmulationActivityBinding
import emu.cosmic.models.EmulationModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.withContext

class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback {
private var emuSurface: Surface? = null
Expand All @@ -23,7 +27,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback {

private val emuThread = Thread {
status.checkRunning(true)
runEmulatorVm()
startEmulator()
goBackToMain()
}
init {
Expand All @@ -35,14 +39,26 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback {

@Suppress("unused") @JvmStatic
fun displayAlert(title: String, msg: String) {
AlertDialog.Builder(activity.applicationContext)
.setTitle(title)
.setMessage(msg)
.setPositiveButton(activity.getString(R.string.positive)) { _, _ ->
activity.goBackToMain()
val quit = Semaphore(1, 1)
activity.stopEmulator()

activity.runOnUiThread {
MaterialAlertDialogBuilder(activity)
.setTitle(title)
.setMessage(msg)
.setCancelable(false)
.setPositiveButton(activity.getString(R.string.positive)) { _, _ ->
quit.release()
}.show()
}
runBlocking {
withContext(Dispatchers.Default) {
quit.acquire()
activity.fps = 0
activity.goBackToMain()
}
}

activity.fps = 0
}
}

Expand Down Expand Up @@ -73,7 +89,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback {
private fun goBackToMain() {
if (!status.isRunning())
return
stopEmulatorVm()
stopEmulator()
runOnUiThread {
val main = Intent(applicationContext, MainActivity::class.java).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(main)
Expand All @@ -83,8 +99,8 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback {
emuThread.join()
}
private external fun swtSurfaceContext(surface: Surface? = null)
private external fun runEmulatorVm()
private external fun stopEmulatorVm()
private external fun startEmulator()
private external fun stopEmulator()
override fun surfaceCreated(holder: SurfaceHolder) {
swtSurfaceContext(holder.surface)
emuSurface = holder.surface
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/layout/about_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="8dp"

android:text="@string/about_details" />

android:text="@string/about_details"
android:textAlignment="center"
android:justificationMode="inter_word"
/>
<TextView
android:id="@+id/aboutCommitVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="8dp"

android:text="@string/about_commit"
android:paddingBottom="10dp" />
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<resources>
<string name="app_name">Cosmic</string>
<string name="positive">Ok</string>
<string name="positive">Continue</string>

<string name="about_details">God be praised</string>
<string name="about_details">Thank you to those who installed and tried to use the alpha\
version of Cosmic. We do not have anything here just yet! Follow the official repository\
for more details and project updates!</string>
<string name="about_commit">Commit version</string>

<string name="toolbar_about">About</string>
Expand Down

0 comments on commit 61f494e

Please sign in to comment.