c64tools
index
d:\products\c64pythontools\github\c64tools\c64tools.py

c64
 
Some classes that represent c64 structures.
 
This file can also be imported as a module and contains the following
classes:
 
    * Window - a basic pygame window for displaying stuff
    * Memory - a basic pygame window for displaying stuff
    * Bitmap - A c64 bitmap representation
    * Char - The representation of a single c64 character
    * Screen - The representation of c64 screen
    * Methods for writing binary contents
 
TODO: remove dependency on pygame
TODO: refactor binary writer helper methods
TODO: add a Sprite class
 
(c) Daniel Krajzewicz 2016–2020
daniel@krajzewicz.de
http://www.krajzewicz.de/blog/c64-python-helper.php
https://github.com/dkrajzew/c64tools
 
Available under LGPL 3.0, all rights reserved

 
Modules
       
pygame

 
Classes
       
__builtin__.object
Window
Bitmap
Char
Memory
Screen

 
class Bitmap
    The representation of a c64 bitmap.
 
  Methods defined here:
__init__(self, data=None)
Constructor
 
Assigns the given data. If no data is given, the data (bitmap)
is initialiased with zeros.
 
:param data: The bitmap data
charAt(self, col, row)
Returns the Char representation of the character at the given position.
 
:param col: The column (in characters) to read the char from 
:param row: The row (in characters) to read the char from
drawAt(self, surface, x, y, fgColor=(255, 255, 255, 255), bgColor=(0, 0, 0, 255))
Draws this bitmap at the given surface and the given position.
 
:param surface: The surface to draw this memory to
:param x: x-offset for drawing
:param y: y-offset for drawing
:param fgColor: foreground color given as a tuple of four integers (rgba), may be None
:param bgColor: background color given as a tuple of four integers (rgba), may be None
fromC64Screen(self, screen, chars)
Filss the bitmap using the given screen and character set information
 
:param screen: The screen to use
:param chars: The character set to use
fromSurface(self, surface, x, y)
Generates the Bitmap from the given surface, starting at the given position.
 
Please note that only white pixels are assumed to be set
 
:param surface: The surface to extract the bitmap from
:param x: x-offset for reading
:param y: y-offset for reading

 
class Char
    A single c64 character
 
  Methods defined here:
__init__(self, data=None)
Constructor, allocates memory.
 
Assigns the given data. If no data is given, the data (character)
is initialiased with zeros.
 
:param data: The character data (should be 8 bytes long)
drawAt(self, surface, x, y, fgColor=(255, 255, 255, 255), bgColor=(0, 0, 0, 255))
Draws this character (in hires) at the given surface and the given position.
 
:param surface: The surface to draw this memory to
:param x: x-offset for drawing
:param y: y-offset for drawing
:param fgColor: foreground color given as a tuple of four integers (rgba), may be None
:param bgColor: background color given as a tuple of four integers (rgba), may be None
drawMulticolorAt(self, surface, x, y, fgColor=(255, 255, 255, 255), bgColor=(0, 0, 0, 255), multi1Color=(192, 192, 192, 255), multi2Color=(128, 128, 128, 255))
Draws this character in multicolor at the given surface and the given position.
 
:param surface: The surface to draw this memory to
:param x: x-offset for drawing
:param y: y-offset for drawing
:param fgColor: foreground color given as a tuple of four integers (rgba), may be None
:param bgColor: background color given as a tuple of four integers (rgba), may be None
:param multi1Color: multi1 color given as a tuple of four integers (rgba), may be None
:param multi2Color: multi2 color given as a tuple of four integers (rgba), may be None
inverse(self)
Inverses the character
same(self, c)
Returns whether the given character is same as this one.
 
:param c: The character to compare this character to
writeInto(self, f)
Writes this character to a file.
 
:param f: The file to write this character to

 
class Memory
    The representation of a c64 memory.
 
  Methods defined here:
__init__(self, data=None)
Constructor
 
Assigns the given data. If no data is given, the data (memory)
is initialiased with zeros.
 
:param data: The memory data (should be 65536 bytes long)
charAt(self, addr)
Returns the eight bytes at the given address as a char
 
:param addr: The address to read the bytes from
drawAt(self, surface, x, y, cols, fgColor=(255, 255, 255, 255), bgColor=(0, 0, 0, 255))
Draws this memory at the given surface and the given position.
 
:param surface: The surface to draw this memory to
:param x: x-offset for drawing
:param y: y-offset for drawing
:param cols: the number of (character) columns
:param fgColor: foreground color given as a tuple of four integers (rgba), may be None
:param bgColor: background color given as a tuple of four integers (rgba), may be None
load(self, fileName)
Loads the given files as a memory dump.
 
Reads the first two bytes as destination (starting address).
Reads the reminder starting at this address, the rest of the memory
is filled with zeros.
 
Loading assures that the memory is complete (is 65536 bytes long)
 
:param fileName: The file to load
 
TODO: check destination byte order (not spent a thought on it)

 
class Screen
    The representation of a c64 screen
 
  Methods defined here:
__init__(self, data=None)
Constructor, allocates memory.
 
Assigns the given data. If no data is given, the data (screen)
is initialiased with zeros.
 
:param data: The screen data (should be 1000 bytes long)
charAt(self, col, row)
Returns the caracter at the given position
 
:param col: The column to get the character from 
:param row: The row to get the character from
setCharAt(self, col, row, char)
Sets the given character at the given position
 
:param col: The column to set the character at 
:param row: The row to set the character at 
:param char: The character to set

 
class Window(__builtin__.object)
    A plain pygame window. Nothing special about it.
 
  Methods defined here:
__init__(self, w, h, title='c64 draw')
Generates and shows a pygame window.
 
:param w: window width
:param h: window height
run(self)
Processes the pygame window events.
 
Should be called in a loop to process the occuring events.
Sets the self.show flag to False when being closed.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
open2Write(fileName)
Opens a file for writing.
 
:param fileName: The name of the file to open for writing
saveChars(fileName, pos, chars)
Saves the given characters.
 
:param fileName: The name of the file to write the given characters to 
:param pos: unused! 
:param chars: The characters to save
 
TODO: remove the pos-parameter
writeByte(f, b)
Writes the given byte as a one-byte-bytearray.
 
:param f: The file to write the byte to 
:param b: The byte to write
writeBytes(f, bs)
Writes the given array as a bytearray.
 
:param f: The file to write the bytes to 
:param bs: The bytes to write