Charpacker

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

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)

drawAt(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 (pygame 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

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

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

drawAt(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 (pygame 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

fromSurface(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 (pygame surface) –

    The surface to extract the bitmap from

  • x (int) –

    x-offset for reading

  • y (int) –

    y-offset for reading

fromC64Screen(screen, chars)

Fills the bitmap using the given screen and character set information

Parameters:
  • screen (Screen instance) –

    The screen to use

  • chars (List[Char]) –

    The character set to use

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 * 8], default: None ) –

    The character data (should be 8 bytes long)

drawAt(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 (pygame 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

drawMulticolorAt(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 (pygame 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 (int) –

    The character to compare this character to

Returns:
  • bool

    Whether the given character is same as self

writeInto(f)

Writes this character to a file.

Parameters:
  • f (file descriptor) –

    The file to write this character to

inverse()

Inverses this character.

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 (int array, default: None ) –

    The screen data (should be 1000 bytes long)

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

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

open2Write(fileName)

Opens a file for writing.

Parameters:
  • fileName (string) –

    The name of the file to open for writing

Returns:
  • file

    The flle opened for binary writing

saveChars(fileName, pos, chars)

Saves the given characters.

Parameters:
  • fileName (string) –

    The name of the file to write the given characters to

  • pos (int) –

    unused!

  • chars (Char[]) ) –

    The characters to save

TODO: remove the pos-parameter

writeByte(f, b)

Writes the given byte as a one-byte-bytearray.

Parameters:
  • f (file descriptor) –

    The file to write the byte to

  • b (int) –

    The byte to write

writeBytes(f, bs)

Writes the given array as a bytearray.

Parameters:
  • f (file descriptor) –

    The file to write the bytes to

  • bs (int[]) –

    The bytes to write