nesemu/debugger/debugger.c

75 lines
1.7 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 "dialog.h"
#include "program_view.h"
#define CTRL_KEY_EXIT 3
#define CTRL_KEY_G 103
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) {
MemoryView m_view;
ProgramView p_view;
create_window();
memory_view_init(&m_view, system->ram, 0, 0);
program_view_init(&p_view, MEMORY_VIEW_WIDTH, 0);
update_panels();
doupdate();
int keycode;
while ((keycode = getch()) != CTRL_KEY_EXIT) {
if (keycode == KEY_UP) {
memory_view_move_cursor(&m_view, 0, MEMORY_VIEW_DIRECTION_DOWN);
}
if (keycode == KEY_DOWN) {
memory_view_move_cursor(&m_view, 0, MEMORY_VIEW_DIRECTION_UP);
}
if (keycode == KEY_LEFT) {
memory_view_move_cursor(&m_view, MEMORY_VIEW_DIRECTION_LEFT, 0);
}
if (keycode == KEY_RIGHT) {
memory_view_move_cursor(&m_view, MEMORY_VIEW_DIRECTION_RIGHT, 0);
}
if (keycode == CTRL_KEY_G) {
Dialog dialog = dialog_create("Goto Address");
bool cancelled = false;
address input = dialog_get_address(&dialog, &cancelled);
dialog_remove(&dialog);
if (!cancelled) {
memory_view_goto(&m_view, input);
memory_view_set_cursor_addr(&m_view, input);
}
}
update_panels();
doupdate();
}
endwin();
}