Skip to content
taublastPublic

About

DrawnCPC: an Amstrad CPC emulator with apps catalog. For Mac, Windows and Web. Built with DrawnUI for Rust.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

DrawnCPC: Amstrad CPC 6128 for desktop and browser with apps catalog

Amstrad CPC 6128 for desktop and browser with apps catalog
Runs on Mac, Windows and Web. Built with DrawnUI for Rust.

Run in browser

⭐ Please star if you like it!

Accuracy · Build it · Credits


Highlights

Thousands of titles, one click File → From Internet… searches the Internet Archive, CPC-Power, Genesis8bit and pouet.net; Play downloads, inserts and starts.
Autostart Play types the command that starts each disk or tape for you; a music disk starts the program that plays it.
Built-in music player .YM chip tunes play in their own player: play, pause, previous, next, title, author and length.
Faithful chips Z80 passes ZEXALL, z80test and Z80 Full Test; CRTC and Gate Array follow the CRTC Compendium: overscan, split screens, rasters, interlace.
6128 keyboard on screen The CPC's own keyboard under its screen, for mouse and touch; keys the CPC holds light up.
Joystick on any keys Arrows and Ctrl by default (Command in the Mac desktop app), moved to any keys in Settings.
Keyboard that feels right Every key is the CPC's, by character or by place.
Your CPC English or French 6128, CRTC type 0, 1, 2 or 4.
Sound AY-3-8912, disk drive clicks and hum.
Saves SAVE, high scores and FORMAT go back into your disk.
Debug tools Hard Pause, debugger with breakpoints, hex editor, disassembler, BASIC listing, chip views.

What it does

Play

  • Disks and tapes. DSK images, and .cdt / .tzx tapes played in real time. A disk or tape you insert yourself (File → Insert disk or tape, File → Recent) goes into the running CPC, as on the real machine. Autostart (Play in the catalog, the green Play in the bar, Commands → Start disk) types the command that starts it, as WinAPE's autorun does. A disk of music with no program of its own starts the program that plays it (Soundtrakker 128 for its songs, The Soundtrakker Player for compiled tunes).
  • Split-mode and modern overscan tricks. The reworked core runs split screens (CRTC "rupture"), overscan and the other screen tricks of modern CPC demos.
  • Saves to its disks. SAVE, a game's high scores or a formatted disk go into the disk in drive A; on the desktop into its file, after a copy of the file as it was (<name>.dsk.bak). In the browser the disk keeps them for the visit. File → Save disk as… saves the disk in drive A as a .dsk of your own, with everything written to it.

Find software

File → From Internet… is a catalogue of thousands of CPC titles, with search, a filter per source, and the same title from several places grouped into one card:

  • Internet Archive's CPC library,
  • CPC-Power, its database of 20,000 programs (its export, fetched once a day),
  • Genesis8bit's free and ex-commercial games, demos, disk zines, music, graphics and utilities,
  • pouet.net, the demoscene's prods for the CPC (demos, intros, diskmags, music disks), from its weekly data dump,
  • index files you add by address.

Play downloads the title, keeps it, puts it in drive A and starts it; Insert puts it in drive A without starting it. A ZIP of several disks offers each one; a ZIP of loose CPC files becomes a disk. On the desktop, lists and pictures are kept on disk, so the catalogue opens at once and updates in the background.

Keyboard and joystick

  • Every key is the CPC's, but one. F10 takes the keyboard to the menus (Escape gives it back). COPY is on Left Alt, f1 to f9 on F1 to F9 and on the numeric pad (f0 there too). Settings → Keyboard puts COPY, ESC, TAB, CONTROL, the function keys and the menu key on any PC key.
  • English or French 6128. Settings → Keyboard picks the CPC: English 6128 (QWERTY) or French, with its own ROMs (AZERTY, é, è, à, ù, ç), and its CRTC chip. PC keys go by what they type (any PC layout) or by where they sit, for games that read keys by place.
  • CPC keyboard on screen. The keyboard button in the top bar shows the 6128's keyboard under its screen: click or touch its keys; SHIFT and CONTROL stay down for the next key. Keys the CPC holds light up, whatever pressed them. On a phone-wide window its keys grow taller and the function and cursor keys get a row of their own.
  • Joystick on the keyboard. Arrows move, Left Ctrl and Right Ctrl fire; Settings → Joystick switches it on and off and puts it on any keys.
  • Commands. Reset starts the CPC afresh; Run, Cat, List and Cls are typed for you, and the commands you typed are listed under Typed lately.

Sound

  • The CPC's sound chip, and the clicks and hum of the disk drive (Settings → Sound, with its tuning).
  • A title of .YM tunes (such as Genesis8bit's collections of CPC game music) opens a tune player: play and pause, previous and next, the tune's name, author and length. Tunes are played by Arnaud Carré's ST-Sound, built in.

Settings keep the keys, the joystick, the CPC and the sound, on the desktop and in the browser. Help → How to use explains it all; Help → About gives the version and credits.

Debug tools

The Debug menu gives what a Multiface or a monitor gave on the real machine, each on a screen of its own:

  • Hard Pause stops the CPC where it stands; Resume lets it go on.
  • Debugger: the Z80's registers (each can be set, each flag switched), step into, over and out, and breakpoints on an address, on a memory read or write, or on a register value.
  • Hex editor: memory, RAM banks and ROMs, edited in hex or as text.
  • Disassemble: the code around any address; a click on a line sets a breakpoint there.
  • Listing: the BASIC program in memory, protected or not, as LIST would show it.
  • CRTC, Gate Array, Disk controller: the video chip's registers, the screen mode and palette, the disk controller's state and its breakpoints.

Text on these screens can be selected and copied (drag, double click, right click → Copy, Ctrl+C), and is read by screen readers; every control works from the keyboard.

The debugger

Accuracy

Measured with the standard test suites; full results and method in docs/accuracy.md.

Suite Result
ZEXDOC, ZEXALL 67 of 67
z80test 1.2a (all flags, MEMPTR, Q) 960 of 960
Z80 Full Test, CPC build all pass
Plustest, instruction and interrupt timing all match but IM 0
Shaker 2.7, CRTC 0 216 of 472 screens match, 182 more close
Shaker 2.7, CRTC 1 98 of 465 screens match, 129 more close

Running it

Desktop (tested on Windows), from drawncpc:

cargo run --release

Browser: web.ps1 (or web.sh) builds the page into drawncpc/dist; serve that folder over http. It needs emsdk's tools on PATH and rustup target add wasm32-unknown-emscripten. For the CPC-Power, Genesis8bit and Pouët sources in the browser, see the next section.

Browser build and CORS

A web page may read an answer from another site only when that site allows it, with an Access-Control-Allow-Origin header (CORS). This holds for every page, whatever it is written in: JavaScript, Blazor or, as here, Rust compiled to WebAssembly. The desktop app is not a web page and reads any site.

  • The Internet Archive allows it (its /cors/ addresses), so its list, covers and disks work in any browser build.
  • CPC-Power, Genesis8bit and pouet.net / scene.org send no such header. A browser page cannot read them directly.

For those three sources the browser build can go through a small helper: cors-worker/, a Cloudflare Worker of about a hundred lines. It reads the address the page asks for, only from those sites (an allow-list), and returns the answer with the header the browser needs. Lists and pictures stay in Cloudflare's edge cache for a few hours to a week, so the sites are asked rarely. For CPC-Power's download check it keeps the site's session cookie for the page and sends the typed letters as a form, the same steps the desktop app takes. You still type the letters yourself.

The helper is optional:

  • Built without it, the browser version shows the Internet Archive and your own disks and tapes (File > Insert disk or tape), and leaves the three other sources out.
  • With it, the browser version offers what the desktop offers: the lists, covers, details, one-click downloads and CPC-Power's check.

To run your own:

cd cors-worker
npx wrangler deploy

This needs a Cloudflare account (the free plan is enough). Then build the browser version with the helper's address:

$env:DRAWNCPC_PROXY = "https://<your worker>/fetch"   # web.sh: DRAWNCPC_PROXY=... ./web.sh
./web.ps1

To serve it under your own site's domain, add a route to cors-worker/wrangler.toml (the file shows how). When the page and the helper share a domain, /fetch alone is enough. For local tests, npx wrangler dev runs the helper on your machine.

Emulation core

DrawnCPC's core runs CPC software as the machine does:

  • Z80: every instruction's flags as on Zilog's NMOS Z80, undocumented bits 5 and 3 included, with MEMPTR and the Q latch; interrupts in modes 1 and 2 with the CPC's timing (the bus waits, the shorter response after some instructions), port reads and writes at the right moment, the refresh register, and every instruction decoded, JP (IX), JP (IY), LD SP,IX and LD SP,IY included.
  • CRTC (6845): counted as the chip counts, after the CRTC Compendium: split-mode ("rupture"), overscan, R0 = 0 and 1 lines, VSYNC protection, interlace sync and video mode. Types 0, 1, 2 and 4 each count as their own chip.
  • Gate Array and monitor: the interrupt counter and acknowledge, its own 26-line VSYNC, mode changes at the right pixel, and a monitor that follows C-HSYNC over a few lines, as a CTM does.
  • Sound: the CPC's AY-3-8912 (not a YM2149), with its register reads and port writes.
  • PPI: the control port's bit set / reset mode.
  • Disk controller and disks: writes and formats (SAVE, high scores); READ ID gives a track's sectors in turn as the disk rotates; DSK and extended DSK images with unformatted tracks, real sector lengths and loose headers; damaged images are refused instead of stopping the emulator.
  • Tape: .cdt / .tzx images played into the cassette input.
  • No stop on any program: every Z80 opcode runs (a test runs them all), and the chips answer what the CPC answers (mode 3, the disk controller's odd cases) instead of stopping the emulator.
  • For the tools: reading and writing memory and registers while the CPC runs (the debugger and the hex editor).

Each of these is a branch of its own (core/<what it does>).

Repository

Folder What it is
drawncpc DrawnCPC app
drawncpc-core DrawnCPC's emulation core; each change on a branch of its own, core/<what it does>, merged into drawnui
drawncpc-egui original egui frontend, kept as it is
cors-worker optional helper the browser build reads CPC-Power, Genesis8bit and pouet.net through
dev/accuracy scripts that run and score the test suites

Credits

  • Emulation core based on Ronald by Marc Dominik Migge (MIT license), reworked and enhanced.
  • psg crate: sound chip.
  • ST-Sound by Arnaud Carré, MIT license (drawncpc/third_party/StSound): .YM tune player.
  • Amstrad CPC CRTC Compendium by Longshot (Logon System), CC BY-NC-ND: technical information the CRTC and Gate Array follow.
  • Amstrad allows the CPC ROMs to be shipped with emulators.

License

MIT, see LICENSE.

About

DrawnCPC: an Amstrad CPC emulator with apps catalog. For Mac, Windows and Web. Built with DrawnUI for Rust.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages