Amstrad CPC emulator and Z80 IDE
An Amstrad CPC 464 and 6128 in your browser with the original firmware and Locomotive BASIC, a Z80 assembler and debugger with the firmware's jumpblock names, live views of the Gate Array, CRTC, PPI, AY and floppy controller, and DSK, CDT and SNA support.
Added
Works with
- Retro disk and tape images Retro computingopens CPC DSK images here
How to use it
The CPC switches on by itself the first time you run something (or press Power on). It
boots its own firmware to "Amstrad 64K Microcomputer (v1)" and BASIC 1.0 on the 464, or
"Amstrad 128K Microcomputer (v3)" and BASIC 1.1 on the 6128, and waits at Ready. Click
the screen to give it the keyboard; paste text onto it to type it in.
Running programs
Drop a file on the screen, or use Open file…:
-
.DSK (standard or extended) — the disk goes into drive A (switching to the 6128) and the first program on it is
RUN. The Tape & disk tab lists the files with a RUN button each, makes a blank disk, and downloads the disk afterSAVEhas written to it. -
.CDT / .TZX — the tape goes in and
RUN"is typed for you (|TAPEfirst on the 6128). With Fast load on, every block the firmware’sCAS READasks for arrives instantly. Tapes with their own loaders play in real time: turn on Warp to wait less. -
.SNA — snapshots (versions 1–3, including compressed v3 memory) load straight into memory. Save .SNA writes the machine’s state as a version 3 snapshot.
Writing Z80 code
The Code & debug tab has examples: hello world through TXT OUTPUT (&BB5A), modes and
inks, drawing straight into screen memory at &C000 (the 8-line interleave), palette cycling
by writing the Gate Array, raster bars timed to the 64 µs line, a frame-flyback interrupt
event (KL NEW FRAME FLY), a scale on the AY, a block moved with the cursor keys
(KM TEST KEY) and lines with the graphics VDU. Assemble & run (Ctrl/⌘+Enter) resets the
CPC, pokes the code into memory and types CALL &4000; RET comes back to BASIC.
Build .CDT and Build .DSK write the program as a binary file (with its load and entry
addresses) on a tape or a DATA-format disk that work on a real CPC. Load as tape plays it
through LOAD"" like a cassette; Load from disk writes it to a disk in drive A, lists it
with CAT and loads it.
The assembler takes CPC-style hex (&BB5A) as well as $BB5A, 0xBB5A and 0BB5Ah;
labels (with or without a colon), local labels starting with ., ORG, EQU (or =),
DEFB/DB, DEFW/DW, DEFS/DS, DEFM strings, $ for the current address, and
expressions with + - * / % & | ^ ~ << >>. Every undocumented instruction is accepted too.
The program starts at the label start if there is one.
BASIC
The BASIC tab types a listing into the machine for you, a key at a time (in warp, so a
long listing takes seconds), optionally after NEW and followed by RUN. There are short
examples: colours, mode 0 lines, SOUND with an envelope, EVERY interrupts, and machine
code poked from DATA lines. ESC twice stops a running program.
Debugging
Beside the editor (below it on a phone) are the machine’s screen, the controls — Run / Continue (F5), Pause (F6), Step (F11), Step over (F10), Step out (Shift+F11) and Reset — the registers (type a new value to change one), the flags (click to flip), the code around PC, the stack and watches. Click a line number to set a breakpoint (a red ●); right-click it to run to that line. When the program stops, ▶ marks the line.
The Debugger tab has the full register set (with the alternate registers, IX/IY, I, R,
interrupt state and MEMPTR), the timing in the frame and the CRTC’s beam position, a
disassembly where calls into the firmware show the routine’s name (CALL &BB5A ; TXT
OUTPUT), breakpoints by address, label or firmware name (TXT OUTPUT stops at every
character the firmware prints), and memory you can edit. Point at the screen to see which
byte and pen make a pixel.
The Chips tab shows the custom chips live:
-
Gate Array — the 16 pens and the border with their colours (hardware number, BASIC
INKnumber and name), the mode, ROM paging and the interrupt counter. -
CRTC 6845 — R0–R17 next to the firmware’s values, and what they make: line length, frame rate, screen size, start address and the beam position. Switch between CRTC types 0 and 1.
-
PPI 8255 + keyboard — the three ports decoded, and the keyboard matrix with the keys that are down.
-
AY-3-8912 — the 16 registers and, per channel, frequency, note, mixer and volume.
-
uPD765 floppy — the main status register, phase, last command and results, and the drives' head positions.
-
Memory map — what each 16K slot reads and writes, including the 6128’s RAM configurations.
How it works
The Z80 is the site’s own core (checked against the FUSE test suite). The Gate Array
stretches every instruction to whole microseconds; the emulator rounds each instruction up to
the next microsecond and adds the extra one the CPC takes for PUSH, RST, EX (SP),HL,
IN/OUT ©, LDI-style block steps and a few more, so a loop counted in "NOPs" takes as
long as on the real machine. The CRTC runs a character (1 µs, 2 bytes) at a time beside the
CPU, so changing the border or a palette entry mid-frame, moving the screen start or
resizing it with R1/R6 shows where it happens. The Gate Array raises an interrupt every 52
HSYNCs (300 a second) and resynchronises at VSYNC, as the firmware expects.
The keyboard is the 10 × 8 matrix read through the AY’s I/O port, the sound is the AY at
1 MHz in stereo (A left, B centre, C right), and the 6128’s floppy controller reads and
writes .DSK images sector by sector: AMSDOS, CAT, SAVE and CP/M work through it.
Reference values: a frame is 312 lines of 64 µs = 19 968 µs (50.08 Hz), the screen starts at
&C000, and pixel line y is at &C000 + (y ÷ 8) × 80 + (y mod 8) × &800 (CPC firmware
guide, SCR NEXT LINE; CPCWiki "Video modes" for the bit order of pixels in each mode).
Limits
-
Timing is per instruction, not per memory cycle: most instructions take exactly the CPC’s number of microseconds, but where an interrupt or a register write lands inside an instruction can be a microsecond off. Effects that need cycle-exact timing within a line (some "rupture" and split-screen demos) may wobble.
-
The CRTC follows types 0 and 1 for the common cases (start address latched each frame, R1/R6/R7/R9 changes, vertical adjust); the differences between types in rarely used corners (and types 2–4) are not emulated, and there is no hardware cursor or light pen.
-
The floppy controller moves data at once and doesn’t emulate rotation timing, weak or overlapping sectors, so some copy-protected disks won’t load.
-
The 464’s disk add-on (DDI-1), the 664, the Plus range, the Multiface and printers are not emulated. Tape loaders that check the motor relay timing closely may fail in real time.
-
The CDT reader takes standard, turbo, pure-tone, pulse and pause blocks; direct-recording and CSW blocks are skipped.
Software to load
The Software tab has the site’s library panel: programs the site may share (none for the CPC yet) and an Open URL / archive.org box. Files you own you can always drop onto the emulator.
Linking to an example
Share link (above the tool) copies the current set-up. Links can be written by hand:
| Parameter | Meaning | Example |
|---|---|---|
|
An assembler example: |
|
|
|
|
|
|
|
|
A BASIC listing for the BASIC tab (lines separated by |
|
|
Sound and fast tape loading on or off |
|
ROMs
The CPC 464 (OS 1, BASIC 1.0), 6128 (OS 3, BASIC 1.1) and AMSDOS ROMs are © Amstrad (the BASIC with Locomotive Software, as its sign-on says). Amstrad has kindly given its permission for its copyrighted material to be redistributed but Amstrad retains its copyright (Amstrad’s redistribution terms for the CPC firmware and AMSDOS; Cliff Lawson’s statement for Amstrad). Caprice32, WinAPE, Arnold and MAME ship the same images on this basis; these come from Caprice32, with the copyright messages unchanged. The emulator, assembler and examples are this site’s own code.
Related: ZX Spectrum emulator and Z80 IDE (the same Z80 core and assembler), YM2149 / AY sound designer, retro timing, C64 emulator, Atari ST emulator.
Feedback is a gift. Something to improve, a feature to add, or a bug? Tell me.
Runs entirely in your browser; nothing you type leaves this page.