# sp65 Users Guide

## Ullrich von Bassewitz

sp65 is a sprite and bitmap utility that is part of the cc65 development suite. It is used to convert graphics and bitmaps into the target formats of the supported machines.

## 1. Overview

## 2. Usage

- 2.1 Command line option overview
- 2.2 Command line options in detail

## 3. Processing pipeline

## 4. Attribute lists

## 5. Input formats

- 5.1 PCX

## 6. Conversions

- 6.1 GEOS bitmap
- 6.2 GEOS icon
- 6.3 Koala image
- 6.4 Lynx sprite
- 6.5 VIC2 sprite

## 7. Output formats

- 7.1 Binary
- 7.2 Assembler code
- 7.3 C code

## 8. Copyright

## 1. Overview

sp65 is a tool that converts images from common formats into formats used on the 6502 platforms that are the targets of the cc65 compiler suite. In addition, it allows some very simple operation with loaded graphics data, like using part of an image for further processing.

The utility has been designed in a way that adding additional source or target formats is easy. The final output is either binary, or C/assembler source.

## 2. Usage

## 2.1 Command line option overview

The sp65 utility accepts the following options:

> `

>     ---------------------------------------------------------------------------
>     Usage: sp65 [options] file [options] [file]
>     Short options:
>       -V                            Print the version number and exit
>       -c fmt[,attrlist]             Convert into target format
>       -h                            Help (this text)
>       -lc                           List all possible conversions
>       -r file[,attrlist]            Read an input file
>       -v                            Increase verbosity
>       -w file[,attrlist]            Write the output to a file

>     Long options:
>       --convert-to fmt[,attrlist]   Convert into target format
>       --dump-palette                Dump palette as table
>       --help                        Help (this text)
>       --list-conversions            List all possible conversions
>       --pop                         Restore the original loaded image
>       --read file[,attrlist]        Read an input file
>       --slice x,y,w,h               Generate a slice from the loaded bitmap
>       --verbose                     Increase verbosity
>       --version                     Print the version number and exit
>       --write file[,attrlist]       Write the output to a file
>     ---------------------------------------------------------------------------

> `

## 2.2 Command line options in detail

Below is a description of all the command line options. For the concept of attribute lists see below.

`-c, --convert-to format[,attrlist]`

  Convert a bitmap into one of the supported target formats. The option argument must at least contain the "format" attribute. For more attributes, see section Conversions.

`--dump-palette`

  Dump palette as table.

`-h, --help`

  Print the short option summary shown above.

`-lc, --list-conversions`

  Print a list of possible conversions.

`--pop`

  Restore the working copy of the bitmap from the one originally loaded from the file. This may for example be used when creating several output files from one input file.

`-r, --read filename[,attrlist]`

  Read an input file. The option argument must at least contain the "name" attribute. See input formats for more information.

`-v, --verbose`

  Increase verbosity. Usually only needed for debugging purposes. You may use this option more than one time for even more verbose output.

`-V, --version`

  Print the version number of the assembler. If you send any suggestions or bugfixes, please include the version number.

`-w, --write filename[,attrlist]`

  Write an output file. The option argument must at least contain the "name" attribute. See output formats for more information.

## 3. Processing pipeline

sp65 consists of

- Front ends that read graphics data,
- processors for graphics data,
- converters
- and output modules for several formats.

These modules can be combined to a pipeline that reads data, does some optional bitmap processing, converts the bitmap into a target format, and writes this binary data to disk in one of several forms.

## 4. Attribute lists

As described in Processing pipeline, sp65 consists of lots of different modules that may be combined in different ways, to convert an input bitmap to some output.

Many of the processors and converters have options to change the way, they're working. To avoid having lots of command line options that must be parsed on high level and passed down to the relevant parts of the program, sp65 features something called "attribute lists". Attribute lists are lists of attribute/value pairs. These lists are parsed by the main program module without any knowledge about their meaning. Lower level parts just grab the attributes they need.

In general, attribute lists look like this:

> `

>             attr1=val1[,attr2=val2[,...]]

> `

Instead of the comma, colons may also be used (even mixed).

To simplify things and to make the most common options look "normal", some mandatory attributes may be given without an attribute name. If the attribute name is missing, the default name is determined by the position. For example, the option `--read` does always need a file name. The attribute name for the file name is "name". To avoid having to type

> `

>             sp65 --read name=ball.pcx ...

> `

the first attribute gets the default name "name" assigned. So if the first attribute doesn't have a name, it is assumed that it is the file name. This means that instead of the line above, one can also use

> `

>             sp65 --read ball.pcx ...

> `

The second attribute for `--read` is the format of the input file. So when using

> `

>             sp65 --read ball.pic:pcx ...

> `

a PCX file named "ball.pic" is read. The long form would be

> `

>             sp65 --read name=ball.pic:format=pcx ...

> `

Changing the order of the attributes is possible only when explicitly specifying the names of the attributes. Using

> `

>             sp65 --read pcx:ball.pic ...

> `

