nesemu/debugger/debugger.c

101 lines
2.8 KiB
C
Raw Normal View History

2024-01-07 16:20:37 -05:00
//
// Created by william on 1/6/24.
//
#include <curses.h>
#include <panel.h>
#include <stdlib.h>
#include "debugger.h"
#include "memory_view.h"
2024-01-11 16:02:53 -05:00
#include "program_view.h"
2024-04-03 23:03:35 -04:00
#include "keys.h"
#include "cpu_view.h"
2024-05-01 12:58:15 -04:00
#include "ppu_view.h"
2024-01-07 16:20:37 -05:00
void debugger_create_window() {
2024-01-07 16:20:37 -05:00
setenv("TERMINFO", "/usr/share/terminfo", 1);
setenv("TERM", "xterm", 1);
initscr();
raw();
noecho();
2024-01-09 14:46:20 -05:00
curs_set(0);
keypad(stdscr, true);
2024-01-07 16:20:37 -05:00
}
2024-05-06 20:23:44 -04:00
LinkedList debugger_create_interactive_windows() {
LinkedList interactive_windows;
InteractWindow *window;
interactive_windows = linked_list_init(true);
window = malloc(sizeof(InteractWindow));
2024-05-06 20:23:44 -04:00
mv_init(window, 0, 0);
linked_list_add(&interactive_windows, window);
window = malloc(sizeof(InteractWindow));
2024-05-06 20:23:44 -04:00
pv_init(window, MEMORY_VIEW_WIDTH, 0);
linked_list_add(&interactive_windows, window);
return interactive_windows;
}
void debugger_uninit_interactive_windows(LinkedList *windows) {
linked_list_cursor_reset(windows);
InteractWindow *window = windows->current->data;
for (int i = 0; i < windows->size; i++) {
window_inter_deinit(window);
window = linked_list_next(windows)->data;
}
linked_list_uninit(windows);
}
2024-01-07 16:20:37 -05:00
void start_debugger(System *system) {
CpuView *cpu_view;
2024-05-01 12:58:15 -04:00
PpuView *ppu_view;
LinkedList interactive_windows;
InteractWindow *current_window;
2024-01-11 16:02:53 -05:00
debugger_create_window();
2024-01-07 16:20:37 -05:00
interactive_windows = debugger_create_interactive_windows(system);
current_window = interactive_windows.current->data;
2024-05-06 20:23:44 -04:00
cpu_view = cv_init(0, MEMORY_VIEW_HEIGHT);
ppu_view = ppv_init(CPU_VIEW_WIDTH, MEMORY_VIEW_HEIGHT);
2024-01-16 15:46:22 -05:00
cursor_enable(&current_window->cursor);
2024-01-07 16:20:37 -05:00
update_panels();
doupdate();
int keycode;
2024-04-03 23:03:35 -04:00
while ((keycode = getch()) != KEY_EXIT_DEBUGGER) {
if (keycode == KEY_NEXT_VIEW) {
2024-01-07 16:20:37 -05:00
2024-01-16 15:46:22 -05:00
cursor_disable(&current_window->cursor);
current_window = linked_list_next(&interactive_windows)->data;
2024-01-16 15:46:22 -05:00
cursor_enable(&current_window->cursor);
2024-04-03 23:03:35 -04:00
} else if (keycode == KEY_VIEW_UP) {
2024-01-16 15:46:22 -05:00
current_window->handle_cursor_move(current_window, 0, CURSOR_OFFSET_UP);
2024-04-03 23:03:35 -04:00
} else if (keycode == KEY_VIEW_DOWN) {
2024-01-14 21:59:13 -05:00
current_window->handle_cursor_move(current_window, 0, CURSOR_OFFSET_DOWN);
2024-04-03 23:03:35 -04:00
} else if (keycode == KEY_VIEW_LEFT) {
2024-01-14 21:59:13 -05:00
current_window->handle_cursor_move(current_window, CURSOR_OFFSET_LEFT, 0);
2024-04-03 23:03:35 -04:00
} else if (keycode == KEY_VIEW_RIGHT) {
2024-01-14 21:59:13 -05:00
current_window->handle_cursor_move(current_window, CURSOR_OFFSET_RIGHT, 0);
2024-01-16 15:46:22 -05:00
} else {
current_window->handle_key_down(current_window, keycode);
2024-01-07 16:20:37 -05:00
}
update_panels();
doupdate();
}
debugger_uninit_interactive_windows(&interactive_windows);
cv_uninit(cpu_view);
2024-05-01 12:58:15 -04:00
ppv_uninit(ppu_view);
2024-01-14 21:59:13 -05:00
2024-01-07 16:20:37 -05:00
endwin();
}