nesemu/debugger/debugger.c

70 lines
1.9 KiB
C

//
// Created by william on 1/6/24.
//
#include <curses.h>
#include <panel.h>
#include <stdlib.h>
#include "debugger.h"
#include "memory_view.h"
#include "program_view.h"
#include "keys.h"
void create_window() {
setenv("TERMINFO", "/usr/share/terminfo", 1);
setenv("TERM", "xterm", 1);
initscr();
raw();
noecho();
curs_set(0);
keypad(stdscr, true);
}
void start_debugger(System *system) {
InteractWindow windows[2];
size_t window_index = 0;
InteractWindow *current_window = &windows[window_index];
create_window();
mv_init(&windows[0], system->ram, 0, 0);
pv_init(&windows[1], system, MEMORY_VIEW_WIDTH, 0);
cursor_enable(&current_window->cursor);
update_panels();
doupdate();
int keycode;
while ((keycode = getch()) != KEY_EXIT_DEBUGGER) {
if (keycode == KEY_NEXT_VIEW) {
window_index++;
if (window_index > 1) {
window_index = 0;
}
cursor_disable(&current_window->cursor);
current_window = &windows[window_index];
cursor_enable(&current_window->cursor);
} else if (keycode == KEY_VIEW_UP) {
current_window->handle_cursor_move(current_window, 0, CURSOR_OFFSET_UP);
} else if (keycode == KEY_VIEW_DOWN) {
current_window->handle_cursor_move(current_window, 0, CURSOR_OFFSET_DOWN);
} else if (keycode == KEY_VIEW_LEFT) {
current_window->handle_cursor_move(current_window, CURSOR_OFFSET_LEFT, 0);
} else if (keycode == KEY_VIEW_RIGHT) {
current_window->handle_cursor_move(current_window, CURSOR_OFFSET_RIGHT, 0);
} else {
current_window->handle_key_down(current_window, keycode);
}
update_panels();
doupdate();
}
window_inter_deinit(&windows[0]);
window_inter_deinit(&windows[1]);
endwin();
}