Skip to main content
Glama
simen

VICE C64 Emulator MCP Server

by simen

getRegisters

Retrieve the current CPU register state to monitor program execution, debug crashes, and understand program flow in Commodore 64 emulation.

Instructions

Get current 6502/6510 CPU register state.

Returns all CPU registers with interpreted flags.

Registers:

  • A: Accumulator (arithmetic operations)

  • X, Y: Index registers (addressing, loops)

  • SP: Stack pointer ($100-$1FF range)

  • PC: Program counter (current instruction address)

  • Flags: N(egative), V(overflow), B(reak), D(ecimal), I(nterrupt), Z(ero), C(arry)

Use this to:

  • Check CPU state at breakpoints

  • Understand program flow

  • Debug crashes (check PC, SP)

Related tools: setRegister, step, continue, status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'getRegisters'. Fetches raw register data from ViceClient.getRegisters(), parses the response into named registers (A, X, Y, PC, SP, flags), decodes flag bits, formats hex values and provides stack overflow warnings.
      async () => {
        try {
          const response = await client.getRegisters();
    
          // Parse register response
          // Format: count(2) + [id(1) + size(1) + value(size)]...
          const count = response.body.readUInt16LE(0);
          const registers: Record<string, number> = {};
          let offset = 2;
    
          const regNames: Record<number, string> = {
            0: "A",
            1: "X",
            2: "Y",
            3: "PC",
            4: "SP",
            5: "FL", // Flags
          };
    
          for (let i = 0; i < count && offset < response.body.length; i++) {
            const id = response.body[offset];
            const size = response.body[offset + 1];
            offset += 2;
    
            let value = 0;
            if (size === 1) {
              value = response.body[offset];
            } else if (size === 2) {
              value = response.body.readUInt16LE(offset);
            }
            offset += size;
    
            const name = regNames[id] || `R${id}`;
            registers[name] = value;
          }
    
          // Parse flags
          const flags = registers.FL || 0;
          const flagsDecoded = {
            negative: !!(flags & 0x80),
            overflow: !!(flags & 0x40),
            break: !!(flags & 0x10),
            decimal: !!(flags & 0x08),
            interrupt: !!(flags & 0x04),
            zero: !!(flags & 0x02),
            carry: !!(flags & 0x01),
            raw: flags,
            // Compact string representation: NV-BDIZC (uppercase = set)
            string: [
              flags & 0x80 ? "N" : "n",
              flags & 0x40 ? "V" : "v",
              "-",
              flags & 0x10 ? "B" : "b",
              flags & 0x08 ? "D" : "d",
              flags & 0x04 ? "I" : "i",
              flags & 0x02 ? "Z" : "z",
              flags & 0x01 ? "C" : "c",
            ].join(""),
          };
    
          return formatResponse({
            a: { value: registers.A, hex: `$${(registers.A || 0).toString(16).padStart(2, "0")}` },
            x: { value: registers.X, hex: `$${(registers.X || 0).toString(16).padStart(2, "0")}` },
            y: { value: registers.Y, hex: `$${(registers.Y || 0).toString(16).padStart(2, "0")}` },
            sp: {
              value: registers.SP,
              hex: `$${(registers.SP || 0).toString(16).padStart(2, "0")}`,
              stackTop: `$01${(registers.SP || 0).toString(16).padStart(2, "0")}`,
            },
            pc: {
              value: registers.PC,
              hex: `$${(registers.PC || 0).toString(16).padStart(4, "0")}`,
            },
            flags: flagsDecoded,
            hint:
              registers.SP !== undefined && registers.SP < 0x10
                ? "Warning: Stack pointer very low - possible stack overflow"
                : registers.SP !== undefined && registers.SP > 0xf0
                ? "Warning: Stack nearly empty - possible stack underflow"
                : "CPU state looks normal",
          });
        } catch (error) {
          return formatError(error as ViceError);
        }
      }
    );
  • src/index.ts:341-446 (registration)
    Registers the 'getRegisters' tool with the MCP server, providing a detailed description but no input schema (no parameters required).
      "getRegisters",
      {
        description: `Get current 6502/6510 CPU register state.
    
    Returns all CPU registers with interpreted flags.
    
    Registers:
    - A: Accumulator (arithmetic operations)
    - X, Y: Index registers (addressing, loops)
    - SP: Stack pointer ($100-$1FF range)
    - PC: Program counter (current instruction address)
    - Flags: N(egative), V(overflow), B(reak), D(ecimal), I(nterrupt), Z(ero), C(arry)
    
    Use this to:
    - Check CPU state at breakpoints
    - Understand program flow
    - Debug crashes (check PC, SP)
    
    Related tools: setRegister, step, continue, status`,
      },
      async () => {
        try {
          const response = await client.getRegisters();
    
          // Parse register response
          // Format: count(2) + [id(1) + size(1) + value(size)]...
          const count = response.body.readUInt16LE(0);
          const registers: Record<string, number> = {};
          let offset = 2;
    
          const regNames: Record<number, string> = {
            0: "A",
            1: "X",
            2: "Y",
            3: "PC",
            4: "SP",
            5: "FL", // Flags
          };
    
          for (let i = 0; i < count && offset < response.body.length; i++) {
            const id = response.body[offset];
            const size = response.body[offset + 1];
            offset += 2;
    
            let value = 0;
            if (size === 1) {
              value = response.body[offset];
            } else if (size === 2) {
              value = response.body.readUInt16LE(offset);
            }
            offset += size;
    
            const name = regNames[id] || `R${id}`;
            registers[name] = value;
          }
    
          // Parse flags
          const flags = registers.FL || 0;
          const flagsDecoded = {
            negative: !!(flags & 0x80),
            overflow: !!(flags & 0x40),
            break: !!(flags & 0x10),
            decimal: !!(flags & 0x08),
            interrupt: !!(flags & 0x04),
            zero: !!(flags & 0x02),
            carry: !!(flags & 0x01),
            raw: flags,
            // Compact string representation: NV-BDIZC (uppercase = set)
            string: [
              flags & 0x80 ? "N" : "n",
              flags & 0x40 ? "V" : "v",
              "-",
              flags & 0x10 ? "B" : "b",
              flags & 0x08 ? "D" : "d",
              flags & 0x04 ? "I" : "i",
              flags & 0x02 ? "Z" : "z",
              flags & 0x01 ? "C" : "c",
            ].join(""),
          };
    
          return formatResponse({
            a: { value: registers.A, hex: `$${(registers.A || 0).toString(16).padStart(2, "0")}` },
            x: { value: registers.X, hex: `$${(registers.X || 0).toString(16).padStart(2, "0")}` },
            y: { value: registers.Y, hex: `$${(registers.Y || 0).toString(16).padStart(2, "0")}` },
            sp: {
              value: registers.SP,
              hex: `$${(registers.SP || 0).toString(16).padStart(2, "0")}`,
              stackTop: `$01${(registers.SP || 0).toString(16).padStart(2, "0")}`,
            },
            pc: {
              value: registers.PC,
              hex: `$${(registers.PC || 0).toString(16).padStart(4, "0")}`,
            },
            flags: flagsDecoded,
            hint:
              registers.SP !== undefined && registers.SP < 0x10
                ? "Warning: Stack pointer very low - possible stack overflow"
                : registers.SP !== undefined && registers.SP > 0xf0
                ? "Warning: Stack nearly empty - possible stack underflow"
                : "CPU state looks normal",
          });
        } catch (error) {
          return formatError(error as ViceError);
        }
      }
    );
  • Low-level ViceClient helper method that sends the VICE binary monitor 'RegistersGet' command (memspace parameter defaults to MainCPU) and returns the raw ViceResponse containing register data.
    async getRegisters(memspace: MemorySpace = MemorySpace.MainCPU): Promise<ViceResponse> {
      const body = Buffer.alloc(1);
      body[0] = memspace;
      // VICE sends RegisterInfo (0x31) as async event with ReqID=0xff
      return this.sendCommand(Command.RegistersGet, body, ResponseType.RegisterInfo);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden of behavioral disclosure. It clearly explains what the tool returns ('all CPU registers with interpreted flags'), provides detailed register explanations, and mentions debugging use cases. However, it doesn't specify if this is a read-only operation (though implied by 'Get'), potential performance impact, or error conditions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and efficiently organized: purpose statement first, then detailed register explanations, followed by usage guidelines, and finally related tools. Every sentence adds value - no redundant or unnecessary information. The bulleted lists make the information easily scannable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 0-parameter tool with no output schema, the description provides excellent context about what information is returned (detailed register explanations) and when to use it. It could be slightly more complete by explicitly stating this is a read-only operation and mentioning any limitations (e.g., only works when emulator is paused), but overall it's very comprehensive for this tool type.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the baseline is 4. The description appropriately doesn't discuss parameters since none exist, and instead focuses on explaining the return value structure (register details) which is valuable context for the agent.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get current 6502/6510 CPU register state' with specific verb ('Get') and resource ('CPU register state'). It distinguishes from siblings like 'readMemory' or 'status' by focusing specifically on CPU registers rather than memory or general emulator status.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly provides usage guidance with 'Use this to:' section listing three specific scenarios: checking CPU state at breakpoints, understanding program flow, and debugging crashes. It also mentions related tools (setRegister, step, continue, status) to help the agent understand alternatives and complementary operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/simen/vice-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server