Wild guess at a Qt GUI.
This commit is contained in:
parent
919af0757e
commit
88d5538984
|
@ -2,6 +2,10 @@
|
|||
#define __MACROMPATCHER_H__ 1
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Known types of ROM images. */
|
||||
enum RomType {
|
||||
eUnknown = 0,
|
||||
|
@ -62,4 +66,8 @@ const char *GetROMErrString(RomErr err);
|
|||
RomErr GetDRVROffset(RomCtx *rom, uint16_t drvrid, uint32_t *offset);
|
||||
RomErr InstallRomdiskDrvr(RomCtx *rom);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* __MACROMPATCHER_H__ */
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
#include "RomPatcher.h"
|
||||
|
||||
RomPatcher::RomPatcher()
|
||||
{
|
||||
openAction = new QAction(tr("&Open"), this);
|
||||
saveAction = new QAction(tr("&Save"), this);
|
||||
exitAction = new QAction(tr("&Exit"), this);
|
||||
|
||||
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
|
||||
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
|
||||
connect(exitAction, SIGNAL(triggered()), this, SLOT(quit()));
|
||||
|
||||
fileMenu = menuBar()->addMenu(tr("&File"));
|
||||
fileMenu->addAction(openAction);
|
||||
fileMenu->addAction(saveAction);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(exitAction);
|
||||
|
||||
int mywidth = 200;
|
||||
int myheight = 300;
|
||||
int yoffset = 25;
|
||||
int xoffset = 5;
|
||||
checksum = new QLabel(this);
|
||||
checksum->setText("Checksum: <NA>");
|
||||
checksum->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||
checksum->move(xoffset, yoffset);
|
||||
yoffset += 25;
|
||||
checksum->setMinimumSize(mywidth, 10);
|
||||
|
||||
applyRomdisk = new QRadioButton("Apply ROMdisk Driver", this);
|
||||
applyRomdisk->move(xoffset, yoffset);
|
||||
applyRomdisk->setMinimumSize(mywidth, 10);
|
||||
applyRomdisk->setEnabled(false);
|
||||
|
||||
applyModsGo = new QPushButton("Apply Mods", this);
|
||||
applyModsGo->move(mywidth/2 - (applyModsGo->width())/2, myheight-50);
|
||||
applyModsGo->setEnabled(false);
|
||||
connect(applyModsGo, SIGNAL(clicked()), this, SLOT(applyMods()));
|
||||
|
||||
setWindowTitle(tr("RomPatcher"));
|
||||
setMinimumSize(mywidth, myheight);
|
||||
|
||||
rom = (RomCtx*)calloc(1, sizeof(RomCtx));
|
||||
}
|
||||
|
||||
void RomPatcher::open()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", "");
|
||||
if(fileName != "") {
|
||||
QFile file(fileName);
|
||||
if(!file.open(QIODevice::ReadOnly)) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
|
||||
return;
|
||||
}
|
||||
|
||||
// create the RomCtx structure and populate it here
|
||||
rom->datasize = rom->filesize = file.size();
|
||||
rom->data = (uint8_t*)calloc(1, rom->datasize);
|
||||
QDataStream stream(&file);
|
||||
stream.readRawData((char*)rom->data, (uint)rom->datasize);
|
||||
file.close();
|
||||
|
||||
if(rom->filesize < (512*1024)) {
|
||||
rom->type = e24bit;
|
||||
}else{
|
||||
rom->type = e32bit;
|
||||
}
|
||||
|
||||
updateChecksumUI();
|
||||
applyRomdisk->setEnabled(true);
|
||||
applyModsGo->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void RomPatcher::save()
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", "");
|
||||
if(fileName != "") {
|
||||
QFile file(fileName);
|
||||
if(!file.open(QIODevice::WriteOnly)) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not save file"));
|
||||
return;
|
||||
}
|
||||
|
||||
// save the RomCtx structure here
|
||||
RomErr err = UpdateChecksum(rom);
|
||||
if(err != eSuccess) {
|
||||
fprintf(stderr, "Error updating checksum: %d %s\n", err, GetROMErrString(err));
|
||||
}
|
||||
|
||||
QDataStream stream(&file);
|
||||
stream.writeRawData((char*)rom->data, (int)rom->datasize);
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void RomPatcher::quit()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void RomPatcher::updateChecksumUI()
|
||||
{
|
||||
uint32_t cksum;
|
||||
char *cksumstr = NULL;
|
||||
GetChecksum(rom, &cksum);
|
||||
asprintf(&cksumstr, "Checksum: %#x", cksum);
|
||||
checksum->setText(cksumstr);
|
||||
free(cksumstr);
|
||||
}
|
||||
|
||||
void RomPatcher::applyMods()
|
||||
{
|
||||
if(applyRomdisk->isChecked()) {
|
||||
printf("Romdisk checked, applying\n");
|
||||
RomErr err = InstallRomdiskDrvr(rom);
|
||||
if(err != eSuccess) {
|
||||
fprintf(stderr, "Error applying romdisk drvr: %d %s\n", err, GetROMErrString(err));
|
||||
}
|
||||
}
|
||||
|
||||
updateChecksumUI();
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
#include <QtGui>
|
||||
#include "../lib/macrompatcher.h"
|
||||
|
||||
class RomPatcher : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RomPatcher();
|
||||
|
||||
private slots:
|
||||
void open();
|
||||
void save();
|
||||
void quit();
|
||||
void applyMods();
|
||||
|
||||
private:
|
||||
void updateChecksumUI();
|
||||
|
||||
QAction *openAction;
|
||||
QAction *saveAction;
|
||||
QAction *exitAction;
|
||||
|
||||
QMenu *fileMenu;
|
||||
|
||||
QLabel *checksum;
|
||||
QRadioButton *applyRomdisk;
|
||||
QPushButton *applyModsGo;
|
||||
|
||||
RomCtx *rom;
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
SOURCES = RomPatcher.cpp main.cpp
|
||||
HEADERS = RomPatcher.h
|
||||
|
||||
CONFIG += qt
|
||||
|
||||
LIBS += ../lib/libmacrom.a
|
|
@ -0,0 +1,12 @@
|
|||
#include <QtGui>
|
||||
#include "RomPatcher.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QApplication app(argc, argv);
|
||||
|
||||
RomPatcher rp;
|
||||
|
||||
rp.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
Loading…
Reference in New Issue