1
2 #include <streams/file_stream.h>
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7 #include <string.h>
8 #include "settings.h"
9 #include "nx.h"
10 #include "settings.fdh"
11
12 #include "libretro_shared.h"
13
14 const char *setfilename = "settings.dat";
15 const uint16_t SETTINGS_VERSION = 0x1602; // serves as both a version and magic
16
17 Settings normal_settings;
18 Settings *settings = &normal_settings;
19
20
settings_load(Settings * setfile)21 bool settings_load(Settings *setfile)
22 {
23 if (!setfile) setfile = &normal_settings;
24
25 if (tryload(settings))
26 {
27 NX_LOG("No saved settings; using defaults.\n");
28
29 memset(setfile, 0, sizeof(Settings));
30 setfile->resolution = 2; // 640x480 Windowed, should be safe value
31 setfile->last_save_slot = 0;
32 setfile->multisave = true;
33
34 setfile->enable_debug_keys = false;
35 setfile->sound_enabled = true;
36 setfile->music_enabled = 1; // both Boss and Regular music
37
38 setfile->instant_quit = false;
39 setfile->emulate_bugs = false;
40 setfile->no_quake_in_hell = false;
41 setfile->inhibit_fullscreen = false;
42 setfile->files_extracted = false;
43
44 // I found that 8bpp->32bpp blits are actually noticably faster
45 // than 32bpp->32bpp blits on several systems I tested. Not sure why
46 // but calling SDL_DisplayFormat seems to actually be slowing things
47 // down. This goes against established wisdom so if you want it back on,
48 // run "displayformat 1" in the console and restart.
49 setfile->displayformat = false;
50
51 return 1;
52 }
53 else
54 {
55 input_set_mappings(settings->input_mappings);
56 }
57
58 return 0;
59 }
60
61 /*
62 void c------------------------------() {}
63 */
64
tryload(Settings * setfile)65 static bool tryload(Settings *setfile)
66 {
67 char setfilename_tmp[1024];
68 RFILE *fp = NULL;
69
70 retro_create_path_string(setfilename_tmp, sizeof(setfilename_tmp), g_dir, setfilename);
71
72 fp = filestream_open(setfilename_tmp, RETRO_VFS_FILE_ACCESS_READ,
73 RETRO_VFS_FILE_ACCESS_HINT_NONE);
74 if (!fp)
75 {
76 NX_ERR("Couldn't open file %s.\n", setfilename_tmp);
77 return 1;
78 }
79
80 NX_LOG("Loading settings...\n");
81
82 setfile->version = 0;
83 filestream_read(fp, setfile, sizeof(Settings));
84
85 if (setfile->version != SETTINGS_VERSION)
86 {
87 NX_ERR("Wrong settings version %04x.\n", setfile->version);
88 return 1;
89 }
90
91 filestream_close(fp);
92 return 0;
93 }
94
95
settings_save(Settings * setfile)96 bool settings_save(Settings *setfile)
97 {
98 char setfilename_tmp[1024];
99 RFILE *fp = NULL;
100
101 if (!setfile)
102 setfile = &normal_settings;
103
104 retro_create_path_string(setfilename_tmp, sizeof(setfilename_tmp), g_dir, setfilename);
105
106 fp = filestream_open(setfilename_tmp, RETRO_VFS_FILE_ACCESS_WRITE,
107 RETRO_VFS_FILE_ACCESS_HINT_NONE);
108 if (!fp)
109 {
110 NX_ERR("Couldn't open file %s.\n", setfilename_tmp);
111 return 1;
112 }
113
114 NX_LOG("Writing settings...\n");
115
116 setfile->version = SETTINGS_VERSION;
117 filestream_write(fp, setfile, sizeof(Settings));
118 filestream_close(fp);
119 return 0;
120 }
121
122
123
124
125