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, downloads, tools

© Copyright Daniel Krajzewicz, 16.05.2020 18:56, cc by-nc-nd

Introduction

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 times 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 a Python library that helps in dealing with c64 graphics.

Documentation

The major module is named “c64tools.py”. It contains classes that represent major c64 artifacts — memory, bitmap, char, screen, etc. These classes usually support loading, drawing, and being extracted from a pygame surface.

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

A brief documentation is given below.

c64tools 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 table below gives an overview about the respectively implemented methods.

MemoryBitmapCharScreen
load x
drawAt x x x
drawMulticolorAt x
charAt(addr) x
charAt(row, col) x x
setCharAt x
fromSurface x
fromC64Screen x
same x
writeInto x
inverse x

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

If you need any extension, please let me know.

Additional applications

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

mem2png.py

mem2png.py” shows a memory dump, optionally saving it as a png-file. When moving over the window, the memory address below 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:

  • --file/-f <MEMORY_DUMP_TO_LOAD>
  • --output/-o <IMAGE_TO_SAVE>
  • --width/-w <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).

charpacker.py

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-colours in each raster line. “charpacker.py” loads an image file (.gif, e.g.) and performs the charpacking — indexing same 8×8 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:

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

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

charset2png.py

charset2png.py” 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 besides each other. Further options for limiting the number of characters to extract, for setting the background colour, 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:

  • --file/-f <FILE>: the memory dump to load
  • --output/-o <FILE>: the name of the file to write the character set to
  • --address/-a <INT>: the address to extract the character set from
  • --number/-n <INT>: the number of characters to extract
  • --pattern/-p <PATTERN>: pattern of multi-char character sets
  • --width/-w <INT>: the width of the image to generate to build
  • --divider/-d <INT>: the height of a divider space between the lines
  • --inverse/-i: invert the characters
  • --background/-b <COLOR>: set the background color, default: #000000
  • --foreground/-c <COLOR>: set the foreground color, default: #ffffff
  • --multicolor1/-1 <COLOR>: set the multi color 1, default: #c0c0c0
  • --multicolor2/-2 <COLOR>: set the multi color 2, default: #808080
  • --multicolor/-m: use multicolor mode
  • --quiet/-q: do not show a window, just write the image

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

filemerge.py

filemerge.py” loads specified files into the same “memory”. The parts of the memory occupied by the loaded files are then saved. The memory address of the loaded files are considered.

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

  • --file/-f <FILE>: the file(s) to load, separated by ','
  • --output/-o <FILE>: the name of the file to write the memory to

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

Availability

c64 Python Tools are licensed under the LGPL v3.0, so if you extend it, please let me know.

The current release is a pre-release v0.8:

The code is available at github at https://github.com/dkrajzew/c64tools.

The PyPI pages is at https://pypi.org/manage/project/c64tools/releases/.

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported licence
Your message
Name:
E-Mail:
Subject:
Message:

Supporting an e-mail address allows us to answer.

Your message has been sent. Thank you.