1 /*
2 * menu_snapshot.c - Implementation of the snapshot settings menu for the SDL UI.
3 *
4 * Written by
5 * Marco van den Heuvel <blackystardust68@yahoo.com>
6 *
7 * This file is part of VICE, the Versatile Commodore Emulator.
8 * See README for copyright notice.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307 USA.
24 *
25 */
26
27 #include "vice.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "archdep.h"
34 #include "lib.h"
35 #include "machine.h"
36 #include "menu_common.h"
37 #include "menu_snapshot.h"
38 #include "resources.h"
39 #include "snapshot.h"
40 #include "ui.h"
41 #include "uifilereq.h"
42 #include "uimenu.h"
43 #include "util.h"
44 #include "vice-event.h"
45
46 static int save_disks = 1;
47 static int save_roms = 0;
48
49 UI_MENU_DEFINE_RADIO(EventStartMode)
50
UI_MENU_CALLBACK(toggle_save_disk_images_callback)51 static UI_MENU_CALLBACK(toggle_save_disk_images_callback)
52 {
53 if (activated) {
54 save_disks = !save_disks;
55 } else {
56 if (save_disks) {
57 return sdl_menu_text_tick;
58 }
59 }
60 return NULL;
61 }
62
UI_MENU_CALLBACK(toggle_save_rom_images_callback)63 static UI_MENU_CALLBACK(toggle_save_rom_images_callback)
64 {
65 if (activated) {
66 save_roms = !save_roms;
67 } else {
68 if (save_roms) {
69 return sdl_menu_text_tick;
70 }
71 }
72 return NULL;
73 }
74
UI_MENU_CALLBACK(save_snapshot_callback)75 static UI_MENU_CALLBACK(save_snapshot_callback)
76 {
77 char *name;
78
79 if (activated) {
80 name = sdl_ui_file_selection_dialog("Choose snapshot file to save", FILEREQ_MODE_SAVE_FILE);
81 if (name != NULL) {
82 util_add_extension(&name, "vsf");
83 if (machine_write_snapshot(name, save_roms, save_disks, 0) < 0) {
84 snapshot_display_error();
85 }
86 lib_free(name);
87 }
88 }
89 return NULL;
90 }
91
92 #if 0
93 /* FIXME */
94 static UI_MENU_CALLBACK(save_snapshot_slot_callback)
95 {
96 char *name;
97
98 if (activated) {
99 name = sdl_ui_slot_selection_dialog("Choose snapshot slot to save", SLOTREQ_MODE_SAVE_SLOT);
100 if (name != NULL) {
101 util_add_extension(&name, "vsf");
102 if (machine_write_snapshot(name, save_roms, save_disks, 0) < 0) {
103 snapshot_display_error();
104 }
105 lib_free(name);
106 }
107 }
108 return NULL;
109 }
110 #endif
111
UI_MENU_CALLBACK(quickload_snapshot_callback)112 static UI_MENU_CALLBACK(quickload_snapshot_callback)
113 {
114 if (activated) {
115 if (machine_read_snapshot("snapshot.vsf", 0) < 0) {
116 snapshot_display_error();
117 }
118 }
119 return NULL;
120 }
121
UI_MENU_CALLBACK(quicksave_snapshot_callback)122 static UI_MENU_CALLBACK(quicksave_snapshot_callback)
123 {
124 if (activated) {
125 if (machine_write_snapshot("snapshot.vsf", save_roms, save_disks, 0) < 0) {
126 snapshot_display_error();
127 }
128 }
129 return NULL;
130 }
131
UI_MENU_CALLBACK(start_stop_recording_history_callback)132 static UI_MENU_CALLBACK(start_stop_recording_history_callback)
133 {
134 int recording_new;
135
136 recording_new = (event_record_active() ? 0 : 1);
137 if (activated) {
138 if (recording_new) {
139 event_record_start();
140 } else {
141 event_record_stop();
142 }
143 return sdl_menu_text_exit_ui;
144 } else {
145 if (!recording_new) {
146 return "(recording)";
147 }
148 }
149 return NULL;
150 }
151
UI_MENU_CALLBACK(start_stop_playback_history_callback)152 static UI_MENU_CALLBACK(start_stop_playback_history_callback)
153 {
154 int playback_new;
155
156 playback_new = (event_playback_active() ? 0 : 1);
157 if (activated) {
158 if (playback_new) {
159 event_playback_start();
160 } else {
161 event_playback_stop();
162 }
163 return sdl_menu_text_exit_ui;
164 } else {
165 if (!playback_new) {
166 return "(playing)";
167 }
168 }
169 return NULL;
170 }
171
UI_MENU_CALLBACK(load_snapshot_callback)172 static UI_MENU_CALLBACK(load_snapshot_callback)
173 {
174 char *name;
175
176 if (activated) {
177 name = sdl_ui_file_selection_dialog("Choose snapshot file to load", FILEREQ_MODE_CHOOSE_FILE);
178 if (name != NULL) {
179 if (machine_read_snapshot(name, 0) < 0) {
180 snapshot_display_error();
181 }
182 lib_free(name);
183 }
184 }
185 return NULL;
186 }
187
188 #if 0
189 /* FIXME */
190 static UI_MENU_CALLBACK(load_snapshot_slot_callback)
191 {
192 char *name;
193
194 if (activated) {
195 name = sdl_ui_slot_selection_dialog("Choose snapshot slot to load", SLOTREQ_MODE_CHOOSE_SLOT);
196 if (name != NULL) {
197 if (machine_read_snapshot(name, 0) < 0) {
198 snapshot_display_error();
199 }
200 lib_free(name);
201 }
202 }
203 return NULL;
204 }
205 #endif
206
UI_MENU_CALLBACK(set_milestone_callback)207 static UI_MENU_CALLBACK(set_milestone_callback)
208 {
209 if (activated) {
210 event_record_set_milestone();
211 return sdl_menu_text_exit_ui;
212 }
213 return NULL;
214 }
215
UI_MENU_CALLBACK(return_to_milestone_callback)216 static UI_MENU_CALLBACK(return_to_milestone_callback)
217 {
218 if (activated) {
219 event_record_reset_milestone();
220 return sdl_menu_text_exit_ui;
221 }
222 return NULL;
223 }
224
UI_MENU_CALLBACK(select_history_files_callback)225 static UI_MENU_CALLBACK(select_history_files_callback)
226 {
227 char *name;
228
229 if (activated) {
230 name = sdl_ui_file_selection_dialog("Select event history directory", FILEREQ_MODE_CHOOSE_DIR);
231 if (name != NULL) {
232 resources_set_string("EventSnapshotDir", name);
233 }
234 }
235 return NULL;
236 }
237
238 static const ui_menu_entry_t save_snapshot_menu[] = {
239 { "Save currently attached disk images",
240 MENU_ENTRY_OTHER,
241 toggle_save_disk_images_callback,
242 NULL },
243 { "Save currently attached ROM images",
244 MENU_ENTRY_OTHER,
245 toggle_save_rom_images_callback,
246 NULL },
247 SDL_MENU_ITEM_SEPARATOR,
248 { "Select filename and save snapshot",
249 MENU_ENTRY_DIALOG,
250 save_snapshot_callback,
251 NULL },
252 SDL_MENU_LIST_END
253 };
254
255 const ui_menu_entry_t snapshot_menu[] = {
256 { "Load snapshot image",
257 MENU_ENTRY_DIALOG,
258 load_snapshot_callback,
259 NULL },
260 { "Save snapshot image",
261 MENU_ENTRY_SUBMENU,
262 submenu_callback,
263 (ui_callback_data_t)save_snapshot_menu },
264 { "Quickload snapshot.vsf",
265 MENU_ENTRY_DIALOG,
266 quickload_snapshot_callback,
267 NULL },
268 { "Quicksave snapshot.vsf",
269 MENU_ENTRY_DIALOG,
270 quicksave_snapshot_callback,
271 NULL },
272 SDL_MENU_ITEM_SEPARATOR,
273 { "Start/stop recording history",
274 MENU_ENTRY_OTHER,
275 start_stop_recording_history_callback,
276 NULL },
277 { "Start/stop playback history",
278 MENU_ENTRY_OTHER,
279 start_stop_playback_history_callback,
280 NULL },
281 { "Set recording milestone",
282 MENU_ENTRY_OTHER,
283 set_milestone_callback,
284 NULL },
285 { "Return to milestone",
286 MENU_ENTRY_OTHER,
287 return_to_milestone_callback,
288 NULL },
289 SDL_MENU_ITEM_SEPARATOR,
290 SDL_MENU_ITEM_TITLE("Record start mode"),
291 { "Save new snapshot",
292 MENU_ENTRY_RESOURCE_RADIO,
293 radio_EventStartMode_callback,
294 (ui_callback_data_t)EVENT_START_MODE_FILE_SAVE },
295 { "Load existing snapshot",
296 MENU_ENTRY_RESOURCE_RADIO,
297 radio_EventStartMode_callback,
298 (ui_callback_data_t)EVENT_START_MODE_FILE_LOAD },
299 { "Start with reset",
300 MENU_ENTRY_RESOURCE_RADIO,
301 radio_EventStartMode_callback,
302 (ui_callback_data_t)EVENT_START_MODE_RESET },
303 { "Overwrite playback",
304 MENU_ENTRY_RESOURCE_RADIO,
305 radio_EventStartMode_callback,
306 (ui_callback_data_t)EVENT_START_MODE_PLAYBACK },
307 SDL_MENU_ITEM_SEPARATOR,
308 { "Select history files/directory",
309 MENU_ENTRY_DIALOG,
310 select_history_files_callback,
311 NULL },
312 SDL_MENU_LIST_END
313 };
314
315 #ifdef ANDROID_COMPILE
loader_load_snapshot(char * name)316 void loader_load_snapshot(char *name)
317 {
318 if (machine_read_snapshot(name, 0) < 0) {
319 snapshot_display_error();
320 }
321 }
322
loader_save_snapshot(char * name)323 void loader_save_snapshot(char *name)
324 {
325 if (machine_write_snapshot(name, save_roms, save_disks, 0) < 0) {
326 snapshot_display_error();
327 }
328 }
329 #endif
330