mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-12-28 12:33:04 +00:00
Lifecycle tweaks that get Android building again
This commit is contained in:
parent
0321c27de6
commit
b2cb35c182
@ -560,12 +560,17 @@ public class Apple2Activity extends Activity {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
nativeOnQuit();
|
nativeOnQuit();
|
||||||
Apple2Activity.this.finish();
|
Apple2Activity.this.finish();
|
||||||
try {
|
new Runnable() {
|
||||||
Thread.sleep(1000);
|
@Override
|
||||||
} catch (InterruptedException ex) {
|
public void run() {
|
||||||
// ...
|
try {
|
||||||
}
|
Thread.sleep(2000);
|
||||||
System.exit(0);
|
} catch (InterruptedException ex) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}.run();
|
||||||
}
|
}
|
||||||
}).setNegativeButton(R.string.no, null).create();
|
}).setNegativeButton(R.string.no, null).create();
|
||||||
/*mQuitDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
/*mQuitDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
|
@ -30,6 +30,8 @@ enum {
|
|||||||
ANDROID_ACTION_POINTER_UP = 0x6,
|
ANDROID_ACTION_POINTER_UP = 0x6,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool shuttingDown = false;
|
||||||
|
|
||||||
#if TESTING
|
#if TESTING
|
||||||
static void _run_tests(void) {
|
static void _run_tests(void) {
|
||||||
char *local_argv[] = {
|
char *local_argv[] = {
|
||||||
@ -134,7 +136,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje
|
|||||||
_run_tests();
|
_run_tests();
|
||||||
// CPU thread is started from testsuite (if needed)
|
// CPU thread is started from testsuite (if needed)
|
||||||
#else
|
#else
|
||||||
timing_startCPU();
|
emulator_start();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,13 +147,8 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsChanged(JNIEnv *env
|
|||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv *env, jobject obj, jint width, jint height) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv *env, jobject obj, jint width, jint height) {
|
||||||
LOG("width:%d height:%d", width, height);
|
LOG("width:%d height:%d", width, height);
|
||||||
static bool graphicsPreviouslyInitialized = false;
|
|
||||||
if (graphicsPreviouslyInitialized) {
|
|
||||||
LOG("shutting down previous context");
|
|
||||||
video_shutdown();
|
|
||||||
}
|
|
||||||
graphicsPreviouslyInitialized = true;
|
|
||||||
|
|
||||||
|
video_shutdown();
|
||||||
video_backend->reshape(width, height);
|
video_backend->reshape(width, height);
|
||||||
video_backend->init((void *)0);
|
video_backend->init((void *)0);
|
||||||
}
|
}
|
||||||
@ -171,6 +168,9 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobje
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobject obj, jboolean isSystemPause) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobject obj, jboolean isSystemPause) {
|
||||||
|
if (shuttingDown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (cpu_isPaused()) {
|
if (cpu_isPaused()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobjec
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeRender(JNIEnv *env, jobject obj) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeRender(JNIEnv *env, jobject obj) {
|
||||||
if (UNLIKELY(emulator_shutting_down)) {
|
if (UNLIKELY(shuttingDown)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,17 +225,16 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject
|
|||||||
#if TESTING
|
#if TESTING
|
||||||
// test driver thread is managing CPU
|
// test driver thread is managing CPU
|
||||||
#else
|
#else
|
||||||
|
shuttingDown = true;
|
||||||
|
|
||||||
LOG("%s", "");
|
LOG("%s", "");
|
||||||
|
|
||||||
c_eject_6(0);
|
c_eject_6(0);
|
||||||
c_eject_6(1);
|
c_eject_6(1);
|
||||||
|
|
||||||
emulator_shutting_down = true;
|
|
||||||
|
|
||||||
cpu_resume();
|
cpu_resume();
|
||||||
if (pthread_join(cpu_thread_id, NULL)) {
|
|
||||||
ERRLOG("OOPS: pthread_join of CPU thread ...");
|
emulator_shutdown();
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,17 +275,22 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnUncaughtException(JNIEnv
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyDown(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyDown(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
|
||||||
|
if (UNLIKELY(shuttingDown)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
android_keycode_to_emulator(keyCode, metaState, true);
|
android_keycode_to_emulator(keyCode, metaState, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyUp(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyUp(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
|
||||||
|
if (UNLIKELY(shuttingDown)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
android_keycode_to_emulator(keyCode, metaState, false);
|
android_keycode_to_emulator(keyCode, metaState, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
jlong Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnTouch(JNIEnv *env, jobject obj, jint action, jint pointerCount, jint pointerIndex, jfloatArray xCoords, jfloatArray yCoords) {
|
jlong Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnTouch(JNIEnv *env, jobject obj, jint action, jint pointerCount, jint pointerIndex, jfloatArray xCoords, jfloatArray yCoords) {
|
||||||
//LOG(": %d/%d/%d :", action, pointerCount, pointerIndex);
|
//LOG(": %d/%d/%d :", action, pointerCount, pointerIndex);
|
||||||
if (UNLIKELY(emulator_shutting_down)) {
|
if (UNLIKELY(shuttingDown)) {
|
||||||
video_shutdown();
|
|
||||||
return 0x0LL;
|
return 0x0LL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetSpeakerVolume(JNIEnv
|
|||||||
assert(goesToTen >= 0);
|
assert(goesToTen >= 0);
|
||||||
sound_volume = goesToTen;
|
sound_volume = goesToTen;
|
||||||
#warning FIXME TODO refactor/remove sound_volume ?
|
#warning FIXME TODO refactor/remove sound_volume ?
|
||||||
speaker_setVolumeZeroToTen(goesToTen);
|
vm_reinitializeAudio();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetAudioLatency(JNIEnv *env, jclass cls, jfloat latencySecs) {
|
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetAudioLatency(JNIEnv *env, jclass cls, jfloat latencySecs) {
|
||||||
|
12
src/misc.c
12
src/misc.c
@ -38,10 +38,8 @@ static void _init_common() {
|
|||||||
|
|
||||||
static void _shutdown_threads(void) {
|
static void _shutdown_threads(void) {
|
||||||
#if !TESTING
|
#if !TESTING
|
||||||
|
# if defined(__linux__) && !defined(ANDROID)
|
||||||
LOG("Emulator waiting for other threads to clean up...");
|
LOG("Emulator waiting for other threads to clean up...");
|
||||||
# if !__linux__
|
|
||||||
# error FIXME TODO on Darwin ...
|
|
||||||
# else
|
|
||||||
do {
|
do {
|
||||||
DIR *dir = opendir("/proc/self/task");
|
DIR *dir = opendir("/proc/self/task");
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
@ -71,6 +69,8 @@ static void _shutdown_threads(void) {
|
|||||||
static struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
|
static struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
|
||||||
nanosleep(&ts, NULL); // 30Hz framerate
|
nanosleep(&ts, NULL); // 30Hz framerate
|
||||||
} while (1);
|
} while (1);
|
||||||
|
# elif defined(__APPLE__)
|
||||||
|
# error TODO FIXME ... verify leaks-n-things with instruments on Darwin
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -96,9 +96,13 @@ int main(int _argc, char **_argv) {
|
|||||||
argv = _argv;
|
argv = _argv;
|
||||||
|
|
||||||
emulator_start();
|
emulator_start();
|
||||||
video_main_loop();
|
|
||||||
|
// main loop ...
|
||||||
|
|
||||||
emulator_shutdown();
|
emulator_shutdown();
|
||||||
|
|
||||||
|
LOG("Emulator exit ...");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user