Mercurial > repos > blastem
comparison menu.c @ 957:1618d3676a35
Save state menu WIP
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 15 Apr 2016 23:57:50 -0700 |
parents | cbc5b39e5518 |
children | 83532f944e3b |
comparison
equal
deleted
inserted
replaced
956:f5550cdffe49 | 957:1618d3676a35 |
---|---|
49 } | 49 } |
50 } | 50 } |
51 //make sure we terminate the string even if we did not hit a null terminator in the source | 51 //make sure we terminate the string even if we did not hit a null terminator in the source |
52 buf[maxchars-1] = 0; | 52 buf[maxchars-1] = 0; |
53 } | 53 } |
54 | |
55 void copy_to_guest(m68k_context *m68k, uint32_t guest_addr, char *src, size_t tocopy) | |
56 { | |
57 char *dst = NULL; | |
58 for (char *cur = src; cur < src+tocopy; cur+=2, guest_addr+=2, dst+=2) | |
59 { | |
60 if (!dst || !(guest_addr & 0xFFFF)) { | |
61 //we may have walked off the end of a memory block, get a fresh native pointer | |
62 dst = get_native_pointer(guest_addr, (void **)m68k->mem_pointers, &m68k->options->gen); | |
63 if (!dst) { | |
64 break; | |
65 } | |
66 } | |
67 src[1] = *cur; | |
68 *src = cur[1]; | |
69 } | |
70 } | |
71 | |
72 #define SAVE_INFO_BUFFER_SIZE (11*40) | |
54 | 73 |
55 #ifdef __ANDROID__ | 74 #ifdef __ANDROID__ |
56 #include <SDL.h> | 75 #include <SDL.h> |
57 #include <jni.h> | 76 #include <jni.h> |
58 char *get_external_storage_path() | 77 char *get_external_storage_path() |
188 copy_string_from_guest(m68k, dst, buf, sizeof(buf)); | 207 copy_string_from_guest(m68k, dst, buf, sizeof(buf)); |
189 char const *pieces[] = {menu->curpath, "/", buf}; | 208 char const *pieces[] = {menu->curpath, "/", buf}; |
190 gen->next_rom = alloc_concat_m(3, pieces); | 209 gen->next_rom = alloc_concat_m(3, pieces); |
191 m68k->should_return = 1; | 210 m68k->should_return = 1; |
192 break; | 211 break; |
212 } | |
193 case 3: { | 213 case 3: { |
194 switch (dst) | 214 switch (dst) |
195 { | 215 { |
196 case 1: | 216 case 1: |
197 m68k->should_return = 1; | 217 m68k->should_return = 1; |
202 break; | 222 break; |
203 } | 223 } |
204 | 224 |
205 break; | 225 break; |
206 } | 226 } |
227 case 4: { | |
228 char *buffer = malloc(SAVE_INFO_BUFFER_SIZE); | |
229 char *cur = buffer; | |
230 if (gen->next_context && gen->next_context->save_dir) { | |
231 char *end = buffer + SAVE_INFO_BUFFER_SIZE; | |
232 char slotfile[] = "slot_0.gst"; | |
233 char const * parts[3] = {gen->next_context->save_dir, "/", slotfile}; | |
234 struct tm ltime; | |
235 char *fname; | |
236 time_t modtime; | |
237 for (int i = 0; i < 10 && cur < end; i++) | |
238 { | |
239 slotfile[5] = i + '0'; | |
240 fname = alloc_concat_m(3, parts); | |
241 modtime = get_modification_time(fname); | |
242 free(fname); | |
243 if (modtime) { | |
244 cur += snprintf(cur, end-cur, "Slot %d - ", i); | |
245 cur += strftime(cur, end-cur, "%c", localtime_r(&modtime, <ime)); | |
246 | |
247 } else { | |
248 cur += snprintf(cur, end-cur, "Slot %d - EMPTY", i); | |
249 } | |
250 //advance past the null terminator for this entry | |
251 cur++; | |
252 } | |
253 if (cur < end) { | |
254 parts[2] = "quicksave.gst"; | |
255 fname = alloc_concat_m(3, parts); | |
256 modtime = get_modification_time(fname); | |
257 free(fname); | |
258 if (modtime) { | |
259 cur += strftime(cur, end-cur, "Quick - %c", localtime_r(&modtime, <ime)); | |
260 } else if ((end-cur) > strlen("Quick - EMPTY")){ | |
261 cur += strlen(strcpy(cur, "Quick - EMPTY")); | |
262 } | |
263 //advance past the null terminator for this entry | |
264 cur++; | |
265 if (cur < end) { | |
266 //terminate the list | |
267 *cur = 0; | |
268 } | |
269 } | |
270 } else { | |
271 *(cur++) = 0; | |
272 *(cur++) = 0; | |
273 } | |
274 copy_to_guest(m68k, dst, buffer, cur-buffer); | |
275 break; | |
207 } | 276 } |
208 default: | 277 default: |
209 fprintf(stderr, "WARNING: write to undefined menu port %X\n", address); | 278 fprintf(stderr, "WARNING: write to undefined menu port %X\n", address); |
210 } | 279 } |
211 menu->state = 0; | 280 menu->state = 0; |