#include <string.h>\r
#include <stdlib.h>\r
#include <stdarg.h>\r
+#include <time.h>\r
\r
#include "menu.h"\r
#include "fonts.h"\r
\r
// ------------ savestate loader ------------\r
\r
+#define STATE_SLOT_COUNT 10\r
+\r
static int state_slot_flags = 0;\r
+static int state_slot_times[STATE_SLOT_COUNT];\r
\r
static void state_check_slots(void)\r
{\r
\r
state_slot_flags = 0;\r
\r
- for (slot = 0; slot < 10; slot++) {\r
- if (emu_check_save_file(slot))\r
+ for (slot = 0; slot < STATE_SLOT_COUNT; slot++) {\r
+ state_slot_times[slot] = 0;\r
+ if (emu_check_save_file(slot, &state_slot_times[slot]))\r
state_slot_flags |= 1 << slot;\r
}\r
}\r
static void draw_savestate_menu(int menu_sel, int is_loading)\r
{\r
int i, x, y, w, h;\r
+ char time_buf[32];\r
\r
if (state_slot_flags & (1 << menu_sel))\r
draw_savestate_bg(menu_sel);\r
\r
w = (13 + 2) * me_mfont_w;\r
- h = (1+2+10+1) * me_mfont_h;\r
+ h = (1+2+STATE_SLOT_COUNT+1) * me_mfont_h;\r
x = g_menuscreen_w / 2 - w / 2;\r
if (x < 0) x = 0;\r
y = g_menuscreen_h / 2 - h / 2;\r
text_out16(x, y, is_loading ? "Load state" : "Save state");\r
y += 3 * me_mfont_h;\r
\r
- menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (13 + 2) * me_mfont_w + 4);\r
+ menu_draw_selection(x - me_mfont_w * 2, y + menu_sel * me_mfont_h, (23 + 2) * me_mfont_w + 4);\r
\r
- /* draw all 10 slots */\r
- for (i = 0; i < 10; i++, y += me_mfont_h)\r
+ /* draw all slots */\r
+ for (i = 0; i < STATE_SLOT_COUNT; i++, y += me_mfont_h)\r
{\r
- text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r
+ if (!(state_slot_flags & (1 << i)))\r
+ strcpy(time_buf, "free");\r
+ else {\r
+ strcpy(time_buf, "USED");\r
+ if (state_slot_times[i] != 0) {\r
+ time_t time = state_slot_times[i];\r
+ struct tm *t = localtime(&time);\r
+ strftime(time_buf, sizeof(time_buf), "%x %R", t);\r
+ }\r
+ }\r
+\r
+ text_out16(x, y, "SLOT %i (%s)", i, time_buf);\r
}\r
text_out16(x, y, "back");\r
\r
\r
static int menu_loop_savestate(int is_loading)\r
{\r
- static int menu_sel = 10;\r
- int menu_sel_max = 10;\r
+ static int menu_sel = STATE_SLOT_COUNT;\r
+ int menu_sel_max = STATE_SLOT_COUNT;\r
unsigned long inp = 0;\r
int ret = 0;\r
\r
} while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
}\r
if (inp & PBTN_MOK) { // save/load\r
- if (menu_sel < 10) {\r
+ if (menu_sel < STATE_SLOT_COUNT) {\r
state_slot = menu_sel;\r
if (emu_save_load_game(is_loading, 0)) {\r
me_update_msg(is_loading ? "Load failed" : "Save failed");\r
#include <errno.h>
#include <dlfcn.h>
#include <zlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "main.h"
#include "menu.h"
#include "../plugins/dfinput/main.h"
#include "revision.h"
+#define REARMED_BIRTHDAY_TIME 1293306830 /* 25 Dec 2010 */
+
#define array_size(x) (sizeof(x) / sizeof(x[0]))
typedef enum
printf("Warning: path truncated: %s\n", buff);
}
-static int emu_check_save_file(int slot)
+static int emu_check_save_file(int slot, int *time)
{
- int ret = emu_check_state(slot);
- return ret == 0 ? 1 : 0;
+ char fname[MAXPATHLEN];
+ struct stat status;
+ int ret;
+
+ ret = emu_check_state(slot);
+ if (ret != 0 || time == NULL)
+ return ret == 0 ? 1 : 0;
+
+ ret = get_state_filename(fname, sizeof(fname), slot);
+ if (ret != 0)
+ return 1;
+
+ ret = stat(fname, &status);
+ if (ret != 0)
+ return 1;
+
+ if (status.st_mtime < REARMED_BIRTHDAY_TIME)
+ return 1; // probably bad rtc like on some Caanoos
+
+ *time = status.st_mtime;
+
+ return 1;
}
static int emu_save_load_game(int load, int unused)