Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
227 lines (196 loc) · 8.81 KB
/
Copy pathmain.cpp
File metadata and controls
227 lines (196 loc) · 8.81 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "maskromtool.h"
#include "romdecoderascii.h"
#include "romdecodercsv.h"
#include "romdecodermarc4.h"
#include "romdecoderarm6.h"
#include "romdecoderjson.h"
#include "romdecoderpython.h"
#include "romdecoderphotograph.h"
#include "romencoderdiff.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QCommandLineParser>
#include <QMessageBox>
int main(int argc, char *argv[]){
QApplication a(argc, argv);
//Stupid portability bug. It's a lot faster to name a font that exists on macOS with no GUI.
if(a.platformName()=="offscreen")
a.setFont(QFont("Helvetica Neue"));
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for (const QString &locale : uiLanguages) {
const QString baseName = "maskromtool_" + QLocale(locale).name();
if (translator.load(":/i18n/" + baseName)) {
a.installTranslator(&translator);
break;
}
}
QCommandLineParser parser;
parser.setApplicationDescription("Mask ROM Tool");
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("image", QCoreApplication::translate("main", "ROM photograph to open."));
parser.addPositionalArgument("json", QCoreApplication::translate("main", "JSON lines to open."));
//Print verbose debugging messages.
QCommandLineOption verboseOption(QStringList() << "V" << "verbose",
QCoreApplication::translate("main", "Print verbose debugging messages."));
parser.addOption(verboseOption);
//Stress test.
QCommandLineOption stressOption(QStringList() << "stress",
QCoreApplication::translate("main", "Stress test bit marking."));
parser.addOption(stressOption);
// Exit after processing other arguments.
QCommandLineOption exitOption(QStringList() << "e" << "exit",
QCoreApplication::translate("main", "Exit after processing arguments."));
parser.addOption(exitOption);
// We used to have an option for OpenGL. Deprecated now that it's default.
QCommandLineOption disableOpenglOption(QStringList() << "disable-opengl",
QCoreApplication::translate("main", "Disable OpenGL."));
parser.addOption(disableOpenglOption);
// Design Rule Check
QCommandLineOption drcOption(QStringList() << "d" << "drc",
QCoreApplication::translate("main", "Run default Design Rule Checks."));
QCommandLineOption DRCOption(QStringList() << "D" << "DRC",
QCoreApplication::translate("main", "Run all Design Rule Checks."));
parser.addOption(drcOption);
parser.addOption(DRCOption);
//Bit Samplers
QCommandLineOption samplerOption(QStringList() << "sampler",
QCoreApplication::translate("main", "Bit Sampling Algorithm."),
"Default"
);
parser.addOption(samplerOption);
// Diffing against ASCII Art
QCommandLineOption asciiDiffOption(QStringList() << "diff-ascii",
QCoreApplication::translate("main", "Compares against ASCII art, for finding errors."),
QCoreApplication::translate("main", "file"));
parser.addOption(asciiDiffOption);
// Exporting to ASCII art.
QCommandLineOption asciiExportOption(QStringList() << "a" << "export-ascii",
QCoreApplication::translate("main", "Export ASCII bits for use in ZorRom."),
QCoreApplication::translate("main", "file"));
parser.addOption(asciiExportOption);
// Exporting to CSV table.
QCommandLineOption csvExportOption(QStringList() << "export-csv",
QCoreApplication::translate("main", "Export CSV bits for use in Matlab or Excel."),
QCoreApplication::translate("main", "file"));
parser.addOption(csvExportOption);
// Exporting to JSON bit positions.
QCommandLineOption jsonExportOption(QStringList() << "export-json",
QCoreApplication::translate("main", "Export JSON bit positions."),
QCoreApplication::translate("main", "file"));
parser.addOption(jsonExportOption);
// Exporting to Python arrays.
QCommandLineOption pythonExportOption(QStringList() << "export-python",
QCoreApplication::translate("main", "Export Python arrays."),
QCoreApplication::translate("main", "file"));
parser.addOption(pythonExportOption);
// Exporting a MARC4 ROM.
QCommandLineOption marc4ExportOption(QStringList() << "export-marc4",
QCoreApplication::translate("main", "Export MARC4 ROM banks, left to right."),
QCoreApplication::translate("main", "file"));
parser.addOption(marc4ExportOption);
// Exporting an ARM6 ROM.
QCommandLineOption arm6ExportOption(QStringList() << "export-arm6",
QCoreApplication::translate("main", "Export ARM6L (MYK82) ROM."),
QCoreApplication::translate("main", "file"));
parser.addOption(arm6ExportOption);
// Exporting a photo.
QCommandLineOption photoExportOption(QStringList() << "export-photo",
QCoreApplication::translate("main", "Export a photograph."),
QCoreApplication::translate("main", "file"));
parser.addOption(photoExportOption);
// Process the actual command line arguments given by the user
parser.process(a);
const QStringList args = parser.positionalArguments();
MaskRomTool mrt(0,
//OpenGL is on by default, unless the platform is offscreen.
!parser.isSet(disableOpenglOption) && !a.platformName().contains("offscreen"));
mrt.show();
for(int i=0; i<args.count(); i++)
mrt.fileOpen(args[i]);
if(parser.isSet(verboseOption)){
//Don't print anything because the function takes care of it for us.
mrt.enableVerbose();
}
//Chooses the sampling algorithm.
if(parser.isSet(samplerOption)){
mrt.chooseSampler(parser.value(samplerOption));
}
if(parser.isSet(asciiDiffOption)){
qDebug()<<"Diffing in ASCII against"<<parser.value(asciiDiffOption);
RomEncoderDiff differ;
differ.readFile(&mrt, parser.value(asciiDiffOption));
}
//Export to ASCII.
if(parser.isSet(asciiExportOption)){
qDebug()<<"Exporting to ASCII.";
RomDecoderAscii exporter;
exporter.writeFile(&mrt, parser.value(asciiExportOption));
}
//Export to CSV.
if(parser.isSet(csvExportOption)){
qDebug()<<"Exporting to CSV.";
RomDecoderCSV exporter;
exporter.writeFile(&mrt, parser.value(asciiExportOption));
}
//Export to JSON bit positions.
if(parser.isSet(jsonExportOption)){
qDebug()<<"Exporting to JSON bit positions.";
RomDecoderJson exporter;
exporter.writeFile(&mrt, parser.value(jsonExportOption));
}
//Export to Python.
if(parser.isSet(pythonExportOption)){
qDebug()<<"Exporting to Python.";
RomDecoderPython exporter;
exporter.writeFile(&mrt, parser.value(pythonExportOption));
}
//Export a photo.
if(parser.isSet(photoExportOption)){
qDebug()<<"Exporting a photo.";
RomDecoderPhotograph exporter;
exporter.writeFile(&mrt, parser.value(photoExportOption));
}
//Export to MARC4.
if(parser.isSet(marc4ExportOption)){
qDebug()<<"Exporting MARC4 ROM. Banks may be in the wrong order.";
RomDecoderMarc4 exporter;
exporter.writeFile(&mrt, parser.value(marc4ExportOption));
}
//Export to ARM6.
if(parser.isSet(arm6ExportOption)){
qDebug()<<"Exporting ARM6 ROM.";
RomDecoderARM6 exporter;
exporter.writeFile(&mrt, parser.value(arm6ExportOption));
}
//Stress test.
if(parser.isSet(stressOption)){
qDebug()<<"Stressing the loaded project.";
for(int i=0; i<10; i++)
mrt.markBits();
}
//We don't return a failure code yet, but will if it comes to that.
if(parser.isSet(DRCOption))
mrt.runDRC(true);
else if(parser.isSet(drcOption))
mrt.runDRC(false);
//We let the GUI take hold unless asked to do otherwise.
if(!parser.isSet(exitOption)){
if(a.platformName().contains("wayland")){
QMessageBox msgBox;
msgBox.setWindowTitle("Wayland is Unstable");
msgBox.setText("The wayland driver is unstable. Please pass '-platform xcb' to maskromtool to use Xorg instead.");
msgBox.exec();
}
//We never launch the GUi for offscreen, because it should always exit.
if(!a.platformName().contains("offscreen"))
return a.exec();
}
//We're exiting here, so the return code should indicate the numer of DRC violations.
long violations=mrt.violations.count();
if(violations>200) //Too large for the shell.
violations=200;
return violations;
}