2015-02-15 17:52:27 +00:00
|
|
|
/*
|
2015-02-19 00:18:38 +00:00
|
|
|
* Apple // emulator for *nix
|
2015-02-15 17:52:27 +00:00
|
|
|
*
|
|
|
|
* This software package is subject to the GNU General Public License
|
|
|
|
* version 2 or later (your choice) as published by the Free Software
|
|
|
|
* Foundation.
|
|
|
|
*
|
|
|
|
* THERE ARE NO WARRANTIES WHATSOEVER.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <jni.h>
|
2015-02-16 04:08:01 +00:00
|
|
|
#include "common.h"
|
2015-02-25 00:03:21 +00:00
|
|
|
#include "video/renderer.h"
|
2015-03-01 05:48:08 +00:00
|
|
|
#include "androidkeys.h"
|
2015-02-15 17:52:27 +00:00
|
|
|
|
2015-03-11 21:42:57 +00:00
|
|
|
static bool nativePaused = false;
|
|
|
|
|
2015-03-14 22:42:02 +00:00
|
|
|
#if TESTING
|
|
|
|
static bool _run_tests(void) {
|
|
|
|
char *local_argv[] = {
|
|
|
|
"-f",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
int local_argc = 0;
|
|
|
|
for (char **p = &local_argv[0]; *p != NULL; p++) {
|
|
|
|
++local_argc;
|
|
|
|
}
|
|
|
|
#if defined(TEST_CPU)
|
|
|
|
extern int test_cpu(int, char *[]);
|
|
|
|
test_cpu(local_argc, local_argv);
|
|
|
|
#elif defined(TEST_VM)
|
|
|
|
extern int test_vm(int, char *[]);
|
|
|
|
test_vm(local_argc, local_argv);
|
|
|
|
#elif defined(TEST_DISPLAY)
|
|
|
|
extern int test_display(int, char *[]);
|
|
|
|
test_display(local_argc, local_argv);
|
|
|
|
#elif defined(TEST_DISK)
|
|
|
|
extern int test_disk(int, char *[]);
|
|
|
|
test_disk(local_argc, local_argv);
|
|
|
|
#else
|
|
|
|
# error "OOPS, no tests specified"
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-10 20:38:14 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobject obj, jstring j_dataDir) {
|
2015-02-23 19:19:41 +00:00
|
|
|
const char *dataDir = (*env)->GetStringUTFChars(env, j_dataDir, 0);
|
|
|
|
data_dir = strdup(dataDir);
|
|
|
|
(*env)->ReleaseStringUTFChars(env, j_dataDir, dataDir);
|
|
|
|
LOG("nativeOnCreate(%s)...", data_dir);
|
2015-03-12 21:45:17 +00:00
|
|
|
|
|
|
|
c_initialize_firsttime();
|
|
|
|
pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL);
|
2015-02-25 00:03:21 +00:00
|
|
|
}
|
2015-02-19 00:18:38 +00:00
|
|
|
|
2015-03-11 19:54:50 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsChanged(JNIEnv *env, jobject obj, jint width, jint height) {
|
|
|
|
LOG("%s", "native graphicsChanged...");
|
|
|
|
video_driver_reshape(width, height);
|
|
|
|
}
|
|
|
|
|
2015-03-10 20:38:14 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeGraphicsInitialized(JNIEnv *env, jobject obj, jint width, jint height) {
|
2015-02-25 00:03:21 +00:00
|
|
|
LOG("%s", "native graphicsInitialized...");
|
|
|
|
video_driver_reshape(width, height);
|
2015-03-12 21:45:17 +00:00
|
|
|
|
2015-03-14 22:42:02 +00:00
|
|
|
#if TESTING
|
|
|
|
_run_tests();
|
|
|
|
#else
|
2015-03-12 21:45:17 +00:00
|
|
|
static bool graphicsPreviouslyInitialized = false;
|
|
|
|
if (graphicsPreviouslyInitialized) {
|
|
|
|
video_driver_shutdown();
|
|
|
|
}
|
|
|
|
graphicsPreviouslyInitialized = true;
|
|
|
|
video_driver_init((void *)0);
|
2015-02-19 00:18:38 +00:00
|
|
|
#endif
|
2015-02-15 17:52:27 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 20:38:14 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobject obj) {
|
2015-03-11 21:42:57 +00:00
|
|
|
if (!nativePaused) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nativePaused = false;
|
2015-02-15 17:52:27 +00:00
|
|
|
LOG("%s", "native onResume...");
|
2015-03-11 06:32:08 +00:00
|
|
|
pthread_mutex_unlock(&interface_mutex);
|
2015-02-15 17:52:27 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 20:38:14 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobject obj) {
|
2015-03-11 21:42:57 +00:00
|
|
|
if (nativePaused) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nativePaused = true;
|
2015-02-15 17:52:27 +00:00
|
|
|
LOG("%s", "native onPause...");
|
2015-03-11 06:32:08 +00:00
|
|
|
pthread_mutex_lock(&interface_mutex);
|
2015-02-15 17:52:27 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 20:38:14 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeRender(JNIEnv *env, jobject obj) {
|
2015-03-11 21:42:57 +00:00
|
|
|
if (nativePaused) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-25 00:03:21 +00:00
|
|
|
c_keys_handle_input(-1, 0, 0);
|
|
|
|
|
|
|
|
#if FPS_LOG
|
|
|
|
static uint32_t prevCount = 0;
|
|
|
|
static uint32_t idleCount = 0;
|
|
|
|
|
|
|
|
idleCount++;
|
|
|
|
|
|
|
|
static struct timespec prev = { 0 };
|
|
|
|
struct timespec now;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
|
|
|
|
if (now.tv_sec != prev.tv_sec) {
|
|
|
|
LOG("native render() : %u", idleCount-prevCount);
|
|
|
|
prevCount = idleCount;
|
|
|
|
prev = now;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-01 05:48:08 +00:00
|
|
|
extern volatile bool _vid_dirty;
|
|
|
|
_vid_dirty = true;
|
2015-02-25 04:53:19 +00:00
|
|
|
video_driver_render();
|
2015-02-25 00:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 21:42:57 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeReboot(JNIEnv *env, jobject obj) {
|
|
|
|
LOG("%s", "native reboot...");
|
|
|
|
cpu65_reboot();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject obj) {
|
|
|
|
LOG("%s", "native quit...");
|
|
|
|
|
|
|
|
c_eject_6(0);
|
|
|
|
c_eject_6(1);
|
|
|
|
|
|
|
|
#ifdef AUDIO_ENABLED
|
|
|
|
speaker_destroy();
|
|
|
|
MB_Destroy();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
video_shutdown();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2015-03-10 20:38:14 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyDown(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
|
2015-03-01 05:48:08 +00:00
|
|
|
#if !TESTING
|
|
|
|
android_keycode_to_emulator(keyCode, metaState, true);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-10 20:38:14 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyUp(JNIEnv *env, jobject obj, jint keyCode, jint metaState) {
|
2015-03-01 05:48:08 +00:00
|
|
|
#if !TESTING
|
|
|
|
android_keycode_to_emulator(keyCode, metaState, false);
|
|
|
|
#endif
|
|
|
|
}
|
2015-03-14 22:42:02 +00:00
|
|
|
|
|
|
|
jboolean Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnTouch(JNIEnv *env, jobject obj, jint action, jfloat keyCode, jfloat metaState) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeIncreaseCPUSpeed(JNIEnv *env, jobject obj) {
|
|
|
|
pthread_mutex_lock(&interface_mutex);
|
|
|
|
|
|
|
|
if (cpu_scale_factor > 1.0) {
|
|
|
|
cpu_scale_factor += 0.25;
|
|
|
|
} else {
|
|
|
|
cpu_scale_factor += 0.05;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu_scale_factor > CPU_SCALE_FASTEST) {
|
|
|
|
cpu_scale_factor = CPU_SCALE_FASTEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
//video_driver_animate_speedscale();
|
|
|
|
|
|
|
|
#warning HACK TODO FIXME ... refactor timing stuff
|
|
|
|
timing_toggle_cpu_speed();
|
|
|
|
timing_toggle_cpu_speed();
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&interface_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeDecreaseCPUSpeed(JNIEnv *env, jobject obj) {
|
|
|
|
pthread_mutex_lock(&interface_mutex);
|
|
|
|
|
|
|
|
if (cpu_scale_factor > 1.0) {
|
|
|
|
cpu_scale_factor -= 0.25;
|
|
|
|
} else {
|
|
|
|
cpu_scale_factor -= 0.05;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu_scale_factor < CPU_SCALE_SLOWEST) {
|
|
|
|
cpu_scale_factor = CPU_SCALE_SLOWEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
//video_driver_animate_speedscale();
|
|
|
|
|
|
|
|
#warning HACK TODO FIXME ... refactor timing stuff
|
|
|
|
timing_toggle_cpu_speed();
|
|
|
|
timing_toggle_cpu_speed();
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&interface_mutex);
|
|
|
|
}
|
|
|
|
|