structures

c64tools - c64 Python helper.

Some classes that represent c64 structures. This file can also be imported as a module. It 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

Char

A single c64 character

__init__(data=None)

Constructor, allocates memory.

Assigns the given data. If no data is given, the data (character) is initialiased with zeros.

Parameters:
  • data (Tuple[int], default: None ) –

    The character data (should be 8 bytes long)

draw_at(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.

Parameters:
  • surface (Surface) –

    The surface to draw this memory to

  • x (int) –

    x-offset for drawing

  • y (int) –

    y-offset for drawing

  • fgColor (Tuple[int, int, int, int], default: (255, 255, 255, 255) ) –

    foreground color given as a tuple of four integers (rgba), may be None

  • bgColor (Tuple[int, int, int, int], default: (0, 0, 0, 255) ) –

    background color given as a tuple of four integers (rgba), may be None

draw_at_multicolor(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.

Parameters:
  • surface (Surface) –

    The surface to draw this memory to

  • x (int) –

    x-offset for drawing

  • y (int) –

    y-offset for drawing

  • fgColor (Tuple[int, int, int, int], default: (255, 255, 255, 255) ) –

    foreground color given as a tuple of four integers (rgba), may be None

  • bgColor (Tuple[int, int, int, int], default: (0, 0, 0, 255) ) –

    background color given as a tuple of four integers (rgba), may be None

  • multi1Color (Tuple[int, int, int, int], default: (192, 192, 192, 255) ) –

    multi1 color given as a tuple of four integers (rgba), may be None

  • multi2Color (Tuple[int, int, int, int], default: (128, 128, 128, 255) ) –

    multi2 color given as a tuple of four integers (rgba), may be None

same(c)

Returns whether the given character is same as this one.

Parameters:
  • c (Char) –

    The character to compare this character to

Returns:
  • bool

    Whether the given character is same as self

write(f)

Writes this character to a file.

Parameters:
  • f (file descriptor) –

    The file to write this character to

inverse()

Inverses this character.

Window

Bases: object

A plain pygame window. Nothing special about it.

__init__(w, h, title='c64 draw')

Generates and shows a pygame window.

Parameters:
  • w (int) –

    window width

  • h (int) –

    window height

  • title (str, default: 'c64 draw' ) –

    the window title

run()

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.

Memory

The representation of a c64 memory.

__init__(data=None)

Constructor

Assigns the given data. If no data is given, the data (memory) is initialiased with zeros.

Parameters:
  • data (List[int], default: None ) –

    The memory data (should be 65536 bytes long)

load(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)

Parameters:
  • filename (str) –

    The file to load

TODO: check destination byte order (not spent a thought on it)

draw_at(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.

Parameters:
  • surface (Surface) –

    The surface to draw this memory to

  • x (int) –

    x-offset for drawing

  • y (int) –

    y-offset for drawing

  • cols (int) –

    the number of (character) columns

  • fgColor (Tuple[int, int, int, int], default: (255, 255, 255, 255) ) –

    foreground color given as a tuple of four integers (rgba), may be None

  • bgColor (Tuple[int, int, int, int], default: (0, 0, 0, 255) ) –

    background color given as a tuple of four integers (rgba), may be None

char_at(addr)

Returns the eight bytes at the given address as a char

Parameters:
  • addr (int) –

    The address to read the bytes from

Returns:
  • Char

    The character built from the bytes at the given address

Bitmap

The representation of a c64 bitmap.

__init__(data=None)

Constructor

Assigns the given data. If no data is given, the data (bitmap) is initialiased with zeros.

Parameters:
  • data (List[int], default: None ) –

    The bitmap data

char_at(col, row)

Returns the Char representation of the character at the given position.

Parameters:
  • col (int) –

    The column (in characters) to read the char from

  • row (int) –

    The row (in characters) to read the char from

Returns:
  • Char

    The character built from the bytes at the given column and row

draw_at(surface, x, y, fgColor=(255, 255, 255, 255), bgColor=(0, 0, 0, 255))

Draws this bitmap at the given surface and the given position.

Parameters:
  • surface (Surface) –

    The surface to draw this memory to

  • x (int) –

    x-offset for drawing

  • y (int) –

    y-offset for drawing

  • fgColor (Tuple[int, int, int, int], default: (255, 255, 255, 255) ) –

    foreground color given as a tuple of four integers (rgba), may be None

  • bgColor (Tuple[int, int, int, int], default: (0, 0, 0, 255) ) –

    background color given as a tuple of four integers (rgba), may be None

from_surface(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

Parameters:
  • surface (Surface) –

    The surface to extract the bitmap from

  • x (int) –

    x-offset for reading

  • y (int) –

    y-offset for reading

from_c64_screen(screen, chars)

Fills the bitmap using the given screen and character set information

Parameters:
  • screen (Bitmap) –

    The screen to use

  • chars (List[Char]) –

    The character set to use

Screen

The representation of a c64 screen

__init__(data=None)

Constructor, allocates memory.

Assigns the given data. If no data is given, the data (screen) is initialiased with zeros.

Parameters:
  • data (List[int], default: None ) –

    The screen data (should be 1000 bytes long)

char_at(col, row)

Returns the caracter at the given position

Parameters:
  • col (int) –

    The column to get the character from

  • row (int) –

    The row to get the character from

Returns:
  • int

    The character at the given row and column

set_char_at(col, row, char)

Sets the given character at the given position

Parameters:
  • col (int) –

    The column to set the character at

  • row (int) –

    The row to set the character at

  • char (int) –

    The character to set