diff --git a/Android/jni/Application.mk b/Android/jni/Application.mk index f61cc566..2885d25d 100644 --- a/Android/jni/Application.mk +++ b/Android/jni/Application.mk @@ -1 +1,2 @@ APP_ABI := armeabi armeabi-v7a ## TODO : x86 +APP_PLATFORM := android-23 diff --git a/Android/jni/apple2ix.mk b/Android/jni/apple2ix.mk index cacea6a0..05014fdd 100644 --- a/Android/jni/apple2ix.mk +++ b/Android/jni/apple2ix.mk @@ -11,10 +11,10 @@ include $(COMMON_SOURCES_MK) # Android build config LOCAL_MODULE := libapple2ix -LOCAL_SRC_FILES := jniprefs.c androidkeys.c +LOCAL_SRC_FILES := #LOCAL_ARM_MODE := arm LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz -lOpenSLES +LOCAL_LDLIBS := $(APPLE2_BASE_LDLIBS) # Add assembly files first ... mostly for the benefit of the ARM assembler ... ifeq ($(TARGET_ARCH_ABI),x86) diff --git a/Android/jni/build.sh b/Android/jni/build.sh index 1c1b085c..2b7cc5a0 100755 --- a/Android/jni/build.sh +++ b/Android/jni/build.sh @@ -3,24 +3,31 @@ package_id="org.deadc0de.apple2ix.basic" apple2_src_path=apple2ix-src glue_srcs="$apple2_src_path/disk.c $apple2_src_path/misc.c $apple2_src_path/display.c $apple2_src_path/vm.c $apple2_src_path/cpu-supp.c $apple2_src_path/audio/speaker.c $apple2_src_path/audio/mockingboard.c" -do_load=0 +do_load=1 do_debug=0 +target_arch=armeabi-v7a usage() { - echo "$0 [--load|--debug]" + echo "$0 [--no-load] [--debug] [--armeabi | --armeabi-v7a]" exit 0 } while test "x$1" != "x"; do case "$1" in "--debug") - do_load=1 do_debug=1 ;; - "--load") - do_load=1 - do_debug=0 + "--no-load") + do_load=0 + ;; + + "--armeabi") + target_arch=armeabi + ;; + + "--v7a") + target_arch=armeabi-v7a ;; "-h") @@ -40,9 +47,8 @@ done set -x -/bin/rm Android.mk - if test "$(basename $0)" = "clean" ; then + /bin/rm $apple2_src_path/rom.c /bin/rm $apple2_src_path/font.c /bin/rm $apple2_src_path/x86/glue.S @@ -54,16 +60,22 @@ if test "$(basename $0)" = "clean" ; then /bin/rm -rf ../gen /bin/rm -rf ../obj + ndk-build clean + ##cd .. + ##ant clean + exit 0 fi +/bin/rm Android.mk + if test "$(basename $0)" = "uninstall" ; then adb uninstall $package_id exit 0 fi -#CC=`which clang` -CC=`which gcc` +CC=`which clang` +#CC=`which gcc` CFLAGS="-std=gnu11" # ROMz @@ -90,19 +102,31 @@ else ln -s apple2ix.mk Android.mk fi -ndk-build V=1 NDK_DEBUG=1 #NDK_TOOLCHAIN_VERSION=clang -#ndk-build V=1 NDK_DEBUG=1 && \ -# ant -f ../build.xml debug +# build native sources +ndk-build V=1 NDK_DEBUG=1 NDK_TOOLCHAIN_VERSION=clang +ret=$? +if test "x$ret" != "x0" ; then + exit $ret +fi -#if test "x$do_load" = "x1" ; then -# ant -f ../build.xml debug install -#fi -# -#if test "x$do_debug" = "x1" ; then -# ( cd .. && ndk-gdb.py --force --start ) -#elif test "x$do_load" = "x1" ; then -# adb shell am start -a android.intent.action.MAIN -n $package_id/.Apple2Activity -#fi +if test "x$do_load" = "x1" ; then + ant -f ../build.xml debug install + ret=$? + if test "x$ret" != "x0" ; then + exit $ret + fi +fi + +if test "x$do_debug" = "x1" ; then + cd .. + /bin/rm ./libs/gdbserver + /bin/ln -s $target_arch/gdbserver libs/gdbserver + ##/bin/rm ./libs/gdb.setup + ##/bin/ln -s $target_arch/gdb.setup libs/gdb.setup + ndk-gdb --verbose --force --launch=org.deadc0de.apple2ix.Apple2Activity +elif test "x$do_load" = "x1" ; then + adb shell am start -a android.intent.action.MAIN -n org.deadc0de.apple2ix.basic/org.deadc0de.apple2ix.Apple2Activity +fi set +x diff --git a/Android/jni/jnihooks.c b/Android/jni/jnihooks.c index 90dc08a4..b09e52f6 100644 --- a/Android/jni/jnihooks.c +++ b/Android/jni/jnihooks.c @@ -31,7 +31,7 @@ enum { }; #if TESTING -static bool _run_tests(void) { +static void _run_tests(void) { char *local_argv[] = { "-f", NULL @@ -41,8 +41,10 @@ static bool _run_tests(void) { ++local_argc; } #if defined(TEST_CPU) + // Currently this test is the only one that runs as a black screen extern int test_cpu(int, char *[]); test_cpu(local_argc, local_argv); + tkill(getpid(), SIGKILL); // and we're done ... #elif defined(TEST_VM) extern int test_vm(int, char *[]); test_vm(local_argc, local_argv); @@ -128,7 +130,9 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje android_stereoBufferSubmitSizeSamples = (unsigned long)stereoBufferSize; #if TESTING + assert(cpu_thread_id == 0 && "CPU thread must not be initialized yet..."); _run_tests(); + // CPU thread is started from testsuite (if needed) #else timing_startCPU(); #endif @@ -158,7 +162,11 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnResume(JNIEnv *env, jobje } LOG("%s", ""); if (!isSystemResume) { +#if TESTING + // test driver thread is managing CPU +#else cpu_resume(); +#endif } } @@ -170,6 +178,9 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobjec video_backend->animation_hideTouchMenu(); +#if TESTING + // test driver thread is managing CPU +#else if (isSystemPause) { // going to background cpu_pauseBackground(); @@ -177,6 +188,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobjec // going to menu cpu_pause(); } +#endif } void Java_org_deadc0de_apple2ix_Apple2Activity_nativeRender(JNIEnv *env, jobject obj) { @@ -214,6 +226,9 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeReboot(JNIEnv *env, jobject } void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject obj) { +#if TESTING + // test driver thread is managing CPU +#else LOG("%s", ""); c_eject_6(0); @@ -226,6 +241,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject if (pthread_join(cpu_thread_id, NULL)) { ERRLOG("OOPS: pthread_join of CPU thread ..."); } +#endif } #define _JAVA_CRASH_NAME "/jcrash.txt" @@ -265,15 +281,11 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnUncaughtException(JNIEnv } void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyDown(JNIEnv *env, jobject obj, jint keyCode, jint metaState) { -#if !TESTING android_keycode_to_emulator(keyCode, metaState, true); -#endif } void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnKeyUp(JNIEnv *env, jobject obj, jint keyCode, jint metaState) { -#if !TESTING android_keycode_to_emulator(keyCode, metaState, false); -#endif } jlong Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnTouch(JNIEnv *env, jobject obj, jint action, jint pointerCount, jint pointerIndex, jfloatArray xCoords, jfloatArray yCoords) { diff --git a/Android/jni/jniprefs.c b/Android/jni/jniprefs.c index 21b4955c..03a7e475 100644 --- a/Android/jni/jniprefs.c +++ b/Android/jni/jniprefs.c @@ -22,6 +22,9 @@ typedef enum AndroidTouchJoystickButtonValues { void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetColor(JNIEnv *env, jclass cls, jint color) { LOG("color : %d", color); +#if TESTING + color_mode = COLOR; +#else if (color < COLOR_NONE || color > COLOR_INTERP) { return; } @@ -30,6 +33,7 @@ void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetColor(JNIEnv *env, jc video_reset(); video_setpage(!!(softswitches & SS_SCREEN)); video_redraw(); +#endif } jboolean Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetSpeakerEnabled(JNIEnv *env, jclass cls, jboolean enabled) { @@ -261,6 +265,11 @@ jint Java_org_deadc0de_apple2ix_Apple2Preferences_nativeGetCPUSpeed(JNIEnv *env, void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetCPUSpeed(JNIEnv *env, jclass cls, jint percentSpeed) { LOG("percentSpeed : %d%%", percentSpeed); +#if TESTING + cpu_scale_factor = CPU_SCALE_FASTEST; + cpu_altscale_factor = CPU_SCALE_FASTEST; + timing_initialize(); +#else bool wasPaused = cpu_isPaused(); if (!wasPaused) { @@ -284,6 +293,7 @@ void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetCPUSpeed(JNIEnv *env, if (!wasPaused) { cpu_resume(); } +#endif } void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeLoadTouchKeyboardJSON(JNIEnv *env, jclass cls, jstring j_jsonPath) { diff --git a/Android/jni/sources.mk b/Android/jni/sources.mk index 06bead5b..c7b6433d 100644 --- a/Android/jni/sources.mk +++ b/Android/jni/sources.mk @@ -30,16 +30,17 @@ APPLE2_AUDIO_SRC = \ APPLE2_META_SRC = \ $(APPLE2_SRC_PATH)/meta/debug.c $(APPLE2_SRC_PATH)/meta/debugger.c $(APPLE2_SRC_PATH)/meta/opcodes.c \ - $(APPLE2_SRC_PATH)/test/sha1.c + $(APPLE2_SRC_PATH)/test/sha1.c $(APPLE2_SRC_PATH)/json_parse.c $(APPLE2_SRC_PATH)/../externals/jsmn/jsmn.c APPLE2_MAIN_SRC = \ $(APPLE2_SRC_PATH)/font.c $(APPLE2_SRC_PATH)/rom.c $(APPLE2_SRC_PATH)/misc.c $(APPLE2_SRC_PATH)/display.c $(APPLE2_SRC_PATH)/vm.c \ $(APPLE2_SRC_PATH)/timing.c $(APPLE2_SRC_PATH)/zlib-helpers.c $(APPLE2_SRC_PATH)/joystick.c $(APPLE2_SRC_PATH)/keys.c \ - $(APPLE2_SRC_PATH)/interface.c $(APPLE2_SRC_PATH)/disk.c $(APPLE2_SRC_PATH)/cpu-supp.c jnihooks.c \ - $(APPLE2_SRC_PATH)/json_parse.c $(APPLE2_SRC_PATH)/../externals/jsmn/jsmn.c + $(APPLE2_SRC_PATH)/interface.c $(APPLE2_SRC_PATH)/disk.c $(APPLE2_SRC_PATH)/cpu-supp.c \ + jnihooks.c jniprefs.c androidkeys.c APPLE2_OPTIM_CFLAGS := -g -O2 APPLE2_BASE_CFLAGS := -DAPPLE2IX=1 -DINTERFACE_TOUCH=1 -DMOBILE_DEVICE=1 -DVIDEO_OPENGL=1 -DDEBUGGER=1 -DAUDIO_ENABLED=1 -std=gnu11 $(APPLE2_OPTIM_CFLAGS) -I$(APPLE2_SRC_PATH) +APPLE2_BASE_LDLIBS := -llog -landroid -lGLESv2 -lz -lOpenSLES LOCAL_WHOLE_STATIC_LIBRARIES += cpufeatures diff --git a/Android/jni/testcpu.mk b/Android/jni/testcpu.mk index 11ae70f2..507c56a7 100644 --- a/Android/jni/testcpu.mk +++ b/Android/jni/testcpu.mk @@ -13,7 +13,7 @@ include $(COMMON_SOURCES_MK) LOCAL_MODULE := libapple2ix LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testcpu.c LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_CPU -DTESTING=1 -LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz +LOCAL_LDLIBS := $(APPLE2_BASE_LDLIBS) # Add assembly files first ... mostly for the benefit of the ARM assembler ... ifeq ($(TARGET_ARCH_ABI),x86) @@ -22,7 +22,7 @@ else LOCAL_SRC_FILES += $(APPLE2_ARM_SRC) endif -LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) +LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) $(APPLE2_AUDIO_SRC) # Build a shared library and let Java/Dalvik drive include $(BUILD_SHARED_LIBRARY) @@ -30,3 +30,4 @@ include $(BUILD_SHARED_LIBRARY) # --OR-- Build an executable so native can drive this show #include $(BUILD_EXECUTABLE) +$(call import-module, android/cpufeatures) diff --git a/Android/jni/testdisk.mk b/Android/jni/testdisk.mk index d70841d8..191ba9c3 100644 --- a/Android/jni/testdisk.mk +++ b/Android/jni/testdisk.mk @@ -12,8 +12,8 @@ include $(COMMON_SOURCES_MK) LOCAL_MODULE := libapple2ix LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testdisk.c -LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_DISK -DTESTING=1 -DCPU_TRACING=1 -DDISK_TRACING=1 -DVM_TRACING=1 -LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz +LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_DISK -DTESTING=1 -DDISK_TRACING=1 +LOCAL_LDLIBS := $(APPLE2_BASE_LDLIBS) # Add assembly files first ... mostly for the benefit of the ARM assembler ... ifeq ($(TARGET_ARCH_ABI),x86) @@ -22,7 +22,7 @@ else LOCAL_SRC_FILES += $(APPLE2_ARM_SRC) endif -LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) +LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) $(APPLE2_AUDIO_SRC) # Build a shared library and let Java/Dalvik drive include $(BUILD_SHARED_LIBRARY) @@ -30,3 +30,4 @@ include $(BUILD_SHARED_LIBRARY) # --OR-- Build an executable so native can drive this show #include $(BUILD_EXECUTABLE) +$(call import-module, android/cpufeatures) diff --git a/Android/jni/testdisplay.mk b/Android/jni/testdisplay.mk index d9de4d04..a58867a2 100644 --- a/Android/jni/testdisplay.mk +++ b/Android/jni/testdisplay.mk @@ -13,7 +13,7 @@ include $(COMMON_SOURCES_MK) LOCAL_MODULE := libapple2ix LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testdisplay.c LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_DISPLAY -DTESTING=1 -LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz +LOCAL_LDLIBS := $(APPLE2_BASE_LDLIBS) # Add assembly files first ... mostly for the benefit of the ARM assembler ... ifeq ($(TARGET_ARCH_ABI),x86) @@ -22,7 +22,7 @@ else LOCAL_SRC_FILES += $(APPLE2_ARM_SRC) endif -LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) +LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) $(APPLE2_AUDIO_SRC) # Build a shared library and let Java/Dalvik drive include $(BUILD_SHARED_LIBRARY) @@ -30,3 +30,4 @@ include $(BUILD_SHARED_LIBRARY) # --OR-- Build an executable so native can drive this show #include $(BUILD_EXECUTABLE) +$(call import-module, android/cpufeatures) diff --git a/Android/jni/testvm.mk b/Android/jni/testvm.mk index db897bb8..5dc4c282 100644 --- a/Android/jni/testvm.mk +++ b/Android/jni/testvm.mk @@ -12,8 +12,8 @@ include $(COMMON_SOURCES_MK) LOCAL_MODULE := libapple2ix LOCAL_SRC_FILES := $(APPLE2_SRC_PATH)/test/testcommon.c $(APPLE2_SRC_PATH)/test/testvm.c -LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_VM -DTESTING=1 -DCPU_TRACING=1 -DDISK_TRACING=1 -DVM_TRACING=1 -LOCAL_LDLIBS := -llog -landroid -lGLESv2 -lz +LOCAL_CFLAGS := $(APPLE2_BASE_CFLAGS) -DTEST_VM -DTESTING=1 +LOCAL_LDLIBS := $(APPLE2_BASE_LDLIBS) # Add assembly files first ... mostly for the benefit of the ARM assembler ... ifeq ($(TARGET_ARCH_ABI),x86) @@ -22,7 +22,7 @@ else LOCAL_SRC_FILES += $(APPLE2_ARM_SRC) endif -LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) +LOCAL_SRC_FILES += $(APPLE2_MAIN_SRC) $(APPLE2_META_SRC) $(APPLE2_VIDEO_SRC) $(APPLE2_AUDIO_SRC) # Build a shared library and let Java/Dalvik drive include $(BUILD_SHARED_LIBRARY) @@ -30,3 +30,4 @@ include $(BUILD_SHARED_LIBRARY) # --OR-- Build an executable so native can drive this show #include $(BUILD_EXECUTABLE) +$(call import-module, android/cpufeatures)