BugFix: BreakPoint toggle error

This commit is contained in:
tudnai 2022-11-11 21:51:58 -08:00
parent 042cbb54d4
commit e8bedfb210
2 changed files with 20 additions and 7 deletions

View File

@ -106,6 +106,14 @@
</PersistentString> </PersistentString>
</PersistentStrings> </PersistentStrings>
</ContextState> </ContextState>
<ContextState
contextName = "m6502_dbg_bp_search:6502_bp.c">
<PersistentStrings>
<PersistentString
value = "breakpoints">
</PersistentString>
</PersistentStrings>
</ContextState>
<ContextState <ContextState
contextName = "HiRes.draw(_:):HiRes.swift"> contextName = "HiRes.draw(_:):HiRes.swift">
<PersistentStrings> <PersistentStrings>
@ -286,6 +294,9 @@
</PersistentString> </PersistentString>
</PersistentStrings> </PersistentStrings>
</ContextState> </ContextState>
<ContextState
contextName = "m6502_dbg_bp_compact:6502_bp.c">
</ContextState>
<ContextState <ContextState
contextName = "ViewController.Reset(_:):ViewController.swift"> contextName = "ViewController.Reset(_:):ViewController.swift">
<PersistentStrings> <PersistentStrings>

View File

@ -80,11 +80,11 @@ void m6502_dbg_bp_sort( uint16_t arr[], int first, int last ) {
} }
/// A recursive binary search function. It returns /// A binary search function. It returns
/// location of addr in given array arr[l..r] is present, /// location of addr in given array arr[l..r] is present,
/// otherwise -1 /// otherwise -1
int m6502_dbg_bp_search(uint16_t arr[], int l, int r, uint16_t addr) { int m6502_dbg_bp_search(uint16_t arr[], int l, int r, uint16_t addr) {
if ( (r >= l) && (addr >= arr[l]) && (addr <= arr[r]) ) { while ( r >= l ) {
int mid = (l + r) / 2; int mid = (l + r) / 2;
// found it // found it
@ -93,12 +93,14 @@ int m6502_dbg_bp_search(uint16_t arr[], int l, int r, uint16_t addr) {
} }
// maybe in the left side? // maybe in the left side?
if (arr[mid] > addr) { else if (arr[mid] > addr) {
return m6502_dbg_bp_search(arr, l, mid - 1, addr); r = mid - 1;
} }
// maybe in the right side? // maybe in the right side?
return m6502_dbg_bp_search(arr, mid + 1, r, addr); else {
l = mid + 1;
}
} }
// addr not found // addr not found
@ -177,8 +179,8 @@ int m6502_dbg_bp_get_not_empty() {
/// move array down to eliminate /// move array down to eliminate
void m6502_dbg_bp_compact() { void m6502_dbg_bp_compact() {
int i = m6502_dbg_bp_get_not_empty(); int i = m6502_dbg_bp_get_not_empty();
memcpy(breakpoints, breakpoints + i, bp_last_idx); memcpy(breakpoints, breakpoints + i, bp_last_idx * sizeof(uint16_t));
memset(breakpoints + bp_last_idx + 1, 0, DEBUG_MAX_BREAKPOINTS - bp_last_idx - 1); memset(breakpoints + bp_last_idx, 0, (DEBUG_MAX_BREAKPOINTS - bp_last_idx) * sizeof(uint16_t));
bp_last_idx = m6502_dbg_bp_get_last(bp_last_idx); bp_last_idx = m6502_dbg_bp_get_last(bp_last_idx);
} }