Spectrum 512 file format

From Atari Wiki
Jump to navigation Jump to search
Spectrum 512    *.SPU

80 words        first scan line of picture (unused) -- should be zeroes
15920 words     picture data (screen memory) for scan lines 1 through 199
9552 words      3 palettes for each scan line (the top scan line is
                not included because Spectrum 512 can't display it)
-----------
51104 bytes     total

Note that the Spectrum 512 mode's three palette changes per scan
line allow more colors on the screen than normally possible, but a
tremendous amount of CPU time is required to maintain the image.

The Spectrum format specifies a palette of 48 colors for each scan line.
To decode a Spectrum picture, one must be know which of these 48 colors
are in effect for a given horizontal pixel position.

Given an x-coordinate (from 0 to 319) and a color index (from 0 to 15),
the following C function will return the proper index into the Spectrum
palette (from 0 to 47):

/*
 *  Given an x-coordinate and a color index, returns the corresponding
 *  Spectrum palette index.
 *
 *  by Steve Belczyk; placed in the public domain December, 1990.
 */
int 
FindIndex(x, c)
	int x, c;
{
	int x1;

	x1 = 10 * c;

	if (1 & c)		/* If c is odd */
		x1 = x1 - 5;
	else			/* If c is even */
		x1 = x1 + 1;

	if (x >= x1 && x < x1 + 160) 
		c = c + 16;
	else if (x >= x1 + 160) 
		c = c + 32;

	return c;
}

Back to ST Picture Formats