I am looking for a good toolkit to auto-generate C64 basic code, which eventually prints different PETSCII graphics. I am wondering, if there is a good workflow for this, e.g. using a graphical PETSCII editor, copying the content (as fake ASCII?) in a Python script, processing it, writing C64 BASIC from python as text file, and converting into a BASIC program file, keeping PETSCII codes intact.

It does not necessarily need to be Python, other languages would also work.

Some more background, in case it is relevant:

The code generator should run on Linux or Windows, compressing a bigger number of PETSCII graphics by finding common strings, then generating C64 BASIC code containing these strings, plus some kind of mapping table to assemble the original images from partial strings.

Are the any documented viable approaches to use PETSCII as Python encoding?

I'll give an example how I expect this to look like. However, I'll use ASCII art here instead of PETSCII to make this render nicely. The real thing will use PETSCII, not ASCII.

Assuming I have ~100 images like:

   .-.`| `-/-.__/.-'\_.-._,'/`-._'\_.-._`-'_/-._.'|/.-'\-
   __/`.-/       `.'_`./`.'       '.\__.-`.'    (_.-\_,-.
   `._-/'          |._.-|           |.'`.|       `(_.`-._
   .-',`)          | /`.|           |`-/`|         ;.-'_/
   `\,-/           |\.-'|           |\-'`|          ;\_,-
   -./`._        [[[[[[[[         [[[[[[[[         .',-'
   -,.'"-"~^-~_~- - - _- -~^-_.~ - -_ - - -~- . "'"-"-""
   ""-'"-""-"~- _~.^-~-^.-^_.- .^~.-  ~-. ~^_-""-""-"'-"
         ""-'"-"    ~- ^. - ~ -~^ - ~  ^~- ~     ""-"'-'

First, I need to draw those in an editor, where PETSCII characters are accessible (preferrably graphical, as my PC keyboard does not have the characters printed).

Then, I want to copy those images as text into some script file like Python.

img[0] = """[[]]-[[]]-[[]]-[[]] ...

Probably, at that point, at least by the script interpreter, this will be interpreted as ASCII. I assume, setting the encoding to something strictly 8-bit, it will not be damaged on binary level though.

Then I would run a string analysis on these, determing strings of a certain length (let's assume, 6 characters each), that can be used to reproduce that image (all images have a symmetry that aligns nicely with that fixed length).

At the end of this step, I have an array of fixed-length strings and a list for every image, with indexes into that string array, to reproduce the image. Now I want to generate a BASIC program to reproduce this data in the C64.

I assume, the most BASIC-like and still compact approach would be to temporarily change the screen RAM pointer, then have a list of print commands, that print all these string segments on screen, then move the screen RAM pointer back.

So, the generated code would look like

PRINT"[[]]-[.-.`| .---._...."

All with PETSCII graphical characters.

  • What kind of code generation? print('10 PRINT "HELLO"\n20 GOTO 10')? Nov 21, 2022 at 11:40
  • 1
    Search for "petscii python" and you should find.
    – UncleBod
    Nov 21, 2022 at 11:58
  • Going through quasi-ASCII might be unnecessary. I seem to recall Unicode has recently added codepoints that make it cover the entire character range of PETSCII… though font and encoding conversion support is another matter. I don’t have any recommendations, though. I think you might have to write your toolkit mostly by hand. Nov 21, 2022 at 12:23

2 Answers 2


The tool PETSCII2BASIC, in combination with Marc's PETSCII Editor, is probably what you are looking for. The editor allows you to draw a PETSCII, and PETSCII2BASIC converts it into BASIC code, taking care of printing the PETSCII characters correctly.

To use the toolchain,

  • draw or import your image in Marc's PETSCII Editor and save it, you get a file filename.c
  • run PETSCII2BASIC.py filename.c to generate a .PRG file based on the filename containing a BASIC program that can be used on a C64 (native or emulator)

PETSCII2BASIC.py -? gives you several options, including starting line number, line number increment, and other output formats.


To me, the most difficult piece is the editor. I would take a deeper look at this online PETSCII Editor, which looks pretty capable, and includes file management.

The save files appear to be JSON, so easily processed by modern script code such as Python (or any other!). Once you have the binary representation of the PETSCII loaded in a scripting language, the conversion to BASIC code output ought to be the most trivial part of this. Perhaps made a little more complicated if you want your script to directly produce a C64 .PRG file instead of text, but that process is well-documented and can be done with existing CLI tools that perform Text<->PRG conversion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .