@@ -67,12 +67,10 @@ CodeViewer::~CodeViewer() {
6767
6868CodeElem CodeViewer::LookUp (uint8_t seg, uint16_t offset, int *idx) {
6969 // binary search
70- CodeElem target;
71- target.offset = offset;
72- target.segment = seg;
73- auto it = std::lower_bound (codes.begin (), codes.end (), target);
74- if (it == codes.end ())
75- it = codes.begin ();
70+ CodeElem target (seg, offset);
71+ auto it = std::upper_bound (codes.begin (), codes.end (), target);
72+ if (it != codes.begin ())
73+ --it;
7674 if (idx)
7775 *idx = it - codes.begin ();
7876 return CodeElem (it->segment , it->offset );
@@ -86,8 +84,8 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
8684 int idx = 0 ;
8785 LookUp (seg, offset, &idx);
8886 cur_row = idx;
89- triggered_bp_line = idx ;
90- need_roll = true ;
87+ triggered_bp_line = - 1 ;
88+ try_roll = true ;
9189 return true ;
9290 }
9391 for (auto it = break_points.begin (); it != break_points.end (); it++) {
@@ -96,7 +94,7 @@ bool CodeViewer::TryTrigBP(uint8_t seg, uint16_t offset, bool is_bp) {
9694 if (e.segment == seg && e.offset == offset) {
9795 cur_row = it->first ;
9896 triggered_bp_line = it->first ;
99- need_roll = true ;
97+ try_roll = true ;
10098 return true ;
10199 }
102100 }
@@ -133,11 +131,13 @@ void CodeViewer::DrawContent() {
133131 else
134132 ImGui::Text (" %s" , e.srcbuf );
135133 }
136- }
137- if (need_roll) {
138- float v = (float )cur_row / max_row * ImGui::GetScrollMaxY ();
139- ImGui::SetScrollY (v);
140- need_roll = false ;
134+ if (try_roll) {
135+ try_roll = false ;
136+ if (!(c.DisplayStart + 1 <= cur_row && cur_row < c.DisplayEnd - 5 )) {
137+ float v = (float )cur_row / max_row * ImGui::GetScrollMaxY ();
138+ ImGui::SetScrollY (v);
139+ }
140+ }
141141 }
142142}
143143
@@ -162,8 +162,7 @@ void CodeViewer::DrawWindow() {
162162 ImGui::Text (" Go to Addr:" );
163163 ImGui::SameLine ();
164164 ImGui::SetNextItemWidth (ImGui::CalcTextSize (" 000000" ).x );
165- ImGui::InputText (" ##input" , adrbuf, 8 );
166- if (adrbuf[0 ] != ' \0 ' && ImGui::IsItemFocused ()) {
165+ if (ImGui::InputText (" ##input" , adrbuf, sizeof (adrbuf), ImGuiInputTextFlags_EnterReturnsTrue)) {
167166 size_t addr;
168167 if (sscanf (adrbuf, " %zX" , &addr) == 1 )
169168 JumpTo (addr >> 16 , addr & 0x0ffff );
@@ -172,7 +171,7 @@ void CodeViewer::DrawWindow() {
172171 ImGui::Checkbox (" STEP" , &step_debug);
173172 ImGui::SameLine ();
174173 ImGui::Checkbox (" TRACE" , &trace_debug);
175- if (triggered_bp_line != - 1 ) {
174+ if (m_emu-> GetPaused () ) {
176175 ImGui::SameLine ();
177176 if (ImGui::Button (" Continue" )) {
178177 if (!step_debug && !trace_debug)
@@ -189,5 +188,5 @@ void CodeViewer::JumpTo(uint8_t seg, uint16_t offset) {
189188 int idx = 0 ;
190189 LookUp (seg, offset, &idx);
191190 cur_row = idx;
192- need_roll = true ;
191+ try_roll = true ;
193192}
0 commit comments