From 652790e165f841c4e970bcfcda5085f8c7a4fd67 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Sat, 1 Feb 2020 03:45:30 +0200 Subject: [PATCH 1/3] Android: Show msgboxf as modal dialog No button or icon handling implemented --- libswirl/android/Android.cpp | 25 ++++++++- libswirl/gui/gui.cpp | 5 +- .../reicast/emulator/NativeGLActivity.java | 54 +++++++++++++++++-- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/libswirl/android/Android.cpp b/libswirl/android/Android.cpp index 992f10c9ce..b5a0f148bc 100644 --- a/libswirl/android/Android.cpp +++ b/libswirl/android/Android.cpp @@ -643,6 +643,7 @@ static jobject g_activity; static jmethodID VJoyStartEditingMID; static jmethodID VJoyStopEditingMID; static jmethodID VJoyResetEditingMID; +static jmethodID MsgboxMID; JNIEXPORT void JNICALL Java_com_reicast_emulator_BaseGLActivity_register(JNIEnv *env, jobject obj, jobject activity) { @@ -651,11 +652,13 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_BaseGLActivity_register(JNIEnv env->DeleteGlobalRef(g_activity); g_activity = NULL; } + if (activity != NULL) { g_activity = env->NewGlobalRef(activity); VJoyStartEditingMID = env->GetMethodID(env->GetObjectClass(activity), "VJoyStartEditing", "()V"); VJoyStopEditingMID = env->GetMethodID(env->GetObjectClass(activity), "VJoyStopEditing", "(Z)V"); VJoyResetEditingMID = env->GetMethodID(env->GetObjectClass(activity), "VJoyResetEditing", "()V"); + MsgboxMID = env->GetMethodID(env->GetObjectClass(activity), "Msgbox", "(Ljava/lang/String;I)I"); } } @@ -694,4 +697,24 @@ bool os_gl_swap() void os_gl_term() { return egl_Term(); -} \ No newline at end of file +} + +#if defined(_ANDROID) +int msgboxf(const wchar* text, unsigned int type, ...) { + va_list args; + + wchar temp[2048]; + va_start(args, type); + vsnprintf(temp, sizeof(temp), text, args); + va_end(args); + printf("msgbox(%d) %s\n", type, temp); + + auto jstr = jvm_attacher.getEnv()->NewStringUTF(temp); + + auto rv = jvm_attacher.getEnv()->CallIntMethod(g_activity, MsgboxMID, jstr, type); + + jvm_attacher.getEnv()->DeleteLocalRef(jstr); + + return rv; +} +#endif \ No newline at end of file diff --git a/libswirl/gui/gui.cpp b/libswirl/gui/gui.cpp index 9f24e29fc4..cdf1b9be49 100644 --- a/libswirl/gui/gui.cpp +++ b/libswirl/gui/gui.cpp @@ -1044,7 +1044,7 @@ GUI* GUI::Create() { return new ReicastUI_impl(); } - +#if !defined(_ANDROID) int msgboxf(const wchar* text, unsigned int type, ...) { va_list args; @@ -1057,4 +1057,5 @@ int msgboxf(const wchar* text, unsigned int type, ...) { g_GUI->DisplayNotification(temp, 2000); return 1; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java b/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java index c8b488dc23..403eee923e 100644 --- a/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java +++ b/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java @@ -1,5 +1,8 @@ package com.reicast.emulator; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -46,13 +49,13 @@ public boolean isSurfaceReady() { } // Called from native code - private void VJoyStartEditing() { + public void VJoyStartEditing() { vjoy_d_cached = VJoy.readCustomVjoyValues(getApplicationContext()); JNIdc.show_osd(); ((NativeGLView)mView).setEditVjoyMode(true); } // Called from native code - private void VJoyResetEditing() { + public void VJoyResetEditing() { VJoy.resetCustomVjoyValues(getApplicationContext()); ((NativeGLView)mView).readCustomVjoyValues(); ((NativeGLView)mView).resetEditMode(); @@ -68,9 +71,54 @@ public void run() { }); } // Called from native code - private void VJoyStopEditing(boolean canceled) { + public void VJoyStopEditing(boolean canceled) { if (canceled) ((NativeGLView)mView).restoreCustomVjoyValues(vjoy_d_cached); ((NativeGLView)mView).setEditVjoyMode(false); } + + class ReadyState { public boolean value = false; } + + public int Msgbox(final String text, final int type) { + + final ReadyState ready = new ReadyState(); + + final Activity activity = this; + + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + AlertDialog ab; + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + + String msg = text; + + if ((type & 0x10) != 0) /* MBX_ICONERROR */ + msg += "\nPlease send a screenshot of this to the Reicast Team"; + + builder.setMessage(msg).setPositiveButton("Okay", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + synchronized (ready) { + ready.value = true; + ready.notify(); + } + } + }); + builder.create().show(); + + } + }); + + try + { + synchronized (ready) { + while (!ready.value) + ready.wait(); + } + } catch(InterruptedException is) { + + } + + return 1; + } } From b915f5468058defccd488832d6f557b09d80967e Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Sat, 1 Feb 2020 04:18:28 +0200 Subject: [PATCH 2/3] generic_fault_handler: Improve logging --- libswirl/linux/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libswirl/linux/common.cpp b/libswirl/linux/common.cpp index 89c19c1a92..66a524b698 100644 --- a/libswirl/linux/common.cpp +++ b/libswirl/linux/common.cpp @@ -91,7 +91,7 @@ extern "C" u8* generic_fault_handler () } else { - fault_printf("generic_fault_handler: not in handled SIGSEGV pc: %lx addr:%p\n", ctx.pc, (void*)trap_si_addr); + fault_printf("generic_fault_handler: not in handled SIGSEGV pc: %lx addr:%p here %p\n", ctx.pc, (void*)trap_si_addr, (void*)generic_fault_handler); trap_handled = false; } From 3308aec787a11a8570b92e16139136fb2cdd8215 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Sat, 1 Feb 2020 04:26:19 +0200 Subject: [PATCH 3/3] Msgbox: Use resource strings --- .../main/java/com/reicast/emulator/NativeGLActivity.java | 9 ++++----- .../reicast/src/main/res/values/strings.xml | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 reicast/android-studio/reicast/src/main/res/values/strings.xml diff --git a/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java b/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java index 403eee923e..0fd7900be6 100644 --- a/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java +++ b/reicast/android-studio/reicast/src/main/java/com/reicast/emulator/NativeGLActivity.java @@ -88,15 +88,15 @@ public int Msgbox(final String text, final int type) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { - AlertDialog ab; AlertDialog.Builder builder = new AlertDialog.Builder(activity); String msg = text; - if ((type & 0x10) != 0) /* MBX_ICONERROR */ - msg += "\nPlease send a screenshot of this to the Reicast Team"; + if ((type & 0x10) != 0) { /* MBX_ICONERROR */ + msg += "\n" + R.string.msgbox_please_report; + } - builder.setMessage(msg).setPositiveButton("Okay", new DialogInterface.OnClickListener() { + builder.setMessage(msg).setPositiveButton(R.string.msgbox_okay, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { synchronized (ready) { ready.value = true; @@ -105,7 +105,6 @@ public void onClick(DialogInterface dialog, int id) { } }); builder.create().show(); - } }); diff --git a/reicast/android-studio/reicast/src/main/res/values/strings.xml b/reicast/android-studio/reicast/src/main/res/values/strings.xml new file mode 100644 index 0000000000..4dc7786fe4 --- /dev/null +++ b/reicast/android-studio/reicast/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + Please send a screenshot of this to the Reicast Team + Okay + \ No newline at end of file