yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::cli::agent::RomDebugAgent Class Reference

ROM Debugging Agent for AI-assisted ROM hacking. More...

#include <rom_debug_agent.h>

Collaboration diagram for yaze::cli::agent::RomDebugAgent:

Classes

struct  BreakpointAnalysis
 Analysis result for a breakpoint hit. More...
 
struct  DetectedIssue
 Detected issue in ROM execution. More...
 
struct  MemoryAnalysis
 Analysis of a memory region. More...
 
struct  PatchComparisonResult
 Results from patch comparison. More...
 

Public Types

enum class  IssueType {
  kBadJumpTarget , kStackImbalance , kWramCorruption , kDmaConflict ,
  kBankOverflow , kInvalidOpcode , kInfiniteLoop , kNullPointer ,
  kAudioDesync , kPpuTimingViolation
}
 Common ROM hacking issue types. More...
 

Public Member Functions

 RomDebugAgent (yaze::agent::EmulatorServiceImpl *emulator_service)
 
absl::StatusOr< BreakpointAnalysisAnalyzeBreakpoint (const yaze::agent::BreakpointHitResponse &hit)
 Analyze a breakpoint hit with full context.
 
absl::StatusOr< MemoryAnalysisAnalyzeMemory (uint32_t address, size_t length)
 Analyze a memory region and identify its purpose.
 
absl::StatusOr< std::string > ExplainExecutionTrace (const std::vector< ExecutionTraceBuffer::TraceEntry > &trace)
 Analyze execution trace and explain program flow.
 
absl::StatusOr< PatchComparisonResultComparePatch (uint32_t address, size_t length, const std::vector< uint8_t > &original)
 Compare original ROM code with patched code.
 
std::vector< DetectedIssueScanForIssues (uint32_t start_address, uint32_t end_address)
 Scan for common ROM hacking issues in a code region.
 
bool IsValidJumpTarget (uint32_t address) const
 Check if an address is a valid jump target.
 
bool HasStackImbalance (uint32_t routine_start, uint32_t routine_end)
 Detect stack imbalance in a subroutine.
 
bool IsMemoryWriteSafe (uint32_t address, size_t length) const
 Check if memory write is safe.
 
std::string DescribeMemoryLocation (uint32_t address) const
 Get human-readable description of a memory address.
 
std::string IdentifyDataType (uint32_t address) const
 Get the data type at a memory address.
 
std::string FormatRegisterState (const std::map< std::string, uint16_t > &regs) const
 Format register state for debugging output.
 
absl::Status LoadSymbols (const std::string &symbol_file)
 Load symbol table for better disassembly.
 
void SetOriginalRom (const std::vector< uint8_t > &rom_data)
 Set the original ROM data for comparison.
 

Private Member Functions

absl::StatusOr< std::string > AnalyzeInstruction (uint32_t address, const uint8_t *code, size_t max_length)
 Analyze the instruction at an address.
 
std::vector< std::string > GetDisassemblyContext (uint32_t address, int before_lines, int after_lines)
 Get surrounding context for an address.
 
std::vector< std::string > BuildCallStack (uint32_t current_pc)
 Build call stack from execution trace.
 
std::optional< DetectedIssueDetectIssuePattern (uint32_t address, const uint8_t *code, size_t length)
 Detect pattern of common issues.
 
bool IsCriticalMemoryArea (uint32_t address) const
 Check if address is in a critical system area.
 
std::optional< std::string > GetStructureInfo (uint32_t address) const
 Get structure information for a memory address.
 

Private Attributes

yaze::agent::EmulatorServiceImplemulator_service_
 
std::unique_ptr< Disassembler65816disassembler_
 
std::unique_ptr< yaze::emu::debug::SymbolProvidersymbol_provider_
 
std::vector< uint8_t > original_rom_
 
std::map< uint32_t, std::string > address_description_cache_
 
std::map< uint32_t, std::string > data_type_cache_
 

Static Private Attributes

static constexpr uint32_t WRAM_START = 0x7E0000
 
static constexpr uint32_t WRAM_END = 0x7FFFFF
 
static constexpr uint32_t GAME_MODE = 0x7E0010
 
static constexpr uint32_t SUBMODULE = 0x7E0011
 
static constexpr uint32_t NMI_FLAG = 0x7E0012
 
static constexpr uint32_t FRAME_COUNTER = 0x7E001A
 
static constexpr uint32_t LINK_X_POS = 0x7E0022
 
