More faithful to the original x48 source
This commit is contained in:
parent
a798ff264d
commit
95965fc6e3
6 changed files with 48 additions and 81 deletions
|
@ -112,7 +112,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
||||||
mSurfaceHolder = getHolder();
|
mSurfaceHolder = getHolder();
|
||||||
mSurfaceHolder.addCallback(this);
|
mSurfaceHolder.addCallback(this);
|
||||||
mainScreen = Bitmap.createBitmap(262, 14+128, Bitmap.Config.RGB_565);
|
mainScreen = Bitmap.createBitmap(262, 14+128, Bitmap.Config.RGB_565);
|
||||||
queuedCodes = new ArrayList<Integer>();
|
queuedCodes = new Vector<Integer>();
|
||||||
ann = new boolean [6];
|
ann = new boolean [6];
|
||||||
buf = new short [(14+128)*262];
|
buf = new short [(14+128)*262];
|
||||||
audiobuf = new short [44100]; // 1s worth
|
audiobuf = new short [44100]; // 1s worth
|
||||||
|
@ -1028,7 +1028,6 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
||||||
}
|
}
|
||||||
|
|
||||||
public void key(int code, boolean down, int pointerID) {
|
public void key(int code, boolean down, int pointerID) {
|
||||||
synchronized(this) {
|
|
||||||
if (code < MAX_TOUCHES) {
|
if (code < MAX_TOUCHES) {
|
||||||
if (down) {
|
if (down) {
|
||||||
Integer cI = code + 1;
|
Integer cI = code + 1;
|
||||||
|
@ -1042,17 +1041,10 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
||||||
touches[code] = 0;
|
touches[code] = 0;
|
||||||
}
|
}
|
||||||
x48.flipScreen();
|
x48.flipScreen();
|
||||||
unpauseEvent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void unpauseEvent() {
|
|
||||||
x48.openConditionVariable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int waitEvent() {
|
public int waitEvent() {
|
||||||
synchronized(this) {
|
|
||||||
if (queuedCodes.size() == 0) {
|
if (queuedCodes.size() == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1060,7 +1052,6 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected int width;
|
protected int width;
|
||||||
protected int height;
|
protected int height;
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.ab.x48;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -35,6 +37,7 @@ public class X48 extends Activity {
|
||||||
static final private int ROM_ID = 123;
|
static final private int ROM_ID = 123;
|
||||||
|
|
||||||
private static EmulatorThread thread;
|
private static EmulatorThread thread;
|
||||||
|
private static Timer SIGALRM;
|
||||||
|
|
||||||
private static boolean errorLib;
|
private static boolean errorLib;
|
||||||
|
|
||||||
|
@ -87,6 +90,8 @@ public class X48 extends Activity {
|
||||||
|
|
||||||
checkPrefs();
|
checkPrefs();
|
||||||
|
|
||||||
|
SIGALRM = new Timer();
|
||||||
|
|
||||||
thread = new EmulatorThread(this);
|
thread = new EmulatorThread(this);
|
||||||
thread.start();
|
thread.start();
|
||||||
mainView.resume();
|
mainView.resume();
|
||||||
|
@ -163,8 +168,7 @@ public class X48 extends Activity {
|
||||||
public native void flipScreen();
|
public native void flipScreen();
|
||||||
public native int loadProg(String filename);
|
public native int loadProg(String filename);
|
||||||
public native void setBlankColor(short s);
|
public native void setBlankColor(short s);
|
||||||
public native void openConditionVariable();
|
public native void SIGALRM();
|
||||||
public native void blockConditionVariable();
|
|
||||||
|
|
||||||
public void emulatorReady() {
|
public void emulatorReady() {
|
||||||
mainView.emulatorReady();
|
mainView.emulatorReady();
|
||||||
|
@ -181,6 +185,12 @@ public class X48 extends Activity {
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
Log.i("x48", "resume");
|
Log.i("x48", "resume");
|
||||||
|
SIGALRM.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
SIGALRM();
|
||||||
|
}
|
||||||
|
}, 0, 20);
|
||||||
if (mainView != null)
|
if (mainView != null)
|
||||||
mainView.resume();
|
mainView.resume();
|
||||||
Log.i("x48", "resumed");
|
Log.i("x48", "resumed");
|
||||||
|
@ -448,6 +458,7 @@ private void managePort(int number, String value) {
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
Log.i("x48", "pause");
|
Log.i("x48", "pause");
|
||||||
|
SIGALRM.cancel();
|
||||||
if (mainView != null)
|
if (mainView != null)
|
||||||
mainView.pause();
|
mainView.pause();
|
||||||
Log.i("x48", "paused");
|
Log.i("x48", "paused");
|
||||||
|
@ -460,8 +471,6 @@ private void managePort(int number, String value) {
|
||||||
if (saveonExit)
|
if (saveonExit)
|
||||||
saveState();
|
saveState();
|
||||||
stopHPEmulator();
|
stopHPEmulator();
|
||||||
if (mainView != null)
|
|
||||||
mainView.unpauseEvent();
|
|
||||||
if (need_to_quit)
|
if (need_to_quit)
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -626,38 +626,20 @@ do_shutdown()
|
||||||
saturn.PC, saturn.t2_ctrl, saturn.timer2);
|
saturn.PC, saturn.t2_ctrl, saturn.timer2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* if (in_debugger)
|
if (in_debugger)
|
||||||
wake = 1;
|
wake = 1;
|
||||||
else*/
|
else
|
||||||
wake = 0;
|
wake = 0;
|
||||||
|
|
||||||
alarms = 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 {
|
||||||
|
|
||||||
/* do {
|
blockConditionVariable();
|
||||||
|
|
||||||
(*android_env)->CallVoidMethod(android_env, android_callback, pauseEvent);
|
|
||||||
|
|
||||||
if (got_alarm) {
|
if (got_alarm) {
|
||||||
|
|
||||||
got_alarm = 0;*/
|
got_alarm = 0;
|
||||||
|
|
||||||
ticks = get_t1_t2();
|
ticks = get_t1_t2();
|
||||||
if (saturn.t2_ctrl & 0x01) {
|
if (saturn.t2_ctrl & 0x01) {
|
||||||
|
@ -667,16 +649,6 @@ LOGI("---");
|
||||||
set_t1 = ticks.t1_ticks;
|
set_t1 = ticks.t1_ticks;
|
||||||
|
|
||||||
interrupt_called = 0;
|
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 (GetEvent()) {
|
||||||
if (interrupt_called)
|
if (interrupt_called)
|
||||||
wake = 1;
|
wake = 1;
|
||||||
|
@ -720,7 +692,12 @@ LOGI("---");
|
||||||
|
|
||||||
alarms++;
|
alarms++;
|
||||||
|
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
if (enter_debugger)
|
||||||
|
{
|
||||||
|
wake = 1;
|
||||||
|
}
|
||||||
|
|
||||||
} while (wake == 0 && exit_state);
|
} while (wake == 0 && exit_state);
|
||||||
|
|
||||||
|
|
|
@ -2415,18 +2415,15 @@ schedule()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
schedule_event--;
|
schedule_event--;
|
||||||
/*
|
|
||||||
if (got_alarm) {
|
if (got_alarm) {
|
||||||
got_alarm = 0;
|
got_alarm = 0;
|
||||||
#ifdef HAVE_XSHM
|
#ifdef HAVE_XSHM
|
||||||
if (disp.display_update) refresh_display();
|
if (disp.display_update) refresh_display();
|
||||||
#endif
|
#endif
|
||||||
GetEvent();
|
GetEvent();
|
||||||
//usleep(500);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
GetEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -427,21 +427,14 @@ Java_org_ab_x48_X48_loadProg( JNIEnv* env,
|
||||||
/**
|
/**
|
||||||
* This function opens the condition variable which releases waiting threads.
|
* 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_mutex_lock(&uiConditionMutex);
|
||||||
pthread_cond_signal(&uiConditionVariable);
|
pthread_cond_signal(&uiConditionVariable);
|
||||||
pthread_mutex_unlock(&uiConditionMutex);
|
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()
|
void blockConditionVariable()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&uiConditionMutex);
|
pthread_mutex_lock(&uiConditionMutex);
|
||||||
|
|
|
@ -631,10 +631,10 @@ GetEvent()
|
||||||
|
|
||||||
//LOGI("code: %d", code);
|
//LOGI("code: %d", code);
|
||||||
//FIX for Zenfone 2
|
//FIX for Zenfone 2
|
||||||
struct timespec req, rem;
|
/*struct timespec req, rem;
|
||||||
req.tv_sec = 0;
|
req.tv_sec = 0;
|
||||||
req.tv_nsec = 100L;
|
req.tv_nsec = 100L;
|
||||||
nanosleep(&req , &rem);
|
nanosleep(&req , &rem);*/
|
||||||
|
|
||||||
if (code < 0)
|
if (code < 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue