diff --git a/src/applesoftfile/applesoftfile.cxx b/src/applesoftfile/applesoftfile.cxx index 5c1a570..ca323f1 100644 --- a/src/applesoftfile/applesoftfile.cxx +++ b/src/applesoftfile/applesoftfile.cxx @@ -52,7 +52,11 @@ void ApplesoftFile::parse(quint16 start_address) line.tokens.append(token); } while (val != 0x00); + Retokenizer ret; + ret.retokenize(line); + current_address = line.next_address; + m_lines.append(line); } @@ -93,78 +97,90 @@ QByteArray ApplesoftFile::extraData() void Retokenizer::retokenize(ApplesoftLine &line) { Q_UNUSED(line); -// QList string_list; -// QList number_list; - -// QByteArray newTokens; - -//// Set Strings aside for a bit to simplify parsing -// QByteArray tmpTokens = line.raw_tokens; -// QByteArray tmpstr; -// bool inString = false; -// for (int idx = 0; idx < line.raw_tokens.length(); idx++) -// { -// quint8 byte = tmpTokens.at(idx); - -// if (byte == '"') { -// if (!inString) { -// inString = true; -// tmpstr.append(byte); -// } else { -// inString = false; -// string_list.append(tmpstr); -// tmpstr = ""; -// newTokens.append(0xff); -// } -// } else if (!inString) { -// newTokens.append(byte); -// } -// } -// if (inString) { -// string_list.append(tmpstr); -// newTokens.append(0xff); -// } + QVector replacements; + QVector tmptokens = line.tokens; + ApplesoftToken token; + QByteArray buffer; -////// Set Numbers aside for a bit too -//// tmpTokens = newTokens; -//// newTokens = ""; -//// bool inNumber = false; -//// QByteArray tmpnum; -//// for (int idx = 0; idx < tmpTokens.length(); idx++) -//// { -//// quint8 byte = tmpTokens.at(idx); + bool inRem = false; -//// if ((byte >= '0' && byte <= '9') || byte == '.') { -//// if (!inNumber) { -//// inNumber = true; -//// tmpnum.append(byte); -//// } -//// } else if (inNumber) { -//// inNumber = false; -//// number_list.append(tmpnum); -//// tmpnum = ""; -//// newTokens.append(0xfe); -//// newTokens.append(byte); -//// } else { -//// newTokens.append(byte); -//// } -//// } -//// if (inNumber) { -//// number_list.append(tmpnum); -//// newTokens.append(0xfe); -//// } + // Handle REMs + while (!tmptokens.isEmpty()) + { + token = tmptokens.takeFirst(); -// line.advanced_tokens = newTokens; + if (!inRem) { + replacements.append(token); + if (token.getByteValue() == ApplesoftToken::ASRem) + { + inRem = true; + } + } + else + { + buffer.append(token.getByteValue()); + } + } + if (inRem) { + ApplesoftToken remstrtoken(ApplesoftToken::RemStringTokenVal, buffer); + replacements.append(remstrtoken); + buffer.clear(); + inRem = false; + } -// // QList tmpParts = tmpTokens.split(':'); + line.tokens = replacements; + replacements.clear(); + + // Handle DATAs + + // Handle Strings + + tmptokens = line.tokens; + bool inString = false; + + while (!tmptokens.isEmpty()) + { + token = tmptokens.takeFirst(); + if (token.getTokenId() >= 0x80) + { + replacements.append(token); + continue; + } + + if (token.getByteValue() == '"') + { + if (!inString) + { + inString = true; + buffer.append(token.getByteValue()); + continue; + } + else + { + buffer.append(token.getByteValue()); + ApplesoftToken strtoken(ApplesoftToken::StringTokenVal, buffer); + replacements.append(strtoken); + buffer.clear(); + inString = false; + continue; + } + } + + if (inString) + { + buffer.append(token.getByteValue()); + continue; + } + + replacements.append(token); + } + + line.tokens = replacements; -//// foreach (QByteArray part, tmpParts) { -//// QByteArray retokenizedPart = retokenzePart(part); -//// } } QByteArray Retokenizer::retokenizePart(QByteArray part) { diff --git a/src/applesoftfile/applesoftformatter.cxx b/src/applesoftfile/applesoftformatter.cxx index bea8a9e..33ae731 100644 --- a/src/applesoftfile/applesoftformatter.cxx +++ b/src/applesoftfile/applesoftformatter.cxx @@ -1,4 +1,5 @@ #include "applesoftformatter.h" +#include "util.h" ApplesoftFormatter::ApplesoftFormatter(QObject *parent) : QObject(parent) @@ -19,23 +20,44 @@ QString ApplesoftFormatter::formatText() } QString retval; + foreach (ApplesoftLine line, m_file->getLines()) { QString linestring = QString("%1 ").arg(line.linenum,5,10,QChar(' ')); retval.append(linestring); - foreach (ApplesoftToken token, line.tokens) { + foreach (ApplesoftToken token, line.tokens) + { QString tokenstr = token.getRawPrintableString(); + if (m_format_options.testFlag(BreakAfterReturn)) { + if (token.getByteValue() == ApplesoftToken::ASReturn) + { + tokenstr += "\n"; + } + } + +#define DEBUGTOKENS +#ifdef DEBUGTOKENS + if (token.getTokenId() >= 0x80) + { + tokenstr = QString(" {%1} ").arg(uint16ToHex(token.getTokenId())); + // tokenstr = " __ "; + } + else + { + tokenstr = QString("%1").arg(QChar(token.getByteValue())); + } +#endif + if (m_format_options.testFlag(ShowCtrlChars)) { tokenstr.replace(QChar(0x7f),QChar(0x2401)); for (int idx = 1; idx <= 0x1f; idx++) { + if (idx == '\n') continue; + if (idx == '\t') continue; tokenstr.replace(QChar(idx),QChar(idx+0x2400)); } } - if (m_format_options.testFlag(BreakAfterReturn)) { - tokenstr.replace("RETURN","RETURN\n"); - } retval.append(tokenstr); } diff --git a/src/applesoftfile/applesofttoken.cxx b/src/applesoftfile/applesofttoken.cxx index bab8f50..1bd8bda 100644 --- a/src/applesoftfile/applesofttoken.cxx +++ b/src/applesoftfile/applesofttoken.cxx @@ -97,8 +97,11 @@ QString ApplesoftToken::getRawPrintableString() return QString(QChar(m_token_id)); } else if (m_token_id <= 0xff) { return m_tokens[m_token_id]; - } else + } else if (m_token_id == StringTokenVal) { + return getByteStringValue(); + } else { return "[temp undefined]"; + } } void ApplesoftToken::initializeTokenTable() diff --git a/src/applesoftfile/applesofttoken.h b/src/applesoftfile/applesofttoken.h index e9e9c5a..27fe5b8 100644 --- a/src/applesoftfile/applesofttoken.h +++ b/src/applesoftfile/applesofttoken.h @@ -12,12 +12,16 @@ public: static const quint16 StringTokenVal = 0x100; static const quint16 RemStringTokenVal = 0x101; static const quint16 DataStringTokenVal = 0x102; + static const quint16 IntegerTokenVal = 0x103; static const quint16 FloatTokenVal = 0x104; + static const quint16 IntVarTokenVal = 0x105; static const quint16 IntAryVarTokenVal = 0x106; + static const quint16 FloatVarTokenVal = 0x107; static const quint16 FloatAryVarTokenVal = 0x108; + static const quint16 StringVarTokenVal = 0x109; static const quint16 StringAryVarTokenVal = 0x10A; @@ -127,8 +131,8 @@ public: quint16 getTokenId() const { return m_token_id; } void setValue(QVariant value); - QVariant getValue() const { return m_payload; } + QByteArray getByteStringValue() const { return m_payload.toByteArray(); } quint16 getWordValue() const { return (quint16) (m_payload.toUInt() & 0xFFFF); } quint8 getByteValue() const { return (quint8) (m_payload.toUInt() & 0xFF); } diff --git a/src/ui/mainwindow.cxx b/src/ui/mainwindow.cxx index e707d1b..147830b 100644 --- a/src/ui/mainwindow.cxx +++ b/src/ui/mainwindow.cxx @@ -82,9 +82,11 @@ void MainWindow::unloadDiskFile() void MainWindow::showLoadDialog() { + QSettings settings; + QString last = settings.value("lastOpened",".").toString(); QString filename = QFileDialog::getOpenFileName(this, tr("Open Disk Image"), - "/home/mlong/Desktop", + last, "Disk Images (*.do *.dsk)"); if (!filename.isEmpty()) { loadDiskFile(filename); diff --git a/src/ui/viewers/applesoftfileviewer.cxx b/src/ui/viewers/applesoftfileviewer.cxx index 9bd717a..9cbfccd 100644 --- a/src/ui/viewers/applesoftfileviewer.cxx +++ b/src/ui/viewers/applesoftfileviewer.cxx @@ -12,7 +12,7 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) : setWindowTitle(title); m_formatter = new ApplesoftFormatter(this); - m_formatter->setFlags(ApplesoftFormatter::PrettyFlags); + m_formatter->setFlags(ApplesoftFormatter::PrettyFlags | ApplesoftFormatter::BreakAfterReturn); connect(ui->findButton,SIGNAL(clicked(bool)), SLOT(findText())); m_isFirstFind = true;