Agent skill
r2000-analyze-symbol
Analyzes a specific memory address or label to determine its purpose (variable, flag, pointer, hardware register) by examining its cross-references and usage patterns.
Install this agent skill to your Project
npx add-skill https://github.com/ricardoquesada/regenerator2000/tree/main/.agent/skills/r2000-analyze-symbol
SKILL.md
Analyze Symbol Workflow
Use this skill when the user asks to "analyze this label", "what is this variable?", or "trace this address". This skill focuses on data flow—understanding what a memory location represents rather than just what code executes.
1. Determine Context & Platform
- Get the Target: If the user provides a label or address, use that. If not, use
r2000_get_disassembly_cursororr2000_get_address_detailsto identify the address under the cursor. - Get the Platform: Use
r2000_get_binary_info.- CRITICAL: Knowing the platform (e.g., C64, VIC-20) is essential for identifying hardware registers (VIC-II, SID, CIA, VIA).
- CONTEXT: Use the
filenameresponse anddescription(if provided) to identify the specific game or program. This allows you to infer domain-specific labels (e.g., "lap_counter" for a racing game, "lives" for a platformer) and look up known memory maps for popular titles. - UNDOCUMENTED OPCODES: If
may_contain_undocumented_opcodesistrue, the binary may use illegal/undocumented MOS 6502 opcodes. When tracing cross-references, be aware that instructions likeLAX,SAX,DCP, etc. are valid and their read/write side effects must be considered in the data flow analysis.
2. Gather Usage Data
- Use
r2000_get_cross_referenceson the target address.- This returns a list of everywhere the address is used (read, write, or modify).
- Note: Pay attention to the instruction type at each reference.
- Writes:
STA,STX,STY,INC,DEC,ASL,LSR,ROR,ROL. - Reads:
LDA,LDX,LDY,BIT,CMP,CPX,CPY,ADC,SBC. - Modify:
INC,DEC,ASL,LSR,ROR,ROL(read-modify-write).
- Writes:
- If
r2000_get_cross_referencesreturns zero results:- The symbol may be referenced indirectly via a pointer — check if the address is in Zero Page (
$00–$FF) and whether nearby code uses($addr),Yor($addr,X)patterns. - It may be a well-known OS/KERNAL address that the disassembler doesn't generate an explicit cross-reference for — check the platform's memory map. If platform = C64, see the C64 Reference section below.
- It may be dead code / an unused variable. Note this in the report.
- The symbol may be referenced indirectly via a pointer — check if the address is in Zero Page (
3. Analyze Patterns (Heuristics)
Is it a Hardware Register?
- Check the address against the platform's memory map. Use your knowledge of the target computer's hardware registers.
- If platform = C64 (see C64 Reference section below):
$D000–$D02E: VIC-II (Sprites, Screen control, IRQ).$D400–$D7FF: SID (Sound voices, filters, volume).$DC00–$DCFF: CIA 1 (Joystick, Keyboard, IRQ).$DD00–$DDFF: CIA 2 (Serial bus, NMI, VIC bank).
- If it matches a hardware register, rename it to the standard hardware name (e.g.,
VIC_SPR0_X,SID_FreqLo1,CIA1_PRA).
Is it a Pointer (16-bit)?
- Is it used in Zero Page (address < $100)?
- Is it used for Indirect Indexed addressing
($xx),Y?- Example:
LDA ($FB),Y
- Example:
- Is it used for Indexed Indirect addressing
($xx,X)? - If so, it's a Pointer. Rename to something like
ptr_screen,ptr_data, orvec_irq.- Suggest generating a comment explaining what it points to.
Is it a Flag (Boolean)?
- Is it only ever set to
0or1(or$00/$FF)? - Is it checked with
BIT,LDA/BEQ/BNE? - If so, it's likely a Flag.
- Rename to
is_active,has_collided,enable_music, etc.
- Rename to
Is it a Counter/Index?
- Is it incremented (
INC) or decremented (DEC) inside a loop? - Is it compared (
CPX,CPY,CMP) against a limit? - If so, it's a Counter or Index.
- Rename to
loop_idx,sprite_count,delay_timer.
- Rename to
Is it a State Variable?
- Does it take multiple distinct values (e.g., 0=Init, 1=Title, 2=Game, 3=Over)?
- Is it used in a jump table dispatch (e.g.,
ASL/TAX/JMP (table,X))? - If so, it's a State Machine Variable.
- Rename to
game_state,current_mode.
- Rename to
4. Synthesize & Action
-
Rename: Use
r2000_set_label_nameto give it a meaningful, descriptive name based on your analysis. Use the following naming conventions consistently:Symbol Kind Convention Example Zero Page variable snake_caseplayer_lives,delay_timerRAM variable snake_casescore_hi,current_levelPointer / vector ptr_prefixptr_screen,vec_irqHardware register UPPER_SNAKEVIC_SPR0_X,SID_FreqLo1Constant / address UPPER_SNAKESCREEN_RAM,CHR_ROM_BASERoutine entry point snake_caseinit_screen,draw_sprite -
Document:
- Use
r2000_set_commentwith"type": "line"at the definition (if it's a variable in memory) to explain its range, purpose, or bitfield layout. - Use
r2000_set_commentwith"type": "side"at key usages to clarify why it's being read or written (e.g., "Reset life counter", "Check for fire button").
- Use
C64 Reference (only when platform = C64)
Use this section only if
r2000_get_binary_inforeturns platform = C64. For other platforms (VIC-20, Apple II, NES, etc.), rely on your own knowledge of that platform's memory map and OS addresses.
C64 Memory Map
| Address Range | Description |
|---|---|
$0000–$00FF |
Zero Page (fast variables, pointers) |
$0100–$01FF |
CPU Stack |
$0200–$03FF |
OS work area, BASIC input buffer |
$0314–$0315 |
Hardware IRQ vector shadow (CINV) |
$0400–$07FF |
Default Screen RAM (1000 bytes + spare) |
$0800–$9FFF |
BASIC program area / free RAM |
$A000–$BFFF |
BASIC ROM (or RAM underneath) |
$C000–$CFFF |
Free RAM |
$D000–$D3FF |
VIC-II registers (when I/O visible) |
$D400–$D7FF |
SID registers (when I/O visible) |
$D800–$DBFF |
Color RAM |
$DC00–$DCFF |
CIA 1 (keyboard, joystick, IRQ timer) |
$DD00–$DDFF |
CIA 2 (serial bus, NMI, VIC bank select) |
$E000–$FFFF |
KERNAL ROM (or RAM underneath) |
Well-Known Zero Page Addresses (C64)
| Address | KERNAL / BASIC Usage |
|---|---|
$00–$01 |
CPU I/O port (memory map control) |
$02–$0F |
KERNAL/BASIC temporaries — avoid reusing |
$22–$25 |
KERNAL indirect pointer temporaries |
$39–$3E |
Floating-point accumulator (BASIC) |
$61–$66 |
Floating-point register 1 (BASIC) |
$90 |
KERNAL status flag (ST) |
$91 |
Stop-key flag |
$C5 |
Last key pressed (matrix code) |
$CB |
Matrix position of current key |
$D3 |
Current cursor column |
Example Output
If you analyze $0314 on C64 and see:
- References: Written during init, read during IRQ handler.
- Context:
$0314is the hardware IRQ vector shadow. - Action: Rename to
IRQ_VECTOR_LO(or standardCINV). Add comment: "Hardware IRQ vector shadow".
If you analyze $20 and see:
- References:
STA ($20),Y. - Context: Zero Page.
- Action: Rename to
ptr_dest. Add comment: "Destination pointer for memory copy".
Reporting Results
After completing the analysis, report to the user:
- Address: The address analyzed and its current label (if any).
- Classification: What kind of symbol it is (flag, counter, pointer, hardware register, state variable, etc.).
- Evidence: The key cross-references or usage patterns that led to the conclusion.
- Actions taken: What was renamed or commented.
- Uncertain / no refs: If
r2000_get_cross_referencesreturned nothing, explain the possibilities (indirect use, KERNAL address, or dead variable).
Always ask the user's confirmation before applying r2000_set_label_name or adding comments, unless they explicitly said "go ahead and rename it."
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
verify-mcp
Verifies the MCP server functionality by running the integration test suite.
update-mcp-docs
Syncs `docs/mcp.md` with the actual tools exposed by `crates/regenerator2000-core/src/mcp/handler.rs`.
r2000-analyze-basic
Analyzes a sequence of memory containing Commodore BASIC tokens, formats address/word data types, and constructs side comments representing the plain BASIC commands.
bump-version
Automates the process of bumping the version and updating the changelog.
code-review
Reviews code changes for bugs, style issues, and best practices. Use when reviewing PRs or checking code quality.
add-mcp-tool
Streamlines the process of adding new tools to the MCP server.
Didn't find tool you were looking for?