39static constexpr const char* STDOUT_LOG_FILE_NAME =
"openmsx_system/openmsx.stdout";
40static constexpr const char* STDERR_LOG_FILE_NAME =
"openmsx_system/openmsx.stderr";
49static int setenv(
const char* name,
const char* value,
int overwrite)
51 if (!overwrite && getenv(name)) {
54 return _putenv_s(name, value);
60static void EnableConsoleOutput()
62 if (AttachConsole(ATTACH_PARENT_PROCESS)) {
63 freopen(
"CONOUT$",
"w", stdout);
64 freopen(
"CONOUT$",
"w", stderr);
69static void initializeSDL()
72 flags |= SDL_INIT_JOYSTICK;
74 flags |= SDL_INIT_NOPARACHUTE;
76 if (SDL_Init(flags) < 0) {
77 throw FatalError(
"Couldn't init SDL: ", SDL_GetError());
85 setenv(
"FREETYPE_PROPERTIES",
"truetype:interpreter-version=35", 0);
88static int main(
int argc,
char **argv)
91 ad_printf(
"Redirecting stdout to %s and stderr to %s\n",
92 STDOUT_LOG_FILE_NAME, STDERR_LOG_FILE_NAME);
94 if (!freopen(STDOUT_LOG_FILE_NAME,
"a", stdout)) {
95 ad_printf(
"Couldn't redirect stdout to logfile, aborting\n");
96 std::cerr <<
"Couldn't redirect stdout to "
97 STDOUT_LOG_FILE_NAME
"\n";
100 if (!freopen(STDERR_LOG_FILE_NAME,
"a", stderr)) {
101 ad_printf(
"Couldn't redirect stderr to logfile, aborting\n");
102 std::cout <<
"Couldn't redirect stderr to "
103 STDERR_LOG_FILE_NAME
"\n";
107 std::string msg =
Date::toString(time(
nullptr)) +
": starting openMSX";
108 std::cout << msg <<
'\n';
109 std::cerr << msg <<
'\n';
113 EnableConsoleOutput();
123 (void)argc; (void)argv;
124 ArgumentGenerator argGen;
125 auto args = argGen.getArgs();
127 std::span<char*> args{argv, size_t(argc)};
129 CommandLineParser parser(reactor);
134 reactor.runStartupScripts(parser);
136 auto& display = reactor.getDisplay();
137 auto& render = display.getRenderSettings().getRendererSetting();
140 render.setValue(render.getDefaultValue());
147 reactor.getEventDistributor().deliverEvents();
150 CliServer cliServer(reactor.getCommandController(),
151 reactor.getEventDistributor(),
152 reactor.getGlobalCliComm());
160 }
catch (FatalError& e) {
161 std::cerr <<
"Fatal error: " << e.getMessage() <<
'\n';
163 }
catch (MSXException& e) {
164 std::cerr <<
"Uncaught exception: " << e.getMessage() <<
'\n';
166 }
catch (std::exception& e) {
167 std::cerr <<
"Uncaught std::exception: " << e.what() <<
'\n';
170 std::cerr <<
"Uncaught exception of unexpected type." <<
'\n';
174 if (SDL_WasInit(SDL_INIT_EVERYTHING)) {
190 return openmsx::main(argc, argv);
int main(int argc, char **argv)
std::string toString(time_t time)
void setMainThread()
Store ID of the main thread, should be called exactly once from the main thread.
This file implemented 3 utility functions:
void randomize()
Seed the (shared) random number generator.