PDC Live

Cyclic Redundancy Check

All bytes sent by Teletext (except packet 26 and the CRC itself) are individually error protected in one of two ways: either by hamming, which detects all 2-bit errors and corrects 1-bit errors, or by a simple odd parity check that detects 1-bit errors. In addition to this, a whole page of displayable data is protected by a 16-bit checksum stored in the last two bytes of packet 27/0, MSB first. The first 37 bytes of this packet are used for the first block of Fastext link information.

The method for calculating the checksum is straightforward. A complete page is assembled in memory as it would be for display. This means that the rows which were transmitted are rearranged in to the right order, and any rows which weren't transmitted are filled with spaces. Then the checksum is initialised to zero, and all the bytes to be summed are fed a byte at a time through a function which mixes their bits in with the evolving checksum. The bytes sent through the function are (in order):

Note that if any packet wasn't received as part of the page, it is assumed to be full of spaces (byte 0x20). The bit-mixer is coded in C as follows:
    unsigned short crc_one_byte(unsigned short c, unsigned char b)
    {
	unsigned char a=b ^ c>>8 ^ c>>4 ^ c>>1 ^ c<<1;
	return c<<8 | a ^ a>>7;
    } 
This code takes the current checksum c and the new byte b and returns the new checksum. It depends on sizeof(unsigned char) being 1 byte and sizeof(unsigned short) being 2 bytes.

This information was obtained by trial and error and from extensive study of the Acorn Advanced Teletext System ROM. If my analysis proves incorrect or incomplete, or if you should happen to have proper documentation on how this is supposed to work, please let me know.


This page was created on 10 October 1996. It was last updated 29 November 1996.
Please send comments to Robin O'Leary pdc at ro dot nu
Copyright (C)1996--2004 Robin O'Leary. All rights reserved.