sp65 Users Guide
1. Overview
sp65 is a tool that converts images from common formats into the Atari Lynx sprite format used by this fork 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 is structured so that adding source or target formats is easy; upstream cc65 ships several other target converters, but this Lynx fork keeps only the Lynx sprite converter. 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 --sprite-sheet attrlist Slice a grid of frames into a sprite-sheet header --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.
--slice x,y,w,h-
Replace the working bitmap with a rectangular sub-image of it: the slice starts at pixel
x,y(top-left origin) and iswwide andhtall. Convert and write the slice as usual, then use--popto restore the full image before the next slice. This is the building block for cutting individual frames out of a sprite sheet by hand. --sprite-sheet attrlist-
Slice the loaded image into a regular grid of equal-sized frames, encode each frame as a standalone Lynx sprite, and write one header containing all frames plus an indexable table of pointers to them. This automates the
--slice/--popchain. See Sprite sheets for the attribute list and an example. -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 (the format attribute), or are
determined by looking at the extension of the file name given. The reader
machinery is table driven so more formats can be added, but at present
PCX is the only input format the tool actually implements.
5.1. PCX
PCX is recognised by the .pcx extension (upper or lower case) or by
giving format=pcx explicitly. There are no additional attributes for
this format. The reader accepts the following PCX variants and rejects
anything else with an error:
| Planes × bits | Interpretation | Palette source |
|---|---|---|
| 1 plane × 1 bpp | Monochrome; pixel becomes index 0 or 1 | Built-in monochrome palette |
| 1 plane × 8 bpp | Indexed (up to 256 entries) | 16-colour palette in the header, or a 256-colour palette appended after the pixel data |
| 3 planes × 8 bpp | Truecolour RGB | None (direct colour) |
| 4 planes × 8 bpp | Truecolour RGBA (rarely seen) | None (direct colour); 4th plane is alpha |
Both uncompressed and PCX run-length-encoded (RLE) pixel data are read; the
two-bit compression field is the only one understood, any other value is an
error. For the common indexed (8 bpp, one plane) case the palette is taken
either from a 256-colour block appended to the file (preceded by the
0x0C marker byte) or, for images using no more than 16 colours, from
the 16-colour palette stored in the header. An indexed file that uses more than
16 distinct indices but carries no appended palette is rejected. Run
sp65 -v … to have the PCX header (version, geometry, plane
layout, compression) dumped while reading.
For the Lynx the practical path is a one-plane, 8 bpp indexed PCX whose pixel indices are the Lynx pen values: the Lynx sprite converter derives the sprite's bit depth straight from the highest index actually used (see below), so keep the index range tight (0–1 for 1 bpp, up to 0–15 for 4 bpp).
6. Conversions
This fork targets the Atari Lynx only, so the Lynx sprite converter is the sole conversion provided. (The generic raw output is also available for writing the loaded bitmap straight out as bytes.)
6.1. 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. This tool produces the pixel data a sprite points at; the sprite control block that references it, and how the hardware paints it, are covered on the Sprites reference page.
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
-
Selects the scan-line encoding for the sprite. The possible values are
literal,packedandshaped. If the attribute is omitted the mode isauto, which currently produces the same output asliteral. See the diagram below for how the two on-cart layouts differ.literalis a totally literal mode with no packing: each scan line stores its pen indices back to back, padded up to whole bytes. If a scan line ends on a pen value whose least significant bit is one, an extra byte is emitted so Suzy's last-pixel hardware bug does not drop the final pixel. If you intend to change literal sprites at runtime, add a one-pixel border of pen 0 at the far left and far right to avoid edge glitches.packedpacks each scan line with run-length encoding and literal runs mixed for the smaller of the two on a per-run basis, producing a compact sprite. This is the encoding the runtime packer inpacktest.cand the build-timespritetest.csample exercise.shapedis likepacked, but the pen index named by theedgeattribute is treated as transparent, so trailing edge pixels are clipped from each line. This produces the smallest sprite possible on the Lynx; the sprite is no longer rectangular. - edge
-
The pen index treated as the transparent edge colour in
shapedmode. Pixels equal to this index that trail the last opaque pixel on a scan line are clipped away. The default is 0. The attribute has no effect in the other modes. - 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).
Both literal and packed store the sprite one scan line
at a time, each line introduced by a byte count (its own length + 1; a count of
1 advances to the next quadrant and 0 ends the sprite). What differs is how the
pen indices inside a line are laid down:
packed chooses run vs literal coding run by run.To generate a packed sprite as a build-time asset (rather than packing at
runtime), point sp65 at an indexed PCX and ask for the packed
mode:
sp65 -r heart.pcx -c lynx-sprite,mode=packed -w heart.h,ident=heart
This emits a C header with a const unsigned char heart[] data
block ready to drop into an SCB's data pointer. The
spritetest sample does exactly this and draws the result
next to the same image in literal mode; packtest is the
runtime-packing counterpart.
6.2. Sprite sheets
A sprite sheet is one image that holds many frames — animation cels, tile variants, a set of glyphs — laid out on a regular grid. It is far more convenient to author than one file per frame: a single palette, frames guaranteed pixel-aligned, one thing to edit.
On the Lynx the frames cannot stay packed together at run time. Suzy sprite
data is a linked list of variable-length scan lines with no constant row stride,
and an SCB's data pointer addresses one whole sprite (terminated by
a zero offset byte). There is no way to point Suzy at a sub-rectangle of a larger
encoded blob, so each frame must be encoded as its own complete
sprite. The sheet is therefore unpacked at build time; the
design rationale is in design/LYNX_SPRITE_SHEET_DESIGN.md.
There are two ways to do that unpacking, and they produce byte-for-byte identical frame data.
The manual route uses --slice
to cut each cell and --pop to restore the
full image between cells, all in one run:
sp65 -r sheet.pcx \
--slice 0,0,16,16 -c lynx-sprite,mode=packed -w frame0.h,format=c,ident=frame0 --pop \
--slice 16,0,16,16 -c lynx-sprite,mode=packed -w frame1.h,format=c,ident=frame1 --pop \
--slice 32,0,16,16 -c lynx-sprite,mode=packed -w frame2.h,format=c,ident=frame2 --pop \
--slice 48,0,16,16 -c lynx-sprite,mode=packed -w frame3.h,format=c,ident=frame3
This needs no special tooling, but produces one standalone
const unsigned char frameN[] per cell, so the program must gather
them into its own table and track the count. The spriteslice
sample does exactly this.
The driver route folds the whole grid into one
--sprite-sheet call:
sp65 -r sheet.pcx --sprite-sheet name=sheet_anim.h,ident=sheet_anim,fw=16,fh=16,mode=packed
That writes a single header with the concatenated frame data and a ready-made table:
#define sheet_anim_COUNT 4
#define sheet_anim_WIDTH 16
#define sheet_anim_HEIGHT 16
const unsigned char sheet_anim_data[] = { /* frame 0..3, back to back */ };
const unsigned char* const sheet_anim[sheet_anim_COUNT] = {
sheet_anim_data + 0, sheet_anim_data + 68, /* ... */
};
Drawing frame i is then just
scb.data = (unsigned char *)sheet_anim[i]. The frame data is
byte-for-byte what the manual chain produces; the only added bytes are the
pointer table itself. The spritesheet sample animates
the same four-frame ball this way.
The attributes accepted by --sprite-sheet are:
- fw, fh
-
Frame cell width and height in pixels. Both are required and must be non-zero.
- cols, rows
-
Grid dimensions. If omitted they are derived from the image size, the cell size, and any
gap/margin. - first, count
-
Select a contiguous sub-range of cells in row-major order, so one sheet can hold several animations.
firstdefaults to 0 andcountto all remaining cells. - gap, margin
-
Pixels between adjacent cells (
gap) and around the whole grid (margin). Both default to 0. - mode, ax, ay, edge
-
Passed through to the sprite encoder for every frame exactly as for a single sprite. The
ax,ayaction point is interpreted in cell-local coordinates and applied to every frame. - name, format, ident
-
Output file
name(required), outputformat(corasm; auto-detected from the file extension if omitted), and theidentsymbol used for the frame table and the_COUNT/_WIDTH/_HEIGHT/_COLORSdefines (required). - bytesperline, base
-
Formatting of the emitted data, as for the C and assembler writers.
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
.PROCwith the given name. In addition, three constants are added as local symbols within the.PROC:COLORS,WIDTHandHEIGHT.
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
#defines are added for<ident>_COLORS,<ident>_WIDTHand<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:
The full license text is reproduced verbatim, together with every other copyright notice in the distribution, on the consolidated Licenses and copyright notices page.