KoMo2  1.0.0
A modern ARM emulator GUI.
RegistersModel.cpp
Go to the documentation of this file.
1 
12 #include <gdkmm/event.h>
13 #include <regex>
14 #include "../views/MainWindowView.h"
15 #include "KoMo2Model.h"
16 #include "iostream"
17 
24  KoMo2Model* const parent)
25  : Model(parent), view(view) {
26  view->setModel(this);
27 }
28 
34 
40 const bool RegistersModel::handleKeyPress(const GdkEventKey* const e) {
41  // MOD1_MASK is the alt key - if not pressed, return
42  if ((e->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)) !=
43  GDK_MOD1_MASK) {
44  return false;
45  }
46 
47  auto* const labelArray = getView()->getLabels();
48  int index;
49 
50  switch (e->keyval) {
51  case GDK_KEY_0:
52  index = 0;
53  break;
54 
55  case GDK_KEY_1:
56  index = 1;
57  break;
58 
59  case GDK_KEY_2:
60  index = 2;
61  break;
62 
63  case GDK_KEY_3:
64  index = 3;
65  break;
66 
67  case GDK_KEY_4:
68  index = 4;
69  break;
70 
71  case GDK_KEY_5:
72  index = 5;
73  break;
74 
75  case GDK_KEY_6:
76  index = 6;
77  break;
78 
79  case GDK_KEY_7:
80  index = 7;
81  break;
82 
83  case GDK_KEY_8:
84  index = 8;
85  break;
86 
87  case GDK_KEY_9:
88  index = 9;
89  break;
90 
91  case GDK_KEY_a:
92  case GDK_KEY_A:
93  index = 10;
94  break;
95 
96  case GDK_KEY_b:
97  case GDK_KEY_B:
98  index = 11;
99  break;
100 
101  case GDK_KEY_c:
102  case GDK_KEY_C:
103  index = 12;
104  break;
105 
106  case GDK_KEY_d:
107  case GDK_KEY_D:
108  index = 13;
109  break;
110 
111  case GDK_KEY_e:
112  case GDK_KEY_E:
113  index = 14;
114  break;
115 
116  case GDK_KEY_p:
117  case GDK_KEY_P:
118  index = 15;
119  break;
120 
121  // any other key
122  default:
123  return false;
124  }
125 
126  // Get the correct accessible object
127  auto accessible = (*labelArray)[1][index].get_accessible();
128 
129  // Build a notification of the object and send the notification to the
130  // screenreader
131  accessible->set_role(Atk::ROLE_NOTIFICATION);
132  accessible->notify_state_change(ATK_STATE_SHOWING, true);
133 
134  return false;
135 }
136 
143  const auto newValues = getRegisterValueFromJimulator();
144  auto* const labelArray = getView()->getLabels();
145 
146  for (long unsigned int i = 0; i < 16; i++) {
147  (*labelArray)[1][i].set_text(newValues[i]);
148 
149  // A string describing the register
150 
151  std::string reg = i != 15 ? std::string("Register ")
152  .append(std::to_string(i))
153  .append(" stores ")
154  : "Program Counter stores ";
155 
156  // Set the accessibility object to describe
157  (*labelArray)[1][i].get_accessible()->set_name(
158  reg + std::regex_replace(newValues[i], std::regex("^0x0{0,7}"), ""));
159  }
160 
161  // Send the new program counter value to disassembly model
163  newValues[newValues.size() - 1]);
164 }
165 
166 // ! Getters and setters
167 
173  return view;
174 }
175 
181 const std::array<std::string, 16>
184 }
void refreshViews()
Handles updating this particular view. Reads register values from Jimulator, sets the label values of...
std::array< std::array< Gtk::Label, 16 >, 2 > *const getLabels()
Return a reference to the member array of labels, labelArray.
DisassemblyModel *const getDisassemblyModel()
Gets the disassemblyModel member variable.
Definition: KoMo2Model.cpp:164
RegistersView *const getView() const
Returns the view for this model.
RegistersView *const view
The view this model represents.
virtual void changeJimulatorState(const JimulatorState newState) override
Handles changes in the Jimulator state.
KoMo2Model *const getParent() const
Returns the parent pointer.
Definition: Model.cpp:67
KoMo2Model *const parent
All models have a parent model - KoMo2Model, the most senior model in the hierarchy, sets its parent to self.
Definition: Model.h:87
Stores data and functions related to the displaying of the KoMo2 GUI element - no particular logic or...
Definition: RegistersView.h:26
JimulatorState
Describe the 5 states of Jimulator.
Definition: Model.h:19
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles any key press events.
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.
Definition: Model.h:35
The logical model of the entire application. All other models should be member variables of this mode...
Definition: KoMo2Model.h:34
const std::array< std::string, 16 > getRegisterValueFromJimulator() const
Gets the register values out of Jimulator.
void setPCValue(const std::string val)
Updates the value of PCValue.
void setModel(RegistersModel *const val)
Sets the model for this view.
RegistersModel(RegistersView *const view, KoMo2Model *const parent)
Constructs a new registers model object.
const std::array< std::string, 16 > getJimulatorRegisterValues()
Queries a register in Jimulator to get it&#39;s current value.
Definition: kcmd.cpp:453