Improve snapshop saving and loading
This commit is contained in:
@@ -51,6 +51,12 @@ static volatile int g_pending_reset = 0;
|
|||||||
static char g_pending_save_state[512];
|
static char g_pending_save_state[512];
|
||||||
static char g_pending_load_state[512];
|
static char g_pending_load_state[512];
|
||||||
|
|
||||||
|
/* Path of the disk image most recently placed in drive 8.
|
||||||
|
* After machine_read_snapshot the virtual device loses track of the attached
|
||||||
|
* D64 and falls back to host-filesystem mode. Re-attaching this path
|
||||||
|
* immediately after a successful snapshot load restores D64 access. */
|
||||||
|
static char g_current_disk_path[512] = {0};
|
||||||
|
|
||||||
/* =========================================================================
|
/* =========================================================================
|
||||||
* VICE integration (compiled only when libvice.a is linked in)
|
* VICE integration (compiled only when libvice.a is linked in)
|
||||||
* ========================================================================= */
|
* ========================================================================= */
|
||||||
@@ -392,11 +398,14 @@ void video_canvas_refresh(video_canvas_t *canvas,
|
|||||||
if (g_pending_disk[0] != '\0') { strncpy(autostart_path, g_pending_disk, sizeof(autostart_path)-1); g_pending_disk[0] = '\0'; }
|
if (g_pending_disk[0] != '\0') { strncpy(autostart_path, g_pending_disk, sizeof(autostart_path)-1); g_pending_disk[0] = '\0'; }
|
||||||
if (g_pending_attach[0] != '\0') { strncpy(attach_path, g_pending_attach, sizeof(attach_path)-1); g_pending_attach[0] = '\0'; }
|
if (g_pending_attach[0] != '\0') { strncpy(attach_path, g_pending_attach, sizeof(attach_path)-1); g_pending_attach[0] = '\0'; }
|
||||||
pthread_mutex_unlock(&g_pending_lock);
|
pthread_mutex_unlock(&g_pending_lock);
|
||||||
if (autostart_path[0] != '\0')
|
if (autostart_path[0] != '\0') {
|
||||||
autostart_disk(8, 0, autostart_path, NULL, 0, AUTOSTART_MODE_RUN);
|
autostart_disk(8, 0, autostart_path, NULL, 0, AUTOSTART_MODE_RUN);
|
||||||
|
strncpy(g_current_disk_path, autostart_path, sizeof(g_current_disk_path) - 1);
|
||||||
|
}
|
||||||
if (attach_path[0] != '\0') {
|
if (attach_path[0] != '\0') {
|
||||||
int r = file_system_attach_disk(8, 0, attach_path);
|
int r = file_system_attach_disk(8, 0, attach_path);
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
|
strncpy(g_current_disk_path, attach_path, sizeof(g_current_disk_path) - 1);
|
||||||
g_load_frames = 0; /* clear old cooldown; new autostart will set a fresh one */
|
g_load_frames = 0; /* clear old cooldown; new autostart will set a fresh one */
|
||||||
g_attach_frames = 75; /* show LED for ~1.5 s immediately after hot-swap */
|
g_attach_frames = 75; /* show LED for ~1.5 s immediately after hot-swap */
|
||||||
}
|
}
|
||||||
@@ -416,12 +425,19 @@ void video_canvas_refresh(video_canvas_t *canvas,
|
|||||||
}
|
}
|
||||||
pthread_mutex_unlock(&g_pending_lock);
|
pthread_mutex_unlock(&g_pending_lock);
|
||||||
if (save_state_path[0] != '\0') {
|
if (save_state_path[0] != '\0') {
|
||||||
int r = machine_write_snapshot(save_state_path, 0, 1, 1);
|
/* save_roms=0, save_disks=0: disk management is handled by our UI;
|
||||||
|
* skipping the drive module avoids path-resolution failures on restore. */
|
||||||
|
int r = machine_write_snapshot(save_state_path, 0, 0, 0);
|
||||||
LOGI("machine_write_snapshot → %d", r);
|
LOGI("machine_write_snapshot → %d", r);
|
||||||
}
|
}
|
||||||
if (load_state_path[0] != '\0') {
|
if (load_state_path[0] != '\0') {
|
||||||
int r = machine_read_snapshot(load_state_path, 0);
|
int r = machine_read_snapshot(load_state_path, 0);
|
||||||
LOGI("machine_read_snapshot → %d", r);
|
LOGI("machine_read_snapshot → %d", r);
|
||||||
|
/* After snapshot restore the virtual device loses its D64 attachment
|
||||||
|
* and falls back to host-filesystem mode. Re-attach the same disk so
|
||||||
|
* the C64 program can continue reading from the image it expected. */
|
||||||
|
if (r == 0 && g_current_disk_path[0] != '\0')
|
||||||
|
file_system_attach_disk(8, 0, g_current_disk_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Drive LED.
|
/* Drive LED.
|
||||||
|
|||||||
Reference in New Issue
Block a user