---
name: tape6502-cartridge
description: Write, test and publish games ("cartridges") for the Tape6502 console, a 6502 CPU built from 2,978 TapeOut NAND gates whose tournament scores are verified on X Layer. Use when asked to make a Tape6502 game, edit a .s cartridge, or prepare one for the Tape6502 store.
---

# Tape6502 cartridge development

A cartridge is a raw 6502 binary that loads and starts at `$0900`. It runs on the same NAND/LATCH netlist that is taped out on X Layer, so the score it writes can be checked on chain, cycle by cycle.

## Tools
- **MCP server (recommended):** the developer connects their wallet in the Studio (`/studio.html`) and gets a personal MCP link (`https://<site>/mcp/u/<key>`, Streamable HTTP, no other auth). Tools: `get_devkit`, `assemble`, `run_cartridge` (runs on the real gate-level chip, returns score, game-over flag and a screenshot), `publish_cartridge`.
- **No agent tools:** paste the source into the Studio (`/studio.html`) and press Run.

## Workflow
1. Start from the starter cartridge (`get_devkit` with `starter: true`, or the Studio's default source).
2. After every change, `run_cartridge` with a key script, and check the screenshot, the score and `game over`.
3. Test a full run: the score must rise from play, `$FA` must become non-zero at the end, and Space must start a new game.
4. `publish_cartridge` with a name, price and supply sends it to the developer's Studio. Nothing is on sale until they press Publish there and sign with their wallet. They get 85% of every sale. Without MCP, the developer pastes the source into the Studio and uses "Play in the arcade", then "Publish the inserted cartridge".

## Memory map (`console.inc`, built into the assembler)
| Address | Name | Use |
|---|---|---|
| `$0900` | | entry point; cartridge up to 62,720 bytes |
| `$0200-$05FF` | `SCREEN` | 32x32 framebuffer, one byte per pixel, colour 0-15 |
| `$0600-$061F` | `VMODE`... | display chip registers (below) |
| `$F0-$F3` | `SEED` | random seed, set by the console or the tournament contract |
| `$F8/$F9` | `SCORELO/HI` | score. This is what tournaments verify |
| `$FA` | `GAMEOVR` | non-zero ends a tournament run |
| `$FD` | `FRAME` | read-only frame counter, +1 every 4,096 cycles (about 36/s) |
| `$FE` | `PRESSES` | read-only count of key presses; compare with your last copy to detect a new press |
| `$FF` | `KEY` | last key: `w a s d` and space (player 1); `i j k l`, `o`, `p` (player 2) |

Palette: 0 black, 1 white, 2 red, 3 cyan, 4 purple, 5 green, 6 blue, 7 yellow, 8 orange, 9 brown, 10 pink, 11 dark grey, 12 grey, 13 light green, 14 light blue, 15 light grey.

The clock is fixed at 150 kHz, so a frame is about 4,096 cycles and a second is 150,000 cycles.

## Rules for verifiable scores
- A run is a pure function of (cartridge, seed, key presses by cycle). Read input only from `$F0-$F3` and `$FD-$FF`.
- Keep the score in `$F8/$F9` and only increase it through play.
- Set `$FA` when the game ends. Restart on Space and clear `$F8-$FA`.
- Don't use self-modifying timing tricks or undocumented opcodes: the netlist implements the documented NMOS 6502 instruction set (Klaus Dormann functional test passed).

## Display chip (browser only, never affects the score)
Write `VMODE` (`$0600`) to switch from the framebuffer to a 256x256 renderer that reads registers only:
- `0` framebuffer (default; best for new games)
- `1` fighter sprites: `VTEXT $0602` banner (0 none, 1 ROUND n, 2 FIGHT!, 3 K.O.), `VROUND $0603`, `VHP $0604/5` health 0-12, `VSPR $0608` 2 sprites x (pose, x, lift, timer)
- `2` board: 8 cells per row at `$0610`, with game, cursor, turn and status at `$0601-$060A`
- `3` platform: player, enemies and level state at `$0601-$0614`

The arcade, scores and tournaments all work in mode 0, so start there.

## Assembler
ca65-compatible subset: labels, `name = value`, `.byte`, `.word`, `.res`, `.segment "CODE"`, `.include "console.inc"`, `<` / `>` byte selectors, `+ - * /` in expressions, `$hex`, `%binary`, `'c'` characters. Errors come back as `file:line: message`.

## Minimal cartridge
```asm
.include "console.inc"
LAST = $10
.segment "CODE"
reset:  sei
        cld
        ldx #$FF
        txs
        lda #0
        sta SCORELO
        sta SCOREHI
        sta GAMEOVR
        lda PRESSES
        sta LAST
loop:   lda PRESSES         ; wait for a new key press
        cmp LAST
        beq loop
        sta LAST
        lda KEY
        cmp #'d'
        bne loop
        inc SCORELO         ; each D press scores 1 and lights one more pixel
        ldx SCORELO
        lda #7
        sta SCREEN,x
        cpx #32
        bne loop
        lda #1
        sta GAMEOVR         ; 32 points ends the run
done:   lda PRESSES
        cmp LAST
        beq done
        sta LAST
        lda KEY
        cmp #' '
        bne done
        jmp reset
```
