mirror of
https://github.com/zoriya/ComSquare.git
synced 2025-12-20 06:05:11 +00:00
Cleaning up
This commit is contained in:
@@ -15,36 +15,53 @@ void usage(char *bin)
|
||||
std::cout << "ComSquare:" << std::endl
|
||||
<< "\tUsage: " << bin << " rom_path [options]" << std::endl
|
||||
<< "Options:" << std::endl
|
||||
<< "\t-h, --help: \tDisplay this help message and exit." << std::endl
|
||||
#ifdef DEBUGGER_ENABLED
|
||||
<< "\t-c, --cpu: \tEnable the debugger of the CPU." << std::endl
|
||||
<< "\t-m, --memory: \tEnable the memory viewer panel." << std::endl
|
||||
<< "\t-h, --header: \tShow the header of the cartridge." << std::endl
|
||||
<< "\t-H, --header: \tShow the header of the cartridge." << std::endl
|
||||
<< "\t-b, --bus: \tShow the memory bus's log." << std::endl
|
||||
<< "\t-g, --cgram: \tShow the palette viewer." << std::endl
|
||||
<< "\t-r, --registers: \tShow the registers viewer." << std::endl;
|
||||
<< "\t-r, --registers: \tShow the registers viewer." << std::endl
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
void parseArguments(int argc, char **argv, SNES &snes)
|
||||
{
|
||||
while (true) {
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{"cpu", no_argument, 0, 'c'},
|
||||
{"apu", no_argument, 0, 'a'},
|
||||
{"memory", no_argument, 0, 'm'},
|
||||
{"header", no_argument, 0, 'h'},
|
||||
{"bus", no_argument, 0, 'b'},
|
||||
{"cgram", no_argument, 0, 'g'},
|
||||
{"registers", no_argument, 0, 'r'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
#ifdef DEBUGGER_ENABLED
|
||||
{"cpu", no_argument, 0, 'c'},
|
||||
{"apu", no_argument, 0, 'a'},
|
||||
{"memory", no_argument, 0, 'm'},
|
||||
{"header", no_argument, 0, 'H'},
|
||||
{"bus", no_argument, 0, 'b'},
|
||||
{"cgram", no_argument, 0, 'g'},
|
||||
{"registers", no_argument, 0, 'r'},
|
||||
#endif
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
#ifdef DEBUGGER_ENABLED
|
||||
char short_options[] = "hcamHbgr";
|
||||
#else
|
||||
char short_options[] = "h";
|
||||
#endif
|
||||
|
||||
int c = getopt_long(argc, argv, "camhbgr", long_options, &option_index);
|
||||
while (true) {
|
||||
int c = getopt_long(argc, argv, short_options, long_options, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
usage(argv[0]);
|
||||
break;
|
||||
exit(2);
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
exit(0);
|
||||
#ifdef DEBUGGER_ENABLED
|
||||
case 'c':
|
||||
snes.enableCPUDebugging();
|
||||
break;
|
||||
@@ -66,15 +83,22 @@ void parseArguments(int argc, char **argv, SNES &snes)
|
||||
case 'r':
|
||||
snes.enableRegisterDebugging();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind != argc - 1) {
|
||||
usage(argv[0]);
|
||||
exit(2);
|
||||
}
|
||||
snes.loadRom(argv[optind]);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
|
||||
if (argc < 2) {
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
@@ -82,10 +106,13 @@ int main(int argc, char **argv)
|
||||
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
|
||||
Renderer::QtSFMLWindow renderer(1100, 1100);
|
||||
try {
|
||||
SNES snes(argv[1], renderer);
|
||||
renderer.createWindow(snes, 60);
|
||||
parseArguments(argc, argv, snes);
|
||||
return QApplication::exec();
|
||||
// TODO remove the new once arrays are newed.
|
||||
auto *snes = new SNES(renderer);
|
||||
parseArguments(argc, argv, *snes);
|
||||
renderer.createWindow(*snes, 60);
|
||||
int ret = QApplication::exec();
|
||||
delete snes;
|
||||
return ret;
|
||||
}
|
||||
catch(std::exception &ex) {
|
||||
std::cerr << ex.what() << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user