Chris Collins

Tools · retro

Commodore VIC-20 and PET: emulator, assembler and debugger

A Commodore VIC-20 (PAL or NTSC, with memory expansions and cartridges) or PET 2001 / 3032 / 4032 / 8032 on one page — the VIC chip's video and sound, the 6522 VIAs and 6520 PIAs, the keyboards, PRG, D64 and TAP files. Boots Microsoft's open-source BASIC 1.1 on a KERNAL written for this site, or your own ROMs. Write 6502 assembly and debug it with breakpoints beside the code.

Added · updated 27 October 2026

How to use it

Both machines on one page, to switch between them. Each also has a page of its own with the details: Commodore VIC-20 and Commodore PET — the same emulator, so everything below works the same there.

Press Power on, or press Assemble & run in the Assembly tab — the machine starts by itself. Pick the VIC-20 or the PET on the Run tab. Click the screen to give it the keyboard.

How to use it

  • BASIC: type on the screen (10 PRINT CHR$(205.5+RND(1));:GOTO 10, RUN), or use Type into the computer and its BASIC examples…. LOAD"$",8, LOAD"NAME",8 and SAVE"NAME",8 use the disk in the Disk drive and Datassette panel; LOAD / SAVE"NAME" the tape.

  • Assembly: pick an example — hello world with CHROUT, border colours, screen and colour memory, the VIC’s three voices and noise, reading keys with GETIN, hooking the 60 Hz interrupt through CINV, a custom character set, multicolour, the joystick and a KERNAL SAVE on the VIC-20; on the PET hello world, screen memory at $8000, CB2 sound, the keyboard and the lower-case set — or write your own, then Assemble & run (Ctrl+Enter). The machine is reset, the page waits for READY., loads the code and runs it with SYS; RTS returns. Download .PRG saves it with its load address, Save to disk puts it on the virtual disk.

  • Run: choose the machine. The VIC-20 can be PAL (6561) or NTSC (6560) and take 3 to 35 KB of expansion — with 8 KB or more in block 1 the screen moves to $1000 and BASIC to $1201, as on the real machine. The PET is a 2001 (8 KB), 3032, 4032 (32 KB) or the 80-column 8032, with the graphics or business keyboard, green, white or amber. Drop a .PRG, .D64, .TAP or .T64 to load it, or a VIC-20 cartridge (.CRT from VICE, a PRG with load address $A000/$2000/$4000/$6000, or a raw 4/8 KB .A0/.BIN image): it starts at reset, as the KERNAL finds the A0CBM signature at $A004.

  • The monitor (Monitor only, or SYS 65280 from BASIC; prompt .) understands 1000 (show a byte), 1000.103F (dump), 1000: A9 41 20 D2 FF 60 (store), 1000G (run) and X (back to BASIC). On a phone, ⌨ Keys opens an on-screen keyboard.

Debugging

As on the C64 page: click a line number beside the code for a breakpoint, F9 toggles the cursor line, right-click for Run to here; F5 continue, F6 pause, F11 step, F10 step over, Shift+F11 step out, Ctrl+F10 run to the cursor. Registers, flags, the stack, disassembly (with the KERNAL jump-table names and the chip registers: CHROUT, VIA2_T1CL, VIC_COLOUR …), memory and watches sit beside the editor; the Debugger tab adds the breakpoint list and three chip views:

  • Video and sound — VIC-20: where the screen, characters and colour RAM are, the size and origin, the raster line, border, background and auxiliary colours, and each voice’s frequency in Hz. PET: the character set, the CRTC registers and the CB2 tone.

  • VIAs and PIAs — ports and data directions, both timers and their latches, ACR/PCR (with the shift register’s sound mode), and which interrupt flags are set and enabled; the keys held.

  • Memory map — what is in each block: RAM, expansion, cartridge, ROM or the stub.

Firmware

