Memory debugger

This commit is contained in:
william 2024-01-07 16:20:37 -05:00
parent cebee66076
commit 084cbed0f4
11 changed files with 296 additions and 70 deletions

View File

@ -12,6 +12,7 @@
<component name="CMakeRunConfigurationManager"> <component name="CMakeRunConfigurationManager">
<generated> <generated>
<config projectName="NESEmulator" targetName="NESEmulator" /> <config projectName="NESEmulator" targetName="NESEmulator" />
<config projectName="NESEmulator" targetName="DEBUG" />
<config projectName="NESEmulator" targetName="ROM" /> <config projectName="NESEmulator" targetName="ROM" />
<config projectName="NESEmulator" targetName="Mappers" /> <config projectName="NESEmulator" targetName="Mappers" />
<config projectName="NESEmulator" targetName="PPU" /> <config projectName="NESEmulator" targetName="PPU" />
@ -24,59 +25,18 @@
</configurations> </configurations>
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="0c3b231e-0637-4ac1-8964-c60fc9e9e691" name="Changes" comment="Added logging for operand decoding"> <list default="true" id="0c3b231e-0637-4ac1-8964-c60fc9e9e691" name="Changes" comment="Things">
<change afterPath="$PROJECT_DIR$/include/ppu.h" afterDir="false" /> <change afterPath="$PROJECT_DIR$/debugger/CMakeLists.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/include/system.h" afterDir="false" /> <change afterPath="$PROJECT_DIR$/debugger/debugger.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/include/types.h" afterDir="false" /> <change afterPath="$PROJECT_DIR$/debugger/debugger.h" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ppu/CMakeLists.txt" afterDir="false" /> <change afterPath="$PROJECT_DIR$/debugger/dialog.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ppu/ppu.c" afterDir="false" /> <change afterPath="$PROJECT_DIR$/debugger/dialog.h" afterDir="false" />
<change afterPath="$PROJECT_DIR$/system.c" afterDir="false" /> <change afterPath="$PROJECT_DIR$/debugger/memory_view.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test_roms/nestest.fdb" afterDir="false" /> <change afterPath="$PROJECT_DIR$/debugger/memory_view.h" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test_roms/nestest.nes" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test_roms/smb.fdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" /> <change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/conandata.yml" beforeDir="false" afterPath="$PROJECT_DIR$/conandata.yml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/conandata.yml" beforeDir="false" afterPath="$PROJECT_DIR$/conandata.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/cpu/CMakeLists.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/cpu.c" beforeDir="false" afterPath="$PROJECT_DIR$/cpu/cpu.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/cpu.h" beforeDir="false" afterPath="$PROJECT_DIR$/cpu/cpu.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/memory.c" beforeDir="false" afterPath="$PROJECT_DIR$/cpu/memory.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/memory.h" beforeDir="false" afterPath="$PROJECT_DIR$/cpu/memory.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/op.c" beforeDir="false" afterPath="$PROJECT_DIR$/cpu/op.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/op.h" beforeDir="false" afterPath="$PROJECT_DIR$/cpu/op.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/ram.c" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/cpu/ram.h" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/include/cpu.h" beforeDir="false" afterPath="$PROJECT_DIR$/include/cpu.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/include/mapper.h" beforeDir="false" afterPath="$PROJECT_DIR$/include/mapper.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/include/rom.h" beforeDir="false" afterPath="$PROJECT_DIR$/include/rom.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.c" beforeDir="false" afterPath="$PROJECT_DIR$/main.c" afterDir="false" /> <change beforePath="$PROJECT_DIR$/main.c" beforeDir="false" afterPath="$PROJECT_DIR$/main.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/mappers/simple_mapper.c" beforeDir="false" afterPath="$PROJECT_DIR$/mappers/simple_mapper.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/rom/ines.c" beforeDir="false" afterPath="$PROJECT_DIR$/rom/ines.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/rom/rom.c" beforeDir="false" afterPath="$PROJECT_DIR$/rom/rom.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/readme.txt" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/readme.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/ascii_1.chr" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/ascii_1.chr" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/ascii_2.chr" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/ascii_2.chr" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/ascii_3.chr" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/ascii_3.chr" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/build_rom.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/build_rom.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/colors.inc" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/colors.inc" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/console.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/console.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/crc.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/crc.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/delay.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/delay.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/devcart.bin" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/devcart.bin" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/macros.inc" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/macros.inc" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/neshw.inc" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/neshw.inc" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/ppu.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/ppu.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/print.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/print.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/shell.inc" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/shell.inc" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/shell.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/shell.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/testing.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/testing.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/common/text_out.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/common/text_out.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/readme.txt" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/readme.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/test_cpu_exec_space_apu.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/test_cpu_exec_space_apu.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/source/test_cpu_exec_space_ppuio.s" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/source/test_cpu_exec_space_ppuio.s" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/test_cpu_exec_space_apu.nes" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/test_cpu_exec_space_apu.nes" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/cpu_exec_space/test_cpu_exec_space_ppuio.nes" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/cpu_exec_space/test_cpu_exec_space_ppuio.nes" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/smb.nes" beforeDir="false" afterPath="$PROJECT_DIR$/test_roms/smb.nes" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -274,6 +234,11 @@
<option name="_new_targetType" value="&quot;PATH&quot;" /> <option name="_new_targetType" value="&quot;PATH&quot;" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration default="true" type="CLionExternalRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true">
<method v="2">
<option name="CLION.EXTERNAL.BUILD" enabled="true" />
</method>
</configuration>
<configuration name="NESEmulator" type="CMakeListConfigurationType" factoryName="CMakeListConfigurationFactory" temporary="true"> <configuration name="NESEmulator" type="CMakeListConfigurationType" factoryName="CMakeListConfigurationFactory" temporary="true">
<method v="2" /> <method v="2" />
</configuration> </configuration>
@ -285,7 +250,7 @@
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" /> <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="CPU" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="CPU" CONFIG_NAME="Debug"> <configuration name="DEBUG" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="DEBUG" CONFIG_NAME="Debug">
<method v="2"> <method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" /> <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method> </method>
@ -295,12 +260,17 @@
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" /> <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="Mappers" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="Mappers" CONFIG_NAME="Debug"> <configuration name="NESEmulator (GDB Server)" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-- /usr/bin/gdbserver localhost:1234 $CMakeCurrentBuildDir$/NESEmulator" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="NESEmulator" CONFIG_NAME="Debug" RUN_PATH="/usr/bin/gnome-terminal">
<method v="2"> <method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" /> <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="NESEmulator" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="NESEmulator" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="NESEmulator" RUN_TARGET_NAME="NESEmulator"> <configuration name="NESEmulator (Term)" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-- $CMakeCurrentBuildDir$/NESEmulator" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="true" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="NESEmulator" CONFIG_NAME="Debug" RUN_PATH="/usr/bin/gnome-terminal">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration name="NESEmulator" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="true" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="NESEmulator" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="NESEmulator" RUN_TARGET_NAME="NESEmulator">
<method v="2"> <method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" /> <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method> </method>
@ -320,11 +290,6 @@
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" /> <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="ROM" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="NESEmulator" TARGET_NAME="ROM" CONFIG_NAME="Debug">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
<configuration default="true" type="PythonConfigurationType" factoryName="Python"> <configuration default="true" type="PythonConfigurationType" factoryName="Python">
<module name="nesemu" /> <module name="nesemu" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
@ -449,11 +414,14 @@
<method v="2" /> <method v="2" />
</configuration> </configuration>
<list> <list>
<item itemvalue="CMake Application.NESEmulator" />
<item itemvalue="CMake Application.CPU" /> <item itemvalue="CMake Application.CPU" />
<item itemvalue="CMake Application.DEBUG" />
<item itemvalue="CMake Application.Mappers" /> <item itemvalue="CMake Application.Mappers" />
<item itemvalue="CMake Application.PPU" /> <item itemvalue="CMake Application.PPU" />
<item itemvalue="CMake Application.ROM" /> <item itemvalue="CMake Application.ROM" />
<item itemvalue="CMake Application.NESEmulator (GDB Server)" />
<item itemvalue="CMake Application.NESEmulator" />
<item itemvalue="CMake Application.NESEmulator (Term)" />
<item itemvalue="CMake Debug.NESEmulator" /> <item itemvalue="CMake Debug.NESEmulator" />
</list> </list>
<recent_temporary> <recent_temporary>
@ -491,7 +459,9 @@
<workItem from="1704429138262" duration="2629000" /> <workItem from="1704429138262" duration="2629000" />
<workItem from="1704484992884" duration="2000" /> <workItem from="1704484992884" duration="2000" />
<workItem from="1704501418104" duration="8204000" /> <workItem from="1704501418104" duration="8204000" />
<workItem from="1704569084127" duration="3000" /> <workItem from="1704569084127" duration="8903000" />
<workItem from="1704582152049" duration="7863000" />
<workItem from="1704660072645" duration="2354000" />
</task> </task>
<task id="LOCAL-00001" summary="Cpu opcodes implementation"> <task id="LOCAL-00001" summary="Cpu opcodes implementation">
<option name="closed" value="true" /> <option name="closed" value="true" />
@ -517,7 +487,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1703369431911</updated> <updated>1703369431911</updated>
</task> </task>
<option name="localTasksCounter" value="4" /> <task id="LOCAL-00004" summary="Things">
<option name="closed" value="true" />
<created>1704569231622</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1704569231622</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -534,7 +512,8 @@
<MESSAGE value="Cpu opcodes implementation" /> <MESSAGE value="Cpu opcodes implementation" />
<MESSAGE value="Gitignore" /> <MESSAGE value="Gitignore" />
<MESSAGE value="Added logging for operand decoding" /> <MESSAGE value="Added logging for operand decoding" />
<option name="LAST_COMMIT_MESSAGE" value="Added logging for operand decoding" /> <MESSAGE value="Things" />
<option name="LAST_COMMIT_MESSAGE" value="Things" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View File

