c64tools

c64tools

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:

Name Type Description Default
w int

window width

required
h int

window height

required

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:

Name Type Description Default
data List[int]

The memory data (should be 65536 bytes long)

None

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:

Name Type Description Default
fileName str

The file to load

required

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:

Name Type Description Default
surface pygame surface

The surface to draw this memory to

required
x int

x-offset for drawing

required
y int

y-offset for drawing

required
cols int

the number of (character) columns

required
fgColor Tuple[int, int, int, int]

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

(255, 255, 255, 255)
bgColor Tuple[int, int, int, int]

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

(0, 0, 0, 255)

charAt(addr)

Returns the eight bytes at the given address as a char

Parameters:

Name Type Description Default
addr int

The address to read the bytes from

required

Returns:

Type Description
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:

Name Type Description Default
data List[int]

The bitmap data

None

charAt(col, row)

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

Parameters:

Name Type Description Default
col int

The column (in characters) to read the char from

required
row int

The row (in characters) to read the char from

required

Returns:

Type Description
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:

Name Type Description Default
surface pygame surface

The surface to draw this memory to

required
x int

x-offset for drawing

required
y int

y-offset for drawing

required
fgColor Tuple[int, int, int, int]

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

(255, 255, 255, 255)
bgColor Tuple[int, int, int, int]

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

(0, 0, 0, 255)

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:

Name Type Description Default
surface pygame surface

The surface to extract the bitmap from

required
x int

x-offset for reading

required
y int

y-offset for reading

required

fromC64Screen(screen, chars)

Fills the bitmap using the given screen and character set information

Parameters:

Name Type Description Default
screen Screen instance

The screen to use

required
chars List[Char]

The character set to use

required

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:

Name Type Description Default
data Tuple[int*8]

The character data (should be 8 bytes long)

None

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:

Name Type Description Default
surface pygame surface

The surface to draw this memory to

required
x int

x-offset for drawing

required
y int

y-offset for drawing

required
fgColor Tuple[int, int, int, int]

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

(255, 255, 255, 255)
bgColor Tuple[int, int, int, int]

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

(0, 0, 0, 255)

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:

Name Type Description Default
surface pygame surface

The surface to draw this memory to

required
x int

x-offset for drawing

required
y int

y-offset for drawing

required
fgColor Tuple[int, int, int, int]

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

(255, 255, 255, 255)
bgColor Tuple[int, int, int, int]

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

(0, 0, 0, 255)
multi1Color Tuple[int, int, int, int]

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

(192, 192, 192, 255)
multi2Color Tuple[int, int, int, int]

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

(128, 128, 128, 255)

same(c)

Returns whether the given character is same as this one.

Parameters:

Name Type Description Default
c int

The character to compare this character to

required

Returns:

Type Description
bool

Whether the given character is same as self

writeInto(f)

Writes this character to a file.

Parameters:

Name Type Description Default
f file descriptor

The file to write this character to

required

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:

Name Type Description Default
data int array

The screen data (should be 1000 bytes long)

None

charAt(col, row)

Returns the caracter at the given position

Parameters:

Name Type Description Default
col int

The column to get the character from

required
row int

The row to get the character from

required

Returns:

Type Description
int

The character at the given row and column

setCharAt(col, row, char)

Sets the given character at the given position

Parameters:

Name Type Description Default
col int

The column to set the character at

required
row int

The row to set the character at

required
char int

The character to set

required

open2Write(fileName)

Opens a file for writing.

Parameters:

Name Type Description Default
fileName string

The name of the file to open for writing

required

Returns:

Type Description
file

The flle opened for binary writing

saveChars(fileName, pos, chars)

Saves the given characters.

Parameters:

Name Type Description Default
fileName string

The name of the file to write the given characters to

required
pos int

unused!

required
chars Char[])

The characters to save

required

TODO: remove the pos-parameter

writeByte(f, b)

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

Parameters:

Name Type Description Default
f file descriptor

The file to write the byte to

required
b int

The byte to write

required

writeBytes(f, bs)

Writes the given array as a bytearray.

Parameters:

Name Type Description Default
f file descriptor

The file to write the bytes to

required
bs int[]

The bytes to write

required