mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-12-26 15:29:19 +00:00
Shunt disk-state-change information back to the Java/Android menu system
This commit is contained in:
parent
edf42b81f9
commit
cdb0f7b06b
@ -35,6 +35,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.deadc0de.apple2ix.basic.BuildConfig;
|
||||
import org.deadc0de.apple2ix.basic.R;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class Apple2Activity extends Activity {
|
||||
|
||||
@ -97,7 +99,7 @@ public class Apple2Activity extends Activity {
|
||||
|
||||
private native void nativeSaveState(String path);
|
||||
|
||||
private native void nativeLoadState(String path);
|
||||
private native String nativeLoadState(String path);
|
||||
|
||||
public native void nativeEmulationResume();
|
||||
|
||||
@ -621,7 +623,22 @@ public class Apple2Activity extends Activity {
|
||||
}).setNeutralButton(R.string.restore, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Apple2Activity.this.nativeLoadState(quickSavePath);
|
||||
// loading state can change the disk inserted ... reflect that in
|
||||
String jsonData = Apple2Activity.this.nativeLoadState(quickSavePath);
|
||||
try {
|
||||
JSONObject map = new JSONObject(jsonData);
|
||||
String diskPath1 = map.getString("disk1");
|
||||
boolean readOnly1 = map.getBoolean("readOnly1");
|
||||
Apple2Preferences.CURRENT_DISK_A.setPath(Apple2Activity.this, diskPath1);
|
||||
Apple2Preferences.CURRENT_DISK_A_RO.saveBoolean(Apple2Activity.this, readOnly1);
|
||||
|
||||
String diskPath2 = map.getString("disk2");
|
||||
boolean readOnly2 = map.getBoolean("readOnly2");
|
||||
Apple2Preferences.CURRENT_DISK_B.setPath(Apple2Activity.this, diskPath2);
|
||||
Apple2Preferences.CURRENT_DISK_B_RO.saveBoolean(Apple2Activity.this, readOnly2);
|
||||
} catch (JSONException je) {
|
||||
Log.v(TAG, "OOPS : "+je);
|
||||
}
|
||||
Apple2Activity.this.mMainMenu.dismiss();
|
||||
}
|
||||
}).setNegativeButton(R.string.cancel, null).create();
|
||||
|
@ -99,6 +99,11 @@ public enum Apple2Preferences {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putString(toString(), str).apply();
|
||||
load(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPath(Apple2Activity activity, String str) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putString(toString(), str).apply();
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_A_RO {
|
||||
@Override
|
||||
@ -133,6 +138,11 @@ public enum Apple2Preferences {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putString(toString(), str).apply();
|
||||
load(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPath(Apple2Activity activity, String str) {
|
||||
activity.getPreferences(Context.MODE_PRIVATE).edit().putString(toString(), str).apply();
|
||||
}
|
||||
},
|
||||
CURRENT_DISK_B_RO {
|
||||
@Override
|
||||
@ -895,6 +905,10 @@ public enum Apple2Preferences {
|
||||
load(activity);
|
||||
}
|
||||
|
||||
public void setPath(Apple2Activity activity, String path) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// accessors
|
||||
|
||||
public boolean booleanValue(Apple2Activity activity) {
|
||||
|
@ -359,7 +359,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeSaveState(JNIEnv *env, jobj
|
||||
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
||||
}
|
||||
|
||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeLoadState(JNIEnv *env, jobject obj, jstring jPath) {
|
||||
jstring Java_org_deadc0de_apple2ix_Apple2Activity_nativeLoadState(JNIEnv *env, jobject obj, jstring jPath) {
|
||||
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
|
||||
|
||||
assert(cpu_isPaused() && "considered dangerous to save state CPU thread is running");
|
||||
@ -370,6 +370,22 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeLoadState(JNIEnv *env, jobj
|
||||
}
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jPath, path);
|
||||
|
||||
// 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);
|
||||
FREE(str);
|
||||
}
|
||||
|
||||
return jstr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user