From f494a10b380f7de2d76e0b0932ae9b6f72e3a063 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Fri, 11 Jan 2019 07:33:23 -0600 Subject: [PATCH] Flesh out the disk settings dialog. This includes pulling appropriate data from the loaded A2R file; we still need to add code to pull from the dialog back into the A2R. --- src/fileio.cpp | 49 ++++++------ src/fileio.h | 1 + src/mainwin.cpp | 168 ++++++++--------------------------------- src/settingsdialog.cpp | 89 ++++++++++++++++++---- src/settingsdialog.h | 10 +-- wozmaker.pro | 12 +-- 6 files changed, 141 insertions(+), 188 deletions(-) diff --git a/src/fileio.cpp b/src/fileio.cpp index ab9344a..3ad949f 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -83,11 +83,8 @@ uint8_t * ReadFile(const char * filename, uint32_t * size) bool LoadA2R(const char * filename) { -/* -Really, this crap should go into fileio.cpp. !!! FIX !!! -*/ - static uint8_t a2rHdr[8] = { 0x41, 0x32, 0x52, 0x32, 0xFF, 0x0A, 0x0D, 0x0A }; - static uint8_t a2rHdr1[8] = { 0x41, 0x32, 0x52, 0x31, 0xFF, 0x0A, 0x0D, 0x0A }; + static uint8_t a2rHdr1[] = "A2R1\xFF\x0A\x0D\x0A"; + static uint8_t a2rHdr[] = "A2R2\xFF\x0A\x0D\x0A"; if (Global::a2r != NULL) free(Global::a2r); @@ -324,9 +321,10 @@ uint8_t * GetMetadata(const char * keyword) for(uint8_t i=0; i= kwLen) - && (memcmp(Global::meta[i], keyword, kwLen) == 0)) + && (memcmp(Global::meta[i], keyword, kwLen) == 0) + && (Global::meta[i][kwLen] == 0x09)) { - return &Global::meta[i][kwLen]; + return &Global::meta[i][kwLen + 1]; } } @@ -336,7 +334,7 @@ uint8_t * GetMetadata(const char * keyword) uint16_t GetRequiredMachineBits(void) { - uint8_t * kw = GetMetadata("requires_machine\x09"); + uint8_t * kw = GetMetadata("requires_machine"); uint32_t kwLen = strlen((char *)kw); uint16_t bits = 0; char type[8]; @@ -380,34 +378,41 @@ uint16_t GetRequiredMachineBits(void) uint16_t GetRequiredRAMInK(void) { - char * kw = (char *)GetMetadata("requires_ram\x09"); + uint16_t ram[13] = { 16, 24, 32, 48, 64, 128, 256, 512, 768, 1024, 1280, 1536, 0 }; + return ram[GetRequiredRAMIndex()]; +} + + +uint16_t GetRequiredRAMIndex(void) +{ + char * kw = (char *)GetMetadata("requires_ram"); if (strcmp(kw, "16K") == 0) - return 16; + return 0; else if (strcmp(kw, "24K") == 0) - return 24; + return 1; else if (strcmp(kw, "32K") == 0) - return 32; + return 2; else if (strcmp(kw, "48K") == 0) - return 48; + return 3; else if (strcmp(kw, "64K") == 0) - return 64; + return 4; else if (strcmp(kw, "128K") == 0) - return 128; + return 5; else if (strcmp(kw, "256K") == 0) - return 256; + return 6; else if (strcmp(kw, "512K") == 0) - return 512; + return 7; else if (strcmp(kw, "768K") == 0) - return 768; + return 8; else if (strcmp(kw, "1M") == 0) - return 1024; + return 9; else if (strcmp(kw, "1.25M") == 0) - return 1280; + return 10; else if (strcmp(kw, "1.5M+") == 0) - return 1536; + return 11; - return 0; + return 12; } /* METADATA Keywords (standard) diff --git a/src/fileio.h b/src/fileio.h index 62bdd04..f959eb5 100644 --- a/src/fileio.h +++ b/src/fileio.h @@ -138,6 +138,7 @@ void UnpackMetadata(Metadata * data); uint8_t * GetMetadata(const char * keyword); uint16_t GetRequiredMachineBits(void); uint16_t GetRequiredRAMInK(void); +uint16_t GetRequiredRAMIndex(void); // Inline functions ("get" functions--need to write "set" functions) diff --git a/src/mainwin.cpp b/src/mainwin.cpp index 4ca0ae1..d601a4f 100644 --- a/src/mainwin.cpp +++ b/src/mainwin.cpp @@ -210,8 +210,37 @@ void MainWin::HandleSaveFile(void) void MainWin::HandleSettings(void) { + // Sanity check + if (Global::a2r == NULL) + return; + SettingsDialog dlg(this); + dlg.line[0].setText((char *)GetMetadata("title")); + dlg.line[1].setText((char *)GetMetadata("subtitle")); + dlg.line[2].setText((char *)GetMetadata("publisher")); + dlg.line[3].setText((char *)GetMetadata("developer")); + dlg.line[4].setText((char *)GetMetadata("copyright")); + dlg.line[5].setText((char *)GetMetadata("version")); + dlg.line[6].setText((char *)GetMetadata("notes")); + dlg.line[7].setText((char *)GetMetadata("side_name")); + dlg.line[8].setText((char *)GetMetadata("contributor")); + + uint16_t machBits = GetRequiredMachineBits(); + + dlg.check[0].setChecked(machBits & 0x001 ? true : false); + dlg.check[1].setChecked(machBits & 0x002 ? true : false); + dlg.check[2].setChecked(machBits & 0x004 ? true : false); + dlg.check[3].setChecked(machBits & 0x008 ? true : false); + dlg.check[4].setChecked(machBits & 0x010 ? true : false); + dlg.check[5].setChecked(machBits & 0x020 ? true : false); + dlg.check[6].setChecked(machBits & 0x040 ? true : false); + dlg.check[7].setChecked(machBits & 0x080 ? true : false); + dlg.check[8].setChecked(machBits & 0x100 ? true : false); + dlg.check[9].setChecked(Global::a2r->writeProtected ? true : false); + + dlg.combo[1].setCurrentIndex(GetRequiredRAMIndex()); + if (dlg.exec() == false) return; @@ -221,143 +250,6 @@ void MainWin::HandleSettings(void) void MainWin::AboutWozMaker(void) { - QMessageBox::about(this, tr("About WOZ Maker"), tr("WOZ Maker v1.0.0\n\nWritten by James Hammons\n\nCopyright (C) 2018 Underground Software")); -} - - -#if 0 -bool MainWin::LoadA2R(const QString filename) -{ -/* -Really, this crap should go into fileio.cpp. !!! FIX !!! -*/ - static uint8_t a2rHdr[8] = { 0x41, 0x32, 0x52, 0x32, 0xFF, 0x0A, 0x0D, 0x0A }; - static uint8_t a2rHdr1[8] = { 0x41, 0x32, 0x52, 0x31, 0xFF, 0x0A, 0x0D, 0x0A }; - - if (Global::a2r != NULL) - free(Global::a2r); - - Global::a2r = (A2R *)ReadFile(filename.toUtf8().data(), &Global::a2rSize); - - if (Global::a2r == NULL) - return false; - - // Sanity check, to see if what we asked for is what we got - if (memcmp(Global::a2r->magic1, a2rHdr, 8) != 0) - { - // It's not a v2 A2R file, maybe it's v1? - if (memcmp(Global::a2r->magic1, a2rHdr1, 8) == 0) - { - // Bytes 8-F are usually: 01 00 8D 00 A5 01 00 00 - // First, allocate mem to copy the old version to the new: - uint8_t * oldfile = (uint8_t *)Global::a2r; - uint8_t * newfile = (uint8_t *)malloc(Global::a2rSize + 36); - memcpy(newfile + 52, oldfile + 16, Global::a2rSize - 16); - - // Make sure creator is set correctly (v1 doesn't have it) - memset(Global::a2r->creator, 0x20, 32); - - // Swap in the new file, free the old one - free(Global::a2r); - Global::a2r = (A2R *)newfile; - Global::a2rSize += 36; // Add in the size of the INFO chunk - - // Fix up stuff that's different between v1 and v2 -//printf("A2R Size: %08X\n", Global::a2rSize); -//printf("A2R Stream Size: %08X (preswap)\n", Global::a2r->strmSize); - SwapBytes32((uint8_t *)&Global::a2r->strmSize); -//printf("A2R Stream Size: %08X (postswap)\n", Global::a2r->strmSize); - uint32_t dataSize = Uint32LE(Global::a2r->strmSize); - uint32_t pos = 0; - - while (pos < dataSize) - { - A2RStream * stream = (A2RStream *)(&Global::a2r->data[pos]); - - if (stream->location == 0xFF) - break; - - SwapBytes32(stream->dataLength); - SwapBytes32(stream->estLoopPoint); - pos += 10 + Uint32LE(stream->dataLength); - } - - // Change INFO to META & fix size (if any, dunno if it's optional) - if (Global::a2rSize > (60 + dataSize)) - { - memcpy(&Global::a2r->data[dataSize], "META", 4); - SwapBytes32(&Global::a2r->data[dataSize + 4]); - } - } - else - { - free(Global::a2r); - Global::a2r = NULL; - - QMessageBox::critical(this, "Bad A2R file", "It may have an .a2r extension, but it isn't a valid A2R file."); - - return false; - } - } - - // Setup individual stream pointers - Global::numStreams = 0; - uint8_t * streamPtr = Global::a2r->data; - - while ((*streamPtr != 0xFF) && (Global::numStreams < 800)) - { - Global::stream[Global::numStreams] = (A2RStream *)streamPtr; - streamPtr += 10 + Uint32LE(Global::stream[Global::numStreams]->dataLength); - Global::numStreams++; - } - - // Metadata check - Global::metadata = NULL; - - if (Global::a2rSize > (60 + Uint32LE(Global::a2r->strmSize))) - { - Global::metadata = (A2RMetadata *)((uint8_t *)Global::a2r + (60 + Uint32LE(Global::a2r->strmSize))); - - // Make sure it's plausible metadata - if (memcmp(Global::metadata->metaTag, "META", 4) != 0) - Global::metadata = NULL; - } - - // Unpack TMNG & XTMG streams to simplify analysis - for(uint32_t i=0; icaptureType == 2) - continue; - - // We skip the first timing byte because it can't tell you what the actual time was when the pulse was seen--it's the time between when the *capture* started and the pulse was seen, not the time between the previous pulse and this one! So that first one is discarded since it's worse than useless; it's misleading. - for(uint32_t j=1; jdataLength); j++) - { - uint32_t a = Global::stream[i]->data[j]; - - while ((Global::stream[i]->data[j] == 0xFF) || (a < 24)) - { - j++; - a += Global::stream[i]->data[j]; - } - - Global::wave[i][Global::waveLen[i]] = a; - Global::waveLen[i]++; - } - } - -//ISO-8061 date format -#if 0 - char buf[200]; - time_t t = time(NULL); - tm * tmp = gmtime(&t); - strftime(buf, sizeof(buf), "%FT%TZ", tmp); - printf("Time is: %s\n", buf); -#endif - - return true; + QMessageBox::about(this, tr("About WOZ Maker"), tr("WOZ Maker v1.0.0\n\nWritten by James Hammons\n\nCopyright (C) 2019 Underground Software")); } -#endif diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 3321f30..214b693 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -1,28 +1,85 @@ // -// settingsdialog.cpp: Dialog for changing Architektonas settings +// settingsdialog.cpp: Dialog for changing disk settings // -// Part of the Architektonas Project -// (C) 2011 Underground Software +// Part of the Wozmaker Project +// (C) 2019 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James Hammons -// -// WHO WHEN WHAT -// --- ---------- ------------------------------------------------------------ -// JLH 06/04/2011 Created this file #include "settingsdialog.h" -//#include "baseunittab.h" -//#include "generaltab.h" SettingsDialog::SettingsDialog(QWidget * parent/*= 0*/): QDialog(parent) { -// tabWidget = new QTabWidget; -// generalTab = new GeneralTab(this); -// baseunitTab = new BaseUnitTab(this); -// tabWidget->addTab(generalTab, tr("General")); -// tabWidget->addTab(baseunitTab, tr("Base Unit")); + QGridLayout * grid = new QGridLayout; + + QStringList lsl = { "Title", "Subtitle", "Publisher", "Developer", "Copyright", "Version", "Language", "Requires", "Notes", "Side", "Side Name", "Contributor" }; + + for(int i=0; i<12; i++) + { + label[i].setText(lsl[i]); + label[i].setAlignment(Qt::AlignRight); + } + + grid->addWidget(&label[0], 0, 0); + grid->addWidget(&label[1], 1, 0); + grid->addWidget(&label[2], 2, 0); + grid->addWidget(&label[3], 3, 0); + grid->addWidget(&label[4], 4, 0); + grid->addWidget(&label[5], 5, 0); + grid->addWidget(&label[6], 5, 2); + grid->addWidget(&label[7], 6, 0, 1, 1, Qt::AlignTop); + + QStringList lesl = { "Title of the software", "If there's a subtitle, put it here", "Who published the software?", "Who wrote the software?", "", "1.0", "Put any additional notes about the disk here", "A, B, Dungeon, Towne, etc.", "Who contributed this disk?" }; + + for(int i=0; i<9; i++) + line[i].setPlaceholderText(lesl[i]); + + QStringList sl1 = { "English", "Spanish", "French", "German", "Chinese", "Japanese", "Italian", "Dutch", "Portuguese", "Danish", "Finnish", "Norwegian", "Swedish", "Russian", "Polish", "Turkish", "Arabic", "Thai", "Czech", "Hungarian", "Catalan", "Croatian", "Greek", "Hebrew", "Romanian", "Slovak", "Ukrainian", "Indonesian", "Malay", "Vietnamese", "Other" }; + QStringList sl2 = { "16K", "24K", "32K", "48K", "64K", "128K", "256K", "512K", "768K", "1M", "1.25M", "1.5M+", "Unknown" }; + QStringList sl3 = { "Disk 1, Side A", "Disk 1, Side B", "Disk 2, Side A", "Disk 2, Side B", "Disk 3, Side A", "Disk 3, Side B", "Disk 4, Side A", "Disk 4, Side B", "Disk 5, Side A", "Disk 5, Side B", "Disk 6, Side A", "Disk 6, Side B", "Disk 7, Side A", "Disk 7, Side B", "Disk 8, Side A", "Disk 8, Side B" }; + + combo[0].insertItems(0, sl1); + combo[1].insertItems(0, sl2); + combo[2].insertItems(0, sl3); + + grid->addWidget(&line[0], 0, 1, 1, -1); + grid->addWidget(&line[1], 1, 1, 1, -1); + grid->addWidget(&line[2], 2, 1, 1, -1); + grid->addWidget(&line[3], 3, 1, 1, -1); + grid->addWidget(&line[4], 4, 1, 1, -1); + grid->addWidget(&line[5], 5, 1); + grid->addWidget(&combo[0], 5, 3); + + QGridLayout * cbGrid = new QGridLayout; + + QStringList cbsl = { "][", "][+", "//e", "//c", "//e Enh.", "IIgs", "//c+", "///", "///+", "Write Protected" }; + + for(int i=0; i<10; i++) + check[i].setText(cbsl[i]); + + cbGrid->addWidget(&check[0], 0, 0); + cbGrid->addWidget(&check[1], 0, 1); + cbGrid->addWidget(&check[2], 0, 2); + cbGrid->addWidget(&check[3], 1, 0); + cbGrid->addWidget(&check[4], 1, 1); + cbGrid->addWidget(&check[5], 1, 2); + cbGrid->addWidget(&check[6], 2, 0); + cbGrid->addWidget(&check[7], 2, 1); + cbGrid->addWidget(&check[8], 2, 2); + + grid->addLayout(cbGrid, 6, 1); + grid->addWidget(&combo[1], 6, 3, 1, 1, Qt::AlignTop); + + grid->addWidget(&label[8], 7, 0); + grid->addWidget(&line[6], 7, 1, 1, -1); + grid->addWidget(&label[9], 8, 0); + grid->addWidget(&combo[2], 8, 1); + grid->addWidget(&label[10], 8, 2); + grid->addWidget(&line[7], 8, 3); + grid->addWidget(&check[9], 9, 3); + grid->addWidget(&label[11], 10, 0); + grid->addWidget(&line[8], 10, 1, 1, -1); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); @@ -30,7 +87,7 @@ SettingsDialog::SettingsDialog(QWidget * parent/*= 0*/): QDialog(parent) connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QVBoxLayout * mainLayout = new QVBoxLayout; -// mainLayout->addWidget(tabWidget); + mainLayout->addLayout(grid); mainLayout->addWidget(buttonBox); setLayout(mainLayout); diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 79ff882..6bf2f52 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -3,9 +3,6 @@ #include -//class GeneralTab; -//class BaseUnitTab; - class SettingsDialog: public QDialog { Q_OBJECT @@ -15,12 +12,13 @@ class SettingsDialog: public QDialog ~SettingsDialog(); private: -// QTabWidget * tabWidget; QDialogButtonBox * buttonBox; public: -// GeneralTab * generalTab; -// BaseUnitTab * baseunitTab; + QLabel label[12]; + QLineEdit line[9]; + QComboBox combo[3]; + QCheckBox check[10]; }; #endif // __SETTINGSDIALOG_H__ diff --git a/wozmaker.pro b/wozmaker.pro index 80f3ece..dde889d 100644 --- a/wozmaker.pro +++ b/wozmaker.pro @@ -1,11 +1,11 @@ # Use 'qmake -o Makefile wozmaker.pro' -CONFIG += qt warn_on release c++11 -RESOURCES += res/resources.qrc -#LIBS += -Ldxflib/lib -ldxf -#LIBS += -lao -QMAKE_LIBS += -static -QT += widgets +CONFIG += qt warn_on release c++11 +RESOURCES += res/resources.qrc +#LIBS += -Ldxflib/lib -ldxf +#LIBS += -lao +#QMAKE_LIBS += -static +QT += widgets # We stuff all the intermediate crap into obj/ so it won't confuse us mere mortals ;-) OBJECTS_DIR = obj -- 2.37.2