Dilettante Habits

Knowing nothing about everything

c64 Python helper

Abstract: An open source Python library for dealing with c64 graphics.

Topics: c64, programming languages/Python, libraries, open source

© Copyright Daniel Krajzewicz, 31.01.2019 21:34, cc by-nc-nd


I dealt a lot with the good old c64, see c64 releases. Some years ago, I got in contact with Crimson/Wrath Designs who not only brought me back to the scene, but as well motivated me to retry coding on the machine. Yet, as time change, it is possible to use your PC for designing graphics, testing methods, and cross-compiling c64 code. But, this of course needs some libraries.

What you may find in the following is a description of some libraries written in Python that help designing c64 code.


The major module is named "c64.py". It contains classes that represent major c64 artifacts - memory, bitmap, char, screen, etc. They usually support loading, drawing, and being extracted from a pygame surface.

In addition, you may find some applications which use this module: a charpacker, a memory to gif converter, a charset extractor.

A brief documentation is given below.

c64 Module

The module includes the following classes:

  • Window: A pygame window for displaying things
  • Memory: A representation of the c64 memory
  • Bitmap: A representation of a c64 bitmap
  • Char: A representation of a single c64 character
  • Screen: A representation of a c64 screen
  • Some helper methods for loading / saving binary files.

The pydoc module documentation can be found here: c64 module pydoc documentation.

Additional applications

Some further applications based on the c64 module exist. They will be described in the following.


This module shows a memory dump, optionally saving it as a png-file. When moving over the window, the cursor position will be shown and additionally, the character address, both in decimal as well as in hexadecimal number system. You may use this information for extracting a character set using "charset2png.py".

Figure 1: mem2png.py screen shot.

The tool has to be started with either one option - the memory dump to load - or the following ones:

  • -f/--file <MEMORY_DUMP_TO_LOAD>
  • -o/--output <IMAGE_TO_SAVE>
  • -w/--width <DISPLAY_WIDTH_IN_CHARACTERS> (the default is 128)

The pydoc module documentation can be found here: mem2png.py module pydoc documentation (but it's not really meaningful).


Charpacking converts a bitmap into a character set and a screen, used either for reducing the overall size, for generating larger fonts, or for allowing other effects, such as changing multi-colors in each raster line. charpacker.py loads an image file (.gif, e.g.) and performs the charpacking - indexing same 8x8 pixel characters. It is somehow a Python-version of the original c64 charpacker "Abraham".

Besides using the charpacker as a command line application, You may as well import it in Your Python application and use the charpack method within a script. You may then incrementally fill a character set from a different bitmaps by passing the results of initial steps as the second parameter.

Figure 2: charpacker.py screen shot.

The tool has to be started with the following options set:

  • -f/--file <IMAGE_TO_LOAD>
  • -s/--screen-output <SCREEN_OUTPUT_FILENAME>
  • -s/--charset-output <CHARSET_OUTPUT_FILENAME>

The pydoc module documentation can be found here: charpacker.py module pydoc documentation.


This tool loads a memory dump, extracts a characters set at the specified position and saves it as an image to the specified file.

You may alter the width of the generated image, given in the number of characters shown beside each other. Further options for limiting the number of characters to extract, for setting the background color, for optionally inverting the character set, and for defining the height of the space between the lines exist. A generated image may look as given in Figure 3.

Figure 3: character set image as generated by charset2png.py.

The tool has to be started with the following options set:

  • -f/--file <IMAGE_TO_LOAD>
  • -s/--screen-output <SCREEN_OUTPUT_FILENAME>
  • -s/--charset-output <CHARSET_OUTPUT_FILENAME>

The pydoc module documentation can be found here: charset2png.py module pydoc documentation.


The code is available at github at https://github.com/dkrajzew/c64. It is licensed under the GPL, so if you extend it, please let me know.

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported licence
Your message

Supporting an e-mail address allows us to answer.

Your message has been sent. Thank you.