static constexpr uint32_t LINK_Y_POS = 0x7E0020
 
static constexpr uint32_t LINK_STATE = 0x7E005D
 
static constexpr uint32_t LINK_DIRECTION = 0x7E002F
 
static constexpr uint32_t SPRITE_TABLE_START = 0x7E0D00
 
static constexpr uint32_t SPRITE_TABLE_END = 0x7E0FFF
 
static constexpr uint32_t SPRITE_STATE = 0x7E0D10
 
static constexpr uint32_t SPRITE_X_LOW = 0x7E0D30
 
static constexpr uint32_t SPRITE_X_HIGH = 0x7E0D20
 
static constexpr uint32_t SPRITE_Y_LOW = 0x7E0D00
 
static constexpr uint32_t SPRITE_Y_HIGH = 0x7E0D20
 
static constexpr uint32_t OAM_BUFFER = 0x7E0800
 
static constexpr uint32_t OAM_BUFFER_END = 0x7E0A1F
 
static constexpr uint32_t DMA0_CONTROL = 0x004300
 
static constexpr uint32_t DMA_ENABLE = 0x00420B
 
static constexpr uint32_t HDMA_ENABLE = 0x00420C
 
static constexpr uint32_t PPU_INIDISP = 0x002100
 
static constexpr uint32_t PPU_BGMODE = 0x002105
 
static constexpr uint32_t PPU_CGADD = 0x002121
 
static constexpr uint32_t PPU_CGDATA = 0x002122
 
static constexpr uint32_t APU_PORT0 = 0x002140
 
static constexpr uint32_t APU_PORT1 = 0x002141
 
static constexpr uint32_t APU_PORT2 = 0x002142
 
static constexpr uint32_t APU_PORT3 = 0x002143
 
static constexpr uint32_t SRAM_START = 0x7EF000
 
static constexpr uint32_t SRAM_END = 0x7EF4FF
 
static constexpr uint32_t PLAYER_NAME = 0x7EF000
 
static constexpr uint32_t PLAYER_HEALTH = 0x7EF36D
 
static constexpr uint32_t PLAYER_MAX_HEALTH = 0x7EF36C
 
static constexpr uint32_t INVENTORY_START = 0x7EF340
 

Detailed Description

ROM Debugging Agent for AI-assisted ROM hacking.

Provides intelligent analysis of ROM execution, breakpoints, memory state, and ASM patches. Designed to help ROM hackers understand crashes, debug patches, and analyze game behavior.

Features:

  • Breakpoint analysis with disassembly and register state
  • Memory region analysis (sprites, tiles, game variables)
  • ASM patch comparison and debugging
  • Pattern detection for common ROM hacking issues
  • Execution trace analysis

Definition at line 35 of file rom_debug_agent.h.

Member Enumeration Documentation

◆ IssueType

Common ROM hacking issue types.

Enumerator
kBadJumpTarget 
kStackImbalance 
kWramCorruption 
kDmaConflict 
kBankOverflow 
kInvalidOpcode 
kInfiniteLoop 
kNullPointer 
kAudioDesync 
kPpuTimingViolation 

Definition at line 84 of file rom_debug_agent.h.

Constructor & Destructor Documentation

◆ RomDebugAgent()

yaze::cli::agent::RomDebugAgent::RomDebugAgent ( yaze::agent::EmulatorServiceImpl * emulator_service)
explicit

Definition at line 79 of file rom_debug_agent.cc.

References disassembler_.

Member Function Documentation

◆ AnalyzeBreakpoint()

◆ AnalyzeMemory()

◆ ExplainExecutionTrace()

absl::StatusOr< std::string > yaze::cli::agent::RomDebugAgent::ExplainExecutionTrace ( const std::vector< ExecutionTraceBuffer::TraceEntry > & trace)

Analyze execution trace and explain program flow.

Definition at line 272 of file rom_debug_agent.cc.

References DescribeMemoryLocation(), yaze::zelda3::description, DMA0_CONTROL, and symbol_provider_.

Here is the call graph for this function:

◆ ComparePatch()

◆ ScanForIssues()

std::vector< RomDebugAgent::DetectedIssue > yaze::cli::agent::RomDebugAgent::ScanForIssues ( uint32_t start_address,
uint32_t end_address )

Scan for common ROM hacking issues in a code region.

Definition at line 545 of file rom_debug_agent.cc.

References DetectIssuePattern(), disassembler_, emulator_service_, kInvalidOpcode, and yaze::agent::EmulatorServiceImpl::ReadMemory().

