More faithful to the original x48 source

This commit is contained in:
shagr4th 2016-12-18 16:53:18 +01:00
parent a798ff264d
commit 95965fc6e3
6 changed files with 48 additions and 81 deletions

View file

@ -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<Integer>();
queuedCodes = new Vector<Integer>();
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;
}
}

View file

@ -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;
@ -87,6 +90,8 @@ public class X48 extends Activity {
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);
}

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -631,10 +631,10 @@ GetEvent()
//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)
{