Skip to main content
Glama
simen

VICE C64 Emulator MCP Server

by simen

writeMemory

Modify Commodore 64 memory by writing bytes to specific addresses for debugging, patching code, or altering screen data in the VICE emulator.

Instructions

Write bytes to the C64's memory.

Directly modifies memory at the specified address. Changes take effect immediately.

Common uses:

  • Poke values for testing

  • Patch code at runtime

  • Modify screen/color RAM directly

  • Change VIC/SID registers

Be careful writing to ROM areas ($A000-$BFFF, $E000-$FFFF) - you may need to bank out ROM first.

Related tools: readMemory, fillMemory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesStart address (0x0000-0xFFFF)
bytesYesArray of bytes to write (0-255 each)

Implementation Reference

  • src/index.ts:292-337 (registration)
    MCP registration of 'writeMemory' tool, including input schema (address and bytes array), description, and thin wrapper handler that validates args and delegates to ViceClient.writeMemory, returning formatted success response.
    server.registerTool(
      "writeMemory",
      {
        description: `Write bytes to the C64's memory.
    
    Directly modifies memory at the specified address. Changes take effect immediately.
    
    Common uses:
    - Poke values for testing
    - Patch code at runtime
    - Modify screen/color RAM directly
    - Change VIC/SID registers
    
    Be careful writing to ROM areas ($A000-$BFFF, $E000-$FFFF) - you may need to bank out ROM first.
    
    Related tools: readMemory, fillMemory`,
        inputSchema: z.object({
          address: z
            .number()
            .min(0)
            .max(0xffff)
            .describe("Start address (0x0000-0xFFFF)"),
          bytes: z
            .array(z.number().min(0).max(255))
            .min(1)
            .describe("Array of bytes to write (0-255 each)"),
        }),
      },
      async (args) => {
        try {
          await client.writeMemory(args.address, args.bytes);
    
          return formatResponse({
            success: true,
            address: {
              value: args.address,
              hex: `$${args.address.toString(16).padStart(4, "0")}`,
            },
            bytesWritten: args.bytes.length,
            message: `Wrote ${args.bytes.length} byte(s) to $${args.address.toString(16).padStart(4, "0")}`,
          });
        } catch (error) {
          return formatError(error as ViceError);
        }
      }
    );
  • Core handler logic in ViceClient class: validates address and data length, ensures VICE is stopped, constructs MemorySet command packet per VICE binary monitor protocol, and sends it via sendCommand.
    async writeMemory(
      address: number,
      data: Buffer | number[],
      memspace: MemorySpace = MemorySpace.MainCPU
    ): Promise<void> {
      const dataBuffer = Buffer.isBuffer(data) ? data : Buffer.from(data);
    
      if (address < 0 || address > 0xffff) {
        throw this.makeError(
          "INVALID_ADDRESS",
          `Address 0x${address.toString(16)} is outside C64 memory range`,
          "C64 addresses are 16-bit (0x0000-0xFFFF)"
        );
      }
    
      if (dataBuffer.length === 0) {
        throw this.makeError(
          "INVALID_DATA",
          "Cannot write empty data",
          "Provide at least one byte to write"
        );
      }
    
      if (address + dataBuffer.length > 0x10000) {
        throw this.makeError(
          "INVALID_RANGE",
          `Write would extend past end of memory (0x${address.toString(16)} + ${dataBuffer.length} bytes)`,
          "Reduce data length or use a lower start address"
        );
      }
    
      // Ensure VICE is stopped before memory write
      await this.ensureStopped();
    
      // Build request per official VICE docs:
      // side_effects(1) + start(2) + end(2) + memspace(1) + bankId(2) + data(N) = 8 byte header + data
      const endAddress = address + dataBuffer.length - 1;
      const body = Buffer.alloc(8 + dataBuffer.length);
      body[0] = 0; // No side effects
      body.writeUInt16LE(address, 1);
      body.writeUInt16LE(endAddress, 3);
      body[5] = memspace;
      body.writeUInt16LE(0, 6); // bankId = 0 (default bank)
      dataBuffer.copy(body, 8);
    
      await this.sendCommand(Command.MemorySet, body);
    }
  • Zod input schema defining parameters: address (0-65535), bytes (non-empty array of 0-255 integers).
    inputSchema: z.object({
      address: z
        .number()
        .min(0)
        .max(0xffff)
        .describe("Start address (0x0000-0xFFFF)"),
      bytes: z
        .array(z.number().min(0).max(255))
        .min(1)
        .describe("Array of bytes to write (0-255 each)"),
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: it directly modifies memory, changes take effect immediately, and warns about ROM areas requiring banking out. It covers mutation nature and immediate effects, though it could add more on error handling or permissions.

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 appropriately sized and front-loaded, starting with the core purpose, followed by behavioral details, common uses, warnings, and related tools. Every sentence adds value without redundancy, making it efficient and well-structured.

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?

Given the tool's complexity (direct memory modification) and no annotations or output schema, the description is largely complete: it explains purpose, behavior, uses, warnings, and related tools. It could improve by detailing return values or error cases, but it covers most essential context for safe use.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents parameters (address and bytes) with ranges and descriptions. The description adds no additional parameter semantics beyond what the schema provides, such as format details or usage examples, meeting the baseline for high coverage.

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 with a specific verb ('Write bytes') and resource ('C64's memory'), and distinguishes it from sibling tools like readMemory and fillMemory. It goes beyond the name by specifying the direct modification of memory at a specified address.

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

Usage Guidelines4/5

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

The description provides clear context for when to use the tool through 'Common uses' (e.g., poke values, patch code, modify RAM, change registers) and mentions a related tool (readMemory) for comparison. However, it lacks explicit guidance on when NOT to use it or alternatives for specific scenarios beyond ROM warnings.

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