2022-02-15 03:12:20 +00:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
|
|
|
* Copyright (C) 2021-2022 tildearrow and contributors
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2021-05-11 20:08:08 +00:00
|
|
|
#include <stdio.h>
|
2022-01-18 02:08:14 +00:00
|
|
|
#include <stdint.h>
|
2021-12-07 09:22:36 +00:00
|
|
|
#include <string>
|
2022-07-25 21:21:39 +00:00
|
|
|
#ifdef HAVE_SDL2
|
2022-01-26 08:00:58 +00:00
|
|
|
#include "SDL_events.h"
|
2022-01-27 09:25:16 +00:00
|
|
|
#endif
|
2021-05-11 20:08:08 +00:00
|
|
|
#include "ta-log.h"
|
2022-01-20 10:04:03 +00:00
|
|
|
#include "fileutils.h"
|
2021-05-11 20:08:08 +00:00
|
|
|
#include "engine/engine.h"
|
|
|
|
|
2021-05-28 20:25:55 +00:00
|
|
|
#ifdef _WIN32
|
2021-05-28 20:57:07 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2021-05-28 20:25:55 +00:00
|
|
|
#include <windows.h>
|
2022-06-09 21:10:51 +00:00
|
|
|
#include <combaseapi.h>
|
2021-12-16 20:51:19 +00:00
|
|
|
#include <shellapi.h>
|
2021-05-28 20:25:55 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2022-07-25 22:23:56 +00:00
|
|
|
#include "cli/cli.h"
|
|
|
|
|
2021-12-11 08:11:40 +00:00
|
|
|
#ifdef HAVE_GUI
|
|
|
|
#include "gui/gui.h"
|
|
|
|
#endif
|
|
|
|
|
2021-05-11 20:08:08 +00:00
|
|
|
DivEngine e;
|
|
|
|
|
2021-12-11 08:11:40 +00:00
|
|
|
#ifdef HAVE_GUI
|
|
|
|
FurnaceGUI g;
|
|
|
|
#endif
|
|
|
|
|
2022-07-25 22:23:56 +00:00
|
|
|
FurnaceCLI cli;
|
|
|
|
|
2021-12-07 17:21:23 +00:00
|
|
|
String outName;
|
2022-01-24 18:15:07 +00:00
|
|
|
String vgmOutName;
|
2022-05-26 05:24:21 +00:00
|
|
|
String zsmOutName;
|
2022-08-04 20:18:48 +00:00
|
|
|
String cmdOutName;
|
2022-01-23 04:50:49 +00:00
|
|
|
int loops=1;
|
2022-07-19 22:01:19 +00:00
|
|
|
int benchMode=0;
|
2022-01-23 04:50:49 +00:00
|
|
|
DivAudioExportModes outMode=DIV_EXPORT_MODE_ONE;
|
2021-12-07 17:21:23 +00:00
|
|
|
|
2021-12-11 08:11:40 +00:00
|
|
|
#ifdef HAVE_GUI
|
|
|
|
bool consoleMode=false;
|
|
|
|
#else
|
|
|
|
bool consoleMode=true;
|
|
|
|
#endif
|
|
|
|
|
2022-02-06 04:48:56 +00:00
|
|
|
bool displayEngineFailError=false;
|
2022-08-04 23:50:52 +00:00
|
|
|
bool cmdOutBinary=false;
|
2022-10-17 19:25:30 +00:00
|
|
|
bool vgmOutDirect=false;
|
2022-02-06 04:48:56 +00:00
|
|
|
|
2021-06-09 08:33:03 +00:00
|
|
|
std::vector<TAParam> params;
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pHelp(String) {
|
2021-06-09 08:33:03 +00:00
|
|
|
printf("usage: furnace [params] [filename]\n"
|
|
|
|
"you may specify the following parameters:\n");
|
|
|
|
for (auto& i: params) {
|
|
|
|
if (i.value) {
|
|
|
|
printf(" -%s %s: %s\n",i.name.c_str(),i.valName.c_str(),i.desc.c_str());
|
|
|
|
} else {
|
|
|
|
printf(" -%s: %s\n",i.name.c_str(),i.desc.c_str());
|
|
|
|
}
|
|
|
|
}
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_QUIT;
|
2021-06-09 08:33:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pAudio(String val) {
|
2022-01-23 04:50:49 +00:00
|
|
|
if (outName!="") {
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("can't use -audio and -output at the same time.");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_ERROR;
|
2022-01-23 04:50:49 +00:00
|
|
|
}
|
2021-06-09 08:33:03 +00:00
|
|
|
if (val=="jack") {
|
|
|
|
e.setAudio(DIV_AUDIO_JACK);
|
|
|
|
} else if (val=="sdl") {
|
|
|
|
e.setAudio(DIV_AUDIO_SDL);
|
|
|
|
} else {
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("invalid value for audio engine! valid values are: jack, sdl.");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_ERROR;
|
2021-06-09 08:33:03 +00:00
|
|
|
}
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2021-06-09 08:33:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pView(String val) {
|
2021-06-09 08:33:03 +00:00
|
|
|
if (val=="pattern") {
|
|
|
|
e.setView(DIV_STATUS_PATTERN);
|
|
|
|
} else if (val=="commands") {
|
|
|
|
e.setView(DIV_STATUS_COMMANDS);
|
|
|
|
} else if (val=="nothing") {
|
|
|
|
e.setView(DIV_STATUS_NOTHING);
|
|
|
|
} else {
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("invalid value for view type! valid values are: pattern, commands, nothing.");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_ERROR;
|
2021-06-09 08:33:03 +00:00
|
|
|
}
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2021-06-09 08:33:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pConsole(String val) {
|
2021-12-11 08:11:40 +00:00
|
|
|
consoleMode=true;
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2021-12-11 08:11:40 +00:00
|
|
|
}
|
|
|
|
|
2022-08-04 23:50:52 +00:00
|
|
|
TAParamResult pBinary(String val) {
|
|
|
|
cmdOutBinary=true;
|
|
|
|
return TA_PARAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-10-17 19:25:30 +00:00
|
|
|
TAParamResult pDirect(String val) {
|
|
|
|
vgmOutDirect=true;
|
|
|
|
return TA_PARAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pLogLevel(String val) {
|
2022-03-24 03:05:09 +00:00
|
|
|
if (val=="trace") {
|
|
|
|
logLevel=LOGLEVEL_TRACE;
|
|
|
|
} else if (val=="debug") {
|
2021-06-09 17:28:46 +00:00
|
|
|
logLevel=LOGLEVEL_DEBUG;
|
|
|
|
} else if (val=="info") {
|
|
|
|
logLevel=LOGLEVEL_INFO;
|
|
|
|
} else if (val=="warning") {
|
|
|
|
logLevel=LOGLEVEL_WARN;
|
|
|
|
} else if (val=="error") {
|
|
|
|
logLevel=LOGLEVEL_ERROR;
|
|
|
|
} else {
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("invalid value for loglevel! valid values are: trace, debug, info, warning, error.");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_ERROR;
|
2021-06-09 17:28:46 +00:00
|
|
|
}
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2021-06-09 17:28:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pVersion(String) {
|
2022-04-01 10:20:00 +00:00
|
|
|
printf("Furnace version " DIV_VERSION ".\n\n");
|
2022-02-15 02:59:26 +00:00
|
|
|
printf("copyright (C) 2021-2022 tildearrow and contributors.\n");
|
|
|
|
printf("licensed under the GNU General Public License version 2 or later\n");
|
2021-06-09 08:33:03 +00:00
|
|
|
printf("<https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.\n\n");
|
|
|
|
printf("this is free software with ABSOLUTELY NO WARRANTY.\n");
|
|
|
|
printf("pass the -warranty parameter for more information.\n\n");
|
|
|
|
printf("DISCLAIMER: this program is not affiliated with Delek in any form.\n");
|
2021-12-07 18:01:59 +00:00
|
|
|
printf("\n");
|
2022-04-01 10:20:00 +00:00
|
|
|
printf("furnace is powered by:\n");
|
2021-12-07 18:01:59 +00:00
|
|
|
printf("- libsndfile by Erik de Castro Lopo and rest of libsndfile team (LGPLv2.1)\n");
|
|
|
|
printf("- SDL2 by Sam Lantinga (zlib license)\n");
|
|
|
|
printf("- zlib by Jean-loup Gailly and Mark Adler (zlib license)\n");
|
2022-06-29 09:57:05 +00:00
|
|
|
printf("- RtMidi by Gary P. Scavone (RtMidi license)\n");
|
|
|
|
printf("- backward-cpp by Google (MIT)\n");
|
2021-12-11 08:11:40 +00:00
|
|
|
printf("- Dear ImGui by Omar Cornut (MIT)\n");
|
2022-06-29 09:57:05 +00:00
|
|
|
printf("- Portable File Dialogs by Sam Hocevar (WTFPL)\n");
|
|
|
|
printf("- Native File Dialog (modified version) by Frogtoss Games (zlib license)\n");
|
|
|
|
printf("- FFTW by Matteo Frigo and Steven G. Johnson (GPLv2)\n");
|
2021-12-07 18:01:59 +00:00
|
|
|
printf("- Nuked-OPM by Nuke.YKT (LGPLv2.1)\n");
|
|
|
|
printf("- Nuked-OPN2 by Nuke.YKT (LGPLv2.1)\n");
|
2022-06-29 09:57:05 +00:00
|
|
|
printf("- Nuked-OPL3 by Nuke.YKT (LGPLv2.1)\n");
|
|
|
|
printf("- Nuked-OPLL by Nuke.YKT (GPLv2)\n");
|
|
|
|
printf("- Nuked-PSG (modified version) by Nuke.YKT (GPLv2)\n");
|
2021-12-11 08:11:40 +00:00
|
|
|
printf("- ymfm by Aaron Giles (BSD 3-clause)\n");
|
2022-06-29 09:57:05 +00:00
|
|
|
printf("- adpcm by superctr (public domain)\n");
|
2021-12-07 18:01:59 +00:00
|
|
|
printf("- MAME SN76496 emulation core by Nicola Salmoria (BSD 3-clause)\n");
|
2022-01-13 07:52:19 +00:00
|
|
|
printf("- MAME AY-3-8910 emulation core by Couriersud (BSD 3-clause)\n");
|
2022-01-16 06:47:19 +00:00
|
|
|
printf("- MAME SAA1099 emulation core by Juergen Buchmueller and Manuel Abadia (BSD 3-clause)\n");
|
2022-06-29 09:57:05 +00:00
|
|
|
printf("- MAME Namco WSG by Nicola Salmoria and Aaron Giles (BSD 3-clause)\n");
|
|
|
|
printf("- MAME RF5C68 core by Olivier Galibert and Aaron Giles (BSD 3-clause)\n");
|
2022-10-03 00:12:31 +00:00
|
|
|
printf("- MAME MSM5232 core by Jarek Burczynski and Hiromitsu Shioya (GPLv2)\n");
|
2022-06-29 09:57:05 +00:00
|
|
|
printf("- MAME MSM6258 core by Barry Rodewald (BSD 3-clause)\n");
|
|
|
|
printf("- MAME YMZ280B core by Aaron Giles (BSD 3-clause)\n");
|
|
|
|
printf("- QSound core by superctr (BSD 3-clause)\n");
|
|
|
|
printf("- VICE VIC-20 by Rami Rasanen and viznut (GPLv2)\n");
|
|
|
|
printf("- VERA core by Frank van den Hoef (BSD 2-clause)\n");
|
|
|
|
printf("- SAASound by Dave Hooper and Simon Owen (BSD 3-clause)\n");
|
2021-12-07 18:01:59 +00:00
|
|
|
printf("- SameBoy by Lior Halphon (MIT)\n");
|
2022-10-11 07:23:29 +00:00
|
|
|
printf("- Mednafen PCE, WonderSwan and Virtual Boy by Mednafen Team (GPLv2)\n");
|
|
|
|
printf("- Mednafen T6W28 by Blargg (GPLv2)\n");
|
2022-10-03 00:12:31 +00:00
|
|
|
printf("- SNES DSP core by Blargg (LGPLv2.1)\n");
|
2021-12-07 18:01:59 +00:00
|
|
|
printf("- puNES by FHorse (GPLv2)\n");
|
2022-06-29 09:57:05 +00:00
|
|
|
printf("- NSFPlay by Brad Smith and Brezza (unknown open-source license)\n");
|
2021-12-07 18:01:59 +00:00
|
|
|
printf("- reSID by Dag Lem (GPLv2)\n");
|
2022-08-28 20:10:16 +00:00
|
|
|
printf("- reSIDfp by Dag Lem, Antti Lankila and Leandro Nini (GPLv2)\n");
|
2022-01-14 08:37:36 +00:00
|
|
|
printf("- Stella by Stella Team (GPLv2)\n");
|
2022-09-18 04:19:08 +00:00
|
|
|
printf("- vgsound_emu (second version, modified version) by cam900 (zlib license)\n");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_QUIT;
|
2021-06-09 08:33:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pWarranty(String) {
|
2021-06-09 08:33:03 +00:00
|
|
|
printf("This program is free software; you can redistribute it and/or\n"
|
|
|
|
"modify it under the terms of the GNU General Public License\n"
|
|
|
|
"as published by the Free Software Foundation; either version 2\n"
|
|
|
|
"of the License, or (at your option) any later version.\n\n"
|
|
|
|
|
|
|
|
"This program is distributed in the hope that it will be useful,\n"
|
|
|
|
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
|
|
|
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
|
|
|
"GNU General Public License for more details.\n\n"
|
|
|
|
|
|
|
|
"You should have received a copy of the GNU General Public License\n"
|
|
|
|
"along with this program; if not, write to the Free Software\n"
|
|
|
|
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_QUIT;
|
2021-06-09 08:33:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pLoops(String val) {
|
2021-12-07 09:22:36 +00:00
|
|
|
try {
|
|
|
|
int count=std::stoi(val);
|
|
|
|
if (count<0) {
|
2022-01-23 04:50:49 +00:00
|
|
|
loops=0;
|
2021-12-07 09:22:36 +00:00
|
|
|
} else {
|
2022-01-23 04:50:49 +00:00
|
|
|
loops=count+1;
|
2021-12-07 09:22:36 +00:00
|
|
|
}
|
|
|
|
} catch (std::exception& e) {
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("loop count shall be a number.");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_ERROR;
|
2021-12-07 09:22:36 +00:00
|
|
|
}
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2021-12-07 09:22:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pOutMode(String val) {
|
2022-01-23 04:50:49 +00:00
|
|
|
if (val=="one") {
|
|
|
|
outMode=DIV_EXPORT_MODE_ONE;
|
|
|
|
} else if (val=="persys") {
|
|
|
|
outMode=DIV_EXPORT_MODE_MANY_SYS;
|
|
|
|
} else if (val=="perchan") {
|
|
|
|
outMode=DIV_EXPORT_MODE_MANY_CHAN;
|
|
|
|
} else {
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("invalid value for outmode! valid values are: one, persys and perchan.");
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_ERROR;
|
2022-01-23 04:50:49 +00:00
|
|
|
}
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2022-01-23 04:50:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 22:01:19 +00:00
|
|
|
TAParamResult pBenchmark(String val) {
|
|
|
|
if (val=="render") {
|
|
|
|
benchMode=1;
|
|
|
|
} else if (val=="seek") {
|
|
|
|
benchMode=2;
|
|
|
|
} else {
|
|
|
|
logE("invalid value for benchmark! valid values are: render and seek.");
|
|
|
|
return TA_PARAM_ERROR;
|
|
|
|
}
|
|
|
|
e.setAudio(DIV_AUDIO_DUMMY);
|
|
|
|
return TA_PARAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pOutput(String val) {
|
2021-12-07 17:21:23 +00:00
|
|
|
outName=val;
|
2022-01-23 04:50:49 +00:00
|
|
|
e.setAudio(DIV_AUDIO_DUMMY);
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2021-12-07 09:22:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:54:31 +00:00
|
|
|
TAParamResult pVGMOut(String val) {
|
2022-01-24 18:15:07 +00:00
|
|
|
vgmOutName=val;
|
|
|
|
e.setAudio(DIV_AUDIO_DUMMY);
|
2022-04-25 20:54:31 +00:00
|
|
|
return TA_PARAM_SUCCESS;
|
2022-01-24 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 05:24:21 +00:00
|
|
|
TAParamResult pZSMOut(String val) {
|
|
|
|
zsmOutName=val;
|
|
|
|
e.setAudio(DIV_AUDIO_DUMMY);
|
|
|
|
return TA_PARAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2022-08-04 20:18:48 +00:00
|
|
|
TAParamResult pCmdOut(String val) {
|
|
|
|
cmdOutName=val;
|
|
|
|
e.setAudio(DIV_AUDIO_DUMMY);
|
|
|
|
return TA_PARAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-06-09 08:33:03 +00:00
|
|
|
bool needsValue(String param) {
|
|
|
|
for (size_t i=0; i<params.size(); i++) {
|
|
|
|
if (params[i].name==param) {
|
|
|
|
return params[i].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void initParams() {
|
|
|
|
params.push_back(TAParam("h","help",false,pHelp,"","display this help"));
|
|
|
|
|
|
|
|
params.push_back(TAParam("a","audio",true,pAudio,"jack|sdl","set audio engine (SDL by default)"));
|
2021-12-07 09:22:36 +00:00
|
|
|
params.push_back(TAParam("o","output",true,pOutput,"<filename>","output audio to file"));
|
2022-01-24 18:15:07 +00:00
|
|
|
params.push_back(TAParam("O","vgmout",true,pVGMOut,"<filename>","output .vgm data"));
|
2022-10-17 19:25:30 +00:00
|
|
|
params.push_back(TAParam("D","direct",false,pDirect,"","set VGM export direct stream mode"));
|
2022-05-26 05:24:21 +00:00
|
|
|
params.push_back(TAParam("Z","zsmout",true,pZSMOut,"<filename>","output .zsm data for Commander X16 Zsound"));
|
2022-08-04 20:18:48 +00:00
|
|
|
params.push_back(TAParam("C","cmdout",true,pCmdOut,"<filename>","output command stream"));
|
2022-08-04 23:50:52 +00:00
|
|
|
params.push_back(TAParam("b","binary",false,pBinary,"","set command stream output format to binary"));
|
2021-06-09 17:28:46 +00:00
|
|
|
params.push_back(TAParam("L","loglevel",true,pLogLevel,"debug|info|warning|error","set the log level (info by default)"));
|
2021-06-09 08:33:03 +00:00
|
|
|
params.push_back(TAParam("v","view",true,pView,"pattern|commands|nothing","set visualization (pattern by default)"));
|
2021-12-11 08:11:40 +00:00
|
|
|
params.push_back(TAParam("c","console",false,pConsole,"","enable console mode"));
|
2021-06-09 08:33:03 +00:00
|
|
|
|
2021-12-07 09:22:36 +00:00
|
|
|
params.push_back(TAParam("l","loops",true,pLoops,"<count>","set number of loops (-1 means loop forever)"));
|
2022-01-23 04:50:49 +00:00
|
|
|
params.push_back(TAParam("o","outmode",true,pOutMode,"one|persys|perchan","set file output mode"));
|
2021-12-07 09:22:36 +00:00
|
|
|
|
2022-07-19 22:01:19 +00:00
|
|
|
params.push_back(TAParam("B","benchmark",true,pBenchmark,"render|seek","run performance test"));
|
|
|
|
|
2022-04-01 10:20:00 +00:00
|
|
|
params.push_back(TAParam("V","version",false,pVersion,"","view information about Furnace."));
|
2021-06-09 08:33:03 +00:00
|
|
|
params.push_back(TAParam("W","warranty",false,pWarranty,"","view warranty disclaimer."));
|
|
|
|
}
|
|
|
|
|
2022-06-29 04:42:34 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
void reportError(String what) {
|
|
|
|
logE("%s",what);
|
|
|
|
MessageBox(NULL,what.c_str(),"Furnace",MB_OK|MB_ICONERROR);
|
|
|
|
}
|
2022-11-05 23:17:54 +00:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
void reportError(String what) {
|
|
|
|
logE("%s",what);
|
|
|
|
#ifdef HAVE_SDL2
|
|
|
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,"Error",what.c_str(),NULL);
|
|
|
|
#endif
|
|
|
|
}
|
2022-06-29 04:42:34 +00:00
|
|
|
#else
|
|
|
|
void reportError(String what) {
|
|
|
|
logE("%s",what);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-04-15 21:00:21 +00:00
|
|
|
// TODO: CoInitializeEx on Windows?
|
2022-04-18 08:17:11 +00:00
|
|
|
// TODO: add crash log
|
2021-05-11 20:08:08 +00:00
|
|
|
int main(int argc, char** argv) {
|
2022-04-11 03:12:02 +00:00
|
|
|
initLog();
|
2022-06-09 21:10:51 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HRESULT coResult=CoInitializeEx(NULL,COINIT_MULTITHREADED);
|
|
|
|
if (coResult!=S_OK) {
|
|
|
|
logE("CoInitializeEx failed!");
|
|
|
|
}
|
2022-02-08 22:35:41 +00:00
|
|
|
#endif
|
2021-12-07 17:21:23 +00:00
|
|
|
outName="";
|
2022-01-24 18:15:07 +00:00
|
|
|
vgmOutName="";
|
2022-05-26 05:24:21 +00:00
|
|
|
zsmOutName="";
|
2022-08-04 20:18:48 +00:00
|
|
|
cmdOutName="";
|
2021-06-09 08:33:03 +00:00
|
|
|
|
|
|
|
initParams();
|
|
|
|
|
|
|
|
// parse arguments
|
|
|
|
String arg, val, fileName;
|
|
|
|
size_t eqSplit, argStart;
|
|
|
|
for (int i=1; i<argc; i++) {
|
|
|
|
arg=""; val="";
|
|
|
|
if (argv[i][0]=='-') {
|
|
|
|
if (argv[i][1]=='-') {
|
|
|
|
argStart=2;
|
|
|
|
} else {
|
|
|
|
argStart=1;
|
|
|
|
}
|
|
|
|
arg=&argv[i][argStart];
|
|
|
|
eqSplit=arg.find_first_of('=');
|
|
|
|
if (eqSplit==String::npos) {
|
|
|
|
if (needsValue(arg)) {
|
|
|
|
if ((i+1)<argc) {
|
|
|
|
val=argv[i+1];
|
|
|
|
i++;
|
|
|
|
} else {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("incomplete param %s.",arg.c_str()));
|
2021-06-09 08:33:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val=arg.substr(eqSplit+1);
|
|
|
|
arg=arg.substr(0,eqSplit);
|
|
|
|
}
|
|
|
|
for (size_t j=0; j<params.size(); j++) {
|
|
|
|
if (params[j].name==arg || params[j].shortName==arg) {
|
2022-04-25 20:54:31 +00:00
|
|
|
switch (params[j].func(val)) {
|
|
|
|
case TA_PARAM_ERROR:
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
case TA_PARAM_SUCCESS:
|
|
|
|
break;
|
|
|
|
case TA_PARAM_QUIT:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
2021-06-09 08:33:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fileName=argv[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-18 09:26:17 +00:00
|
|
|
e.setConsoleMode(consoleMode);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (consoleMode) {
|
|
|
|
HANDLE winin=GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
HANDLE winout=GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
int termprop=0;
|
|
|
|
int termpropi=0;
|
|
|
|
GetConsoleMode(winout,(LPDWORD)&termprop);
|
|
|
|
GetConsoleMode(winin,(LPDWORD)&termpropi);
|
|
|
|
termprop|=ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
|
|
|
termpropi&=~ENABLE_LINE_INPUT;
|
|
|
|
SetConsoleMode(winout,termprop);
|
|
|
|
SetConsoleMode(winin,termpropi);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-12-13 19:40:03 +00:00
|
|
|
if (fileName.empty() && consoleMode) {
|
2022-04-11 03:12:02 +00:00
|
|
|
logI("usage: %s file",argv[0]);
|
2021-05-11 20:08:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2022-04-11 03:12:02 +00:00
|
|
|
logI("Furnace version " DIV_VERSION ".");
|
2021-12-13 19:40:03 +00:00
|
|
|
if (!fileName.empty()) {
|
2022-04-11 03:12:02 +00:00
|
|
|
logI("loading module...");
|
2022-01-20 10:04:03 +00:00
|
|
|
FILE* f=ps_fopen(fileName.c_str(),"rb");
|
2021-12-13 19:40:03 +00:00
|
|
|
if (f==NULL) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("couldn't open file! (%s)",strerror(errno)));
|
2021-12-13 19:40:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (fseek(f,0,SEEK_END)<0) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("couldn't open file! (couldn't get file size: %s)",strerror(errno)));
|
2021-12-13 19:40:03 +00:00
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
ssize_t len=ftell(f);
|
2022-01-18 02:08:14 +00:00
|
|
|
if (len==(SIZE_MAX>>1)) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("couldn't open file! (couldn't get file length: %s)",strerror(errno)));
|
2021-12-13 19:40:03 +00:00
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (len<1) {
|
|
|
|
if (len==0) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError("that file is empty!");
|
2021-12-13 19:40:03 +00:00
|
|
|
} else {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("couldn't open file! (tell error: %s)",strerror(errno)));
|
2021-12-13 19:40:03 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
unsigned char* file=new unsigned char[len];
|
|
|
|
if (fseek(f,0,SEEK_SET)<0) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("couldn't open file! (size error: %s)",strerror(errno)));
|
2021-12-13 19:40:03 +00:00
|
|
|
fclose(f);
|
2021-12-16 07:21:43 +00:00
|
|
|
delete[] file;
|
2021-12-13 19:40:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (fread(file,1,(size_t)len,f)!=(size_t)len) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("couldn't open file! (read error: %s)",strerror(errno)));
|
2021-12-13 19:40:03 +00:00
|
|
|
fclose(f);
|
2021-12-16 07:21:43 +00:00
|
|
|
delete[] file;
|
2021-12-13 19:40:03 +00:00
|
|
|
return 1;
|
2021-05-11 20:08:08 +00:00
|
|
|
}
|
|
|
|
fclose(f);
|
2021-12-16 07:21:43 +00:00
|
|
|
if (!e.load(file,(size_t)len)) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("could not open file! (%s)",e.getLastError()));
|
2021-12-13 19:40:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2021-05-11 20:08:08 +00:00
|
|
|
}
|
2022-01-17 04:32:13 +00:00
|
|
|
if (!e.init()) {
|
2022-02-06 04:48:56 +00:00
|
|
|
if (consoleMode) {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError("could not initialize engine!");
|
2022-02-06 04:48:56 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
2022-06-29 04:42:34 +00:00
|
|
|
logE("could not initialize engine!");
|
2022-02-06 21:21:48 +00:00
|
|
|
displayEngineFailError=true;
|
2022-02-06 04:48:56 +00:00
|
|
|
}
|
2021-05-11 20:08:08 +00:00
|
|
|
}
|
2022-07-19 22:01:19 +00:00
|
|
|
if (benchMode) {
|
|
|
|
logI("starting benchmark!");
|
|
|
|
if (benchMode==2) {
|
|
|
|
e.benchmarkSeek();
|
|
|
|
} else {
|
|
|
|
e.benchmarkPlayback();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2022-08-04 20:18:48 +00:00
|
|
|
if (outName!="" || vgmOutName!="" || cmdOutName!="") {
|
|
|
|
if (cmdOutName!="") {
|
2022-08-04 23:50:52 +00:00
|
|
|
SafeWriter* w=e.saveCommand(cmdOutBinary);
|
2022-08-04 20:18:48 +00:00
|
|
|
if (w!=NULL) {
|
|
|
|
FILE* f=fopen(cmdOutName.c_str(),"wb");
|
|
|
|
if (f!=NULL) {
|
|
|
|
fwrite(w->getFinalBuf(),1,w->size(),f);
|
|
|
|
fclose(f);
|
|
|
|
} else {
|
|
|
|
reportError(fmt::sprintf("could not open file! (%s)",e.getLastError()));
|
|
|
|
}
|
|
|
|
w->finish();
|
|
|
|
delete w;
|
|
|
|
} else {
|
|
|
|
reportError("could not write command stream!");
|
|
|
|
}
|
|
|
|
}
|
2022-01-24 18:15:07 +00:00
|
|
|
if (vgmOutName!="") {
|
2022-10-17 19:25:30 +00:00
|
|
|
SafeWriter* w=e.saveVGM(NULL,true,0x171,false,vgmOutDirect);
|
2022-01-24 18:15:07 +00:00
|
|
|
if (w!=NULL) {
|
|
|
|
FILE* f=fopen(vgmOutName.c_str(),"wb");
|
|
|
|
if (f!=NULL) {
|
|
|
|
fwrite(w->getFinalBuf(),1,w->size(),f);
|
|
|
|
fclose(f);
|
|
|
|
} else {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError(fmt::sprintf("could not open file! (%s)",e.getLastError()));
|
2022-01-24 18:15:07 +00:00
|
|
|
}
|
|
|
|
w->finish();
|
|
|
|
delete w;
|
|
|
|
} else {
|
2022-06-29 04:42:34 +00:00
|
|
|
reportError("could not write VGM!");
|
2022-01-24 18:15:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outName!="") {
|
|
|
|
e.setConsoleMode(true);
|
|
|
|
e.saveAudio(outName.c_str(),loops,outMode);
|
|
|
|
e.waitAudioFile();
|
|
|
|
}
|
2022-01-23 04:50:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-11 08:11:40 +00:00
|
|
|
|
|
|
|
if (consoleMode) {
|
2022-07-25 22:23:56 +00:00
|
|
|
bool cliSuccess=false;
|
|
|
|
cli.bindEngine(&e);
|
|
|
|
if (!cli.init()) {
|
|
|
|
reportError("error while starting CLI!");
|
|
|
|
} else {
|
|
|
|
cliSuccess=true;
|
|
|
|
}
|
2022-04-11 03:12:02 +00:00
|
|
|
logI("playing...");
|
2021-12-11 08:11:40 +00:00
|
|
|
e.play();
|
2022-07-25 22:23:56 +00:00
|
|
|
if (cliSuccess) {
|
|
|
|
cli.loop();
|
|
|
|
cli.finish();
|
|
|
|
e.quit();
|
|
|
|
return 0;
|
|
|
|
} else {
|
2022-07-25 21:21:39 +00:00
|
|
|
#ifdef HAVE_SDL2
|
2022-07-25 22:23:56 +00:00
|
|
|
SDL_Event ev;
|
|
|
|
while (true) {
|
|
|
|
SDL_WaitEvent(&ev);
|
|
|
|
if (ev.type==SDL_QUIT) break;
|
|
|
|
}
|
|
|
|
e.quit();
|
|
|
|
return 0;
|
2022-01-27 09:25:16 +00:00
|
|
|
#else
|
2022-07-25 22:23:56 +00:00
|
|
|
while (true) {
|
2022-01-27 09:25:16 +00:00
|
|
|
#ifdef _WIN32
|
2022-07-25 22:23:56 +00:00
|
|
|
Sleep(500);
|
2022-01-27 09:25:16 +00:00
|
|
|
#else
|
2022-07-25 22:23:56 +00:00
|
|
|
usleep(500000);
|
2022-01-27 09:25:16 +00:00
|
|
|
#endif
|
2022-07-25 22:23:56 +00:00
|
|
|
}
|
2022-01-27 09:25:16 +00:00
|
|
|
#endif
|
2022-07-25 22:23:56 +00:00
|
|
|
}
|
2021-05-11 20:08:08 +00:00
|
|
|
}
|
2021-12-11 08:11:40 +00:00
|
|
|
|
2021-12-11 18:34:11 +00:00
|
|
|
#ifdef HAVE_GUI
|
2021-12-11 08:11:40 +00:00
|
|
|
g.bindEngine(&e);
|
2022-06-29 04:42:34 +00:00
|
|
|
if (!g.init()) {
|
2022-10-02 21:12:02 +00:00
|
|
|
reportError(g.getLastError());
|
2022-06-29 04:42:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2021-12-11 08:11:40 +00:00
|
|
|
|
2022-02-06 04:48:56 +00:00
|
|
|
if (displayEngineFailError) {
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("displaying engine fail error.");
|
2022-02-06 04:48:56 +00:00
|
|
|
g.showError("error while initializing audio!");
|
|
|
|
}
|
|
|
|
|
2022-02-02 06:14:21 +00:00
|
|
|
if (!fileName.empty()) {
|
|
|
|
g.setFileName(fileName);
|
|
|
|
}
|
|
|
|
|
2021-12-11 08:11:40 +00:00
|
|
|
g.loop();
|
2022-04-11 03:12:02 +00:00
|
|
|
logI("closing GUI.");
|
2021-12-19 21:01:24 +00:00
|
|
|
g.finish();
|
2021-12-11 18:34:11 +00:00
|
|
|
#else
|
2022-04-11 03:12:02 +00:00
|
|
|
logE("GUI requested but GUI not compiled!");
|
2021-12-11 18:34:11 +00:00
|
|
|
#endif
|
2021-12-13 22:09:46 +00:00
|
|
|
|
2022-04-11 03:12:02 +00:00
|
|
|
logI("stopping engine.");
|
2021-12-13 22:09:46 +00:00
|
|
|
e.quit();
|
2022-06-09 21:10:51 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (coResult==S_OK || coResult==S_FALSE) {
|
|
|
|
CoUninitialize();
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-11 20:08:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-16 20:51:19 +00:00
|
|
|
|
2022-11-16 03:24:23 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "winMain.cpp"
|
|
|
|
#endif
|