Here is the call graph for this function:

◆ IsValidJumpTarget()

bool yaze::cli::agent::RomDebugAgent::IsValidJumpTarget ( uint32_t address) const

Check if an address is a valid jump target.

Definition at line 595 of file rom_debug_agent.cc.

References WRAM_END, and WRAM_START.

Referenced by ComparePatch().

◆ HasStackImbalance()

bool yaze::cli::agent::RomDebugAgent::HasStackImbalance ( uint32_t routine_start,
uint32_t routine_end )

Detect stack imbalance in a subroutine.

Definition at line 618 of file rom_debug_agent.cc.

References disassembler_, emulator_service_, and yaze::agent::EmulatorServiceImpl::ReadMemory().

Here is the call graph for this function:

◆ IsMemoryWriteSafe()

bool yaze::cli::agent::RomDebugAgent::IsMemoryWriteSafe ( uint32_t address,
size_t length ) const

Check if memory write is safe.

Definition at line 683 of file rom_debug_agent.cc.

References DMA0_CONTROL, and NMI_FLAG.

◆ DescribeMemoryLocation()

◆ IdentifyDataType()

std::string yaze::cli::agent::RomDebugAgent::IdentifyDataType ( uint32_t address) const

◆ FormatRegisterState()

std::string yaze::cli::agent::RomDebugAgent::FormatRegisterState ( const std::map< std::string, uint16_t > & regs) const

Format register state for debugging output.

Definition at line 851 of file rom_debug_agent.cc.

◆ LoadSymbols()

absl::Status yaze::cli::agent::RomDebugAgent::LoadSymbols ( const std::string & symbol_file)

Load symbol table for better disassembly.

Definition at line 866 of file rom_debug_agent.cc.

References symbol_provider_.

◆ SetOriginalRom()

void yaze::cli::agent::RomDebugAgent::SetOriginalRom ( const std::vector< uint8_t > & rom_data)

Set the original ROM data for comparison.

Definition at line 870 of file rom_debug_agent.cc.

References original_rom_.

◆ AnalyzeInstruction()

absl::StatusOr< std::string > yaze::cli::agent::RomDebugAgent::AnalyzeInstruction ( uint32_t address,
const uint8_t * code,
size_t max_length )
private

Analyze the instruction at an address.

Definition at line 876 of file rom_debug_agent.cc.

Referenced by AnalyzeBreakpoint().

◆ GetDisassemblyContext()

std::vector< std::string > yaze::cli::agent::RomDebugAgent::GetDisassemblyContext ( uint32_t address,
int before_lines,
int after_lines )
private

Get surrounding context for an address.

Definition at line 954 of file rom_debug_agent.cc.

References emulator_service_, and yaze::agent::EmulatorServiceImpl::GetDisassembly().

Referenced by AnalyzeBreakpoint().

Here is the call graph for this function:

◆ BuildCallStack()

std::vector< std::string > yaze::cli::agent::RomDebugAgent::BuildCallStack ( uint32_t current_pc)
private

Build call stack from execution trace.

Definition at line 984 of file rom_debug_agent.cc.

References emulator_service_, yaze::agent::EmulatorServiceImpl::GetExecutionTrace(), and symbol_provider_.

Referenced by AnalyzeBreakpoint().

Here is the call graph for this function:

◆ DetectIssuePattern()

std::optional< RomDebugAgent::DetectedIssue > yaze::cli::agent::RomDebugAgent::DetectIssuePattern ( uint32_t address,
const uint8_t * code,
size_t length )
private

Detect pattern of common issues.

Definition at line 1021 of file rom_debug_agent.cc.

References kInfiniteLoop, kInvalidOpcode, kStackImbalance, and kWramCorruption.

Referenced by AnalyzeBreakpoint(), and ScanForIssues().

◆ IsCriticalMemoryArea()

bool yaze::cli::agent::RomDebugAgent::IsCriticalMemoryArea ( uint32_t address) const
private

Check if address is in a critical system area.

Definition at line 1093 of file rom_debug_agent.cc.

References DMA0_CONTROL, and NMI_FLAG.

Referenced by ComparePatch().

◆ GetStructureInfo()

std::optional< std::string > yaze::cli::agent::RomDebugAgent::GetStructureInfo ( uint32_t address) const
private

Get structure information for a memory address.

Definition at line 1117 of file rom_debug_agent.cc.

References DMA0_CONTROL, OAM_BUFFER, OAM_BUFFER_END, SPRITE_TABLE_END, and SPRITE_TABLE_START.

