2015-02-15 17:52:27 +00:00
|
|
|
/*
|
2015-10-22 05:13:26 +00:00
|
|
|
* Apple // emulator for *ix
|
2015-02-15 17:52:27 +00:00
|
|
|
*
|
|
|
|
* This software package is subject to the GNU General Public License
|
2015-10-22 05:13:26 +00:00
|
|
|
* version 3 or later (your choice) as published by the Free Software
|
2015-02-15 17:52:27 +00:00
|
|
|
* Foundation.
|
|
|
|
*
|
2015-10-22 05:13:26 +00:00
|
|
|
* Copyright 2015 Aaron Culliney
|
2015-02-15 17:52:27 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-02-16 04:08:01 +00:00
|
|
|
#include "common.h"
|
2015-03-01 05:48:08 +00:00
|
|
|
#include "androidkeys.h"
|
2015-02-15 17:52:27 +00:00
|
|
|
|
2015-07-11 21:37:41 +00:00
|
|
|
#include <cpu-features.h>
|
2015-03-23 01:53:13 +00:00
|
|
|
#include <jni.h>
|
|
|
|
|
2015-06-28 19:49:26 +00:00
|
|
|
unsigned long android_deviceSampleRateHz = 0;
|
2015-07-05 01:14:21 +00:00
|
|
|
unsigned long android_monoBufferSubmitSizeSamples = 0;
|
|
|
|
unsigned long android_stereoBufferSubmitSizeSamples = 0;
|
2015-09-26 21:58:09 +00:00
|
|
|
|
|
|
|
bool android_armArch = false;
|
|
|
|
bool android_armArchV7A = false;
|
|
|
|
bool android_arm64Arch = false;
|
|
|
|
|
|
|
|
bool android_x86 = false;
|
|
|
|
bool android_x86_64 = false;
|
|
|
|
|
2015-07-11 21:37:41 +00:00
|
|
|
bool android_armNeonEnabled = false;
|
|
|
|
bool android_x86SSSE3Enabled = false;
|
2015-06-28 19:49:26 +00:00
|
|
|
|
2015-04-02 02:59:38 +00:00
|
|
|
enum {
|
|
|
|
ANDROID_ACTION_DOWN = 0x0,
|
|
|
|
ANDROID_ACTION_UP = 0x1,
|
|
|
|
ANDROID_ACTION_MOVE = 0x2,
|
|
|
|
ANDROID_ACTION_CANCEL = 0x3,
|
|
|
|
ANDROID_ACTION_POINTER_DOWN = 0x5,
|
|
|
|
ANDROID_ACTION_POINTER_UP = 0x6,
|
|
|
|
};
|
|
|
|
|
2015-10-04 20:39:57 +00:00
|
|
|
typedef enum lifecycle_seq_t {
|
|
|
|
APP_RUNNING = 0,
|
|
|
|
APP_REQUESTED_SHUTDOWN,
|
|
|
|
APP_FINISHED,
|
|
|
|
} lifecycle_seq_t;
|
|
|
|
|
|
|
|
static lifecycle_seq_t appState = APP_RUNNING;
|
2015-09-12 22:33:22 +00:00
|
|
|
|
2015-03-14 22:42:02 +00:00
|
|
|
#if TESTING
|
2015-12-17 04:58:50 +00:00
|
|
|
static bool running_tests = false;
|
2015-09-07 06:43:26 +00:00
|
|
|
static void _run_tests(void) {
|
2015-03-14 22:42:02 +00:00
|
|
|
char *local_argv[] = {
|
|
|
|
"-f",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
int local_argc = 0;
|
|
|
|
for (char **p = &local_argv[0]; *p != NULL; p++) {
|
|
|
|
++local_argc;
|
|
|
|
}
|
|
|
|
#if defined(TEST_CPU)
|
2015-09-07 06:43:26 +00:00
|
|
|
// Currently this test is the only one that runs as a black screen
|
2015-03-14 22:42:02 +00:00
|
|
|
extern int test_cpu(int, char *[]);
|
|
|
|
test_cpu(local_argc, local_argv);
|
2015-09-07 06:43:26 +00:00
|
|
|
tkill(getpid(), SIGKILL); // and we're done ...
|
2015-03-14 22:42:02 +00:00
|
|
|
#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-09-19 06:04:30 +00:00
|
|
|
static inline int _androidTouchEvent2InterfaceEvent(jint action) {
|
2015-04-02 02:59:38 +00:00
|
|
|
switch (action) {
|
|
|
|
case ANDROID_ACTION_DOWN:
|
|
|
|
return TOUCH_DOWN;
|
|
|
|
case ANDROID_ACTION_MOVE:
|
|
|
|
return TOUCH_MOVE;
|
|
|
|
case ANDROID_ACTION_UP:
|
|
|
|
return TOUCH_UP;
|
|
|
|
case ANDROID_ACTION_POINTER_DOWN:
|
|
|
|
return TOUCH_POINTER_DOWN;
|
|
|
|
case ANDROID_ACTION_POINTER_UP:
|
|
|
|
return TOUCH_POINTER_UP;
|
|
|
|
case ANDROID_ACTION_CANCEL:
|
|
|
|
return TOUCH_CANCEL;
|
|
|
|
default:
|
|
|
|
LOG("Unknown Android event : %d", action);
|
|
|
|
return TOUCH_CANCEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 03:26:34 +00:00
|
|
|
static void discover_cpu_family(void) {
|
2015-11-01 21:43:09 +00:00
|
|
|
LOG("Discovering CPU family...");
|
|
|
|
|
|
|
|
AndroidCpuFamily family = android_getCpuFamily();
|
|
|
|
uint64_t features = android_getCpuFeatures();
|
|
|
|
if (family == ANDROID_CPU_FAMILY_X86) {
|
2015-11-29 22:35:01 +00:00
|
|
|
android_x86 = true;
|
2015-11-01 21:43:09 +00:00
|
|
|
if (features & ANDROID_CPU_X86_FEATURE_SSSE3) {
|
|
|
|
LOG("nANDROID_CPU_X86_FEATURE_SSSE3");
|
|
|
|
android_x86SSSE3Enabled = true;
|
|
|
|
}
|
|
|
|
if (features & ANDROID_CPU_X86_FEATURE_MOVBE) {
|
|
|
|
LOG("ANDROID_CPU_X86_FEATURE_MOVBE");
|
|
|
|
}
|
|
|
|
if (features & ANDROID_CPU_X86_FEATURE_POPCNT) {
|
|
|
|
LOG("ANDROID_CPU_X86_FEATURE_POPCNT");
|
|
|
|
}
|
|
|
|
} else if (family == ANDROID_CPU_FAMILY_ARM) {
|
|
|
|
if (features & ANDROID_CPU_ARM_FEATURE_ARMv7) {
|
|
|
|
LOG("ANDROID_CPU_ARM_FEATURE_ARMv7");
|
|
|
|
android_armArchV7A = true;
|
|
|
|
} else {
|
|
|
|
LOG("!!! NOT ANDROID_CPU_ARM_FEATURE_ARMv7");
|
|
|
|
android_armArch = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (features & ANDROID_CPU_ARM_FEATURE_VFPv3) {
|
|
|
|
LOG("ANDROID_CPU_ARM_FEATURE_VFPv3");
|
|
|
|
}
|
|
|
|
if (features & ANDROID_CPU_ARM_FEATURE_NEON) {
|
|
|
|
LOG("ANDROID_CPU_ARM_FEATURE_NEON");
|
|
|
|
android_armNeonEnabled = true;
|
|
|
|
}
|
|
|
|
if (features & ANDROID_CPU_ARM_FEATURE_LDREX_STREX) {
|
|
|
|
LOG("ANDROID_CPU_ARM_FEATURE_LDREX_STREX");
|
|
|
|
}
|
|
|
|
} else if (family == ANDROID_CPU_FAMILY_ARM64) {
|
|
|
|
#warning FIXME TODO ...
|
|
|
|
//android_arm64Arch = true;
|
|
|
|
android_armArchV7A = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 03:26:34 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// JNI functions
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jclass cls, jstring j_dataDir, jint sampleRate, jint monoBufferSize, jint stereoBufferSize) {
|
2015-02-23 19:19:41 +00:00
|
|
|
const char *dataDir = (*env)->GetStringUTFChars(env, j_dataDir, 0);
|
2015-04-15 04:48:55 +00:00
|
|
|
|
|
|
|
// Android lifecycle can call onCreate() multiple times...
|
|
|
|
if (data_dir) {
|
|
|
|
LOG("IGNORING multiple calls to nativeOnCreate ...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-02 03:26:34 +00:00
|
|
|
discover_cpu_family();
|
|
|
|
|
2015-09-27 22:04:10 +00:00
|
|
|
// Do not remove this deadc0de ... it forces a runtime load-library/link error on Gingerbread devices if we have
|
|
|
|
// incorrectly compiled the app against a later version of the NDK!!!
|
2015-09-27 21:30:20 +00:00
|
|
|
int pagesize = getpagesize();
|
|
|
|
LOG("PAGESIZE IS : %d", pagesize);
|
|
|
|
|
2015-09-19 18:47:36 +00:00
|
|
|
data_dir = strdup(dataDir);
|
2015-09-26 22:20:54 +00:00
|
|
|
if (crashHandler && crashHandler->init) {
|
|
|
|
crashHandler->init(data_dir);
|
2015-09-19 18:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->ReleaseStringUTFChars(env, j_dataDir, dataDir);
|
|
|
|
LOG("data_dir : %s", data_dir);
|
|
|
|
|
2015-06-28 19:49:26 +00:00
|
|
|
android_deviceSampleRateHz = (unsigned long)sampleRate;
|
2015-07-05 01:14:21 +00:00
|
|
|
android_monoBufferSubmitSizeSamples = (unsigned long)monoBufferSize;
|
|
|
|
android_stereoBufferSubmitSizeSamples = (unsigned long)stereoBufferSize;
|
2015-06-28 19:49:26 +00:00
|
|
|
|
2015-12-20 07:48:16 +00:00
|
|
|
joydriver_setClampBeyondRadius(true);
|
|
|
|
|
2016-01-24 17:29:47 +00:00
|
|
|
//#define DO_CPU65_TRACING 1
|
|
|
|
#if DO_CPU65_TRACING
|
|
|
|
# warning !!!!!!!!!! this will quickly eat up disk space !!!!!!!!!!
|
|
|
|
char *trfile = NULL;
|
|
|
|
asprintf(&trfile, "%s/%s", data_dir, "cpu_trace.txt");
|
|
|
|
cpu65_trace_begin(trfile);
|
|
|
|
ASPRINTF_FREE(trfile);
|
|
|
|
#endif
|
|
|
|
|
2015-12-17 04:58:50 +00:00
|
|
|
#if !TESTING
|
2015-09-13 21:24:17 +00:00
|
|
|
cpu_pause();
|
2015-09-12 22:33:22 +00:00
|
|
|
emulator_start();
|
2015-03-23 04:44:03 +00:00
|
|
|
#endif
|
2015-02-25 00:03:21 +00:00
|
|
|
}
|
2015-02-19 00:18:38 +00:00
|
|
|
|
2016-02-15 04:40:51 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2View_nativeGraphicsChanged(JNIEnv *env, jclass cls, jint width, jint height, jboolean landscape) {
|
2015-11-01 18:14:40 +00:00
|
|
|
// WARNING : this can happen on non-GL thread
|
2016-02-15 04:40:51 +00:00
|
|
|
LOG("width:%d height:%d landscape:%d", width, height, landscape);
|
|
|
|
video_reshape(width, height, landscape);
|
2015-03-11 19:54:50 +00:00
|
|
|
}
|
|
|
|
|
2016-02-15 04:40:51 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2View_nativeGraphicsInitialized(JNIEnv *env, jclass cls, jint width, jint height, jboolean landscape) {
|
2015-12-17 04:58:50 +00:00
|
|
|
// WARNING : this needs to happen on the GL thread only
|
2016-02-15 04:40:51 +00:00
|
|
|
LOG("width:%d height:%d landscape:%d", width, height, landscape);
|
2016-02-06 21:13:31 +00:00
|
|
|
_video_setRenderThread(pthread_self()); // Assume Android knows what it's doing ;-P
|
2016-02-15 04:40:51 +00:00
|
|
|
|
|
|
|
assert(cpu_isPaused());
|
|
|
|
|
2016-02-06 22:45:59 +00:00
|
|
|
video_shutdown(false);
|
2016-02-15 04:40:51 +00:00
|
|
|
video_reshape(width, height, landscape);
|
2016-02-06 21:13:31 +00:00
|
|
|
video_init();
|
2015-02-15 17:52:27 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationResume(JNIEnv *env, jclass cls) {
|
2015-12-17 04:58:50 +00:00
|
|
|
#if TESTING
|
|
|
|
// test driver thread is managing CPU
|
|
|
|
if (!running_tests) {
|
|
|
|
running_tests = true;
|
|
|
|
assert(cpu_thread_id == 0 && "CPU thread must not be initialized yet...");
|
|
|
|
_run_tests();
|
|
|
|
}
|
|
|
|
#else
|
2015-07-28 05:36:39 +00:00
|
|
|
if (!cpu_isPaused()) {
|
2015-03-11 21:42:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-09-19 18:47:36 +00:00
|
|
|
LOG("...");
|
2015-10-31 21:01:47 +00:00
|
|
|
cpu_resume();
|
2015-09-07 06:43:26 +00:00
|
|
|
#endif
|
2015-02-15 17:52:27 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationPause(JNIEnv *env, jclass cls) {
|
2015-10-04 20:39:57 +00:00
|
|
|
if (appState != APP_RUNNING) {
|
2015-09-12 22:33:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-12-12 07:42:57 +00:00
|
|
|
|
2016-01-24 17:29:47 +00:00
|
|
|
#if DO_CPU65_TRACING
|
|
|
|
cpu65_trace_checkpoint();
|
|
|
|
#endif
|
|
|
|
|
2015-12-12 07:42:57 +00:00
|
|
|
disk6_flush(0);
|
|
|
|
disk6_flush(1);
|
|
|
|
|
2015-07-28 05:36:39 +00:00
|
|
|
if (cpu_isPaused()) {
|
2015-03-11 21:42:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-09-19 18:47:36 +00:00
|
|
|
LOG("...");
|
2015-07-05 01:17:04 +00:00
|
|
|
|
2015-09-07 06:43:26 +00:00
|
|
|
#if TESTING
|
|
|
|
// test driver thread is managing CPU
|
|
|
|
#else
|
2015-09-13 21:24:17 +00:00
|
|
|
cpu_pause();
|
2015-09-07 06:43:26 +00:00
|
|
|
#endif
|
2015-02-15 17:52:27 +00:00
|
|
|
}
|
|
|
|
|
2015-11-01 18:14:40 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2View_nativeRender(JNIEnv *env, jclass cls) {
|
2015-10-04 21:21:28 +00:00
|
|
|
SCOPE_TRACE_VIDEO("nativeRender");
|
|
|
|
|
2015-10-04 20:39:57 +00:00
|
|
|
if (UNLIKELY(appState != APP_RUNNING)) {
|
|
|
|
if (appState == APP_REQUESTED_SHUTDOWN) {
|
|
|
|
appState = APP_FINISHED;
|
|
|
|
emulator_shutdown();
|
|
|
|
}
|
2015-06-07 04:18:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-15 04:40:51 +00:00
|
|
|
//#define FPS_LOG 1
|
2015-02-25 00:03:21 +00:00
|
|
|
#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) {
|
2015-08-22 06:41:53 +00:00
|
|
|
LOG("FPS : %u", idleCount-prevCount);
|
2015-02-25 00:03:21 +00:00
|
|
|
prevCount = idleCount;
|
|
|
|
prev = now;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-06 21:13:31 +00:00
|
|
|
video_render();
|
2015-02-25 00:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeReboot(JNIEnv *env, jclass cls) {
|
2015-09-19 18:47:36 +00:00
|
|
|
LOG("...");
|
2015-03-11 21:42:57 +00:00
|
|
|
cpu65_reboot();
|
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jclass cls) {
|
2015-09-07 06:43:26 +00:00
|
|
|
#if TESTING
|
|
|
|
// test driver thread is managing CPU
|
|
|
|
#else
|
2015-10-04 20:39:57 +00:00
|
|
|
appState = APP_REQUESTED_SHUTDOWN;
|
2015-09-12 22:33:22 +00:00
|
|
|
|
2015-09-19 18:47:36 +00:00
|
|
|
LOG("...");
|
2015-03-11 21:42:57 +00:00
|
|
|
|
2015-10-16 04:23:21 +00:00
|
|
|
disk6_eject(0);
|
|
|
|
disk6_eject(1);
|
2015-03-11 21:42:57 +00:00
|
|
|
|
2016-01-24 17:29:47 +00:00
|
|
|
#if DO_CPU65_TRACING
|
|
|
|
cpu65_trace_end();
|
|
|
|
#endif
|
|
|
|
|
2015-07-05 01:17:04 +00:00
|
|
|
cpu_resume();
|
2015-09-07 06:43:26 +00:00
|
|
|
#endif
|
2015-03-11 21:42:57 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 20:11:12 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyDown(JNIEnv *env, jclass cls, jint keyCode, jint metaState) {
|
2015-10-04 20:39:57 +00:00
|
|
|
if (UNLIKELY(appState != APP_RUNNING)) {
|
2015-09-12 22:33:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-01 05:48:08 +00:00
|
|
|
android_keycode_to_emulator(keyCode, metaState, true);
|
|
|
|
}
|
|
|
|
|
2015-12-20 20:11:12 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyUp(JNIEnv *env, jclass cls, jint keyCode, jint metaState) {
|
2015-10-04 20:39:57 +00:00
|
|
|
if (UNLIKELY(appState != APP_RUNNING)) {
|
2015-09-12 22:33:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-01 05:48:08 +00:00
|
|
|
android_keycode_to_emulator(keyCode, metaState, false);
|
|
|
|
}
|
2015-03-14 22:42:02 +00:00
|
|
|
|
2015-12-20 07:48:16 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2View_nativeOnJoystickMove(JNIEnv *env, jclass cls, jint x, jint y) {
|
|
|
|
joydriver_setAxisValue((uint8_t)x, (uint8_t)y);
|
|
|
|
}
|
|
|
|
|
2015-12-20 06:57:08 +00:00
|
|
|
jlong Java_org_deadc0de_apple2ix_Apple2View_nativeOnTouch(JNIEnv *env, jclass cls, jint action, jint pointerCount, jint pointerIndex, jfloatArray xCoords, jfloatArray yCoords) {
|
2015-08-22 06:41:53 +00:00
|
|
|
//LOG(": %d/%d/%d :", action, pointerCount, pointerIndex);
|
2015-10-04 21:21:28 +00:00
|
|
|
|
|
|
|
SCOPE_TRACE_TOUCH("nativeOnTouch");
|
|
|
|
|
2015-10-04 20:39:57 +00:00
|
|
|
if (UNLIKELY(appState != APP_RUNNING)) {
|
2015-07-31 04:36:22 +00:00
|
|
|
return 0x0LL;
|
2015-06-07 04:18:27 +00:00
|
|
|
}
|
2015-04-02 02:59:38 +00:00
|
|
|
|
|
|
|
jfloat *x_coords = (*env)->GetFloatArrayElements(env, xCoords, 0);
|
|
|
|
jfloat *y_coords = (*env)->GetFloatArrayElements(env, yCoords, 0);
|
|
|
|
|
2015-09-19 06:04:30 +00:00
|
|
|
int joyaction = _androidTouchEvent2InterfaceEvent(action);
|
2015-04-02 02:59:38 +00:00
|
|
|
|
|
|
|
//for (unsigned int i=0; i<pointerCount; i++) {
|
|
|
|
// LOG("\t[%f,%f]", x_coords[i], y_coords[i]);
|
|
|
|
//}
|
|
|
|
|
2015-07-31 04:36:22 +00:00
|
|
|
int64_t flags = interface_onTouchEvent(joyaction, pointerCount, pointerIndex, x_coords, y_coords);
|
2015-04-02 02:59:38 +00:00
|
|
|
|
|
|
|
(*env)->ReleaseFloatArrayElements(env, xCoords, x_coords, 0);
|
|
|
|
(*env)->ReleaseFloatArrayElements(env, yCoords, y_coords, 0);
|
2015-07-31 04:36:22 +00:00
|
|
|
return flags;
|
2015-03-14 22:42:02 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, jclass cls, jstring jPath, jboolean driveA, jboolean readOnly) {
|
2015-06-06 19:23:14 +00:00
|
|
|
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
2015-04-08 05:40:22 +00:00
|
|
|
int drive = driveA ? 0 : 1;
|
|
|
|
int ro = readOnly ? 1 : 0;
|
2015-04-18 21:53:01 +00:00
|
|
|
|
2015-10-31 06:15:53 +00:00
|
|
|
assert(cpu_isPaused() && "considered dangerous to insert disk image when CPU thread is running");
|
|
|
|
|
2015-08-22 06:41:53 +00:00
|
|
|
LOG(": (%s, %s, %s)", path, driveA ? "drive A" : "drive B", readOnly ? "read only" : "read/write");
|
2015-10-16 04:23:21 +00:00
|
|
|
if (disk6_insert(drive, path, ro)) {
|
2015-04-08 05:40:22 +00:00
|
|
|
char *gzPath = NULL;
|
|
|
|
asprintf(&gzPath, "%s.gz", path);
|
2015-10-16 04:23:21 +00:00
|
|
|
if (disk6_insert(drive, gzPath, ro)) {
|
2015-04-18 21:53:01 +00:00
|
|
|
char *diskImageUnreadable = "Disk Image Unreadable";
|
|
|
|
unsigned int cols = strlen(diskImageUnreadable);
|
2016-02-07 05:23:40 +00:00
|
|
|
video_animations->animation_showMessage(diskImageUnreadable, cols, 1);
|
2015-04-08 05:40:22 +00:00
|
|
|
} else {
|
2016-02-07 05:23:40 +00:00
|
|
|
video_animations->animation_showDiskChosen(drive);
|
2015-04-08 05:40:22 +00:00
|
|
|
}
|
2015-12-31 06:16:57 +00:00
|
|
|
ASPRINTF_FREE(gzPath);
|
2015-04-08 05:40:22 +00:00
|
|
|
} else {
|
2016-02-07 05:23:40 +00:00
|
|
|
video_animations->animation_showDiskChosen(drive);
|
2015-04-08 05:40:22 +00:00
|
|
|
}
|
|
|
|
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEjectDisk(JNIEnv *env, jclass cls, jboolean driveA) {
|
2015-09-19 18:47:36 +00:00
|
|
|
LOG("...");
|
2015-10-16 04:23:21 +00:00
|
|
|
disk6_eject(!driveA);
|
2015-08-22 21:16:56 +00:00
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeSaveState(JNIEnv *env, jclass cls, jstring jPath) {
|
2015-11-23 03:04:46 +00:00
|
|
|
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
|
|
|
|
2015-12-20 06:57:08 +00:00
|
|
|
assert(cpu_isPaused() && "considered dangerous to save state when CPU thread is running");
|
2015-11-23 03:04:46 +00:00
|
|
|
|
|
|
|
LOG(": (%s)", path);
|
|
|
|
if (!emulator_saveState(path)) {
|
|
|
|
LOG("OOPS, could not save emulator state");
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
|
|
|
}
|
|
|
|
|
2015-12-20 20:53:17 +00:00
|
|
|
jstring Java_org_deadc0de_apple2ix_Apple2Activity_nativeLoadState(JNIEnv *env, jclass cls, jstring jPath) {
|
2015-11-23 03:04:46 +00:00
|
|
|
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
|
|
|
|
2015-12-20 06:57:08 +00:00
|
|
|
assert(cpu_isPaused() && "considered dangerous to save state when CPU thread is running");
|
2015-11-23 03:04:46 +00:00
|
|
|
|
|
|
|
LOG(": (%s)", path);
|
|
|
|
if (!emulator_loadState(path)) {
|
|
|
|
LOG("OOPS, could not load emulator state");
|
|
|
|
}
|
|
|
|
|
|
|
|
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
2015-12-12 19:42:33 +00:00
|
|
|
|
|
|
|
// restoring state may cause a change in disk paths, so we need to notify the Java/Android menu system of the change
|
|
|
|
// (normally we drive state from the Java/menu side...)
|
|
|
|
char *disk1 = disk6.disk[0].file_name;
|
|
|
|
bool readOnly1 = disk6.disk[0].is_protected;
|
|
|
|
char *disk2 = disk6.disk[1].file_name;
|
|
|
|
bool readOnly2 = disk6.disk[1].is_protected;
|
|
|
|
char *str = NULL;
|
|
|
|
jstring jstr = NULL;
|
|
|
|
asprintf(&str, "{ disk1 = \"%s\"; readOnly1 = %s; disk2 = \"%s\"; readOnly2 = %s }", (disk1 ?: ""), readOnly1 ? "true" : "false", (disk2 ?: ""), readOnly2 ? "true" : "false");
|
|
|
|
if (str) {
|
|
|
|
jstr = (*env)->NewStringUTF(env, str);
|
2015-12-31 06:16:57 +00:00
|
|
|
ASPRINTF_FREE(str);
|
2015-12-12 19:42:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return jstr;
|
2015-11-23 03:04:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-27 01:40:05 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Constructor
|
|
|
|
|
|
|
|
__attribute__((constructor(CTOR_PRIORITY_LATE)))
|
|
|
|
static void _init_jnihooks(void) {
|
2015-11-01 21:43:09 +00:00
|
|
|
// ...
|
2015-04-27 01:40:05 +00:00
|
|
|
}
|
|
|
|
|