diff --git a/app/src/main/java/org/ab/x48/HPView.java b/app/src/main/java/org/ab/x48/HPView.java index 8c9da39..62caa67 100644 --- a/app/src/main/java/org/ab/x48/HPView.java +++ b/app/src/main/java/org/ab/x48/HPView.java @@ -112,7 +112,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna mSurfaceHolder = getHolder(); mSurfaceHolder.addCallback(this); mainScreen = Bitmap.createBitmap(262, 14+128, Bitmap.Config.RGB_565); - queuedCodes = new ArrayList(); + queuedCodes = new Vector(); ann = new boolean [6]; buf = new short [(14+128)*262]; audiobuf = new short [44100]; // 1s worth @@ -1028,37 +1028,28 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna } public void key(int code, boolean down, int pointerID) { - synchronized(this) { - if (code < MAX_TOUCHES) { - if (down) { - Integer cI = code + 1; - queuedCodes.add(cI); - touches[code] = pointerID; - performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, - HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); - } else { - Integer cI = code + 100; - queuedCodes.add(cI); - touches[code] = 0; - } - x48.flipScreen(); - unpauseEvent(); + if (code < MAX_TOUCHES) { + if (down) { + Integer cI = code + 1; + queuedCodes.add(cI); + touches[code] = pointerID; + performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, + HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } else { + Integer cI = code + 100; + queuedCodes.add(cI); + touches[code] = 0; } + x48.flipScreen(); } } - public void unpauseEvent() { - x48.openConditionVariable(); - } - public int waitEvent() { - synchronized(this) { - if (queuedCodes.size() == 0) { - return 0; - } else { - int c = queuedCodes.remove(0); - return c; - } + if (queuedCodes.size() == 0) { + return 0; + } else { + int c = queuedCodes.remove(0); + return c; } } diff --git a/app/src/main/java/org/ab/x48/X48.java b/app/src/main/java/org/ab/x48/X48.java index 905cf0e..1783bc8 100644 --- a/app/src/main/java/org/ab/x48/X48.java +++ b/app/src/main/java/org/ab/x48/X48.java @@ -3,6 +3,8 @@ package org.ab.x48; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; import android.app.Activity; @@ -35,6 +37,7 @@ public class X48 extends Activity { static final private int ROM_ID = 123; private static EmulatorThread thread; + private static Timer SIGALRM; private static boolean errorLib; @@ -86,7 +89,9 @@ public class X48 extends Activity { mainView = (HPView) findViewById(R.id.hpview); checkPrefs(); - + + SIGALRM = new Timer(); + thread = new EmulatorThread(this); thread.start(); mainView.resume(); @@ -163,8 +168,7 @@ public class X48 extends Activity { public native void flipScreen(); public native int loadProg(String filename); public native void setBlankColor(short s); - public native void openConditionVariable(); - public native void blockConditionVariable(); + public native void SIGALRM(); public void emulatorReady() { mainView.emulatorReady(); @@ -181,6 +185,12 @@ public class X48 extends Activity { protected void onResume() { super.onResume(); Log.i("x48", "resume"); + SIGALRM.schedule(new TimerTask() { + @Override + public void run() { + SIGALRM(); + } + }, 0, 20); if (mainView != null) mainView.resume(); Log.i("x48", "resumed"); @@ -448,6 +458,7 @@ private void managePort(int number, String value) { protected void onPause() { super.onPause(); Log.i("x48", "pause"); + SIGALRM.cancel(); if (mainView != null) mainView.pause(); Log.i("x48", "paused"); @@ -460,8 +471,6 @@ private void managePort(int number, String value) { if (saveonExit) saveState(); stopHPEmulator(); - if (mainView != null) - mainView.unpauseEvent(); if (need_to_quit) System.exit(0); } diff --git a/app/src/main/jni/actions.c b/app/src/main/jni/actions.c index d0d8a7c..afdf17b 100644 --- a/app/src/main/jni/actions.c +++ b/app/src/main/jni/actions.c @@ -626,38 +626,20 @@ do_shutdown() saturn.PC, saturn.t2_ctrl, saturn.timer2); #endif - /* if (in_debugger) + if (in_debugger) wake = 1; - else*/ + else wake = 0; alarms = 0; - - // android_refresh_screen(); - - /* do { -LOGI("---"); - pause(); -LOGI("---"); - if (got_alarm) { - got_alarm = 0; - -#ifdef HAVE_XSHM - if (disp.display_update) refresh_display(); -#endif*/ - -//android_refresh_screen(); -// usleep(50000); do { - /* do { - - (*android_env)->CallVoidMethod(android_env, android_callback, pauseEvent); + blockConditionVariable(); if (got_alarm) { - got_alarm = 0;*/ + got_alarm = 0; ticks = get_t1_t2(); if (saturn.t2_ctrl & 0x01) { @@ -667,16 +649,6 @@ LOGI("---"); set_t1 = ticks.t1_ticks; interrupt_called = 0; - - - // android_refresh_screen(); - // usleep(50000); - //LOGI("enter pauseEvent"); - //(*android_env)->CallVoidMethod(android_env, android_callback, pauseEvent); - // LOGI("exit pauseEvent"); - - blockConditionVariable(); - if (GetEvent()) { if (interrupt_called) wake = 1; @@ -720,7 +692,12 @@ LOGI("---"); alarms++; - //} + } + + if (enter_debugger) + { + wake = 1; + } } while (wake == 0 && exit_state); diff --git a/app/src/main/jni/emulate.c b/app/src/main/jni/emulate.c index 98a741f..7f3fd5f 100644 --- a/app/src/main/jni/emulate.c +++ b/app/src/main/jni/emulate.c @@ -2415,18 +2415,15 @@ schedule() #endif schedule_event--; -/* + if (got_alarm) { got_alarm = 0; #ifdef HAVE_XSHM if (disp.display_update) refresh_display(); #endif GetEvent(); - //usleep(500); } -*/ - GetEvent(); } int diff --git a/app/src/main/jni/main.c b/app/src/main/jni/main.c index f72e546..fdb1c90 100644 --- a/app/src/main/jni/main.c +++ b/app/src/main/jni/main.c @@ -427,21 +427,14 @@ Java_org_ab_x48_X48_loadProg( JNIEnv* env, /** * This function opens the condition variable which releases waiting threads. */ -void Java_org_ab_x48_X48_openConditionVariable(JNIEnv *env,jobject o) +void Java_org_ab_x48_X48_SIGALRM(JNIEnv *env,jobject o) { + got_alarm = 1; pthread_mutex_lock(&uiConditionMutex); pthread_cond_signal(&uiConditionVariable); pthread_mutex_unlock(&uiConditionMutex); } -/** - * This function blocks on the condition variable associated with the - */ -void Java_org_ab_x48_X48_blockConditionVariable(JNIEnv *env,jobject o) -{ - blockConditionVariable(); -} - void blockConditionVariable() { pthread_mutex_lock(&uiConditionMutex); diff --git a/app/src/main/jni/x48.c b/app/src/main/jni/x48.c index 31ee379..71c21fc 100644 --- a/app/src/main/jni/x48.c +++ b/app/src/main/jni/x48.c @@ -626,15 +626,15 @@ GetEvent() /*wake = (*android_env)->CallIntMethod(android_env, android_callback, waitEvent); return wake; */ - + int code = (*android_env)->CallIntMethod(android_env, android_callback, waitEvent); //LOGI("code: %d", code); //FIX for Zenfone 2 - struct timespec req, rem; + /*struct timespec req, rem; req.tv_sec = 0; req.tv_nsec = 100L; - nanosleep(&req , &rem); + nanosleep(&req , &rem);*/ if (code < 0) {