1818
1919casioemu::Emulator *m_emu = nullptr ;
2020
21+ size_t get_real_pc (const CodeElem& e) {
22+ return get_real_pc (e.segment , e.offset );
23+ }
24+
25+ size_t get_real_pc (uint8_t seg, uint16_t off) {
26+ return (seg << 16 ) | off;
27+ }
28+
2129CodeViewer::CodeViewer (std::string path) {
2230 src_path = path;
2331 std::ifstream f (src_path, std::ios::in);
@@ -51,10 +59,7 @@ CodeViewer::CodeViewer(std::string path) {
5159}
5260
5361bool operator <(const CodeElem &a, const CodeElem &b) {
54- if (a.segment != b.segment )
55- return a.segment < b.segment ;
56- else
57- return a.offset < b.offset ;
62+ return get_real_pc (a) < get_real_pc (b);
5863}
5964
6065CodeViewer::~CodeViewer () {
@@ -81,7 +86,7 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
8186 int idx = 0 ;
8287 LookUp (seg, offset, &idx);
8388 cur_row = idx;
84- bp = idx;
89+ triggered_bp_line = idx;
8590 need_roll = true ;
8691 return true ;
8792 }
@@ -90,7 +95,7 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
9095 CodeElem e = codes[it->first ];
9196 if (e.segment == seg && e.offset == offset) {
9297 cur_row = it->first ;
93- bp = it->first ;
98+ triggered_bp_line = it->first ;
9499 need_roll = true ;
95100 return true ;
96101 }
@@ -106,7 +111,7 @@ void CodeViewer::DrawContent() {
106111 for (int line_i = c.DisplayStart ; line_i < c.DisplayEnd ; line_i++) {
107112 CodeElem e = codes[line_i];
108113 auto it = break_points.find (line_i);
109- if (line_i == bp ) {
114+ if (line_i == triggered_bp_line ) {
110115 // the break point is triggered!
111116 ImGui::TextColored (ImVec4 (0.0 , 1.0 , 0.0 , 1.0 ), " [ > ]" );
112117 } else if (it == break_points.end () || !break_points[line_i]) {
@@ -121,36 +126,14 @@ void CodeViewer::DrawContent() {
121126 }
122127 }
123128 ImGui::SameLine ();
124- ImGui::TextColored (ImVec4 (1.0 , 1.0 , 0.0 , 1.0 ), " %d:%04x " , e. segment , e. offset );
129+ ImGui::TextColored (ImVec4 (1.0 , 1.0 , 0.0 , 1.0 ), " %05zX " , get_real_pc (e) );
125130 ImGui::SameLine ();
126- if (selected_addr != (int64_t )e.segment * 0x10000 + e.offset ) { // not selected
127- ImGui::Text (" %s" , e.srcbuf );
128- if (ImGui::IsItemHovered () && ImGui::IsMouseClicked (0 )) {
129- cur_row = line_i;
130- selected_addr = codes[cur_row].segment * 0x10000 + codes[cur_row].offset ;
131- }
132- } else { // selected
133- ImGui::InputText (" ##data" , e.srcbuf , strlen (e.srcbuf ), ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AlwaysOverwrite);
134- if (ImGui::IsWindowFocused ()) {
135- if (ImGui::IsKeyPressed (ImGui::GetKeyIndex (ImGuiKey_DownArrow))) {
136- cur_row++;
137- if (cur_row >= max_row)
138- cur_row = max_row;
139- need_roll = true ;
140- } else if (ImGui::IsKeyPressed (ImGui::GetKeyIndex (ImGuiKey_UpArrow))) {
141- cur_row--;
142- if (cur_row < 0 )
143- cur_row = 0 ;
144- need_roll = true ;
145- }
146- }
147- }
131+ ImGui::Text (" %s" , e.srcbuf );
148132 }
149133 }
150134 if (need_roll) {
151135 float v = (float )cur_row / max_row * ImGui::GetScrollMaxY ();
152136 ImGui::SetScrollY (v);
153- selected_addr = codes[cur_row].segment * 0x10000 + codes[cur_row].offset ;
154137 need_roll = false ;
155138 }
156139}
@@ -171,13 +154,13 @@ void CodeViewer::DrawWindow() {
171154 if (!is_loaded) {
172155 ImGui::SetNextWindowSize (ImVec2 (w * 50 , h * 10 ), ImGuiCond_FirstUseEver);
173156 ImGui::SetNextWindowContentSize (ImVec2 (w * 50 , h * 10 ));
174- ImGui::Begin (" Disassemble Window " );
157+ ImGui::Begin (" Disassembly " );
175158 ImGui::SetCursorPos (ImVec2 (w * 2 , h * 5 ));
176- ImGui::Text (" Please wait loading ..." );
159+ ImGui::Text (" Loading ..." );
177160 ImGui::End ();
178161 return ;
179162 }
180- ImGui::Begin (" Disassemble Window " , 0 );
163+ ImGui::Begin (" Disassembly " , 0 );
181164 ImGui::BeginChild (" ##scrolling" , ImVec2 (0 , -ImGui::GetWindowHeight () / 2 ));
182165 DrawContent ();
183166 ImGui::EndChild ();
@@ -187,29 +170,23 @@ void CodeViewer::DrawWindow() {
187170 ImGui::SetNextItemWidth (ImGui::CalcTextSize (" 000000" ).x );
188171 ImGui::InputText (" ##input" , adrbuf, 8 );
189172 if (adrbuf[0 ] != ' \0 ' && ImGui::IsItemFocused ()) {
190- try {
191- uint32_t addr = std::stoi ( adrbuf, 0 , 16 );
173+ size_t addr;
174+ if ( sscanf ( adrbuf, " %zX " , &addr) == 1 )
192175 JumpTo (addr >> 16 , addr & 0x0ffff );
193- } catch (std::invalid_argument const &ex) {
194- // do nothing
195- } catch (std::out_of_range const &ex) {
196- // do nothing
197- }
198176 }
199177 ImGui::SameLine ();
200178 ImGui::Checkbox (" STEP" , &step_debug);
201179 ImGui::SameLine ();
202180 ImGui::Checkbox (" TRACE" , &trace_debug);
203- if (bp != -1 ) {
181+ if (triggered_bp_line != -1 ) {
204182 ImGui::SameLine ();
205183 if (ImGui::Button (" Continue" )) {
206184 if (!step_debug && !trace_debug)
207- break_points[bp ] = 0 ;
185+ break_points[triggered_bp_line ] = 0 ;
208186 m_emu->SetPaused (false );
209- bp = -1 ;
187+ triggered_bp_line = -1 ;
210188 }
211189 }
212-
213190 DrawMonitor ();
214191 ImGui::End ();
215192 debug_flags = DEBUG_BREAKPOINT | (step_debug ? DEBUG_STEP : 0 ) | (trace_debug ? DEBUG_RET_TRACE : 0 );
0 commit comments