All docs

Compiler & Build Targets

The vpy_cli compiler: its four targets and what each produces, the C backend, debug info, errors with file and line, multibank ROMs, assets and the project file.

Vectrex Studio has one compiler, vpy_cli. It is a modular 9-phase Rust pipeline (the buildtools/ workspace) that the IDE bundles and runs on every build. It compiles VPy to a Vectrex cartridge ROM or to native ARM code for three ARM targets. The editor's language server, vpy_lsp, is built from the same workspace on the compiler's own parser, so the squiggles in the editor match the build errors.

The old single-pass compiler (Core) and the IDE's compiler selector are gone. Every build goes through vpy_cli.


Build Targets

TargetHardwareProducesStatus
m6809Any Vectrex, from a cartridge ROM.bin ROM (single-bank 32 KB, or multibank) and a .pdb✅ Production
pitrexPiTrex (Raspberry Pi expansion board).img (ARM32)Ran on hardware with the v0.3 SDK; not yet tested with the v0.4 SDK
rp2350The RP2350 debug cartridgeAn ELF, and an SD card RAM image (build/<name>_sd.bin) for the cartridge's launcher✅ Runs on a real console
uvm2The UVMC2 (Ultimate Vectrex Multicart 2)A .um2 image for the SD card, and its ELF✅ Runs on a real console

Pick the target in the IDE's Settings panel (it takes effect on the next build), or with --target on the command line.

m6809: the Vectrex cartridge

The standard target. It produces a .bin ROM image for a real Vectrex or the IDE's JSVecX emulator, plus the .pdb debug symbols that source-level debugging uses. It supports single-bank (32 KB) and multibank (64 KB–4 MB) ROMs, described below.

pitrex: ARM32

Produces ARM32 code linked against the PiTrex SDK into a .img. PiTrex is a Raspberry Pi expansion board for the Vectrex that drives the beam at ARM speeds, so far more geometry fits in a frame. The IDE emulator has a PiTrex renderer and PSG audio, and you can configure overlay images (PNG) per project to appear behind the vectors. pitrex has its own backend, so a few builtins differ there. For example, for v in arr is not implemented on pitrex: loop over range(0, len(arr)) instead.

rp2350: the debug cartridge

Compiles to ARM Thumb-2 for the RP2350 debug cartridge. Builtins become svc calls into the cartridge BIOS, which the IDE's RP2350 emulator answers the same way. The cartridge's second core plays the audio, so the tempo does not depend on how much you draw. Build for SD (--ram on the command line) links the game into RAM so the cartridge's SD launcher can load it; the IDE copies it to the card. Debug → Debug on Cartridge runs it on the cartridge over SWD with the IDE's debugger.

With [rp2350] backend = "c" the program is built through C instead (see below). That brings the 3D, effects and jukebox builtins to rp2350, and the result is always the SD card RAM image.

uvm2: the UVMC2 multicart

Compiles to ARM Thumb-2 for the UVMC2 and links it through the pico-sdk into a .um2, the image the multicart's menu loads from its SD card. The game halts the console's 6809 and drives the VIA itself. It runs from the cartridge's SRAM, code included, with both cores, PIO and DMA (always on for this target). It runs in the IDE's UVM2 emulator. Build → Upload to Cartridge puts it on the multicart over USB and starts it, and Debug → Debug on Cartridge debugs it there. See Cartridges.

The 3D builtins (meshes, scenes, skeletons, effects) and the jukebox are uvm2 features. On m6809 and pitrex they are a compile error. See VPy 3D.

Which targets need the SDK

The ARM targets build against the uvmc2-sdk release the project pins in its [sdk] table. The IDE downloads that release on the first build that needs it.

BuildSDK
m6809Not needed
pitrexOptional (vpy-c/, the libvpy C runtime)
rp2350 with the C backendRequired (vpy-c/, rp2350-sdk/)
uvm2Required (uvm2-sdk/), plus the pico-sdk and the Arm GNU Toolchain 15.2, which the IDE also downloads

Details, and how command-line builds find an installed SDK: Projects and the SDK.


The C backend (uvm2, rp2350)

For uvm2 and rp2350 there are two code generators. The default writes ARM assembly. The C backend writes the whole program as C and compiles it with gcc against libvpy, the SDK runtime C games use:

[uvm2]
backend = "c"
sdk_opt = "O2"                # optional: the SDK's C libraries at -O2, -Os or -O1
defs = "UVM2_DRAW_SCALE=127"  # optional: defines for the SDK, separated by ;
 
