Using ChatGPT to write programs for the Commodore 64 in 2023

I used ChatGPT to see how well it could write programs for the Commodore 64, starting with a very simple BASIC prompt. One of the first responses was exactly what you’d expect: a classic loop that printed text over and over. Another response tried to do more, using nested loops along with POKE and PEEK statements to change colors while printing “RETRO HACK SHACK” across the screen.

I tested the BASIC output in the VICE emulator so I could paste code in quickly and see what happened. The first issue wasn’t really with the generated code at all, but with character translation. ChatGPT returned the program in uppercase, and when that was pasted into the emulator it mapped some characters incorrectly because of the Commodore keyboard layout, so I converted the letters to lowercase before trying again.

First BASIC example
First BASIC example

Once the code was entered cleanly, the more elaborate BASIC example didn’t run properly and locked up. Looking through it, the loops themselves were fine, but the POKE and PEEK usage wasn’t right for what the program claimed to be doing. I went ahead and simplified it by removing one loop and replacing the original memory access with `POKE 646` plus a random value so the text color changed as the phrase printed repeatedly. With those small edits, it did what the generated program seemed to be aiming for.

Second BASIC example
Second BASIC example

I then asked for something more ambitious in BASIC: a Space Invaders style game. The first answer refused, and another answer drifted toward something more like Python, but a later prompt finally produced a BASIC listing. It still needed cleanup before it would even parse on a Commodore 64. Variable names with underscores didn’t survive the trip into the emulator, and one variable used `OR` inside the name, which BASIC treated as the logical operator instead of part of the identifier.

Assembly example
Assembly example

After renaming variables, the program at least ran, but it didn’t really behave as intended. The generated code relied on `INKEY`, which wasn’t suitable here, so I changed it to use `GET` while keeping the same basic structure. I also added a short delay and changed the alien movement so it jumped by small random amounts. The result wasn’t a graphical Space Invaders clone, but it did become a playable little coordinate game where lining up the player and alien positions incremented the score.

C64 poetry
C64 poetry

For assembly, I kept the request generic and got back a simple 6502 “hello world” style example along with a recommendation to use DASM or ACME. I tried DASM, assembled the code, and loaded the resulting PRG. The code itself was close, but it had been placed at the BASIC start address, so the Commodore 64 tried to treat it like BASIC and failed. I fixed that by loading the machine code at `$1000` instead and adding a tiny BASIC stub that effectively did `SYS 4096` so it would auto-start.

I also had ChatGPT generate a poem about the Commodore 64, which was actually pretty decent aside from a repeated word or two. The assembly program then ran in the emulator and on a real Commodore 64 from a BackBit cartridge, printing its message correctly.

— Aaron

Watch Now!

Links

Timestamps

00:00 – Intro

06:09 – PCBWay Ad

07:05 – First BASIC example

15:31 – Second BASIC example

24:50 – Assembly example

32:12 – C64 poetry

«
»