nesemu/debugger/debugger.c

70 lines
1.9 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"
2024-01-07 16:20:37 -05:00
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) {
2024-01-14 21:59:13 -05:00
InteractWindow windows[2];
2024-01-16 15:46:22 -05:00
size_t window_index = 0;
InteractWindow *current_window = &windows[window_index];
2024-01-11 16:02:53 -05:00
2024-01-07 16:20:37 -05:00
create_window();
2024-01-14 21:59:13 -05:00
memory_view_init(&windows[0], system->ram, 0, 0);
2024-04-08 14:19:59 -04:00
pv_init(&windows[1], system, MEMORY_VIEW_WIDTH, 0);
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-16 15:46:22 -05:00
window_index++;
if (window_index > 1) {
window_index = 0;
}
2024-01-07 16:20:37 -05:00
2024-01-16 15:46:22 -05:00
cursor_disable(&current_window->cursor);
current_window = &windows[window_index];
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();
}
2024-01-14 21:59:13 -05:00
window_inter_deinit(&windows[0]);
window_inter_deinit(&windows[1]);
2024-01-07 16:20:37 -05:00
endwin();
}