[rp2350]
backend = "c"                 # if absent, [uvm2] backend is used
  • Smaller code. On a large game we measured 224 KB of code with the C backend against 323 KB with the ARM backend. On uvm2 everything runs from SRAM, so that space goes to levels and assets.
  • Same 2D drawing as C games. The 2D builtins are libvpy's own, so text and vectors draw exactly as in a C game. The 3D, effects and jukebox builtins go to the same C layer as from the ARM backend.
  • Same semantics as the ARM backend: 32-bit wrapping integers, truncating /, typed arrays.
  • Not complete yet. Builtins libvpy has no counterpart for in this backend (levels, enemies, animations, samples) are a compile error for now.
  • Optimised code. gcc inlines and reorders. In the debugger a line may be skipped, and some locals show as optimised out here.

How VPy and C line up call by call: VPy and C.


Debug info in every build

TargetDebug infoUsed by
m6809.pdb: line map per file, functions, variablesBreakpoints, stepping, call stack, hover and Change Value in JSVecX
rp2350, uvm2 (ARM backend)A .loc line entry per statement and unwind (CFI) data, in the ELF's debug sectionsThe IDE's ARM debugger, arm-none-eabi-gdb, the call stack
rp2350, uvm2 (C backend)#line directives, so gcc's own debug info points at your .vpy linesThe same, plus C types for globals and locals

The debug sections are not part of the image: the binary that runs is the same with or without them. The IDE always builds with debug info. Line information carries the real file, so main.vpy:10 and util.vpy:10 are different places. See Debugging.


Errors with file and line

Many mistakes that used to build into something broken are now compile errors. In a multi-file project the error names the file:

src/space.vpy:18: error: …

Among them:

  • a DRAW_VECTOR of a .vec that does not exist (every target)
  • a function named like an imported module
  • a parameter spelled like a global or module const in another case (names are case-insensitive)
  • a const and a variable with the same name
  • a loop variable that is an array or a constant
  • an import, module or member that cannot be resolved
  • reading a name that is not a parameter, a local or a module-level name, and calling a function with the wrong number of arguments
  • on m6809: recursion, a const that cannot be folded or does not fit in 16 bits, and a builtin that needs constant arguments given a variable

Click an entry in the Errors panel to jump to it.


Compiler Pipeline

One crate per phase:

PhaseCrateResponsibility
1vpy_loaderLoad the .vpyproj project file (TOML)
2vpy_parserParse VPy source to an AST
3vpy_unifierMerge the modules, resolve imports; lower structs, enums and N-D arrays
4vpy_bank_allocatorAssign functions and data to ROM banks
5vpy_codegenAST → assembly or C, per target (with tree shaking)
6vpy_assemblerMC6809 assembly → machine code (two-pass)
7vpy_linkerSymbol resolution, inter-bank references
8vpy_binary_writerEmit the final .bin ROM image
9vpy_debug_genGenerate the .pdb debug symbols

