mirror of
https://github.com/markdavidlong/AppleSAWS.git
synced 2026-04-20 20:16:35 +00:00
Added first push of DisassemblerMetadata processing stuff
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
#include "EntryPointModel.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
EntryPointModel::EntryPointModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QVariant EntryPointModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal)
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (section == 0)
|
||||
return "";
|
||||
|
||||
}
|
||||
}
|
||||
else // Orientation == Qt::Vertical
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return "0x"+uint16ToHex(m_entryPoints[section].address);
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
int EntryPointModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
// if (parent.isValid())
|
||||
return m_entryPoints.count();
|
||||
// else
|
||||
// return 0;
|
||||
}
|
||||
|
||||
int EntryPointModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
//if (parent.isValid())
|
||||
return 1;
|
||||
// else
|
||||
// return 0;
|
||||
}
|
||||
|
||||
QVariant EntryPointModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
EntryPoint ep = m_entryPoints[index.row()];
|
||||
if (index.column() == 0)
|
||||
{
|
||||
return ep.note;
|
||||
}
|
||||
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool EntryPointModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
|
||||
if (data(index, role) != value) {
|
||||
if (index.column() == 0)
|
||||
{
|
||||
m_entryPoints[index.row()].note = value.toString();
|
||||
}
|
||||
|
||||
emit dataChanged(index, index, QVector<int>() << role);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags EntryPointModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
if (index.column() == 0)
|
||||
return Qt::ItemIsEditable | QAbstractTableModel::flags(index);
|
||||
else
|
||||
return QAbstractTableModel::flags(index);
|
||||
}
|
||||
|
||||
bool EntryPointModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginInsertRows(parent, row, row + count - 1);
|
||||
// FIXME: Implement me!
|
||||
endInsertRows();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EntryPointModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
beginRemoveRows(parent, row, row + count - 1);
|
||||
for (int idx = 0; idx < count; idx++)
|
||||
{
|
||||
m_entryPoints.removeAt(row);
|
||||
}
|
||||
endRemoveRows();
|
||||
return false;
|
||||
}
|
||||
|
||||
void EntryPointModel::doTestData()
|
||||
{
|
||||
EntryPoint ep;
|
||||
ep.address = 0x0010;
|
||||
ep.note = "Test Entry Point 1";
|
||||
addEntryPoint(ep);
|
||||
ep.address = 0x0020;
|
||||
ep.note = "Test Entry Point 2";
|
||||
addEntryPoint(ep);
|
||||
ep.address = 0x0030;
|
||||
ep.note = "Test Entry Point 3";
|
||||
addEntryPoint(ep);
|
||||
|
||||
}
|
||||
|
||||
void EntryPointModel::addEntryPoint(EntryPoint ep)
|
||||
{
|
||||
if (!m_entryPoints.count())
|
||||
{
|
||||
m_entryPoints.append(ep);
|
||||
insertRows(m_entryPoints.count(),1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < m_entryPoints.count(); idx++)
|
||||
{
|
||||
if (ep.address < m_entryPoints[idx].address)
|
||||
break;
|
||||
}
|
||||
m_entryPoints.insert(idx,ep);
|
||||
insertRows(idx,1);
|
||||
}
|
||||
}
|
||||
|
||||
void EntryPointModel::removeSelection(QModelIndexList selection)
|
||||
{
|
||||
if (selection.count() > 1)
|
||||
{
|
||||
qWarning() << "Unexpected number of items to remove. Only removing the first.";
|
||||
}
|
||||
if (selection.count())
|
||||
{
|
||||
removeRow(selection[1].row());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef ENTRYPOINTMODEL_H
|
||||
#define ENTRYPOINTMODEL_H
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
struct EntryPoint {
|
||||
quint16 address;
|
||||
QString note;
|
||||
};
|
||||
|
||||
class EntryPointModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EntryPointModel(QObject *parent = 0);
|
||||
|
||||
// Header:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;//DONE
|
||||
|
||||
// Basic functionality:
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; //DONE
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;//DONE
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;//DONE
|
||||
|
||||
// Editable:
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
// Add data:
|
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
|
||||
// Remove data:
|
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
||||
|
||||
void doTestData();
|
||||
|
||||
void addEntryPoint(EntryPoint ep);
|
||||
|
||||
void removeSelection(QModelIndexList selection);
|
||||
|
||||
private:
|
||||
QList<EntryPoint> m_entryPoints;
|
||||
|
||||
};
|
||||
|
||||
#endif // ENTRYPOINTMODEL_H
|
||||
@@ -1,27 +1,44 @@
|
||||
#include "binaryfilemetadata.h"
|
||||
|
||||
BinaryFileMetadata::BinaryFileMetadata()
|
||||
BinaryFileMetadata::BinaryFileMetadata(QString filename)
|
||||
{
|
||||
|
||||
m_filename = filename;
|
||||
}
|
||||
|
||||
void BinaryFileMetadata::addEntryPoint(quint16 address)
|
||||
{
|
||||
if (!containsEntryPoint(address))
|
||||
{
|
||||
m_entryPoints.append(address);
|
||||
qSort(m_entryPoints);
|
||||
}
|
||||
}
|
||||
//void BinaryFileMetadata::setEntryPoint(quint16 address, QString note)
|
||||
//{
|
||||
// EntryPoint ep;
|
||||
// ep.address = address;
|
||||
// ep.note = note;
|
||||
// setEntryPoint(ep);
|
||||
//}
|
||||
|
||||
void BinaryFileMetadata::addDataRange(AddressRange range)
|
||||
{
|
||||
m_dataRanges.append(range);
|
||||
}
|
||||
//void BinaryFileMetadata::setEntryPoint(EntryPoint ep)
|
||||
//{
|
||||
// m_entryPoints.insert(ep.address,ep);
|
||||
//}
|
||||
|
||||
|
||||
//bool BinaryFileMetadata::hasEntryPointAtAddress(quint16 address)
|
||||
//{
|
||||
// return m_entryPoints.contains(address);
|
||||
//}
|
||||
|
||||
//void BinaryFileMetadata::removeEntryPoint(quint16 address)
|
||||
//{
|
||||
// if (hasEntryPointAtAddress(address))
|
||||
// {
|
||||
// m_entryPoints.remove(address);
|
||||
// }
|
||||
//}
|
||||
|
||||
bool BinaryFileMetadata::load()
|
||||
{
|
||||
return false;
|
||||
setSymbol(0x0000,"Test Symbol 1");
|
||||
setSymbol(0x0006,"Test Symbol 2");
|
||||
// setEntryPoint(0x0010,"Test Entry Point 1");
|
||||
// setEntryPoint(0x0020,"Test Entry Point 2");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinaryFileMetadata::save()
|
||||
@@ -29,15 +46,39 @@ bool BinaryFileMetadata::save()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BinaryFileMetadata::containsEntryPoint(quint16 address)
|
||||
void BinaryFileMetadata::setSymbol(quint16 address, QString name)
|
||||
{
|
||||
return m_entryPoints.contains(address);
|
||||
AssemSymbol symbol;
|
||||
symbol.address = address;
|
||||
symbol.name = name;
|
||||
setSymbol(symbol);
|
||||
}
|
||||
|
||||
void BinaryFileMetadata::removeEntryPoint(quint16 address)
|
||||
void BinaryFileMetadata::setSymbol(AssemSymbol symbol)
|
||||
{
|
||||
if (containsEntryPoint(address))
|
||||
m_symbols.insert(symbol.address, symbol);
|
||||
}
|
||||
|
||||
AssemSymbol BinaryFileMetadata::getSymbolAtAddress(quint16 address)
|
||||
{
|
||||
if (hasSymbolAtAddress(address))
|
||||
{
|
||||
m_entryPoints.removeAll(address);
|
||||
return m_symbols[address];
|
||||
}
|
||||
return AssemSymbol();
|
||||
}
|
||||
|
||||
void BinaryFileMetadata::removeSymbol(AssemSymbol symbol)
|
||||
{
|
||||
removeSymbol(symbol.address);
|
||||
}
|
||||
|
||||
void BinaryFileMetadata::removeSymbol(quint16 address)
|
||||
{
|
||||
if (hasSymbolAtAddress(address))
|
||||
{
|
||||
m_symbols.remove(address);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,50 +3,53 @@
|
||||
|
||||
#include <Qt>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
|
||||
|
||||
struct AddressRange
|
||||
{
|
||||
public:
|
||||
quint16 start;
|
||||
quint16 end;
|
||||
|
||||
quint16 length() { return end-start; }
|
||||
|
||||
bool contains(quint16 address) { return (address >= start && address <= end); }
|
||||
|
||||
struct AssemSymbol {
|
||||
quint16 address;
|
||||
QString name;
|
||||
};
|
||||
|
||||
class BinaryFileMetadata
|
||||
{
|
||||
public:
|
||||
enum UseType {
|
||||
UNKNOWN = 0x00,
|
||||
ROM = 0x01,
|
||||
IO = 0x02,
|
||||
BASIC = 0x04,
|
||||
OPCODE = 0x08,
|
||||
DATA = 0x10
|
||||
};
|
||||
|
||||
BinaryFileMetadata();
|
||||
BinaryFileMetadata(QString filename);
|
||||
|
||||
void addEntryPoint(quint16 address);
|
||||
void addDataRange(AddressRange range);
|
||||
void setFilename(QString filename) { m_filename = filename; }
|
||||
QString filename() const { return m_filename; }
|
||||
|
||||
bool load();
|
||||
bool save();
|
||||
|
||||
bool containsEntryPoint(quint16 address);
|
||||
void removeEntryPoint(quint16 address);
|
||||
// void setEntryPoint(quint16 address, QString note = "");
|
||||
// void setEntryPoint(EntryPoint ep);
|
||||
|
||||
QList<quint16> getEntryPoints() { return m_entryPoints; }
|
||||
QList<AddressRange> getDataRanges() { return m_dataRanges; }
|
||||
// bool hasEntryPointAtAddress(EntryPoint ep);
|
||||
// bool hasEntryPointAtAddress(quint16 address);
|
||||
|
||||
// void removeEntryPoint(quint16 address);
|
||||
|
||||
// QList<EntryPoint> getEntryPointList() const { return m_entryPoints.values(); }
|
||||
// QMap<quint16,EntryPoint> getEntryPointMap() const { return m_entryPoints; }
|
||||
|
||||
void setSymbol(quint16 address, QString name);
|
||||
void setSymbol(AssemSymbol symbol);
|
||||
bool hasSymbol(AssemSymbol symbol) const { return hasSymbolAtAddress(symbol.address); }
|
||||
bool hasSymbolAtAddress(quint16 address) const { return m_symbols.contains(address); }
|
||||
AssemSymbol getSymbolAtAddress(quint16 address);
|
||||
void removeSymbol(AssemSymbol symbol);
|
||||
void removeSymbol(quint16 address);
|
||||
|
||||
QList<AssemSymbol> getSymbolList() const { return m_symbols.values(); }
|
||||
QMap<quint16, AssemSymbol> getSymbolMap() const { return m_symbols; }
|
||||
|
||||
private:
|
||||
QList<quint16> m_entryPoints;
|
||||
QList<AddressRange> m_dataRanges;
|
||||
|
||||
QMap<quint16,AssemSymbol> m_symbols;
|
||||
QString m_filename;
|
||||
};
|
||||
|
||||
#endif // BINARYFILEMETADATA_H
|
||||
|
||||
Reference in New Issue
Block a user