will make sp65 complain, because it tries to read a file named "pcx" with an (unknown) format of "ball.pic". The following however will work:

> `

>             sp65 --read format=pcx:name=ball.pic ...

> `

The attributes that are valid for each processor or converter are listed below.

## 5. Input formats

Input formats are either specified explicitly when using `--read`, or are determined by looking at the extension of the file name given.

## 5.1 PCX

While sp65 is prepared for more, this is currently the only possible input format. There are no additional attributes for this format.

## 6. Conversions

## 6.1 GEOS bitmap

The current bitmap working copy is converted to a GEOS compacted bitmap. This format is used by several GEOS functions (i.e. 'BitmapUp') and is described in 'The Official GEOS Programmers Reference Guide', chapter 4, section 'Bit-Mapped Graphics'.

## 6.2 GEOS icon

The current bitmap working copy is converted to GEOS icon format. A GEOS icon has the same format as a C64 high resolution sprite (24x21, monochrome, 63 bytes). There are no additional attributes for this conversion.

## 6.3 Koala image

## 6.4 Lynx sprite

Lynx can handle 1, 2, 3 and 4 bits per pixel indexed sprites. The maximum size of a sprite is roughly 508 pixels but in reality the Lynx screen is only 160 by 102 pixels which makes very large sprites useless.

The number per pixels is taken from the number of colors of the input bitmap.

There are a few attributes that you can give to the conversion software.

mode

  The first is what kind of encoding to use for the sprite. The attribute for this is called "mode" and the possible values are "literal", "packed" or "transparent". The default is "packed" if no mode is specified.

  The "literal" is a totally literal mode with no packing. In this mode the number of pixels per scanline will be a multiple of 8 both right and left from the action point.

  If the source bitmap edge ends with a color where the least significant bit is one then there will be an extra 8 zero bits on that scan line.

  So if you are using totally literal sprites and intend to change them at runtime then please add a single pixel border far left and far right with zeros in order to prevent graphical glitches in the game.

  The standard encoding is called "packed". In this mode the sprite is packed using run-length encoding and literal coding mixed for optimisation to produce a small sprite.

  The last encoding mode "transparent" is like packed. But here we know that the index 0 will be transparent so we can clip off all 0 pixels from the left and right edge of the sprite. This will produce the smallest sprite possible on the Lynx. The sprite is not rectangular anymore.

ax

  The sprite is painted around the Anchor point. The anchor point x can be between 0 and the width of the sprite - 1. If anchor point x is zero then painting the sprite in location 10,20 will set the left edge of the sprite 10 pixels from the left of the Lynx screen. When the sprite is scaled by hardware the anchor point stays in place and the sprite grows or shrinks around the anchor point. The default value is 0 (left).

ay

  The sprite is painted around the Anchor point. The anchor point y can be between 0 and the height of the sprite - 1. If anchor point y is zero then painting the sprite in location 10,20 will set the top of the sprite 20 pixels from the top of the Lynx screen. When the sprite is scaled by hardware the anchor point stays in place and the sprite grows or shrinks around the anchor point. The default value is 0 (top).

## 6.5 VIC2 sprite

## 7. Output formats

Using `--write` it is possible to write processed data to an output file. An attribute "name" is mandatory, it is used as the file name for the output. The output format can be specified using an attribute named "format". If this attribute doesn't exist, the output format is determined by looking at the file name extension.

## 7.1 Binary

For this format, the processed data is written to the output file in raw binary format. There are no additional attributes (besides "name" and "format") for this output format.

## 7.2 Assembler code

For this format, the processed data is written to the output file in ca65 assembler format. There are several attributes for this output format:

base

  The value for this attribute specifies the numeric base for the data values. It may be either 2, 10 or 16. The default is 16. If the base is 2, the numbers are prefixed by '%', if the base is 16, the numbers are prefixed by '$'. For base 10, there is no prefix.

bytesperline

  The value for this attribute specifies the number of bytes output in one line of the assembler file. The default is 16.

ident

  This is an optional attribute. When given, the output processor will wrap the data into a `.PROC` with the given name. In addition, three constants are added as local symbols within the `.PROC`: `COLORS`, `WIDTH` and `HEIGHT`.

## 7.3 C code

When using C output format, a small piece of C source code is generated that defines the data containing the output in an array of `unsigned char`.

Possible attributes for this format are:

base

  The value for this attribute specifies the numeric base for the data values. It may be either 10 or 16. The default is 16. If the base is 16, the numbers are prefixed by 0x. For base 10, there is no prefix.

bytesperline

  The value for this attribute specifies the number of bytes output in one line of the C source code. The default is 16.

ident

  This is an optional attribute. When given, the output processor will wrap the data into an array of unsigned char with the given name. In addition, three `#define`s are added for `<ident>_COLORS`, `<ident>_WIDTH` and `<ident>_HEIGHT`.

## 8. Copyright

sp65 (and all cc65 binutils) are (C) Copyright 1998-2012 Ullrich von Bassewitz and others. For usage of the binaries and/or sources the following conditions do apply:

This software is provided 'as-is', without any expressed or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.