mirror of
https://github.com/trudnai/Steve2.git
synced 2024-06-13 09:29:36 +00:00
Breakpoint documentation
This commit is contained in:
parent
2751a7a57a
commit
f5f204adb0
|
@ -32,12 +32,18 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "6502_bp.h"
|
#include "6502_bp.h"
|
||||||
|
|
||||||
|
/// Array of addresses of active breakpoints
|
||||||
uint16_t breakpoints[DEBUG_MAX_BREAKPOINTS];
|
uint16_t breakpoints[DEBUG_MAX_BREAKPOINTS];
|
||||||
|
/// Index of last valid breakpoint element in the array
|
||||||
int bp_last_idx = 0;
|
int bp_last_idx = 0;
|
||||||
|
/// Index of current breapoint
|
||||||
|
/// @note It is more like a temporary variable
|
||||||
int bp_idx = 0;
|
int bp_idx = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/// Swap 2 items
|
||||||
|
/// @param a Pointer of first item
|
||||||
|
/// @param b Pointer to second item
|
||||||
static void swap(uint16_t * a, uint16_t * b) {
|
static void swap(uint16_t * a, uint16_t * b) {
|
||||||
uint16_t temp = *a;
|
uint16_t temp = *a;
|
||||||
*a = *b;
|
*a = *b;
|
||||||
|
@ -45,6 +51,11 @@ static void swap(uint16_t * a, uint16_t * b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// m6502_dbg_bp_sort
|
||||||
|
/// Sort breakpoint array ascending
|
||||||
|
/// @param arr Breakpoint array
|
||||||
|
/// @param first Index of first element to sort
|
||||||
|
/// @param last Index of last element to sort
|
||||||
void m6502_dbg_bp_sort( uint16_t arr[], int first, int last ) {
|
void m6502_dbg_bp_sort( uint16_t arr[], int first, int last ) {
|
||||||
if ( first < last ) {
|
if ( first < last ) {
|
||||||
uint16_t pivot = first; // (first + last) / 2;
|
uint16_t pivot = first; // (first + last) / 2;
|
||||||
|
@ -78,8 +89,11 @@ void m6502_dbg_bp_sort( uint16_t arr[], int first, int last ) {
|
||||||
|
|
||||||
|
|
||||||
/// A binary search function. It returns
|
/// A binary search function. It returns
|
||||||
/// location of addr in given array arr[l..r] is present,
|
/// @param arr Breakpoint array
|
||||||
/// otherwise -1
|
/// @param l Left index
|
||||||
|
/// @param r Right index
|
||||||
|
/// @param addr Address to search for
|
||||||
|
/// @return lIndex of addr in Breakpoints, 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) {
|
||||||
while ( r >= l ) {
|
while ( r >= l ) {
|
||||||
int mid = (l + r) / 2;
|
int mid = (l + r) / 2;
|
||||||
|
@ -105,21 +119,20 @@ int m6502_dbg_bp_search(uint16_t arr[], int l, int r, uint16_t addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_get_empty
|
/// Get index of the last BP
|
||||||
/// Get an empty slot in the bp astorage
|
/// @param i Current last index
|
||||||
/// @return Index of the empty breakpoint or -1 if error
|
/// @return Index of the last breakpoint or 0 if non
|
||||||
int m6502_dbg_bp_get_last(int i) {
|
int m6502_dbg_bp_get_last(int i) {
|
||||||
for(; i >= 0; i--) {
|
for(; i >= 0; i--) {
|
||||||
if ( breakpoints[i] ) {
|
if ( breakpoints[i] ) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// no empty slots
|
// index should be 0 if there is no any BPs
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_get_first
|
|
||||||
/// Get first valid BP
|
/// Get first valid BP
|
||||||
/// @return addr of BP or 0 if non
|
/// @return addr of BP or 0 if non
|
||||||
uint16_t m6502_dbg_bp_get_next() {
|
uint16_t m6502_dbg_bp_get_next() {
|
||||||
|
@ -134,7 +147,6 @@ uint16_t m6502_dbg_bp_get_next() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_get_first
|
|
||||||
/// Get first valid BP
|
/// Get first valid BP
|
||||||
/// @return addr of BP or 0 if non
|
/// @return addr of BP or 0 if non
|
||||||
uint16_t m6502_dbg_bp_get_first() {
|
uint16_t m6502_dbg_bp_get_first() {
|
||||||
|
@ -157,7 +169,6 @@ int m6502_dbg_bp_get_empty() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_get_not_empty
|
|
||||||
/// Get first not empty slot in the bp storage
|
/// Get first not empty slot in the bp storage
|
||||||
/// @return Index of the empty breakpoint or -1 if error
|
/// @return Index of the empty breakpoint or -1 if error
|
||||||
int m6502_dbg_bp_get_not_empty() {
|
int m6502_dbg_bp_get_not_empty() {
|
||||||
|
@ -171,8 +182,7 @@ int m6502_dbg_bp_get_not_empty() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_compact
|
/// Move array down to eliminate leading zeros
|
||||||
/// 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 * sizeof(uint16_t));
|
memcpy(breakpoints, breakpoints + i, bp_last_idx * sizeof(uint16_t));
|
||||||
|
@ -181,9 +191,9 @@ void m6502_dbg_bp_compact() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_get_first
|
/// Check if BP exists
|
||||||
/// Get first valid BP
|
/// @param addr Address to check
|
||||||
/// @return addr of BP or 0 if non
|
/// @return 1 (true) if exists, 0 (false) if not
|
||||||
_Bool m6502_dbg_bp_is_exists(uint16_t addr) {
|
_Bool m6502_dbg_bp_is_exists(uint16_t addr) {
|
||||||
if (addr) {
|
if (addr) {
|
||||||
int i = m6502_dbg_bp_search(breakpoints, 0, bp_last_idx, addr);
|
int i = m6502_dbg_bp_search(breakpoints, 0, bp_last_idx, addr);
|
||||||
|
@ -194,9 +204,8 @@ _Bool m6502_dbg_bp_is_exists(uint16_t addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_add
|
|
||||||
/// Add breakpoint
|
/// Add breakpoint
|
||||||
/// @param addr address to add
|
/// @param addr Address to add
|
||||||
/// @return Index of breakpoint or -1 if error
|
/// @return Index of breakpoint or -1 if error
|
||||||
int m6502_dbg_bp_add(uint16_t addr) {
|
int m6502_dbg_bp_add(uint16_t addr) {
|
||||||
if (bp_last_idx < DEBUG_MAX_BREAKPOINTS - 1) {
|
if (bp_last_idx < DEBUG_MAX_BREAKPOINTS - 1) {
|
||||||
|
@ -209,7 +218,6 @@ int m6502_dbg_bp_add(uint16_t addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// m6502_dbg_bp_del
|
|
||||||
/// Remove a breakpoint
|
/// Remove a breakpoint
|
||||||
/// @param addr address to remove
|
/// @param addr address to remove
|
||||||
void m6502_dbg_bp_del(uint16_t addr) {
|
void m6502_dbg_bp_del(uint16_t addr) {
|
||||||
|
@ -222,12 +230,14 @@ void m6502_dbg_bp_del(uint16_t addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Delete all breakpoints
|
||||||
void m6502_dbg_bp_del_all(void) {
|
void m6502_dbg_bp_del_all(void) {
|
||||||
bp_idx = 0;
|
bp_idx = 0;
|
||||||
memset(breakpoints, 0, sizeof(breakpoints));
|
memset(breakpoints, 0, sizeof(breakpoints));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Initialize Breakpoints
|
||||||
void m6502_dbg_init(void) {
|
void m6502_dbg_init(void) {
|
||||||
m6502_dbg_bp_del_all();
|
m6502_dbg_bp_del_all();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user