Commodore’s KERNAL, BASIC, editor and character ROMs are still under copyright and aren’t freely redistributable, so none are shipped. By default the machines boot Microsoft BASIC 1.1 for the 6502 — released under the MIT licence in 2025 (source) and the ancestor of Commodore BASIC, built by this site’s script in its PET configuration — on a stub KERNAL written for this site (source on the References tab, MIT): the jump table’s CHROUT $FFD2, GETIN $FFE4, CHRIN $FFCF, PLOT $FFF0, SCNKEY $FF9F, SETLFS, SETNAM, MEMTOP, MEMBOT …; a screen editor; the keyboard scan on the 60 Hz interrupt into the real KERNAL’s buffer ($0277/$C6 on the VIC-20, $026F/$9E on the PET); the RAM vectors CINV, CBINV and NMINV; RUN/STOP + RESTORE; and a monitor (SYS 65280). LOAD and SAVE go to a virtual 1541 (.D64) and Datassette (.TAP). Monitor only boots just the stub.

The keyboard matrices are the hardware’s: the VIC-20’s (VIA 2 port B drives the columns, port A reads the rows, in the order of the KERNAL’s own decode table), the PET graphics keyboard’s (PIA 1 selects one of ten rows, port B reads it; from Norbert Landsteiner’s PET Keys — Series 2001 Edition and MAME), and the business keyboard’s (from MAME).

If you own the ROMs, Load my ROM files…: for the VIC-20 the 8 KB KERNAL and BASIC and the 4 KB character ROM; for the PET the chips by address (b000 … f000, the editor at $E000), VICE’s basic2 / basic4 files, or a dump of the top of memory. Commodore’s chips are recognised by CRC-32; they are kept per machine in this browser’s IndexedDB.

Presenting

⛶ Present (or F) shows just the VIC-20 or PET screen, filling the window — for a talk or a classroom. The keyboard keeps working; Esc closes it. With Link options → Open in presentation mode and Start automatically, a share link opens full screen and runs the program in the editor.

Limits

  • The CPU runs instruction by instruction with the documented cycle counts, not cycle by cycle. The VIC-20 screen is drawn a line at a time, so border and colour changes between lines show, but changes in the middle of a line don’t; the border position is approximate. The PET screen is drawn once a frame.

  • VIC sound is a simple square-wave model (frequency Φ2 / n / (255 − X), n = 256, 128, 64, 32 for the bass, alto, soprano and noise registers) with a 15-bit noise generator, not the real chip’s filters.

  • Tape and disk work at the KERNAL / BASIC level (no drive CPU, IEEE-488 or serial bus, fast loaders or protected disks); no printer, light pen or paddles; the PET has no CRTC timing tricks. Cartridges with bank switching aren’t supported.

  • The open BASIC is BASIC 1.1: no OPEN/PRINT# files. Programs that call undocumented ROM routines need the real ROMs. PET BASIC 1 keeps its keyboard buffer elsewhere, so typing into it doesn’t work.

  • The colours are approximations (palettes for these machines disagree).

Linking to an example

Links can be written by hand. Settings not in the link keep their defaults.

Parameter Meaning Example

machine

vic20 or pet

machine=pet

mode

Tab: run, asm, debug, refs

mode=asm

example

VIC-20: hello, colours, screen, sound, keys, irq, chars, multicolour, joystick, save; PET: hello, screen, sound, keys, charset

example=sound

video

VIC-20 chip: pal or ntsc

video=ntsc

mem

VIC-20 expansion in KB: 0, 3, 8, 16, 24, 32, 35

mem=8

pet

PET model: 2001, 3032, 4032 or 8032

pet=8032

present=1, autostart=1

Open the screen full-window and run the program

autostart=1

Privacy

Everything runs in your browser. The first time, the page fetches the open BASIC and a font from this site (about 30 KB). Programs, disks, tapes and ROMs you open stay in this browser (IndexedDB) and are never sent anywhere.

Runs entirely in your browser; nothing you type leaves this page.