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"
|
|
|
|
#include "dialog.h"
|
|
|
|
|
|
|
|
#define CTRL_KEY_EXIT 3
|
|
|
|
#define CTRL_KEY_G 103
|
|
|
|
|
|
|
|
MemoryView view;
|
|
|
|
|
|
|
|
void create_window() {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void start_debugger(System *system) {
|
|
|
|
create_window();
|
|
|
|
|
|
|
|
memory_view_init(&view, system->ram);
|
|
|
|
|
|
|
|
update_panels();
|
|
|
|
doupdate();
|
|
|
|
|
|
|
|
int keycode;
|
|
|
|
while ((keycode = getch()) != CTRL_KEY_EXIT) {
|
2024-01-09 14:46:20 -05:00
|
|
|
if (keycode == KEY_UP) {
|
2024-01-09 15:56:54 -05:00
|
|
|
memory_view_move_cursor(&view, 0, MEMORY_VIEW_DIRECTION_DOWN);
|
2024-01-07 16:20:37 -05:00
|
|
|
}
|
|
|
|
|
2024-01-09 14:46:20 -05:00
|
|
|
if (keycode == KEY_DOWN) {
|
2024-01-09 15:56:54 -05:00
|
|
|
memory_view_move_cursor(&view, 0, MEMORY_VIEW_DIRECTION_UP);
|
2024-01-09 14:46:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == KEY_LEFT) {
|
2024-01-09 15:56:54 -05:00
|
|
|
memory_view_move_cursor(&view, MEMORY_VIEW_DIRECTION_LEFT, 0);
|
2024-01-09 14:46:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == KEY_RIGHT) {
|
2024-01-09 15:56:54 -05:00
|
|
|
memory_view_move_cursor(&view, MEMORY_VIEW_DIRECTION_RIGHT, 0);
|
2024-01-07 16:20:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (keycode == CTRL_KEY_G) {
|
2024-01-09 14:46:20 -05:00
|
|
|
Dialog dialog = dialog_create("Goto Address");
|
|
|
|
|
|
|
|
bool cancelled = false;
|
|
|
|
address input = dialog_get_address(&dialog, &cancelled);
|
|
|
|
dialog_remove(&dialog);
|
|
|
|
|
|
|
|
if (!cancelled) {
|
|
|
|
memory_view_goto(&view, input);
|
|
|
|
memory_view_set_cursor_addr(&view, input);
|
|
|
|
}
|
2024-01-07 16:20:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
update_panels();
|
|
|
|
doupdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
endwin();
|
|
|
|
}
|