| 1 | #ifndef DISASMVIEWER_H |
| 2 | #define DISASMVIEWER_H |
| 3 | |
| 4 | #include "Dasm.h" |
| 5 | #include <QFrame> |
| 6 | #include <QPixmap> |
| 7 | |
| 8 | class CommMemoryRequest; |
| 9 | class QScrollBar; |
| 10 | class Breakpoints; |
| 11 | class SymbolTable; |
| 12 | struct MemoryLayout; |
| 13 | |
| 14 | class DisasmViewer : public QFrame |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | public: |
| 18 | DisasmViewer(QWidget* parent = nullptr); |
| 19 | |
| 20 | void setMemory(unsigned char* memPtr); |
| 21 | void setBreakpoints(Breakpoints* bps); |
| 22 | void setMemoryLayout(MemoryLayout* ml); |
| 23 | void setSymbolTable(SymbolTable* st); |
| 24 | void memoryUpdated(CommMemoryRequest* req); |
| 25 | void updateCancelled(CommMemoryRequest* req); |
| 26 | uint16_t programCounter() const; |
| 27 | uint16_t cursorAddress() const; |
| 28 | |
| 29 | QSize sizeHint() const override; |
| 30 | |
| 31 | enum {Top, Middle, Bottom, Closest, TopAlways, MiddleAlways, BottomAlways, Reload}; |
| 32 | |
| 33 | void setAddress(uint16_t addr, int infoLine = FIRST_INFO_LINE, int method = Top); |
| 34 | void setCursorAddress(uint16_t addr, int infoLine = FIRST_INFO_LINE, int method = Top); |
| 35 | void copyCodeToClipboard() const; |
| 36 | void setProgramCounter(uint16_t pc, bool reload = false); |
| 37 | void scrollBarAction(int action); |
| 38 | void scrollBarChanged(int value); |
| 39 | void updateLayout(); |
| 40 | void refresh(); |
| 41 | |
| 42 | private: |
| 43 | void requestMemory(uint16_t start, uint16_t end, uint16_t addr, int infoLine, int method); |
| 44 | int findPosition(uint16_t addr, int infoLine, int method); |
| 45 | |
| 46 | void resizeEvent(QResizeEvent* e) override; |
| 47 | void paintEvent(QPaintEvent* e) override; |
| 48 | void keyPressEvent(QKeyEvent* e) override; |
| 49 | void mousePressEvent(QMouseEvent* e) override; |
| 50 | void wheelEvent(QWheelEvent* e) override; |
| 51 | |
| 52 | int findDisasmLine(uint16_t lineAddr, int infoLine = 0); |
| 53 | int lineAtPos(const QPoint& pos); |
| 54 | |
| 55 | private: |
| 56 | QScrollBar* scrollBar; |
| 57 | |
| 58 | QPixmap breakMarker; |
| 59 | QPixmap watchMarker; |
| 60 | QPixmap pcMarker; |
| 61 | |
| 62 | uint16_t programAddr; |
| 63 | uint16_t cursorAddr; |
| 64 | int cursorLine; |
| 65 | |
| 66 | QList<int> jumpStack; |
| 67 | |
| 68 | int wheelRemainder; |
| 69 | |
| 70 | // layout information |
| 71 | int frameL, frameR, frameT, frameB; |
| 72 | int labelFontHeight, labelFontAscent; |
| 73 | int codeFontHeight, codeFontAscent; |
| 74 | int xAddr, xMCode[4], xMnem, xMnemArg; |
| 75 | int visibleLines, partialBottomLine; |
| 76 | int disasmTopLine; |
| 77 | DisasmLines disasmLines; |
| 78 | |
| 79 | // display data |
| 80 | unsigned char* memory; |
| 81 | bool waitingForData; |
| 82 | CommMemoryRequest* nextRequest; |
| 83 | Breakpoints* breakpoints; |
| 84 | MemoryLayout* memLayout; |
| 85 | SymbolTable* symTable; |
| 86 | |
| 87 | signals: |
| 88 | void breakpointToggled(int addr); |
| 89 | }; |
| 90 | |
| 91 | #endif // DISASMVIEWER_H |