15 #include "../views/MainWindowView.h" 28 :
Model(parent), view(view) {
44 row->get_accessible()->set_description(s);
53 for (
long unsigned int i = 0; i < rows->size(); i++) {
54 (*rows)[i].getButton()->signal_clicked().connect(
65 getView()->add_events(Gdk::SMOOTH_SCROLL_MASK);
66 getView()->signal_scroll_event().connect(
77 switch (e->direction) {
84 case GDK_SCROLL_SMOOTH:
103 const uint32_t formatMe)
const {
104 std::stringstream stream;
107 stream <<
"0x" << std::setfill(
'0') << std::setw(8) << std::uppercase
108 << std::hex << formatMe;
122 for (
long unsigned int i = 0; i < vals.size(); i++) {
123 auto& row = (*rows)[i];
124 auto flag = row.get_state_flags();
127 row.setAddressVal(vals[i].address);
129 row.setHex(vals[i].hex);
130 row.setDisassembly(vals[i].disassembly);
131 row.setBreakpoint(vals[i].breakpoint);
134 row.get_accessible()->set_description(s);
147 std::string bp = row.
getBreakpoint() ?
"breakpoint set" :
"no breakpoint";
150 std::stringstream gHex;
152 const auto addr = std::regex_replace(gHex.str(), std::regex(
"^0x0{0,7}"),
"");
155 const std::string disassemblyInfo =
159 std::stringstream ss;
160 ss <<
"address " << addr <<
", " << disassemblyInfo << bp;
171 const std::string mnemonic)
const {
173 std::istringstream iss(mnemonic);
174 std::vector<std::string> m(std::istream_iterator<std::string>{iss},
175 std::istream_iterator<std::string>());
189 std::string outputText =
"";
194 }
catch (std::out_of_range
const&) {
210 std::vector<std::string> m)
const {
211 if (m[0] ==
"defb") {
214 for (
long unsigned int i = 1; i < m.size(); i++) {
219 m[1] = std::regex_replace(s, std::regex(
",[^,]*$"),
"");
236 std::vector<std::string> m)
const {
254 const std::pair<std::vector<std::string>, std::string>
256 std::string out =
"";
260 }
catch (std::out_of_range
const&) {
261 out +=
"At label \"" + m[0] +
"\", ";
272 return std::make_pair(m, out);
285 std::vector<std::string> m)
const {
286 for (
long unsigned int i = 1; i < m.size(); i++) {
288 std::string reg =
"\\?" + std::to_string(i) +
"\\?";
290 s = std::regex_replace(s, std::regex(reg), m[i]);
302 if (param[0] ==
'R' || param[0] ==
'r') {
303 return "Register " + param.erase(0, 1);
304 }
else if (param[0] ==
'#') {
305 return param.erase(0, 1);
333 const uint32_t address) {
349 row.set_state_flags(
NORMAL);
383 if ((e->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) ==
386 if (e->keyval == GDK_KEY_m || e->keyval == GDK_KEY_M) {
397 if ((*rows)[0].has_focus() && e->keyval == GDK_KEY_Up) {
398 auto scroll = GdkEventScroll();
399 scroll.direction = GDK_SCROLL_UP;
405 else if ((*rows)[rows->size() - 1].has_focus() && e->keyval == GDK_KEY_Down) {
406 auto scroll = GdkEventScroll();
407 scroll.direction = GDK_SCROLL_DOWN;
414 long unsigned int hasFocus = -1;
416 for (
long unsigned int i = 0; i < rows->size(); i++) {
417 if ((*rows)[i].has_focus()) {
422 if (hasFocus == static_cast<long unsigned int>(-1)) {
427 else if (e->keyval == GDK_KEY_Return) {
433 else if (e->keyval == GDK_KEY_Escape) {
434 if (hasFocus < rows->size() / 2) {
473 const std::array<Jimulator::MemoryValues, 13>
void setEnglishMnemonic(const bool val)
Set the value of the englishMnemonic member variable.
void setModel(DisassemblyModel *const val)
Sets the value of the model member.
const Gtk::StateFlags NORMAL
The CSS state flags for an un-highlighted memory row.
A single instance of this class represents a single read memory address and the associated data - thi...
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles any key press events.
const Gtk::StateFlags PC_ADDRESS_FOCUSED
The CSS state flags for e memory row that has keyboard focus and is currently stored in the Program C...
const Gtk::StateFlags FOCUSED
The CSS state flags for a memory row that has keyboard focus.
const std::unordered_map< std::string, std::string > mnemonicsMap
A map pairing ARM mnemonic commands with the English translation string associated with them for the ...
const std::string getAddress() const
Get the text in the address box.
KoMo2Model *const getParent() const
Returns the parent pointer.
TerminalView *const getTerminalView()
Get the TerminalView.
DisassemblyModel(DisassemblyView *const view, KoMo2Model *const parent)
Construct a new DisassemblyModel::DisassemblyModel object.
const bool setBreakpoint(const uint32_t address)
Sets a breakpoint.
std::vector< DisassemblyRows > *const getRows()
Gets a pointer to the rows of views.
const std::string toLowerCase(std::string s) const
Converts a string to lower case.
void onBreakpointToggle(DisassemblyRows *const row)
Handle the toggling of a breakpoint within the DisassemblyView.
const bool getBreakpoint()
Returns if a breakpoint is set or not.
bool englishMnemonic
Whether or not ARM mnemonics should be read in English when being read by a screenreader, or if they should be left as ARM mnemonics.
const std::string intToFormattedHexString(const uint32_t formatMe) const
Converts a fixed width 32-bit integer to a hex string, padded with 0's to 8 characters, pre-fixed with "0x", and raised to all capitals.
JimulatorState
Describe the 5 states of Jimulator.
Gtk::TextView *const getTextView()
Returns a constant pointer to the output box.
const std::string buildMnemonicString(std::string s, std::vector< std::string > m) const
Builds the output mnemonics string from the vector making up the current ARM command and the value re...
void setupButtonHandlers()
Adds button handlers to every breakpoint button.
void setBreakpoint(const bool text)
Set the state of the breakpoint button. This is a little unusual - it sets the state in terms of CSS ...
MainWindowView *const getMainWindow() const
Gets the mainWindow member variable.
void updateCSSFlags(const Gtk::StateFlags state, DisassemblyRows &row, const uint32_t address)
Handles setting the CSS flags for each disassembly row, which determines which CSS class it uses and ...
DisassemblyView *const view
The view this model represents.
static uint32_t memoryIndex
Fixed width integer representing the memory address of the view at the top of the container...
A file containing the definition of the KoMo2Model class.
The superclass for all other Model classes. Uses a pure virtual function, so is abastract. Keeps KoMo2Model as a friend so it alone can call setJimulatorState. This class provides basic data that are needed by all other.
const Gtk::StateFlags PC_ADDRESS
The CSS state flags for if the memory row is currently stored in the Program Counter.
void refreshViews()
Refreshes the values in the views to display the new values fetched from Jimulator.
const std::string sanitizeParamters(std::string param) const
Sanitizes any of the paramters used with an ARM mnemonic.
ControlsView *const getControlsView()
Get the ControlsView.
virtual void changeJimulatorState(const JimulatorState newState) override
Handles changes of Jimulator state.
const std::string buildDisassemblyRowAccessibilityString(DisassemblyRows &val)
Generates the string to set for the accessibility model.
void incrementMemoryIndex(const uint32_t val)
Updates the list pointers to a new value. Val is multipled by 4 - for example, if val is 1...
std::string PCValue
Stores the value currently in the program counter.
const std::string convertMnemonicToEnglish(const std::string mnemonic) const
Converts a mnemonic into plain English.
The logical model of the entire application. All other models should be member variables of this mode...
Represents the entire disassembly window in the overall KoMo2 GUI. Contains several rows of memory va...
void addScrollRecognition()
Adds scroll recognition to the container object, which causes scroll events to be sent to the member ...
const std::vector< std::string > parseDEFB(std::vector< std::string > v) const
Parses the DEFB ARM mnemonic - since a single ARM command is broken into a vector by the spaces betwe...
const std::array< Jimulator::MemoryValues, 13 > getMemoryValues() const
Reads memory values from Jimulator.
const std::pair< std::vector< std::string >, std::string > parseLabel(std::vector< std::string > m) const
Parses labels from an ARM command. If the first index in the vector is not a recognised keyword...
void setPCValue(const std::string val)
Updates the value of PCValue.
Gtk::LinkButton *const getHelpButton()
Gets the helpButton member variable.
std::array< Jimulator::MemoryValues, 13 > getJimulatorMemoryValues(const uint32_t s_address_int)
Get the memory values from Jimulator, starting to s_address.
const bool handleScroll(GdkEventScroll *const e)
Handles the scroll events.
const std::string getDisassembly()
Gets the disassembly text for the breakpoint row.
DisassemblyView *const getView()
Returns a pointer to the view object.
const std::vector< std::string > parseSWI(std::vector< std::string > m) const
Parses the SWI ARM mnemonic - the SWI command always takes 1 paramter, but means very different thing...
const uint32_t getAddressVal() const
Get the addressVal member.