@ -5,12 +5,14 @@ add_subdirectory(cpu)
add_subdirectory(ppu) add_subdirectory(ppu)
add_subdirectory(mappers) add_subdirectory(mappers)
add_subdirectory(rom) add_subdirectory(rom)
add_subdirectory(debugger)
list(APPEND EXTRA_INCLUDES list(APPEND EXTRA_INCLUDES
"${PROJECT_SOURCE_DIR}/cpu" "${PROJECT_SOURCE_DIR}/cpu"
"${PROJECT_SOURCE_DIR}/ppu" "${PROJECT_SOURCE_DIR}/ppu"
"${PROJECT_SOURCE_DIR}/mappers" "${PROJECT_SOURCE_DIR}/mappers"
"${PROJECT_SOURCE_DIR}/rom") "${PROJECT_SOURCE_DIR}/rom"
"${PROJECT_SOURCE_DIR}/debugger")
add_executable(NESEmulator main.c add_executable(NESEmulator main.c
system.c system.c
@ -19,7 +21,7 @@ add_executable(NESEmulator main.c
find_package(log.c) find_package(log.c)
target_link_libraries(NESEmulator CPU PPU Mappers ROM log.c::log.c) target_link_libraries(NESEmulator CPU PPU Mappers ROM DEBUG log.c::log.c)
target_include_directories(NESEmulator PUBLIC target_include_directories(NESEmulator PUBLIC
"${PROJECT_BINARY_DIR}" "${PROJECT_BINARY_DIR}"
${EXTRA_INCLUDES}) ${EXTRA_INCLUDES})

View File

@ -2,5 +2,6 @@
# To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements # To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements
requirements: requirements:
- "ncurses/6.4"
- "libcheck/0.15.2" - "libcheck/0.15.2"
- "log.c/cci.20200620" - "log.c/cci.20200620"

8
debugger/CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
add_library(DEBUG
debugger.c
memory_view.c
dialog.c)
find_package(Curses)
target_link_libraries(DEBUG Curses::Curses)

63
debugger/debugger.c Normal file
View File

@ -0,0 +1,63 @@
//
// 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_UP 65
#define CTRL_KEY_DOWN 66
#define CTRL_KEY_G 103
MemoryView view;
void create_window() {
setenv("TERMINFO", "/usr/share/terminfo", 1);
setenv("TERM", "xterm", 1);
initscr();
raw();
noecho();
// wborder(window, '|', '|', '-', '-', '+', '+', '+', '+');
}
void destroy_window() {
endwin();
}
void some_func(char* user_input) {
}
void start_debugger(System *system) {
create_window();
memory_view_init(&view, system->ram);
update_panels();
doupdate();
int keycode;
while ((keycode = getch()) != CTRL_KEY_EXIT) {
if (keycode == CTRL_KEY_UP) {
memory_view_scroll(&view, -1, system->ram);
}
if (keycode == CTRL_KEY_DOWN) {
memory_view_scroll(&view, 1, system->ram);
}
if (keycode == CTRL_KEY_G) {
Dialog dialog = dialog_create("Goto Address", &some_func);
}
update_panels();
doupdate();
}
endwin();
}

12
debugger/debugger.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by william on 1/6/24.
//
#include "../include/system.h"
#ifndef NESEMULATOR_DEBUGGER_H
#define NESEMULATOR_DEBUGGER_H
void start_debugger(System *system);
#endif //NESEMULATOR_DEBUGGER_H

21
debugger/dialog.c Normal file
View File

@ -0,0 +1,21 @@
//
// Created by william on 1/7/24.
//
#include <string.h>
#include "dialog.h"
Dialog dialog_create(char *message, void (*callback)(char *user_input)) {
Dialog dialog;
int width = (int) strlen(message) + 2;
WINDOW *window = newwin(3, width, 2, 2);
box(window, 0, 0);
mvwprintw(window, 0, 1, "%s", message);
dialog.panel = new_panel(window);
dialog.callback = callback;
return dialog;
}

18
debugger/dialog.h Normal file
View File

@ -0,0 +1,18 @@
//
// Created by william on 1/7/24.
//
#ifndef NESEMULATOR_DIALOG_H
#define NESEMULATOR_DIALOG_H
#include <panel.h>
typedef struct dialog {
PANEL *panel;
void (*callback)(char *user_input);
} Dialog;
Dialog dialog_create(char *message, void (*callback)(char *user_input));
#endif //NESEMULATOR_DIALOG_H

65
debugger/memory_view.c Normal file
View File

@ -0,0 +1,65 @@
#include <curses.h>
#include <panel.h>
#include <assert.h>
#include "memory_view.h"
//
// Created by william on 1/6/24.
//
void write_line(WINDOW *window, int line, address base_address, byte *data) {
mvwprintw(window, line + 2, 1, "[%04x]", base_address);
for (int i = 0; i <= MEMORY_VIEW_LINE_BYTE_COUNT; i++) {
mvwprintw(window, line + 2, 8 + i * 3, "%02x", data[i]);
}
}
void memory_view_init(MemoryView *view, ram ram) {
WINDOW *window = newwin(MEMORY_VIEW_HEIGHT, MEMORY_VIEW_WIDTH, 0, 0);
box(window, 0, 0);
mvwprintw(window, 0, 1, " MEMORY VIEW ");
mvwprintw(window, 1, 1, " +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f");
view->panel = new_panel(window);
view->base_address = 0xfc00;
memory_view_print(view, ram);
}
void memory_view_print(MemoryView *view, ram ram) {
for (int line = 0; line <= MEMORY_VIEW_LINE_COUNT; line++) {
address line_address = view->base_address + line * (MEMORY_VIEW_LINE_BYTE_COUNT + 1);
byte *data = &ram[line_address];
write_line(view->panel->win, line, line_address, data);
}
}
void memory_view_goto(MemoryView *view, address target, ram ram) {
assert(target < RAM_SIZE);
address max_base_address = RAM_SIZE - MEMORY_VIEW_BYTE_COUNT;
if (target > max_base_address) {
target = max_base_address;
}
view->base_address = target;
memory_view_print(view, ram);
}
void memory_view_scroll(MemoryView *view, char direction, ram ram) {
assert(direction == MEMORY_VIEW_DIRECTION_DOWN || direction == MEMORY_VIEW_DIRECTION_UP);
int offset = 0;
if (direction == MEMORY_VIEW_DIRECTION_DOWN && view->base_address > MEMORY_VIEW_LINE_BYTE_COUNT) {
offset -= MEMORY_VIEW_LINE_BYTE_COUNT + 1;
}
if (direction == MEMORY_VIEW_DIRECTION_UP && view->base_address < RAM_SIZE - MEMORY_VIEW_BYTE_COUNT) {
offset += MEMORY_VIEW_LINE_BYTE_COUNT + 1;
}
address target = view->base_address + offset;
memory_view_goto(view, target, ram);
}

33
debugger/memory_view.h Normal file
View File

@ -0,0 +1,33 @@
//
// Created by william on 1/6/24.
//
#ifndef NESEMULATOR_MEMORY_VIEW_H
#define NESEMULATOR_MEMORY_VIEW_H
#include <panel.h>
#include "../include/types.h"
#define MEMORY_VIEW_HEIGHT 19
#define MEMORY_VIEW_WIDTH 56
#define MEMORY_VIEW_LINE_COUNT 0xf
#define MEMORY_VIEW_LINE_BYTE_COUNT 0xf
#define MEMORY_VIEW_BYTE_COUNT 0xff
#define MEMORY_VIEW_DIRECTION_UP 1
#define MEMORY_VIEW_DIRECTION_DOWN -1
typedef struct memory_view {
PANEL *panel;
address base_address;
} MemoryView;
void memory_view_init(MemoryView *view, ram ram);
void memory_view_print(MemoryView *view, ram ram);
void memory_view_goto(MemoryView *view, address target, ram ram);
void memory_view_scroll(MemoryView *view, char direction, ram ram);
#endif //NESEMULATOR_MEMORY_VIEW_H

38
main.c
View File

@ -17,26 +17,50 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <log.h> #include <log.h>
#include "debugger/debugger.h"
#include "include/rom.h" #include "include/rom.h"
#include "include/system.h" #include "include/system.h"
int main() { //int win() {
log_set_level(LOG_INFO); // printf("NCURSES\n");
//
// setlocale(LC_ALL, "");
// setenv("TERM", "xterm-256color", 1);
// setenv("TERMINFO", "/usr/share/terminfo", 1);
//
// initscr();
// printw("Hello World !!!");
// refresh();
// getch();
// endwin();
//
// return EXIT_SUCCESS;
//}
char *rom_path = "../test_roms/nestest.nes"; int main() {
System system; System system;
log_set_level(LOG_INFO);
system_init(&system); system_init(&system);
char *rom_path = "../test_roms/nestest.nes";
if (!rom_load(rom_path, &system)) { if (!rom_load(rom_path, &system)) {
system_uninit(&system); system_uninit(&system);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
system_start(&system); start_debugger(&system);
system_loop(&system);
system_uninit(&system);
return EXIT_SUCCESS; system_uninit(&system);
return 0;
//
// system_start(&system);
// system_loop(&system);
// system_uninit(&system);
// return EXIT_SUCCESS;
// return win();
} }