Renamed debugger view functions, fixed crash when exiting

This commit is contained in:
william 2024-04-30 11:18:34 -04:00
parent d0562fdea4
commit 4b4ce45804
3 changed files with 28 additions and 26 deletions

View File

@ -28,7 +28,7 @@ void start_debugger(System *system) {
create_window(); create_window();
memory_view_init(&windows[0], system->ram, 0, 0); mv_init(&windows[0], system->ram, 0, 0);
pv_init(&windows[1], system, MEMORY_VIEW_WIDTH, 0); pv_init(&windows[1], system, MEMORY_VIEW_WIDTH, 0);
cursor_enable(&current_window->cursor); cursor_enable(&current_window->cursor);

View File

@ -7,7 +7,7 @@
// //
// Created by william on 6/1/24. // Created by william on 6/1/24.
// //
void memory_view_write_line(MemoryView *view, int line, address base_address, byte *data) { void mv_write_line(MemoryView *view, int line, address base_address, byte *data) {
window_inter_print(view->window, 0, line + 1, "[%04x]", base_address); window_inter_print(view->window, 0, line + 1, "[%04x]", base_address);
for (int i = 0; i <= MEMORY_VIEW_LINE_BYTE_COUNT; i++) { for (int i = 0; i <= MEMORY_VIEW_LINE_BYTE_COUNT; i++) {
@ -15,7 +15,7 @@ void memory_view_write_line(MemoryView *view, int line, address base_address, by
} }
} }
void memory_view_cursor_init(MemoryView *view) { void mv_cursor_init(MemoryView *view) {
Cursor *cursor = &view->window->cursor; Cursor *cursor = &view->window->cursor;
window_inter_cursor_init(view->window, 0xf, 0xf); window_inter_cursor_init(view->window, 0xf, 0xf);
cursor->min_x = 8; cursor->min_x = 8;
@ -24,7 +24,7 @@ void memory_view_cursor_init(MemoryView *view) {
cursor->width = 2; cursor->width = 2;
} }
void memory_view_handle_key_down(InteractWindow *window, int keycode) { void mv_handle_key_down(InteractWindow *window, int keycode) {
if (keycode == KEY_GOTO) { if (keycode == KEY_GOTO) {
Dialog dialog = dialog_create("Goto Address"); Dialog dialog = dialog_create("Goto Address");
@ -34,38 +34,40 @@ void memory_view_handle_key_down(InteractWindow *window, int keycode) {
if (!cancelled) { if (!cancelled) {
MemoryView *view = window->view; MemoryView *view = window->view;
memory_view_goto(view, input); mv_goto(view, input);
memory_view_cursor_set_addr(view, input); mv_cursor_set_addr(view, input);
} }
} }
} }
void memory_view_init(InteractWindow *interact, ram ram, int x, int y) { void mv_init(InteractWindow *interact, ram ram, int x, int y) {
MemoryView *view = malloc(sizeof(MemoryView)); MemoryView *view = malloc(sizeof(MemoryView));
view->window = interact; view->window = interact;
view->ram = ram; view->ram = ram;
view->base_address = 0x0000; view->base_address = 0x0000;
interact->view = view; interact->view = view;
interact->handle_cursor_move = &memory_view_cursor_move; interact->handle_cursor_move = &mv_cursor_move;
interact->handle_key_down = &memory_view_handle_key_down; interact->handle_key_down = &mv_handle_key_down;
interact->deinit = NULL;
window_inter_init(interact, x, y, MEMORY_VIEW_WIDTH, MEMORY_VIEW_HEIGHT, "MEMORY VIEW"); window_inter_init(interact, x, y, MEMORY_VIEW_WIDTH, MEMORY_VIEW_HEIGHT, "MEMORY VIEW");
window_inter_print(interact, 0, 0, " +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f"); window_inter_print(interact, 0, 0, " +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f");
memory_view_print(view); mv_print(view);
memory_view_cursor_init(view); mv_cursor_init(view);
} }
void memory_view_print(MemoryView *view) { void mv_print(MemoryView *view) {
for (int line = 0; line <= MEMORY_VIEW_LINE_COUNT; line++) { for (int line = 0; line <= MEMORY_VIEW_LINE_COUNT; line++) {
address line_address = view->base_address + line * (MEMORY_VIEW_LINE_BYTE_COUNT + 1); address line_address = view->base_address + line * (MEMORY_VIEW_LINE_BYTE_COUNT + 1);
byte *data = &view->ram[line_address]; byte *data = &view->ram[line_address];
memory_view_write_line(view, line, line_address, data); mv_write_line(view, line, line_address, data);
} }
} }
void memory_view_goto(MemoryView *view, address target) { void mv_goto(MemoryView *view, address target) {
assert(target <= RAM_SIZE); assert(target <= RAM_SIZE);
address max_base_address = RAM_SIZE - MEMORY_VIEW_BYTE_COUNT; address max_base_address = RAM_SIZE - MEMORY_VIEW_BYTE_COUNT;
@ -75,10 +77,10 @@ void memory_view_goto(MemoryView *view, address target) {
address line_addr = target & 0xfff0; address line_addr = target & 0xfff0;
view->base_address = line_addr; view->base_address = line_addr;
memory_view_print(view); mv_print(view);
} }
void memory_view_scroll(MemoryView *view, int direction) { void mv_scroll(MemoryView *view, int direction) {
assert(direction == CURSOR_OFFSET_DOWN || direction == CURSOR_OFFSET_UP); assert(direction == CURSOR_OFFSET_DOWN || direction == CURSOR_OFFSET_UP);
int offset = 0; int offset = 0;
@ -90,23 +92,23 @@ void memory_view_scroll(MemoryView *view, int direction) {
} }
address target = view->base_address + offset; address target = view->base_address + offset;
memory_view_goto(view, target); mv_goto(view, target);
} }
void memory_view_cursor_move(InteractWindow *window, int horizontal, int vertical) { void mv_cursor_move(InteractWindow *window, int horizontal, int vertical) {
MemoryView *view = (MemoryView *) window->view; MemoryView *view = (MemoryView *) window->view;
if (vertical == CURSOR_OFFSET_DOWN && view->window->cursor.pos_y == 0xf || if (vertical == CURSOR_OFFSET_DOWN && view->window->cursor.pos_y == 0xf ||
vertical == CURSOR_OFFSET_UP && view->window->cursor.pos_y == 0) { vertical == CURSOR_OFFSET_UP && view->window->cursor.pos_y == 0) {
// Scroll the view // Scroll the view
memory_view_scroll(view, vertical); mv_scroll(view, vertical);
} }
// We are not on any edge, move the cursor // We are not on any edge, move the cursor
cursor_move(&view->window->cursor, horizontal, vertical); cursor_move(&view->window->cursor, horizontal, vertical);
} }
void memory_view_cursor_set_addr(MemoryView *view, address target) { void mv_cursor_set_addr(MemoryView *view, address target) {
int view_byte = target - view->base_address; int view_byte = target - view->base_address;
int x = view_byte & 0x0f; int x = view_byte & 0x0f;

View File

@ -29,14 +29,14 @@ typedef struct memory_view {
* @param view A pointer to the view to initialize * @param view A pointer to the view to initialize
* @param ram A pointer to the RAM * @param ram A pointer to the RAM
*/ */
void memory_view_init(InteractWindow *interact, ram ram, int x, int y); void mv_init(InteractWindow *interact, ram ram, int x, int y);
/** /**
* Prints the RAM content from the viewer base address. * Prints the RAM content from the viewer base address.
* *
* @param view * @param view
*/ */
void memory_view_print(MemoryView *view); void mv_print(MemoryView *view);
/** /**
* Sets the viewer base address to the target address page (the first byte) and prints the RAM. * Sets the viewer base address to the target address page (the first byte) and prints the RAM.
@ -44,7 +44,7 @@ void memory_view_print(MemoryView *view);
* @param view * @param view
* @param target The target address to print * @param target The target address to print
*/ */
void memory_view_goto(MemoryView *view, address target); void mv_goto(MemoryView *view, address target);
/** /**
* Scrolls the base address up or down by steps of 0x10. * Scrolls the base address up or down by steps of 0x10.
@ -52,7 +52,7 @@ void memory_view_goto(MemoryView *view, address target);
* @param view * @param view
* @param direction The scroll direction * @param direction The scroll direction
*/ */
void memory_view_scroll(MemoryView *view, int direction); void mv_scroll(MemoryView *view, int direction);
/** /**
* Moves the cursor up, down, right or left. * Moves the cursor up, down, right or left.
@ -61,7 +61,7 @@ void memory_view_scroll(MemoryView *view, int direction);
* @param horizontal * @param horizontal
* @param vertical * @param vertical
*/ */
void memory_view_cursor_move(InteractWindow *window, int horizontal, int vertical); void mv_cursor_move(InteractWindow *window, int horizontal, int vertical);
/** /**
* Moves the cursor to a specific memory address. * Moves the cursor to a specific memory address.
@ -70,6 +70,6 @@ void memory_view_cursor_move(InteractWindow *window, int horizontal, int vertica
* @param view * @param view
* @param target * @param target
*/ */
void memory_view_cursor_set_addr(MemoryView *view, address target); void mv_cursor_set_addr(MemoryView *view, address target);
#endif //NESEMULATOR_MEMORY_VIEW_H #endif //NESEMULATOR_MEMORY_VIEW_H