Retrocomputing by Macc Magyar English

Port · 2025 · AI experiment

Back to the PET.

A port of shiru8bit’s Commodore PET PETSCII demo to the Commodore 64, in Kick Assembler. The question was never whether it could be done, but how much of it a language model could carry — the whole port was written by Claude Opus 5.

It works: all fifteen effects run, the music plays, and the demo goes through from beginning to end.

SOURCE Commodore PET TARGET Commodore 64 LANGUAGE 6510 ASM / Kick TIME about 2.5 hours
The original demo — shiru8bit The port’s source — GitHub

September 2025

The original runs on a Commodore PET: forty columns, twenty-five rows, no colour, no sprites, no raster interrupts. Just PETSCII characters, pushed into screen memory fast enough to read as movement. That is exactly what makes it a good thing to port — there is almost nothing in it tied to the PET’s own hardware. Almost.

The demo’s title screen on a C64
The title screen — on the C64 now, in the PET’s own character set

The trick: the screen stays at $8000

The PET puts screen memory at $8000. The C64 puts it at $0400 — but point the VIC at bank 2 and the screen lands at the same address the PET used. That one decision carries most of the port: the effects, the row tables and the scene layout needed no rebasing at all.

Which is why thirteen of the fifteen effects came across exactly as they were. The other two changed only where they reached for the PET’s sound hardware.

The character set

The demo does not work in the C64’s own font — it needs the PET’s, or the wrong glyphs appear. So the PET character set is copied into RAM at $8800. With one catch: the PET inverted characters in hardware and the C64 does not. Codes $80$ff have to exist as real reversed glyphs, because the effects’ density tables treat $a0 as the densest character on the screen. Only the 128 original glyphs travel in the file; the other half is generated at startup by an EOR loop.

Matrix effect
The green blocks are reversed PETSCII glyphs — from the half generated at run time

Sound: from the 6522 to SID

The PET has no sound chip. Sound comes from the 6522’s shift register: an 8-bit pattern clocked out of the CB2 line at a rate a timer sets. Look at it closely and that is a pulse wave whose duty cycle is the bit pattern and whose frequency is the timer period. Which is to say: a SID pulse voice, with extra steps.

So the music is not rewritten — the original data plays. The same packed note tables, the same player; only the two routines that touched the hardware were replaced. And the tuning holds: measured back from a recording, every note longer than two frames lands within 1.1 cents.

Two scenes make their own sound after the music stops. One is noise (it rewrites the shift register faster than the ear can follow it as a pitch — that became SID’s noise waveform), the other is speech, as a 1-bit digi. That one maps onto the C64’s $d418 volume digi, and the sample rate came out cycle-for-cycle identical: the two cycles the SID write costs were taken back out of the loop’s own padding.

Wave effect
Character waves — the effect’s logic is the original, untouched

The memory that only just fits

The original fits in a 32K PET because the packed data deliberately overlaps the area scenes are unpacked into: whatever is consumed first sits highest, so a scene only ever overwrites what the demo has already finished with. That is also why it cannot be re-run without reloading — neither the original nor this.

It is the most fragile thing the port inherited, so it is checked rather than trusted: every build walks the demo’s actual scene order and fails if any scene would land on something still needed — or on its own compressed source.

What is not identical

A PAL C64 runs at 50 Hz against the PET’s 60, so the whole demo is about 17% slower — picture and music together, since both are frame-locked. The speech digi is a quarter of a semitone flat, because the C64’s PAL clock is not a round megahertz. And the $d418 digi is loud on a 6581 and quiet on an 8580 — that is the chip, not the code.

The PET’s face
“Only Commodore PET makes it possible”

The intro

One scene has no PET original. The demo opens by scrolling the screen away — on the PET, the boot message. On the C64 there was nothing there to scroll, so now there is a page of text: typed out a character a frame, terminal style, with a blinking cursor, waiting for a key. Then it scrolls off exactly as the boot message did.

The intro page
The intro — this is what gets scrolled away

And the experiment?

The port — code, documentation, sound work, verification tools — took about two and a half hours, all of it with Claude Opus 5. The interesting part is not the translating; converting the effects is mechanical work. The interesting part was where something had to be decided: that the screen should stay at $8000; that the music player should be carried across rather than stubbed out, because the scenes advance on the markers it raises; and that the tuning should be proved by measuring a recording rather than by listening to it.

The full source, the porting notes and the verification tools are on GitHub. The credit for the demo itself remains shiru8bit’s entirely — the effects, the graphics and the music are all theirs. This is only a change of address.

shiru.untergrund.net github.com/AbelVincze/Backtothepet-c64-ai-port