Referenced by AnalyzeMemory().

Member Data Documentation

◆ WRAM_START

constexpr uint32_t yaze::cli::agent::RomDebugAgent::WRAM_START = 0x7E0000
staticconstexprprivate

Definition at line 191 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation(), IdentifyDataType(), and IsValidJumpTarget().

◆ WRAM_END

constexpr uint32_t yaze::cli::agent::RomDebugAgent::WRAM_END = 0x7FFFFF
staticconstexprprivate

Definition at line 192 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation(), IdentifyDataType(), and IsValidJumpTarget().

◆ GAME_MODE

constexpr uint32_t yaze::cli::agent::RomDebugAgent::GAME_MODE = 0x7E0010
staticconstexprprivate

Definition at line 195 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ SUBMODULE

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SUBMODULE = 0x7E0011
staticconstexprprivate

Definition at line 196 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ NMI_FLAG

constexpr uint32_t yaze::cli::agent::RomDebugAgent::NMI_FLAG = 0x7E0012
staticconstexprprivate

◆ FRAME_COUNTER

constexpr uint32_t yaze::cli::agent::RomDebugAgent::FRAME_COUNTER = 0x7E001A
staticconstexprprivate

Definition at line 198 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ LINK_X_POS

constexpr uint32_t yaze::cli::agent::RomDebugAgent::LINK_X_POS = 0x7E0022
staticconstexprprivate

Definition at line 201 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ LINK_Y_POS

constexpr uint32_t yaze::cli::agent::RomDebugAgent::LINK_Y_POS = 0x7E0020
staticconstexprprivate

Definition at line 202 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ LINK_STATE

constexpr uint32_t yaze::cli::agent::RomDebugAgent::LINK_STATE = 0x7E005D
staticconstexprprivate

Definition at line 203 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ LINK_DIRECTION

constexpr uint32_t yaze::cli::agent::RomDebugAgent::LINK_DIRECTION = 0x7E002F
staticconstexprprivate

Definition at line 204 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ SPRITE_TABLE_START

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SPRITE_TABLE_START = 0x7E0D00
staticconstexprprivate

◆ SPRITE_TABLE_END

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SPRITE_TABLE_END = 0x7E0FFF
staticconstexprprivate

◆ SPRITE_STATE

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SPRITE_STATE = 0x7E0D10
staticconstexprprivate

Definition at line 209 of file rom_debug_agent.h.

◆ SPRITE_X_LOW

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SPRITE_X_LOW = 0x7E0D30
staticconstexprprivate

Definition at line 210 of file rom_debug_agent.h.

◆ SPRITE_X_HIGH

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SPRITE_X_HIGH = 0x7E0D20
staticconstexprprivate

Definition at line 211 of file rom_debug_agent.h.

◆ SPRITE_Y_LOW

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SPRITE_Y_LOW = 0x7E0D00
staticconstexprprivate

Definition at line 212 of file rom_debug_agent.h.

◆ SPRITE_Y_HIGH

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SPRITE_Y_HIGH = 0x7E0D20
staticconstexprprivate

Definition at line 213 of file rom_debug_agent.h.

◆ OAM_BUFFER

constexpr uint32_t yaze::cli::agent::RomDebugAgent::OAM_BUFFER = 0x7E0800
staticconstexprprivate

Definition at line 216 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation(), GetStructureInfo(), and IdentifyDataType().

◆ OAM_BUFFER_END

constexpr uint32_t yaze::cli::agent::RomDebugAgent::OAM_BUFFER_END = 0x7E0A1F
staticconstexprprivate

Definition at line 217 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation(), GetStructureInfo(), and IdentifyDataType().

◆ DMA0_CONTROL

constexpr uint32_t yaze::cli::agent::RomDebugAgent::DMA0_CONTROL = 0x004300
staticconstexprprivate

◆ DMA_ENABLE

constexpr uint32_t yaze::cli::agent::RomDebugAgent::DMA_ENABLE = 0x00420B
staticconstexprprivate

Definition at line 221 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ HDMA_ENABLE

constexpr uint32_t yaze::cli::agent::RomDebugAgent::HDMA_ENABLE = 0x00420C
staticconstexprprivate

Definition at line 222 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ PPU_INIDISP

constexpr uint32_t yaze::cli::agent::RomDebugAgent::PPU_INIDISP = 0x002100
staticconstexprprivate

Definition at line 225 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ PPU_BGMODE

constexpr uint32_t yaze::cli::agent::RomDebugAgent::PPU_BGMODE = 0x002105
staticconstexprprivate

Definition at line 226 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ PPU_CGADD

constexpr uint32_t yaze::cli::agent::RomDebugAgent::PPU_CGADD = 0x002121
staticconstexprprivate

Definition at line 227 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ PPU_CGDATA

constexpr uint32_t yaze::cli::agent::RomDebugAgent::PPU_CGDATA = 0x002122
staticconstexprprivate

Definition at line 228 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ APU_PORT0

constexpr uint32_t yaze::cli::agent::RomDebugAgent::APU_PORT0 = 0x002140
staticconstexprprivate

Definition at line 231 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation(), and IdentifyDataType().

◆ APU_PORT1

constexpr uint32_t yaze::cli::agent::RomDebugAgent::APU_PORT1 = 0x002141
staticconstexprprivate

Definition at line 232 of file rom_debug_agent.h.

◆ APU_PORT2

constexpr uint32_t yaze::cli::agent::RomDebugAgent::APU_PORT2 = 0x002142
staticconstexprprivate

Definition at line 233 of file rom_debug_agent.h.

◆ APU_PORT3

constexpr uint32_t yaze::cli::agent::RomDebugAgent::APU_PORT3 = 0x002143
staticconstexprprivate

Definition at line 234 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation(), and IdentifyDataType().

◆ SRAM_START

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SRAM_START = 0x7EF000
staticconstexprprivate

Definition at line 237 of file rom_debug_agent.h.

Referenced by AnalyzeMemory(), DescribeMemoryLocation(), and IdentifyDataType().

◆ SRAM_END

constexpr uint32_t yaze::cli::agent::RomDebugAgent::SRAM_END = 0x7EF4FF
staticconstexprprivate

Definition at line 238 of file rom_debug_agent.h.

Referenced by AnalyzeMemory(), DescribeMemoryLocation(), and IdentifyDataType().

◆ PLAYER_NAME

constexpr uint32_t yaze::cli::agent::RomDebugAgent::PLAYER_NAME = 0x7EF000
staticconstexprprivate

Definition at line 239 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ PLAYER_HEALTH

constexpr uint32_t yaze::cli::agent::RomDebugAgent::PLAYER_HEALTH = 0x7EF36D
staticconstexprprivate

Definition at line 240 of file rom_debug_agent.h.

Referenced by AnalyzeMemory(), and DescribeMemoryLocation().

◆ PLAYER_MAX_HEALTH

constexpr uint32_t yaze::cli::agent::RomDebugAgent::PLAYER_MAX_HEALTH = 0x7EF36C
staticconstexprprivate

Definition at line 241 of file rom_debug_agent.h.

Referenced by AnalyzeMemory(), and DescribeMemoryLocation().

◆ INVENTORY_START

constexpr uint32_t yaze::cli::agent::RomDebugAgent::INVENTORY_START = 0x7EF340
staticconstexprprivate

Definition at line 242 of file rom_debug_agent.h.

Referenced by AnalyzeMemory(), DescribeMemoryLocation(), and IdentifyDataType().

◆ emulator_service_

yaze::agent::EmulatorServiceImpl* yaze::cli::agent::RomDebugAgent::emulator_service_
private

◆ disassembler_

std::unique_ptr<Disassembler65816> yaze::cli::agent::RomDebugAgent::disassembler_
private

Definition at line 281 of file rom_debug_agent.h.

Referenced by ComparePatch(), HasStackImbalance(), RomDebugAgent(), and ScanForIssues().

◆ symbol_provider_

std::unique_ptr<yaze::emu::debug::SymbolProvider> yaze::cli::agent::RomDebugAgent::symbol_provider_
private

◆ original_rom_

std::vector<uint8_t> yaze::cli::agent::RomDebugAgent::original_rom_
private

Definition at line 283 of file rom_debug_agent.h.

Referenced by SetOriginalRom().

◆ address_description_cache_

std::map<uint32_t, std::string> yaze::cli::agent::RomDebugAgent::address_description_cache_
mutableprivate

Definition at line 286 of file rom_debug_agent.h.

Referenced by DescribeMemoryLocation().

◆ data_type_cache_

std::map<uint32_t, std::string> yaze::cli::agent::RomDebugAgent::data_type_cache_
mutableprivate

Definition at line 287 of file rom_debug_agent.h.

Referenced by IdentifyDataType().


The documentation for this class was generated from the following files: