-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathdesktop-ui.cpp
208 lines (177 loc) · 6.06 KB
/
desktop-ui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "desktop-ui.hpp"
namespace ruby {
Video video;
Audio audio;
Input input;
}
auto locate(const string& name) -> string {
// First, check the application directory
// This allows ares to function in 'portable' mode
string location = {Path::program(), name};
if(inode::exists(location)) return location;
// On macOS, also check the AppBundle Resource path
#if defined(PLATFORM_MACOS)
location = {Path::resources(), name};
if(inode::exists(location)) return location;
#endif
// Check the userData directory, this is the default
// on non-windows platforms for any resouces that did not
// ship with the executable.
// On Windows, this allows settings from to be carried over
// from previous versions (pre-portable)
location = {Path::userData(), "ares/", name};
if(inode::exists(location)) return location;
// On non-windows platforms, this time check the shared
// data directory, on Windows, default to program dir,
// this ensures Portable mode is the default on Windows platforms.
#if !defined(PLATFORM_WINDOWS)
string shared_location = {Path::sharedData(), "ares/", name};
if(inode::exists(shared_location)) return shared_location;
// On non-windows platforms, after exhausting other options,
// default to userData.
directory::create({Path::userData(), "ares/"});
return {Path::userData(), "ares/", name};
#else
return {Path::program(), name};
#endif
}
#include <nall/main.hpp>
auto nall::main(Arguments arguments) -> void {
//force early allocation for better proximity to executable code
ares::Memory::FixedAllocator::get();
#if defined(PLATFORM_WINDOWS)
bool createTerminal = arguments.take("--terminal");
terminal::redirectStdioToTerminal(createTerminal);
#endif
Application::setName("ares");
Application::setScreenSaver(false);
mia::setHomeLocation([]() -> string {
if(auto location = settings.paths.home) return location;
return locate("Systems/");
});
mia::setSaveLocation([]() -> string {
return settings.paths.saves;
});
if(arguments.take("--fullscreen")) {
program.startFullScreen = true;
}
if(string system; arguments.take("--system", system)) {
program.startSystem = system;
}
if(string shader; arguments.take("--shader", shader)) {
program.startShader = shader;
}
if(arguments.take("--no-file-prompt")) {
program.noFilePrompt = true;
}
inputManager.create();
Emulator::construct();
settings.load();
if(arguments.find("--setting")) {
string settingValue;
while(arguments.take("--setting", settingValue)) {
auto kv = settingValue.split("=", 1L);
if(kv.size() == 2) {
auto node = settings[kv[0]];
if(node) {
node.setValue(kv[1]);
} else {
print("Invalid setting: ", settingValue, "\n");
return;
}
} else {
print("Invalid setting: ", settingValue, "\n");
return;
}
}
settings.process(true);
}
if(arguments.take("--help")) {
print("Usage: ares [OPTIONS]... game(s)\n\n");
print("Options:\n");
print(" --help Displays available options and exit\n");
#if defined(PLATFORM_WINDOWS)
print(" --terminal Create new terminal window\n");
#endif
print(" --fullscreen Start in full screen mode\n");
#if defined(PLATFORM_WINDOWS)
print(" --no/--Borderless Disable/Enable Borderless Window");
#endif
print(" --system name Specify the system name\n");
print(" --shader name Specify the name of the shader to use\n");
print(" --setting name=value Specify a value for a setting\n");
print(" --dump-all-settings Show a list of all existing settings and exit\n");
print(" --no-file-prompt Do not prompt to load (optional) additional roms (eg: 64DD)\n");
print("\n");
print("Available Systems:\n");
print(" ");
for(auto& emulator : emulators) {
print(emulator->name, ", ");
}
print("\n");
return;
}
#if defined(PLATFORM_WINDOWS)
if(arguments.take("--noBorderless")) {
settings.general.borderless = false;
}
if(arguments.take("--Borderless")) {
settings.general.borderless = true;
}
#endif
if(arguments.take("--dump-all-settings")) {
function<void(const Markup::Node&, string)> dump;
dump = [&](const Markup::Node& node, string prefix) -> void {
for(const auto& setting : node) {
print(prefix, setting.name(), "\n");
dump(setting, string(prefix, setting.name(), "/"));
}
};
dump(settings, "");
return;
}
program.startGameLoad.reset();
for(auto argument : arguments) {
if(file::exists(argument)) program.startGameLoad.append(argument);
}
Instances::presentation.construct();
Instances::settingsWindow.construct();
Instances::toolsWindow.construct();
Instances::gameBrowserWindow.construct();
program.create();
presentation.loadEmulators();
#if defined(PLATFORM_WINDOWS)
presentation.setVisible(true);
#endif
Application::onMain({&Program::main, &program});
Application::run();
settings.save();
Instances::presentation.destruct();
Instances::settingsWindow.destruct();
Instances::toolsWindow.destruct();
Instances::gameBrowserWindow.destruct();
}
#if defined(PLATFORM_WINDOWS) && defined(ARCHITECTURE_AMD64) && !defined(BUILD_LOCAL)
#include <nall/windows/windows.hpp>
#include <intrin.h>
//this code must run before C++ global initializers
//it works with any valid combination of GCC, Clang, or MSVC and MingW or MSVCRT
//ref: https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization
auto preCppInitializer() -> int {
int data[4] = {};
__cpuid(data, 1);
bool sse42 = data[2] & 1 << 20;
if(!sse42) FatalAppExitA(0, "This build of ares requires a CPU that supports SSE4.2.");
return 0;
}
extern "C" {
#if defined(_MSC_VER)
#pragma comment(linker, "/include:preCppInitializerEntry")
#pragma section(".CRT$XCT", read)
__declspec(allocate(".CRT$XCT"))
#else
__attribute__((section (".CRT$XCT"), used))
#endif
decltype(&preCppInitializer) preCppInitializerEntry = preCppInitializer;
}
#endif