mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-12-27 06:29:19 +00:00
Refactor JNI plumbing for consistency
This commit is contained in:
parent
22b1bc9ad8
commit
145b6a6cef
@ -72,27 +72,27 @@ public class Apple2Activity extends Activity {
|
|||||||
|
|
||||||
public final static int REQUEST_PERMISSION_RWSTORE = 42;
|
public final static int REQUEST_PERMISSION_RWSTORE = 42;
|
||||||
|
|
||||||
private native void nativeOnCreate(String dataDir, int sampleRate, int monoBufferSize, int stereoBufferSize);
|
private static native void nativeOnCreate(String dataDir, int sampleRate, int monoBufferSize, int stereoBufferSize);
|
||||||
|
|
||||||
private static native void nativeOnKeyDown(int keyCode, int metaState);
|
private static native void nativeOnKeyDown(int keyCode, int metaState);
|
||||||
|
|
||||||
private static native void nativeOnKeyUp(int keyCode, int metaState);
|
private static native void nativeOnKeyUp(int keyCode, int metaState);
|
||||||
|
|
||||||
private native void nativeSaveState(String path);
|
private static native void nativeSaveState(String path);
|
||||||
|
|
||||||
private native String nativeLoadState(String path);
|
private static native String nativeLoadState(String path);
|
||||||
|
|
||||||
public native void nativeEmulationResume();
|
private static native void nativeEmulationResume();
|
||||||
|
|
||||||
public native void nativeEmulationPause();
|
private static native void nativeEmulationPause();
|
||||||
|
|
||||||
private native void nativeOnQuit();
|
private static native void nativeOnQuit();
|
||||||
|
|
||||||
private native void nativeReboot();
|
private static native void nativeReboot();
|
||||||
|
|
||||||
public native void nativeChooseDisk(String path, boolean driveA, boolean readOnly);
|
private static native void nativeChooseDisk(String path, boolean driveA, boolean readOnly);
|
||||||
|
|
||||||
public native void nativeEjectDisk(boolean driveA);
|
private static native void nativeEjectDisk(boolean driveA);
|
||||||
|
|
||||||
public final static boolean isNativeBarfed() {
|
public final static boolean isNativeBarfed() {
|
||||||
return sNativeBarfed;
|
return sNativeBarfed;
|
||||||
@ -516,12 +516,16 @@ public class Apple2Activity extends Activity {
|
|||||||
return mainMenuShowing || menusShowing;
|
return mainMenuShowing || menusShowing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void maybeResumeCPU() {
|
public void maybeResumeEmulation() {
|
||||||
if (mMenuStack.size() == 0 && !mPausing.get()) {
|
if (mMenuStack.size() == 0 && !mPausing.get()) {
|
||||||
nativeEmulationResume();
|
nativeEmulationResume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pauseEmulation() {
|
||||||
|
nativeEmulationPause();
|
||||||
|
}
|
||||||
|
|
||||||
public void maybeRebootQuit() {
|
public void maybeRebootQuit() {
|
||||||
nativeEmulationPause();
|
nativeEmulationPause();
|
||||||
|
|
||||||
@ -541,6 +545,14 @@ public class Apple2Activity extends Activity {
|
|||||||
registerAndShowDialog(rebootQuitDialog);
|
registerAndShowDialog(rebootQuitDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void chooseDisk(String path, boolean driveA, boolean readOnly) {
|
||||||
|
nativeChooseDisk(path, driveA, readOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ejectDisk(boolean driveA) {
|
||||||
|
nativeEjectDisk(driveA);
|
||||||
|
}
|
||||||
|
|
||||||
public void quitEmulator() {
|
public void quitEmulator() {
|
||||||
nativeOnQuit();
|
nativeOnQuit();
|
||||||
finish();
|
finish();
|
||||||
|
@ -562,7 +562,7 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
|||||||
ejectButton.setOnClickListener(new View.OnClickListener() {
|
ejectButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mActivity.nativeEjectDisk(/*driveA:*/true);
|
mActivity.ejectDisk(/*driveA:*/true);
|
||||||
Apple2Preferences.CURRENT_DISK_A.saveString(mActivity, "");
|
Apple2Preferences.CURRENT_DISK_A.saveString(mActivity, "");
|
||||||
dynamicSetup();
|
dynamicSetup();
|
||||||
}
|
}
|
||||||
@ -574,7 +574,7 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
|||||||
ejectButton.setOnClickListener(new View.OnClickListener() {
|
ejectButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
mActivity.nativeEjectDisk(/*driveA:*/false);
|
mActivity.ejectDisk(/*driveA:*/false);
|
||||||
Apple2Preferences.CURRENT_DISK_B.saveString(mActivity, "");
|
Apple2Preferences.CURRENT_DISK_B.saveString(mActivity, "");
|
||||||
dynamicSetup();
|
dynamicSetup();
|
||||||
}
|
}
|
||||||
@ -616,17 +616,16 @@ public class Apple2DisksMenu implements Apple2MenuView {
|
|||||||
final String imageName = str;
|
final String imageName = str;
|
||||||
|
|
||||||
if (imageName.equals(Apple2Preferences.CURRENT_DISK_A.stringValue(mActivity))) {
|
if (imageName.equals(Apple2Preferences.CURRENT_DISK_A.stringValue(mActivity))) {
|
||||||
mActivity.nativeEjectDisk(/*driveA:*/true);
|
mActivity.ejectDisk(/*driveA:*/true);
|
||||||
Apple2Preferences.CURRENT_DISK_A.saveString(mActivity, "");
|
Apple2Preferences.CURRENT_DISK_A.saveString(mActivity, "");
|
||||||
dynamicSetup();
|
dynamicSetup();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (imageName.equals(Apple2Preferences.CURRENT_DISK_B.stringValue(mActivity))) {
|
if (imageName.equals(Apple2Preferences.CURRENT_DISK_B.stringValue(mActivity))) {
|
||||||
mActivity.nativeEjectDisk(/*driveA:*/false);
|
mActivity.ejectDisk(/*driveA:*/false);
|
||||||
Apple2Preferences.CURRENT_DISK_B.saveString(mActivity, "");
|
Apple2Preferences.CURRENT_DISK_B.saveString(mActivity, "");
|
||||||
dynamicSetup();
|
dynamicSetup();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String title = mActivity.getResources().getString(R.string.header_disks);
|
String title = mActivity.getResources().getString(R.string.header_disks);
|
||||||
|
@ -198,7 +198,7 @@ public class Apple2MainMenu {
|
|||||||
mMainMenuPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
mMainMenuPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss() {
|
public void onDismiss() {
|
||||||
Apple2MainMenu.this.mActivity.maybeResumeCPU();
|
Apple2MainMenu.this.mActivity.maybeResumeEmulation();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ public class Apple2MainMenu {
|
|||||||
mShowingRebootQuit.set(false);
|
mShowingRebootQuit.set(false);
|
||||||
mShowingSaveRestore.set(false);
|
mShowingSaveRestore.set(false);
|
||||||
|
|
||||||
mActivity.nativeEmulationPause();
|
mActivity.pauseEmulation();
|
||||||
|
|
||||||
mMainMenuPopup.showAtLocation(mParentView, Gravity.CENTER, 0, 0);
|
mMainMenuPopup.showAtLocation(mParentView, Gravity.CENTER, 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -1034,7 +1034,7 @@ public enum Apple2Preferences {
|
|||||||
file = new File(fullPath);
|
file = new File(fullPath);
|
||||||
}
|
}
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
activity.nativeChooseDisk(fullPath, isDriveA, isReadOnly);
|
activity.chooseDisk(fullPath, isDriveA, isReadOnly);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Cannot insert: " + fullPath);
|
Log.d(TAG, "Cannot insert: " + fullPath);
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ class Apple2View extends GLSurfaceView implements InputManagerCompat.InputDevice
|
|||||||
Apple2View.this.mGraphicsInitializedRunnable = null;
|
Apple2View.this.mGraphicsInitializedRunnable = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Apple2View.this.mActivity.maybeResumeCPU();
|
Apple2View.this.mActivity.maybeResumeEmulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -143,7 +143,7 @@ static void discover_cpu_family(void) {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// JNI functions
|
// JNI functions
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobject obj, jstring j_dataDir, jint sampleRate, jint monoBufferSize, jint stereoBufferSize) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jclass cls, jstring j_dataDir, jint sampleRate, jint monoBufferSize, jint stereoBufferSize) {
|
||||||
const char *dataDir = (*env)->GetStringUTFChars(env, j_dataDir, 0);
|
const char *dataDir = (*env)->GetStringUTFChars(env, j_dataDir, 0);
|
||||||
|
|
||||||
// Android lifecycle can call onCreate() multiple times...
|
// Android lifecycle can call onCreate() multiple times...
|
||||||
@ -193,7 +193,7 @@ void Java_org_deadc0de_apple2ix_Apple2View_nativeGraphicsInitialized(JNIEnv *env
|
|||||||
video_backend->init((void *)0);
|
video_backend->init((void *)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationResume(JNIEnv *env, jobject obj) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationResume(JNIEnv *env, jclass cls) {
|
||||||
#if TESTING
|
#if TESTING
|
||||||
// test driver thread is managing CPU
|
// test driver thread is managing CPU
|
||||||
if (!running_tests) {
|
if (!running_tests) {
|
||||||
@ -210,7 +210,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationResume(JNIEnv *env
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationPause(JNIEnv *env, jobject obj) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEmulationPause(JNIEnv *env, jclass cls) {
|
||||||
if (appState != APP_RUNNING) {
|
if (appState != APP_RUNNING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -261,12 +261,12 @@ void Java_org_deadc0de_apple2ix_Apple2View_nativeRender(JNIEnv *env, jclass cls)
|
|||||||
video_backend->render();
|
video_backend->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeReboot(JNIEnv *env, jobject obj) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeReboot(JNIEnv *env, jclass cls) {
|
||||||
LOG("...");
|
LOG("...");
|
||||||
cpu65_reboot();
|
cpu65_reboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jobject obj) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnQuit(JNIEnv *env, jclass cls) {
|
||||||
#if TESTING
|
#if TESTING
|
||||||
// test driver thread is managing CPU
|
// test driver thread is managing CPU
|
||||||
#else
|
#else
|
||||||
@ -324,7 +324,7 @@ jlong Java_org_deadc0de_apple2ix_Apple2View_nativeOnTouch(JNIEnv *env, jclass cl
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, jobject obj, jstring jPath, jboolean driveA, jboolean readOnly) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, jclass cls, jstring jPath, jboolean driveA, jboolean readOnly) {
|
||||||
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
||||||
int drive = driveA ? 0 : 1;
|
int drive = driveA ? 0 : 1;
|
||||||
int ro = readOnly ? 1 : 0;
|
int ro = readOnly ? 1 : 0;
|
||||||
@ -349,12 +349,12 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeChooseDisk(JNIEnv *env, job
|
|||||||
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEjectDisk(JNIEnv *env, jobject obj, jboolean driveA) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeEjectDisk(JNIEnv *env, jclass cls, jboolean driveA) {
|
||||||
LOG("...");
|
LOG("...");
|
||||||
disk6_eject(!driveA);
|
disk6_eject(!driveA);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeSaveState(JNIEnv *env, jobject obj, jstring jPath) {
|
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeSaveState(JNIEnv *env, jclass cls, jstring jPath) {
|
||||||
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
||||||
|
|
||||||
assert(cpu_isPaused() && "considered dangerous to save state when CPU thread is running");
|
assert(cpu_isPaused() && "considered dangerous to save state when CPU thread is running");
|
||||||
@ -367,7 +367,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeSaveState(JNIEnv *env, jobj
|
|||||||
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
jstring Java_org_deadc0de_apple2ix_Apple2Activity_nativeLoadState(JNIEnv *env, jobject obj, jstring jPath) {
|
jstring Java_org_deadc0de_apple2ix_Apple2Activity_nativeLoadState(JNIEnv *env, jclass cls, jstring jPath) {
|
||||||
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
||||||
|
|
||||||
assert(cpu_isPaused() && "considered dangerous to save state when CPU thread is running");
|
assert(cpu_isPaused() && "considered dangerous to save state when CPU thread is running");
|
||||||
|
Loading…
Reference in New Issue
Block a user