Chris Collins

Tools · retro

C64 BASIC and PETSCII

Commodore 64 BASIC V2 tokeniser and detokeniser (PRG ↔ listing with {clr}/{red} control codes), PETSCII ↔ Unicode for both character sets, and a 40×25 PETSCII screen editor that exports screen and colour bytes, a BASIC PRINT program, or 6502 assembler.

Added

Works with

How to use it

Three tabs:

  • BASIC listing — open a .PRG to list it, or type a program and download it as a .PRG that loads at $0801 (change the load address for other machines or memory layouts). Control characters in strings use petcat-style codes: {clr}, {home}, {red}, {rvon}, {down}, {3 down} to repeat, or {$hh} for any byte. Graphics characters can be typed as their Unicode equivalents (♥, ┼, ▚…). The tokenised bytes are shown live, with the keyword table beside them.

  • Screen editor — draw a 40×25 PETSCII screen with any of the 256 characters (including reverse video) in the 16 colours, with border and background. Type mode lets you type straight onto the screen. Export it as:

    • a BASIC program that PRINTs it (download a ready-to-run .PRG),

    • assembler that copies screen and colour data into $0400 and $D800, or

    • raw bytes (1000 screen codes and 1000 colours).

  • PETSCII text — convert between Unicode text and PETSCII bytes, see the screen codes to POKE, and browse the full PETSCII table for either character set.

Notes

  • BASIC V2 has 76 keywords, $80 (END) to $CB (GO), plus π as $FF. Like the C64’s own tokeniser, text inside quotes, after REM, and after DATA (until the next :) is not tokenised, and ? becomes PRINT.

  • In the lower/upper case set, letters outside strings are tokenised whatever their case (print and PRINT both work); inside strings, capitals become shifted letters.

  • A stored line is: a 2-byte link to the next line, a 2-byte line number, the tokenised text, and a zero byte. The program ends with a $0000 link. If the links don’t match the load address the program was saved from elsewhere; the C64 relinks it on load.

  • PETSCII graphics map to the Unicode 13 "Symbols for Legacy Computing" characters; the screen editor’s font is drawn for this tool (letters from the public-domain font8x8, graphics drawn by hand) rather than copied from the Commodore character ROM, so it looks close to, but not exactly like, a real C64.

  • The BASIC export POKEs any quote marks (printing one would switch on quote mode) and the bottom-right cell (printing it would scroll the screen).

Everything runs in your browser.

Sharing

Share link copies a link to the open tab with its contents: a BASIC listing (?src=, with ?load= and ?blower=1 for the lower-case set), a PETSCII text (?ptext=, ?plower=1), or a whole 40×25 screen with colours (packed in ?s=). For example ?ptext={clr}{red}HELLO.

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