Added new ApplesoftToken class

This commit is contained in:
Mark Long 2015-12-14 03:20:36 -06:00
parent d652dad5c8
commit db6b50831b
5 changed files with 162 additions and 89 deletions

View File

@ -23,7 +23,8 @@ SOURCES += src/main.cpp \
src/catalogwidget.cxx \
src/mainwindow.cxx \
src/hiresviewwidget.cxx \
src/applesoftfileviewer.cxx
src/applesoftfileviewer.cxx \
src/applesofttoken.cxx
HEADERS += \
src/diskfile.h \
@ -41,7 +42,8 @@ HEADERS += \
src/catalogwidget.h \
src/mainwindow.h \
src/hiresviewwidget.h \
src/applesoftfileviewer.h
src/applesoftfileviewer.h \
src/applesofttoken.h
FORMS += \
src/catalogwidget.ui \

View File

@ -3,10 +3,7 @@
ApplesoftFile::ApplesoftFile(QByteArray data) : GenericFile(data)
{
if (m_tokens.size() == 0)
{
makeTokens();
}
if (!data.isEmpty())
{
@ -25,40 +22,71 @@ void ApplesoftFile::setData(QByteArray data)
m_detokenized = detokenize();
}
QList<ApplesoftLine> ApplesoftFile::detokenize()
QList<ApplesoftLine> ApplesoftFile::detokenize(quint16 start_address)
{
QList<ApplesoftLine> retval;
int idx = 0;
quint8 val = 0;
quint16 current_address = start_address;
while (idx < m_data.length()) {
ApplesoftLine line;
line.address = current_address;
line.next_address = (quint8) m_data[idx] + (((quint8) m_data[idx+1]) *256);
line.tokens.append(m_data[idx]);
line.tokens.append(m_data[idx+1]);
idx++; idx++;
line.linenum = (quint8) m_data[idx] + (((quint8) m_data[idx+1])*256);
line.tokens.append(m_data[idx]);
line.tokens.append(m_data[idx+1]);
idx++; idx++;
if (line.next_address == 0x00) { break; }
do {
val = m_data[idx++];
line.tokens.append(val);
if (val >= 0x80) {
line.detokenized_line.append(m_tokens[val]);
} else {
if (val >= 0x20) {
line.detokenized_line.append(val);
} else if (val == 0x7F) {
QChar ch = QChar(0x2401);
line.detokenized_line.append(ch);
}else if (val > 0x00) {
QChar ch = QChar(0x2400 + val);
line.detokenized_line.append(ch);
}
}
ApplesoftToken token(val);
line.tokens.append(token);
// line.raw_tokens.append(val);
// if (val >= 0x80) {
// // line.detokenized_line.append("~");
// line.detokenized_line.append(m_tokens[val]);
// } else {
// if (val >= 0x20) {
// line.detokenized_line.append(val);
// } else if (val == 0x7F) {
// QChar ch = QChar(0x2401);
// line.detokenized_line.append(ch);
// }else if (val > 0x00) {
// QChar ch = QChar(0x2400 + val);
// line.detokenized_line.append(ch);
// }
// }
} while (val != 0x00);
Retokenizer::retokenize(line);
//Make Detokenized line
foreach (ApplesoftToken token, line.tokens) {
quint16 tokenval = token.getTokenId();
line.detokenized_line.append(token.getRawPrintableString());
// if (tokenval >= 0x80 && tokenval < 0xFE) {
// line.detokenized_line.append("{kwd}");
// } else if (tokenval >= 0xF0) {
// line.detokenized_line.append(ApplesoftToken::getStringForToken(tokenval));
// } else {
// if (tokenval >= 0x20) {
// line.detokenized_line.append(tokenval);
// } else if (tokenval == 0x7F) {
// QChar ch = QChar(0x2401);
// line.detokenized_line.append(ch);
// }else if (tokenval > 0x00) {
// QChar ch = QChar(0x2400 + tokenval);
// line.detokenized_line.append(ch);
// }
// }
}
current_address = line.next_address;
retval.append(line);
}
@ -115,62 +143,87 @@ QByteArray ApplesoftFile::extraData()
return m_data.mid(m_data_end);
}
void ApplesoftFile::makeTokens()
void Retokenizer::retokenize(ApplesoftLine &line)
{
m_tokens[0x80] = " END "; m_tokens[0x81] = " FOR "; m_tokens[0x82] = " NEXT ";
m_tokens[0x83] = " DATA "; m_tokens[0x84] = " INPUT "; m_tokens[0x85] = " DEL ";
m_tokens[0x86] = " DIM "; m_tokens[0x87] = " READ "; m_tokens[0x88] = " GR ";
m_tokens[0x89] = " TEXT "; m_tokens[0x8A] = " PR# "; m_tokens[0x8B] = " IN# ";
m_tokens[0x8C] = " CALL "; m_tokens[0x8D] = " PLOT "; m_tokens[0x8E] = " HLIN ";
m_tokens[0x8F] = " VLIN "; m_tokens[0x90] = " HGR2 "; m_tokens[0x91] = " HGR ";
m_tokens[0x92] = " HCOLOR= "; m_tokens[0x93] = " HPLOT "; m_tokens[0x94] = " DRAW ";
m_tokens[0x95] = " XDRAW "; m_tokens[0x96] = " HTAB "; m_tokens[0x97] = " HOME ";
m_tokens[0x98] = " ROT= "; m_tokens[0x99] = " SCALE= "; m_tokens[0x9A] = " SHLOAD ";
m_tokens[0x9B] = " TRACE "; m_tokens[0x9C] = " NOTRACE "; m_tokens[0x9D] = " NORMAL ";
m_tokens[0x9E] = " INVERSE "; m_tokens[0x9F] = " FLASH "; m_tokens[0xA0] = " COLOR= ";
m_tokens[0xA1] = " POP "; m_tokens[0xA2] = " VTAB "; m_tokens[0xA3] = " HIMEM: ";
m_tokens[0xA4] = " LOMEM: "; m_tokens[0xA5] = " ONERR "; m_tokens[0xA6] = " RESUME ";
m_tokens[0xA7] = " RECALL "; m_tokens[0xA8] = " STORE "; m_tokens[0xA9] = " SPEED= ";
m_tokens[0xAA] = " LET "; m_tokens[0xAB] = " GOTO "; m_tokens[0xAC] = " RUN ";
m_tokens[0xAD] = " IF "; m_tokens[0xAE] = " RESTORE "; m_tokens[0xAF] = " & ";
m_tokens[0xB0] = " GOSUB "; m_tokens[0xB1] = " RETURN "; m_tokens[0xB2] = " REM ";
m_tokens[0xB3] = " STOP "; m_tokens[0xB4] = " ON "; m_tokens[0xB5] = " WAIT ";
m_tokens[0xB6] = " LOAD "; m_tokens[0xB7] = " SAVE "; m_tokens[0xB8] = " DEF ";
m_tokens[0xB9] = " POKE "; m_tokens[0xBA] = " PRINT "; m_tokens[0xBB] = " CONT ";
m_tokens[0xBC] = " LIST "; m_tokens[0xBD] = " CLEAR "; m_tokens[0xBE] = " GET ";
m_tokens[0xBF] = " NEW "; m_tokens[0xC0] = " TAB("; m_tokens[0xC1] = " TO ";
m_tokens[0xC2] = " FN "; m_tokens[0xC3] = " SPC( "; m_tokens[0xC4] = " THEN ";
m_tokens[0xC5] = " AT "; m_tokens[0xC6] = " NOT "; m_tokens[0xC7] = " STEP ";
m_tokens[0xC8] = " + "; m_tokens[0xC9] = " - "; m_tokens[0xCA] = " * ";
m_tokens[0xCB] = " / "; m_tokens[0xCC] = " ^ "; m_tokens[0xCD] = " AND ";
m_tokens[0xCE] = " OR "; m_tokens[0xCF] = " > "; m_tokens[0xD0] = " = ";
m_tokens[0xD1] = " < "; m_tokens[0xD2] = " SGN"; m_tokens[0xD3] = " INT";
m_tokens[0xD4] = " ABS"; m_tokens[0xD5] = " USR"; m_tokens[0xD6] = " FRE";
m_tokens[0xD7] = " SCRN( "; m_tokens[0xD8] = " PDL"; m_tokens[0xD9] = " POS";
m_tokens[0xDA] = " SQR"; m_tokens[0xDB] = " RND"; m_tokens[0xDC] = " LOG";
m_tokens[0xDD] = " EXP"; m_tokens[0xDE] = " COS"; m_tokens[0xDF] = " SIN";
m_tokens[0xE0] = " TAN"; m_tokens[0xE1] = " ATN"; m_tokens[0xE2] = " PEEK";
m_tokens[0xE3] = " LEN"; m_tokens[0xE4] = " STR$"; m_tokens[0xE5] = " VAL";
m_tokens[0xE6] = " ASC"; m_tokens[0xE7] = " CHR$"; m_tokens[0xE8] = " LEFT$ ";
m_tokens[0xE9] = " RIGHT$ "; m_tokens[0xEA] = " MID$ "; m_tokens[0xEB] = "{Token 0xEB} ";
m_tokens[0xEC] = "{Token 0xEC} ";
m_tokens[0xED] = "{Token 0xED} ";
m_tokens[0xEE] = "{Token 0xEE} ";
m_tokens[0xEF] = "{Token 0xEF} ";
m_tokens[0xF0] = "{Token 0xF0} ";
m_tokens[0xF1] = "{Token 0xF1} ";
m_tokens[0xF2] = "{Token 0xF2} ";
m_tokens[0xF3] = "{Token 0xF3} ";
m_tokens[0xF4] = "{Token 0xF4} ";
m_tokens[0xF5] = "{Token 0xF5} ";
m_tokens[0xF6] = "{Token 0xF6} ";
m_tokens[0xF7] = "{Token 0xF7} ";
m_tokens[0xF8] = "{Token 0xF8} ";
m_tokens[0xF9] = "{Token 0xF9} ";
m_tokens[0xFA] = "{Token 0xFA} ";
m_tokens[0xFB] = "{Token 0xFB} ";
m_tokens[0xFC] = "{Token 0xFC} ";
m_tokens[0xFD] = "{Token 0xFD} ";
m_tokens[0xFE] = "{Token 0xFE} ";
m_tokens[0xFF] = "{Token 0xFF} ";
// QList <QByteArray> string_list;
// QList <QByteArray> 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);
// }
////// 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);
//// 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);
//// }
// line.advanced_tokens = newTokens;
// // QList<QByteArray> tmpParts = tmpTokens.split(':');
//// foreach (QByteArray part, tmpParts) {
//// QByteArray retokenizedPart = retokenzePart(part);
//// }
}
QByteArray Retokenizer::retokenizePart(QByteArray part) {
QByteArray retval;
return retval;
}

View File

@ -4,13 +4,18 @@
#include <QByteArray>
#include <QStringList>
#include <QMap>
#include <QVector>
#include "genericfile.h"
#include "applesofttoken.h"
struct ApplesoftLine {
qint16 address;
quint16 next_address;
quint16 linenum;
QByteArray tokens;
QVector<ApplesoftToken> tokens;
// QByteArray raw_tokens;
// QByteArray advanced_tokens;
QString detokenized_line;
};
@ -26,13 +31,20 @@ public:
QStringList extraDataHexValues();
private:
void makeTokens();
QList<ApplesoftLine> detokenize();
QList<ApplesoftLine> detokenize(quint16 start_address = 0x0801);
int m_data_end;
QMap<quint8,QString> m_tokens;
quint16 m_length;
QList<ApplesoftLine> m_detokenized;
friend class Retokenizer;
};
class Retokenizer {
public:
static void retokenize(ApplesoftLine &line);
private:
QByteArray retokenizePart(QByteArray part);
};
#endif // APPLESOFTFILE_H

View File

@ -80,6 +80,11 @@ int HiresViewWidget::findRowCol(int offset) {
void HiresViewWidget::makeOffsetTable() {
m_rowTable = new QMap<int,int>();
for (int idx = 0; idx < 8192; idx++)
{
(*m_rowTable)[idx] = -1; // Fill the memory holes. Brute force, but it works.
}
int count = 0;
int outer = 0x0000;
@ -122,6 +127,7 @@ void HiresViewWidget::makeOffsetTable() {
outer += 0x0080;
}
}
QMap<int,int> *HiresViewWidget::m_rowTable = 0;

View File

@ -105,9 +105,9 @@ void MainWindow::handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescripti
strings.append(linestring);
}
QString fulltext = Qt::convertFromPlainText(strings.join("\n"));
fulltext.replace("POKE","<font color=\"purple\">POKE</font>");
fulltext.replace("PEEK","<font color=\"purple\">PEEK</font>");
fulltext.replace("CALL","<font color=\"blue\">CALL</font>");
// fulltext.replace("{kwd}","<font color=\"red\">{kwd}</font>");
// fulltext.replace("{num}","<font color=\"red\">{num}</font>");
// fulltext.replace("{string}","<font color=\"red\">{string}</font>");
fulltext.replace("GOTO","<b><font color=\"green\">GOTO</font></b>");
fulltext.replace("GOSUB","<b><font color=\"green\">GOSUB</font></b>");
// fulltext.replace("0","<font color=\"orange\">0</font>");