with one click
r2000-analyze-routine
// Analyzes a disassembly subroutine to determine its function by examining code, cross-references, and memory usage, leveraging target system expertise.
// Analyzes a disassembly subroutine to determine its function by examining code, cross-references, and memory usage, leveraging target system expertise.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | r2000-analyze-routine |
| description | Analyzes a disassembly subroutine to determine its function by examining code, cross-references, and memory usage, leveraging target system expertise. |
Use this skill when the user asks to "analyze this routine" or "what does this function do?"
r2000_get_binary_info to get the system, filename, description, and may_contain_undocumented_opcodes hint.system field tells you the target computer (e.g., Commodore 64, VIC-20). You MUST become an expert in that specific target computer's memory map, hardware registers, and KERNAL routines.filename and description tell you the specific software being analyzed. Use this to identify standard libraries (e.g., "Hubbard music driver", "Exomizer decompressor") and to understand the likely purpose of routines based on the game's genre (e.g., "check_collision" in a shooter).may_contain_undocumented_opcodes is true, expect illegal/undocumented MOS 6502 opcodes (e.g., LAX, SAX, SLO, DCP, ISC) within routines. These are valid instructions — do not treat them as disassembly errors.r2000_get_disassembly_cursor first — the routine starts at the cursor address.RTS, JMP, or RTI) of the routine.JMP to a shared epilogue — that still marks the end of this routine's body. Others fall through into the next routine with no explicit return; use cross-references and logic flow to determine the boundary.r2000_read_region (with "view": "disasm") to get the instructions.SEI / CLI bracketing → IRQ setup/teardown.LDA/STA and DEX/DEY/BNE → Memory copy or fill.ADC/SBC chains → Math or decompressor.r2000_get_binary_info) to recognize system-specific patterns:
r2000_get_cross_references on the entry point to see who calls it.LDA $C000, STA $02):
system value from r2000_get_binary_info.r2000_get_cross_references on that address to understand:
$00–$FF) and used with ($addr),Y? → indirect pointer.Combine findings into a summary:
See Step 7 for the exact comment block format to use when documenting your findings.
Add a multi-line comment block on top of the routine, rename the label to a descriptive one, and add side-comments to key instructions to explain the logic flow.
The multi-line comment block must be placed above the first instruction of the routine using r2000_set_comment with "type": "line". It should follow this exact format — the separator line must be used as both the first and last line of the comment:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
<Summary of what the routine does>
Inputs: <registers or memory locations used as arguments, or "None">
Outputs: <registers or memory locations modified, or "None">
Side Effects: <hardware changes, screen updates, etc., or "None">
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
To document the routine, use:
r2000_set_label_name — to give the routine a descriptive name.r2000_set_comment with "type": "line" — to add the multi-line comment block above the entry point.r2000_set_comment with "type": "side" — to annotate key instructions within the routine body with short inline notes (e.g., explaining what a register holds, why a branch is taken, or what a memory address represents). Crucial for making the code readable for others.RTS/JMP/RTI at the apparent end, the routine may intentionally fall through. Check if the next label is also a valid entry point called independently.JMP sub_routine at the end is a tail call — the routine ends there. Do not include the target routine's body in this routine's analysis.RTS. The epilogue belongs to none of them specifically; note this in the comment.LAX, SAX, SLO, etc.). Check the may_contain_undocumented_opcodes hint from r2000_get_binary_info. If true, these are expected — don't stop disassembly at them. Even if false, remain aware of their existence.JSR routines, those routines may share Zero Page with the main program — context is IRQ-relative.After completing the analysis, report to the user: