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):
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.