Skip to content

Commit

Permalink
File/Export/Solver Set Bytes. Close #114.
Browse files Browse the repository at this point in the history
  • Loading branch information
travisgoodspeed committed Jul 20, 2024
1 parent 4e72f49 commit 48487ea
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 19 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ is a Zilog Z8 ROM from a music synthesize module.
## Release Changelog

`master` -- Gatorom's solver-set option now uses descriptive
fiilenames.
fiilenames. GUI can now export a set of solved results with
File/Export/SolverSetBytes.

2024-07-14 -- Fixes crash when deleting a double-selected item. Delete
and backspace now delete objects like `D`. Multiple disassemblers.
Expand Down
5 changes: 1 addition & 4 deletions gatomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,15 @@ int main(int argc, char *argv[]) {

GatoSolver solver(gr, grader);
for(solver.init(); !solver.finished(); solver.next()){
int state=solver.state;
//QString statestring=QString::asprintf("%04x", state); //Older behavior, with hash.
QString statestring=gr->descriptiveFilename();

//We aren't interested in zero scores or empty results.
if(solver.grade()>0 && gr->preview().length()>0){
std::cout<<solver.grade()<<" \t"
<<gr->preview().toStdString()<<"\t"
<<parser.value(solvesetOption).toStdString()<<statestring.toStdString()<<".bin\n";
//All outputs go when we're dumping the set.
if(parser.isSet(solvesetOption)){

if(solver.grade()>90 && parser.isSet(solvesetOption)){
QFile outfile(parser.value(solvesetOption)+statestring+".bin");
outfile.open(QIODevice::WriteOnly);
outfile.write(gr->decoded);
Expand Down
15 changes: 14 additions & 1 deletion maskromtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,21 +1811,34 @@ void MaskRomTool::on_actionRedo_triggered(){
redo();
}


//Shows the ASCII strings dialog.
void MaskRomTool::on_stringsButton_triggered(){
gatorom();
stringsDialog.show();
}

//Shows the solver dialog.
void MaskRomTool::on_actionSolver_triggered(){
gatorom();
solverDialog.show();
}


void MaskRomTool::on_exportSolverSetBytes_triggered(){
//QFileDialog::getSaveFileName(this,tr("Save JSON"), tr("bits.json"));
QString filename = QFileDialog::getExistingDirectory(this,tr("Export Directory"));
filename += "/solver";

if(!filename.isEmpty())
solverDialog.solve(filename);
}



void MaskRomTool::on_actionDisassembly_triggered(){
gatorom();
disDialog.show();
}



2 changes: 2 additions & 0 deletions maskromtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ private slots:

void on_crosshaircolorButton_triggered();

void on_exportSolverSetBytes_triggered();

private:
Ui::MaskRomTool *ui;
qreal thresholdR, thresholdG, thresholdB;
Expand Down
6 changes: 6 additions & 0 deletions maskromtool.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<addaction name="exportHistogram"/>
<addaction name="separator"/>
<addaction name="exportROMBytes"/>
<addaction name="exportSolverSetBytes"/>
</widget>
<widget class="QMenu" name="menuImport">
<property name="title">
Expand Down Expand Up @@ -510,6 +511,11 @@
<string>Crosshair Color</string>
</property>
</action>
<action name="exportSolverSetBytes">
<property name="text">
<string>Solver Set Bytes</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
49 changes: 37 additions & 12 deletions romsolverdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,10 @@ void RomSolverDialog::on_editYara_textChanged(){
yararule=ui->editYara->toPlainText();
}


/* This runs through the potential solutions, using the GUI
* settings.
/* Returns a new GatoGrader based upon the GUI settings.
*/
void RomSolverDialog::on_butSolve_clicked(){
GatoGrader* RomSolverDialog::grader(){
GatoGrader *grader=0;
GatoROM *gr=&(mrt->gr);
QString oldstate=gr->description();

mrt->solutionsDialog.clearSolutions();
mrt->solutionsDialog.show();

int index=ui->tabWidget->currentIndex();
switch(index){
Expand All @@ -71,16 +64,42 @@ void RomSolverDialog::on_butSolve_clicked(){
break;
default:
qDebug()<<"Unknown solver tab"<<index;
return;
break;
}

return grader;
}

/* This generates the GUI solutions and populates the solution set.
* If "solveset" is not empty, each solution will be exported as
* well.
*/
void RomSolverDialog::solve(QString solveset){
GatoGrader *grader=0;
GatoROM *gr=&(mrt->gr);
QString oldstate=gr->description();

mrt->solutionsDialog.clearSolutions();
mrt->solutionsDialog.show();

grader=this->grader();
if(!grader) return;

GatoSolver solver(gr, grader);
for(solver.init(); !solver.finished(); solver.next()){
int grade=solver.grade();
QString statestring=gr->description();
QString statestring=gr->descriptiveFilename();

if(grade>=90){
mrt->solutionsDialog.registerSolution(grade, statestring);

//When called from File/Export/SolveSetBINs
if(solveset.length()>0){
QFile outfile(solveset+statestring+".bin");
outfile.open(QIODevice::WriteOnly);
outfile.write(gr->decoded);
outfile.close();
}
}
}

Expand All @@ -95,10 +114,16 @@ void RomSolverDialog::on_butSolve_clicked(){
mrt->gr.configFromDescription(oldstate);
mrt->decodeDialog.update();


if(grader)
delete grader;
}

/* This runs through the potential solutions, using the GUI
* settings.
*/
void RomSolverDialog::on_butSolve_clicked(){
solve();
}



4 changes: 3 additions & 1 deletion romsolverdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QTemporaryFile>

class MaskRomTool;
class GatoGrader;


namespace Ui {
Expand All @@ -21,10 +22,11 @@ class RomSolverDialog : public QDialog
void setMaskRomTool(MaskRomTool *mrt);
void setYaraRule(QString rule);
QString yararule;
GatoGrader* grader();
void solve(QString solveset="");

private slots:
void on_butSolve_clicked();

void on_editYara_textChanged();

private:
Expand Down

0 comments on commit 48487ea

Please sign in to comment.