2021-12-13 12:12:54 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2022 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
|
|
|
|
#include <QtWidgets/QApplication>
|
2022-05-27 09:48:59 +00:00
|
|
|
#include <QtWidgets/QMessageBox>
|
2021-12-13 12:12:54 +00:00
|
|
|
#include <cstdlib>
|
2022-03-04 10:40:03 +00:00
|
|
|
#include <csignal>
|
2021-12-13 12:12:54 +00:00
|
|
|
|
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "EmuThread.h"
|
|
|
|
#include "QtHost.h"
|
|
|
|
|
|
|
|
#include "CDVD/CDVD.h"
|
|
|
|
#include "Frontend/GameList.h"
|
2022-06-18 09:35:17 +00:00
|
|
|
#include "Frontend/LogSink.h"
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2022-04-18 14:58:34 +00:00
|
|
|
#include "common/CrashHandler.h"
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
static void PrintCommandLineVersion()
|
|
|
|
{
|
2022-06-18 09:35:17 +00:00
|
|
|
Host::InitializeEarlyConsole();
|
2022-05-11 08:24:56 +00:00
|
|
|
std::fprintf(stderr, "%s\n", (QtHost::GetAppNameAndVersion() + QtHost::GetAppConfigSuffix()).toUtf8().constData());
|
2021-12-13 12:12:54 +00:00
|
|
|
std::fprintf(stderr, "https://pcsx2.net/\n");
|
|
|
|
std::fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintCommandLineHelp(const char* progname)
|
|
|
|
{
|
|
|
|
PrintCommandLineVersion();
|
|
|
|
std::fprintf(stderr, "Usage: %s [parameters] [--] [boot filename]\n", progname);
|
|
|
|
std::fprintf(stderr, "\n");
|
|
|
|
std::fprintf(stderr, " -help: Displays this information and exits.\n");
|
|
|
|
std::fprintf(stderr, " -version: Displays version information and exits.\n");
|
2022-03-12 14:52:52 +00:00
|
|
|
std::fprintf(stderr, " -batch: Enables batch mode (exits after shutting down).\n");
|
|
|
|
std::fprintf(stderr, " -elf <file>: Overrides the boot ELF with the specified filename.\n");
|
|
|
|
std::fprintf(stderr, " -disc <path>: Uses the specified host DVD drive as a source.\n");
|
2022-05-03 04:26:49 +00:00
|
|
|
std::fprintf(stderr, " -bios: Starts the BIOS (System Menu/OSDSYS).\n");
|
2021-12-13 12:12:54 +00:00
|
|
|
std::fprintf(stderr, " -fastboot: Force fast boot for provided filename.\n");
|
|
|
|
std::fprintf(stderr, " -slowboot: Force slow boot for provided filename.\n");
|
|
|
|
std::fprintf(stderr, " -state <index>: Loads specified save state by index.\n");
|
2022-05-03 04:26:49 +00:00
|
|
|
std::fprintf(stderr, " -statefile <filename>: Loads state from the specified filename.\n");
|
2021-12-13 12:12:54 +00:00
|
|
|
std::fprintf(stderr, " -fullscreen: Enters fullscreen mode immediately after starting.\n");
|
|
|
|
std::fprintf(stderr, " -nofullscreen: Prevents fullscreen mode from triggering if enabled.\n");
|
2022-05-29 14:18:09 +00:00
|
|
|
std::fprintf(stderr, " -earlyconsolelog: Forces logging of early console messages to console.\n");
|
2021-12-13 12:12:54 +00:00
|
|
|
std::fprintf(stderr, " --: Signals that no more arguments will follow and the remaining\n"
|
|
|
|
" parameters make up the filename. Use when the filename contains\n"
|
|
|
|
" spaces or starts with a dash.\n");
|
|
|
|
std::fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::shared_ptr<VMBootParameters>& AutoBoot(std::shared_ptr<VMBootParameters>& autoboot)
|
|
|
|
{
|
|
|
|
if (!autoboot)
|
|
|
|
autoboot = std::make_shared<VMBootParameters>();
|
2022-03-12 14:52:52 +00:00
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
return autoboot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ParseCommandLineOptions(int argc, char* argv[], std::shared_ptr<VMBootParameters>& autoboot)
|
|
|
|
{
|
|
|
|
bool no_more_args = false;
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (!no_more_args)
|
|
|
|
{
|
|
|
|
#define CHECK_ARG(str) !std::strcmp(argv[i], str)
|
|
|
|
#define CHECK_ARG_PARAM(str) (!std::strcmp(argv[i], str) && ((i + 1) < argc))
|
|
|
|
|
|
|
|
if (CHECK_ARG("-help"))
|
|
|
|
{
|
|
|
|
PrintCommandLineHelp(argv[0]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG("-version"))
|
|
|
|
{
|
|
|
|
PrintCommandLineVersion();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG("-batch"))
|
|
|
|
{
|
2022-05-03 04:26:49 +00:00
|
|
|
QtHost::SetBatchMode(true);
|
2021-12-13 12:12:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG("-fastboot"))
|
|
|
|
{
|
2022-05-03 04:26:49 +00:00
|
|
|
AutoBoot(autoboot)->fast_boot = true;
|
2021-12-13 12:12:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG("-slowboot"))
|
|
|
|
{
|
2022-05-03 04:26:49 +00:00
|
|
|
AutoBoot(autoboot)->fast_boot = false;
|
2021-12-13 12:12:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG_PARAM("-state"))
|
|
|
|
{
|
2022-05-03 04:26:49 +00:00
|
|
|
AutoBoot(autoboot)->state_index = std::atoi(argv[++i]);
|
2021-12-13 12:12:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG_PARAM("-statefile"))
|
|
|
|
{
|
|
|
|
AutoBoot(autoboot)->save_state = argv[++i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (CHECK_ARG_PARAM("-elf"))
|
|
|
|
{
|
|
|
|
AutoBoot(autoboot)->elf_override = argv[++i];
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-12 14:52:52 +00:00
|
|
|
else if (CHECK_ARG_PARAM("-disc"))
|
|
|
|
{
|
|
|
|
AutoBoot(autoboot)->source_type = CDVD_SourceType::Disc;
|
|
|
|
AutoBoot(autoboot)->filename = argv[++i];
|
|
|
|
continue;
|
|
|
|
}
|
2022-05-03 04:26:49 +00:00
|
|
|
else if (CHECK_ARG("-bios"))
|
2021-12-13 12:12:54 +00:00
|
|
|
{
|
2022-05-03 04:26:49 +00:00
|
|
|
AutoBoot(autoboot)->source_type = CDVD_SourceType::NoDisc;
|
2021-12-13 12:12:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-03 04:26:49 +00:00
|
|
|
else if (CHECK_ARG("-fullscreen"))
|
2021-12-13 12:12:54 +00:00
|
|
|
{
|
2022-05-03 04:26:49 +00:00
|
|
|
AutoBoot(autoboot)->fullscreen = true;
|
2021-12-13 12:12:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-03 04:26:49 +00:00
|
|
|
else if (CHECK_ARG("-nofullscreen"))
|
2021-12-13 12:12:54 +00:00
|
|
|
{
|
2022-05-03 04:26:49 +00:00
|
|
|
AutoBoot(autoboot)->fullscreen = false;
|
2021-12-13 12:12:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-29 14:18:09 +00:00
|
|
|
else if (CHECK_ARG("-earlyconsolelog"))
|
|
|
|
{
|
2022-06-18 09:35:17 +00:00
|
|
|
Host::InitializeEarlyConsole();
|
2022-05-29 14:18:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-12-13 12:12:54 +00:00
|
|
|
else if (CHECK_ARG("--"))
|
|
|
|
{
|
|
|
|
no_more_args = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (argv[i][0] == '-')
|
|
|
|
{
|
2022-06-18 09:35:17 +00:00
|
|
|
Host::InitializeEarlyConsole();
|
2022-05-03 04:26:49 +00:00
|
|
|
std::fprintf(stderr, "Unknown parameter: '%s'", argv[i]);
|
2021-12-13 12:12:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK_ARG
|
|
|
|
#undef CHECK_ARG_PARAM
|
|
|
|
}
|
|
|
|
|
2022-03-12 14:52:52 +00:00
|
|
|
if (!AutoBoot(autoboot)->filename.empty())
|
|
|
|
AutoBoot(autoboot)->filename += ' ';
|
2021-12-13 12:12:54 +00:00
|
|
|
|
2022-03-12 14:52:52 +00:00
|
|
|
AutoBoot(autoboot)->filename += argv[i];
|
2021-12-13 12:12:54 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 04:26:49 +00:00
|
|
|
// check autoboot parameters, if we set something like fullscreen without a bios
|
|
|
|
// or disc, we don't want to actually start.
|
|
|
|
if (autoboot && !autoboot->source_type.has_value() && autoboot->filename.empty() && autoboot->elf_override.empty())
|
|
|
|
{
|
2022-06-18 09:35:17 +00:00
|
|
|
Host::InitializeEarlyConsole();
|
2022-05-03 04:26:49 +00:00
|
|
|
Console.Warning("Skipping autoboot due to no boot parameters.");
|
|
|
|
autoboot.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we don't have autoboot, we definitely don't want batch mode (because that'll skip
|
|
|
|
// scanning the game list).
|
|
|
|
if (QtHost::InBatchMode() && !autoboot)
|
|
|
|
{
|
2022-06-18 09:35:17 +00:00
|
|
|
Host::InitializeEarlyConsole();
|
2022-05-03 04:26:49 +00:00
|
|
|
Console.Warning("Disabling batch mode, because we have no autoboot.");
|
|
|
|
QtHost::SetBatchMode(false);
|
|
|
|
}
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-27 09:48:59 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
// See note at the end of the file as to why we don't do this on Windows.
|
|
|
|
static bool PerformEarlyHardwareChecks()
|
|
|
|
{
|
|
|
|
// NOTE: No point translating this message, because the configuration isn't loaded yet, so we
|
|
|
|
// won't know which language to use, and loading the configuration uses float instructions.
|
|
|
|
const char* error;
|
|
|
|
if (VMManager::PerformEarlyHardwareChecks(&error))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
QMessageBox::critical(nullptr, QStringLiteral("Hardware Check Failed"), QString::fromUtf8(error));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-04-18 14:58:34 +00:00
|
|
|
CrashHandler::Install();
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
|
|
|
|
|
|
QApplication app(argc, argv);
|
2022-05-27 09:48:59 +00:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
if (!PerformEarlyHardwareChecks())
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
#endif
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
std::shared_ptr<VMBootParameters> autoboot;
|
|
|
|
if (!ParseCommandLineOptions(argc, argv, autoboot))
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
MainWindow* main_window = new MainWindow(QApplication::style()->objectName());
|
|
|
|
|
|
|
|
if (!QtHost::Initialize())
|
|
|
|
{
|
|
|
|
delete main_window;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2022-05-24 08:04:26 +00:00
|
|
|
// actually show the window, the emuthread might still be starting up at this point
|
2021-12-13 12:12:54 +00:00
|
|
|
main_window->initialize();
|
|
|
|
|
2022-05-03 04:26:49 +00:00
|
|
|
// skip scanning the game list when running in batch mode
|
|
|
|
if (!QtHost::InBatchMode())
|
|
|
|
main_window->refreshGameList(false);
|
|
|
|
|
2021-12-13 12:12:54 +00:00
|
|
|
main_window->show();
|
|
|
|
|
|
|
|
if (autoboot)
|
|
|
|
g_emu_thread->startVM(std::move(autoboot));
|
2022-04-04 11:27:23 +00:00
|
|
|
else
|
|
|
|
main_window->startupUpdateCheck();
|
2021-12-13 12:12:54 +00:00
|
|
|
|
|
|
|
const int result = app.exec();
|
|
|
|
|
|
|
|
QtHost::Shutdown();
|
|
|
|
return result;
|
|
|
|
}
|