Phase 5 has a backend per target (m6809/, pitrex/, arm/ for rp2350, uvm2/) plus the C generator. Phases 1–4 are shared by every target. The ARM targets are assembled and linked by the Arm GNU toolchain instead of phases 6–8 (uvm2 through the pico-sdk's CMake).


Multibank ROMs (m6809)

⚠️ Not a Vectrex standard feature. The Vectrex has no native bank-switching protocol. Stock cartridges are limited to 32 KB, and a stock console will not run a multibank ROM. The scheme below is a custom cartridge design specific to Vectrex Studio. The IDE emulator implements it, so you can develop multibank games without hardware. To run one on a real Vectrex you need a cartridge that implements it.

VPy supports ROMs from 32 KB up to 4 MB with no changes to game code. Add two META directives:

META ROM_TOTAL_SIZE = 65536    # pick your target size (see table)
META ROM_BANK_SIZE  = 16384    # always 16 KB per bank

The compiler divides the ROM into 16 KB banks, assigns functions and assets by call-graph analysis, and generates every bank-switching wrapper.

The bank-switching mechanism

Address rangeContentsSwitching
$0000–$3FFFBanked window: one of N selectable 16 KB ROM banksChanges on demand
$4000–$7FFFHelpers bank: the last 16 KB of the ROMFixed, always visible

The bank at $0000–$3FFF is selected by writing its number to $DF00:

LDA   #2          ; bank number 0..N-2
STA   $DF00       ; the cartridge's decoder latches A
                  ; → bank 2 is now mapped at $0000-$3FFF

$DF00 sits in the Vectrex I/O hole. The BIOS, RAM and VIA do not respond there, so the write is harmless on stock hardware and unambiguous on the custom cartridge. The decoder is typically a 74HC373 latch plus a single decoder chip.

The compiler puts cross-bank call wrappers in the helpers bank, where they are always visible. A wrapper saves the current bank, switches, calls, and restores the bank before returning. Builtins that touch banked assets (DRAW_VECTOR, SHOW_LEVEL, UPDATE_LEVEL, PLAY_SFX) do this automatically.

Supported sizes

ROM_TOTAL_SIZEBanksCapacitySuggested chip
32768232 KB27C256 (single-bank, no switching)
65536464 KB27C512 ✅ fully tested
1310728128 KB27C010
26214416256 KB27C020
52428832512 KB27C040 / 29F040 Flash
1048576641 MB27C080 / 29F080
20971521282 MBM27C160
41943042564 MB29F320 Flash

The 4-bank (64 KB) configuration is fully tested. Larger configurations compile, but cross-bank symbol resolution is still being completed.

The minimum custom cartridge is an EPROM plus a latch and a decoder, under $10 in parts. See EPROM Programmer for burning the chip.


Assets

VPy projects use JSON assets under assets/, each made in its own IDE editor. The compiler finds them by folder, and code names them with a string literal holding the file name, case-sensitive. Only the assets your code names are embedded. The exceptions are the sprites a level or animation references and the .venemy files, which are pulled in automatically.

TypeFolderEditorUsed from VPy
.vecassets/vectors/Vector EditorDRAW_VECTOR("n", x, y), DRAW_VECTOR_EX, DRAW_VECTOR_ROT, DRAW_VECTOR_3D
.vanimassets/animations/Animation EditorDRAW_ANIM("n", x, y, mirror)
.vplayassets/playground/PlaygroundLOAD_LEVEL("n"), SHOW_LEVEL(), UPDATE_LEVEL()
.venemyassets/enemies/Enemy EditorPlaced by a level; SPAWN_ENEMIES("level")
.vmusassets/music/Music EditorPLAY_MUSIC("n")
.vsfxassets/sfx/SFX EditorPLAY_SFX("n")
.vinstrassets/instruments/Instrument EditorPLAY_NOTE("n", channel, note)
.vrecassets/recordings/Recording viewerDRAW_RECORDING("n", x, y, scale, frame)
.vsmpassets/samples/Sample playerPLAY_SAMPLE("n") (rp2350, pitrex)
.vmesh, .vscene, .vskel, .vclipassets/meshes/, scenes/, skeletons/, clips/3D editorsuvm2 (and rp2350 with the C backend); see VPy 3D

A build only warns about an asset that fails to load, and then stops on an undefined symbol. vpy_cli check-asset <file> loads and compiles one asset with the backends' own code and prints the real error. The same assets build for C projects as headers: see VPy and C.

.vec: vector graphics

Paths of points relative to the sprite's centre, each with an intensity and a closed/open flag:

{"version":"1.0","name":"ship","canvas":{"width":256,"height":256,"origin":"center"},
 "layers":[{"name":"default","visible":true,"paths":[
   {"name":"hull","intensity":127,"closed":true,
    "points":[{"x":0,"y":12},{"x":-10,"y":-8},{"x":10,"y":-8}]}]}]}

A point can carry z (for DRAW_VECTOR_3D) and its own intensity (the segment to that point). walkableAreas and collisionMesh make a sprite a platform in levels. Every point is a beam move, so keep point counts low.

.vanim: animations

{"version":"1.0","name":"walk","loop":true,"base_refs":[],
 "frames":[{"index":0,"duration_ticks":8,"vec_refs":["walk_1"],"paths":[]},
           {"index":1,"duration_ticks":8,"vec_refs":["walk_2"],"paths":[]}]}

vec_refs and base_refs name .vec files. base_refs are drawn on every frame. duration_ticks is in 50 Hz frames. A frame may also hold inline paths (VPy only). DRAW_ANIM advances the animation itself, so call it every frame.

.vplay: levels

Levels are authored in the Playground. Each object in a layer has an id, a type, a position, scale and rotation, and names a .vec (vectorName) or a .venemy (enemyType):

{"version":"2.0","type":"level","metadata":{"name":"level1"},
 "worldBounds":{"xMin":-128,"xMax":127,"yMin":-128,"yMax":127},
 "layers":{"background":[],"foreground":[],"gameplay":[
   {"id":"p1","type":"background","vectorName":"platform","layer":"gameplay",
    "x":0,"y":-60,"scale":1,"rotation":0,"collidable":true},
   {"id":"e1","type":"enemy","vectorName":"crawler","enemyType":"crawler","aiType":"patrol",
    "layer":"gameplay","x":40,"y":-40,"scale":1,"rotation":0}]}}

An enemy's aiType is static, patrol, chase, flee or wander, with patrolWaypoints or walkable_areas as needed.

.venemy: enemy types

{"version":"1.0","name":"crawler",
 "actions":[{"name":"walk","sprite":"assets/vectors/crawler.vec","loop":true}],
 "stats":{"hp":1,"speed":1,"action_duration":180},
 "behavior":{"type":"patrol","patrol":{"waypoints":[],"loop":true,"mirrorOnPatrol":true,
                                       "defaultFacing":"right","patrolAction":""}}}

sprite is a path from the project root to a .vec or .vanim. An optional state_machine, edited in the Enemy Editor, handles the events ENEMY_FIRE_EVENT(i, "name") fires. The compiler turns enemy types into constant tables at build time. There is no runtime interpreter.


Level System

Camera and scrolling

camera_x: i16 = 0
 
def loop():
    camera_x = clamp(camera_x + J1_X() / 16, GET_SCROLL_LIMIT_LEFT(), GET_SCROLL_LIMIT_RIGHT())
    SET_CAMERA_X(camera_x)
    SHOW_LEVEL()

Object positions in a .vplay are world coordinates. SHOW_LEVEL() subtracts the camera offset before drawing and culls objects outside the view. LOAD_LEVEL() resets the camera to 0.

Enemies

def main():
    LOAD_LEVEL("level1")
    SPAWN_ENEMIES("level1")     # the enemies that level places
 
def loop():
    SHOW_LEVEL()
    UPDATE_ENEMIES()            # behaviour and state machines
    DRAW_ENEMIES()

The runtime walks the enemy tables each frame, with no dynamic allocation. Read and change spawned enemies with GET_ENEMY_X(i), GET_ENEMY_ACTIVE(i), SET_ENEMY_X(i, x), KILL_ENEMY(i) and the rest in the language reference.

Wander AI and walkable areas

wander enemies navigate by walkable areas. Define them on a platform .vec (every level that uses it inherits them) or per object in the .vplay. Transitions between areas can be explicit or derived by the compiler from how close the platforms are. All of this is authored in the Playground.


Project File (.vpyproj)

This is what File → New → Project (language VPy) writes:

[project]
name    = "mygame"
version = "0.1.0"
entry   = "src/main.vpy"
 
[build]
output        = "build/mygame.bin"
optimization  = 2
debug_symbols = true
 
[sources]
vpy = ["src/**/*.vpy"]
 
[resources]
vectors     = ["assets/vectors/*.vec"]
music       = ["assets/music/*.vmus"]
sfx         = ["assets/sfx/*.vsfx"]
animations  = ["assets/animations/*.vanim"]
levels      = ["assets/playground/*.vplay"]
enemies     = ["assets/enemies/*.venemy"]
instruments = ["assets/instruments/*.vinstr"]
recordings  = ["assets/recordings/*.vrec"]
samples     = ["assets/samples/*.vsmp"]
meshes      = ["assets/meshes/*.vmesh"]
scenes      = ["assets/scenes/*.vscene"]
skeletons   = ["assets/skeletons/*.vskel"]
clips       = ["assets/clips/*.vclip"]
 
[sdk]
version = "v1.4.4"
FieldRequiredDescription
project.entryYesThe main .vpy file
build.outputYesThe output path
build.optimizationNo0–2, default 2
build.debug_symbolsNo.pdb generation (the IDE always builds with debug info)
[resources]NoDocuments the asset folders; the compiler finds assets by folder
sdk.versionNoThe uvmc2-sdk release for the ARM targets. A project without one is pinned to the latest the first time a build needs the SDK
[uvm2] / [rp2350]Nobackend = "c", sdk_opt, defs (see the C backend section above)

Building from the Command Line

# Build a project for a target (m6809 is the default)
vpy_cli build path/to/game.vpyproj --target uvm2
 
# rp2350 linked for the SD launcher; --debug also writes the .pdb on m6809
vpy_cli build path/to/game.vpyproj --target rp2350 --ram
 
# The generated assembly only
vpy_cli asm path/to/game.vpyproj -o game.asm
 
# Check one asset, or compile it to a C header
vpy_cli check-asset assets/vectors/ship.vec
vpy_cli compile-asset assets/vectors/ship.vec --format c --out gen/ship.h

vpy_cli never downloads anything. For uvm2 it uses the SDK and pico-sdk the IDE installed, found through the project's [sdk] pin, or UVMC2_SDK pointing at any SDK checkout. Build a project through its .vpyproj for the ARM targets: a bare .vpy is not enough there.

From a checkout of the repository, cargo build --bin vpy_cli builds the compiler and cargo test --all (in buildtools/) runs its tests.