diff --git a/lib/macrompatcher.h b/lib/macrompatcher.h index 98b01df..052fce6 100644 --- a/lib/macrompatcher.h +++ b/lib/macrompatcher.h @@ -2,6 +2,10 @@ #define __MACROMPATCHER_H__ 1 #include +#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__ */ diff --git a/qtgui/RomPatcher.cpp b/qtgui/RomPatcher.cpp new file mode 100644 index 0000000..f482a09 --- /dev/null +++ b/qtgui/RomPatcher.cpp @@ -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: "); + 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(); +} diff --git a/qtgui/RomPatcher.h b/qtgui/RomPatcher.h new file mode 100644 index 0000000..a298633 --- /dev/null +++ b/qtgui/RomPatcher.h @@ -0,0 +1,31 @@ +#include +#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; +}; diff --git a/qtgui/RomPatcher.pro b/qtgui/RomPatcher.pro new file mode 100644 index 0000000..e7f6aaa --- /dev/null +++ b/qtgui/RomPatcher.pro @@ -0,0 +1,6 @@ +SOURCES = RomPatcher.cpp main.cpp +HEADERS = RomPatcher.h + +CONFIG += qt + +LIBS += ../lib/libmacrom.a diff --git a/qtgui/main.cpp b/qtgui/main.cpp new file mode 100644 index 0000000..5f3901a --- /dev/null +++ b/qtgui/main.cpp @@ -0,0 +1,12 @@ +#include +#include "RomPatcher.h" + +int main(int argc, char **argv) { + QApplication app(argc, argv); + + RomPatcher rp; + + rp.show(); + + return app.exec(); +}