Revert adding A2V3 format as it is unnecessary

- Re-gzipping ejected images is based solely on the file extension and not the actual file stream contents
    - Read/write disk images with extension ".gz" are re-gzipped in-place upon ejection
    - Read/write disk images without extension ".gz" are not changed upon ejection
    - Read-only disk images maintain current behavior (no modifications performed at all)
This commit is contained in:
Aaron Culliney 2017-07-06 19:36:37 -10:00
parent f8b570869f
commit 55cba116e4
10 changed files with 23 additions and 83 deletions

View File

@ -119,17 +119,6 @@ public class Apple2DisksMenu implements Apple2MenuView {
return true;
}
},
CURRENT_DISK_PATH_A_GZ {
@Override
public String getPrefKey() {
return "driveAInsertedDiskGZ";
}
@Override
public Object getPrefDefault() {
return true;
}
},
CURRENT_DISK_PATH_B {
@Override
public String getPrefKey() {
@ -152,17 +141,6 @@ public class Apple2DisksMenu implements Apple2MenuView {
return true;
}
},
CURRENT_DISK_PATH_B_GZ {
@Override
public String getPrefKey() {
return "driveBInsertedDiskGZ";
}
@Override
public Object getPrefDefault() {
return true;
}
},
USE_NEWSCHOOL_DISK_SELECTION {
@Override
public String getPrefKey() {
@ -385,26 +363,21 @@ public class Apple2DisksMenu implements Apple2MenuView {
map.put("disk", imageName);
map.put("drive", isDriveA ? "0" : "1");
map.put("readOnly", isReadOnly ? "true" : "false");
if (onLaunch) {
boolean wasGzipped = (boolean) (isDriveA ? Apple2Preferences.getJSONPref(SETTINGS.CURRENT_DISK_PATH_A_GZ) : Apple2Preferences.getJSONPref(SETTINGS.CURRENT_DISK_PATH_B_GZ));
map.put("wasGzipped", wasGzipped ? "true" : "false");
}
String jsonString = nativeChooseDisk(map.toString());
try {
diskArgs.pfd.close(); // at this point diskArgs.pfd !null
} catch (IOException ioe) {
Log.e(TAG, "Error attempting to close PFD : " + ioe);
if (diskArgs.pfd != null) {
try {
diskArgs.pfd.close();
} catch (IOException ioe) {
Log.e(TAG, "Error attempting to close PFD : " + ioe);
}
}
diskArgs.pfd = null;
map = new JSONObject(jsonString);
boolean inserted = map.getBoolean("inserted");
if (inserted) {
boolean wasGzipped = map.getBoolean("wasGzipped");
Apple2Preferences.setJSONPref(isDriveA ? Apple2DisksMenu.SETTINGS.CURRENT_DISK_PATH_A_GZ : Apple2DisksMenu.SETTINGS.CURRENT_DISK_PATH_B_GZ, wasGzipped);
} else {
if (!inserted) {
ejectDisk(isDriveA);
}

View File

@ -415,15 +415,6 @@ public class Apple2MainMenu {
}
map = new JSONObject(jsonString);
{
boolean wasGzippedA = map.getBoolean("wasGzippedA");
Apple2Preferences.setJSONPref(Apple2DisksMenu.SETTINGS.CURRENT_DISK_PATH_A_GZ, wasGzippedA);
}
{
boolean wasGzippedB = map.getBoolean("wasGzippedB");
Apple2Preferences.setJSONPref(Apple2DisksMenu.SETTINGS.CURRENT_DISK_PATH_B_GZ, wasGzippedB);
}
restored = map.getBoolean("loadStateSuccess");
} catch (Throwable t) {

View File

@ -410,16 +410,8 @@ jstring Java_org_deadc0de_apple2ix_Apple2DisksMenu_nativeChooseDisk(JNIEnv *env,
inserted = false;
} else {
video_animations->animation_showDiskChosen(drive);
// possibly override was_gzipped, if specified in args ...
bool wasGzipped = false;
if (json_mapParseBoolValue(jsonData, "wasGzipped", &wasGzipped)) {
disk6.disk[drive].was_gzipped = wasGzipped;
}
}
// remember if image was gzipped
prefs_setBoolValue(PREF_DOMAIN_VM, drive == 0 ? PREF_DISK_DRIVEA_GZ : PREF_DISK_DRIVEB_GZ, disk6.disk[drive].was_gzipped); // HACK FIXME TODO ... refactor : this is erased on the Java side when we resume emulation
json_mapSetBoolValue(jsonData, "wasGzipped", disk6.disk[drive].was_gzipped);
json_mapSetBoolValue(jsonData, "inserted", inserted);
if (fd >= 0) {
@ -543,10 +535,7 @@ jstring Java_org_deadc0de_apple2ix_Apple2Activity_nativeLoadState(JNIEnv *env, j
}
bool loadStateSuccess = true;
if (emulator_loadState(fdState, (int)fdA, (int)fdB)) {
json_mapSetBoolValue(jsonData, "wasGzippedA", disk6.disk[0].was_gzipped);
json_mapSetBoolValue(jsonData, "wasGzippedB", disk6.disk[1].was_gzipped);
} else {
if (!emulator_loadState(fdState, (int)fdA, (int)fdB)) {
loadStateSuccess = false;
LOG("OOPS, could not load emulator state");
// FIXME TODO : should show invalid state animation here ...

View File

@ -798,7 +798,7 @@ const char *disk6_eject(int drive) {
int ret = -1;
off_t compressed_size = -1;
if (disk6.disk[drive].was_gzipped) {
if (is_gz(disk6.disk[drive].file_name)) {
// backup uncompressed data ...
uint8_t *compressed_data = drive == 0 ? &disk_a_raw[0] : &disk_b_raw[0];
@ -855,7 +855,6 @@ const char *disk6_eject(int drive) {
disk6.disk[drive].nib_image_data = NULL;
disk6.disk[drive].nibblized = false;
disk6.disk[drive].is_protected = false;
disk6.disk[drive].was_gzipped = false;
disk6.disk[drive].track_valid = false;
disk6.disk[drive].track_dirty = false;
disk6.disk[drive].skew_table = NULL;
@ -921,7 +920,8 @@ const char *disk6_insert(int fd, int drive, const char * const file_name, int re
}
disk6.disk[drive].fd = fd;
err = zlib_inflate_inplace(disk6.disk[drive].fd, expected, &(disk6.disk[drive].was_gzipped));
bool file_actually_was_gzipped; // but we don't care ...
err = zlib_inflate_inplace(disk6.disk[drive].fd, expected, &file_actually_was_gzipped);
if (err) {
ERRLOG("OOPS, An error occurred when attempting to inflate/load a disk image [%s] : [%s]", file_name, err);
break;
@ -1091,7 +1091,7 @@ bool disk6_saveState(StateHelper_s *helper) {
}
LOG("SAVE stepper_phases[%lu] = %02x", i, stepper_phases);
state = disk6.disk[i].was_gzipped;
state = 0; // placeholder ...
if (!helper->save(fd, &state, 1)) {
break;
}
@ -1227,16 +1227,10 @@ static bool _disk6_loadState(StateHelper_s *helper, JSON_ref json) {
stepper_phases = state & 0x3; // HACK NOTE : this is unnecessarily encoded twice ...
}
// format A2V3+ : was_gzipped, (otherwise placeholder)
// placeholder ...
if (!helper->load(fd, &state, 1)) {
break;
}
if (helper->version >= 3) {
disk6.disk[i].was_gzipped = (state != 0);
// remember if image was gzipped
prefs_setBoolValue(PREF_DOMAIN_VM, i == 0 ? PREF_DISK_DRIVEA_GZ : PREF_DISK_DRIVEB_GZ, disk6.disk[i].was_gzipped);
}
if (!helper->load(fd, &state, 1)) {
break;

View File

@ -62,7 +62,6 @@ typedef struct diskette_t {
long track_width;
int phase;
int run_byte;
bool was_gzipped;
} diskette_t;
typedef struct drive_t {

View File

@ -17,8 +17,7 @@
#define SAVE_MAGICK "A2VM"
#define SAVE_MAGICK2 "A2V2"
#define SAVE_MAGICK3 "A2V3"
#define SAVE_VERSION 3
#define SAVE_VERSION 2
#define SAVE_MAGICK_LEN sizeof(SAVE_MAGICK)
typedef struct module_ctor_node_s {
@ -113,9 +112,7 @@ static int _load_magick(int fd) {
// check header
if (memcmp(magick, SAVE_MAGICK3, SAVE_MAGICK_LEN) == 0) {
return 3;
} else if (memcmp(magick, SAVE_MAGICK2, SAVE_MAGICK_LEN) == 0) {
if (memcmp(magick, SAVE_MAGICK2, SAVE_MAGICK_LEN) == 0) {
return 2;
} else if (memcmp(magick, SAVE_MAGICK, SAVE_MAGICK_LEN) == 0) {
return 1;
@ -134,7 +131,7 @@ bool emulator_saveState(int fd) {
do {
// save header
if (!_save_state(fd, (const uint8_t *)SAVE_MAGICK3, SAVE_MAGICK_LEN)) {
if (!_save_state(fd, (const uint8_t *)SAVE_MAGICK2, SAVE_MAGICK_LEN)) {
break;
}

View File

@ -86,8 +86,6 @@
// vm
#define PREF_CPU_SCALE "cpuScale"
#define PREF_CPU_SCALE_ALT "cpuScaleAlt"
#define PREF_DISK_DRIVEA_GZ "driveAInsertedDiskGZ"
#define PREF_DISK_DRIVEB_GZ "driveBInsertedDiskGZ"
typedef void (*prefs_change_callback_f)(const char * _NONNULL domain);

View File

@ -1,5 +1,5 @@
unsigned char data[] = {
0x41, 0x32, 0x56, 0x33, 0x00, 0x01, 0x01, 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00, 0x7a, 0x61, 0x70,
0x41, 0x32, 0x56, 0x32, 0x00, 0x01, 0x01, 0x00, 0xaa, 0x01, 0x00, 0x00, 0x00, 0x7a, 0x61, 0x70,
0x70, 0x6c, 0x65, 0x32, 0x69, 0x78, 0x3a, 0x2f, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
0x3a, 0x2f, 0x2f, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x2e, 0x65,
0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x2e, 0x64,

View File

@ -453,7 +453,7 @@ TEST test_load_A2V2_good2() {
const char *homedir = HOMEDIR;
char *savData = NULL;
ASPRINTF(&savData, "%s/a2_emul_a2v2.dat", homedir);
ASPRINTF(&savData, "%s/a2_emul_a2v2-2.dat", homedir);
if (savData) {
unlink(savData);
}
@ -564,7 +564,7 @@ TEST test_load_A2V2_good2() {
PASS();
}
TEST test_load_A2V3_good1() {
TEST test_load_A2V2_good3() {
// ensure stable test
disk6_eject(0);
@ -575,11 +575,11 @@ TEST test_load_A2V3_good1() {
// write saved state to disk
#include "test/a2v3-good1.h"
#include "test/a2v2-good3.h"
const char *homedir = HOMEDIR;
char *savData = NULL;
ASPRINTF(&savData, "%s/a2_emul_a2v3.dat", homedir);
ASPRINTF(&savData, "%s/a2_emul_a2v2-3.dat", homedir);
if (savData) {
unlink(savData);
}
@ -672,7 +672,7 @@ TEST test_load_A2V3_good1() {
ASSERT(!alt_speed_enabled);
// Mockingboard ...
#include "test/a2v3-good1-mb.h"
#include "test/a2v2-good3-mb.h"
size_t mbSiz = sizeof(mbData);
mb_testAssertA2V2(mbData, mbSiz);
@ -707,8 +707,7 @@ GREATEST_SUITE(test_suite_ui) {
RUN_TESTp(test_load_A2V2_good1);
RUN_TESTp(test_load_A2V2_good2);
RUN_TESTp(test_load_A2V3_good1);
RUN_TESTp(test_load_A2V2_good3);
#if INTERFACE_TOUCH
# warning TODO : touch joystick(s), keyboard, mouse, menu