FreeBSD/sys/boot/arm/at91/libat91/xmodem.c
/*
 * int GetRecord(char , char *)
 *  This private function receives a x-modem record to the pointer and
 * returns non-zero on success.
 */
int GetRecord(char , char *)
This private function receives a x-modem record to the pointer and
returns non-zero on success.
int GetRecord ( char char * ) This private function receives a x - modem record to the pointer and returns non - zero on success .
static int
GetRecord(char blocknum, char *dest)
{
	int		size;
	int		ch;
	unsigned	chk, j;
	chk = 0;
	if ((ch = getc(TO)) == -1)
		goto err;
	if (ch != blocknum) 
		goto err;
	if ((ch = getc(TO)) == -1) 
		goto err;
	if (ch != (~blocknum & 0xff))
		goto err;
	for (size = 0; size < PACKET_SIZE; ++size) {
		if ((ch = getc(TO)) == -1)
			goto err;
		chk = chk ^ ch << 8;
		for (j = 0; j < 8; ++j) {
			if (chk & 0x8000)
				chk = chk << 1 ^ 0x1021;
			else
				chk = chk << 1;
		}
		*dest++ = ch;
	}
	chk &= 0xFFFF;
	if (((ch = getc(TO)) == -1) || ((ch & 0xff) != ((chk >> 8) & 0xFF)))
		goto err;
	if (((ch = getc(TO)) == -1) || ((ch & 0xff) != (chk & 0xFF)))
		goto err;
	putchar(ACK);
	return (1);
err:;
	putchar(CAN);
	return (0);
}
static int GetRecord ( char blocknum , char * dest ) { int size ; int ch ; unsigned chk , j ; chk = 0 ; if ( ( ch = getc ( TO ) ) == -1 ) goto err ; if ( ch != blocknum ) goto err ; if ( ( ch = getc ( TO ) ) == -1 ) goto err ; if ( ch != ( ~ blocknum & 0xff ) ) goto err ; for ( size = 0 ; size < PACKET_SIZE ; ++ size ) { if ( ( ch = getc ( TO ) ) == -1 ) goto err ; chk = chk ^ ch << 8 ; for ( j = 0 ; j < 8 ; ++ j ) { if ( chk & 0x8000 ) chk = chk << 1 ^ 0x1021 ; else chk = chk << 1 ; } * dest ++ = ch ; } chk &= 0xFFFF ; if ( ( ( ch = getc ( TO ) ) == -1 ) || ( ( ch & 0xff ) != ( ( chk >> 8 ) & 0xFF ) ) ) goto err ; if ( ( ( ch = getc ( TO ) ) == -1 ) || ( ( ch & 0xff ) != ( chk & 0xFF ) ) ) goto err ; putchar ( ACK ) ; return ( 1 ) ; err : ; putchar ( CAN ) ; return ( 0 ) ; }
int GetRecord(char , char *)
  This private function receives a x-modem record to the pointer and
 returns non-zero on success.
int GetRecord ( char char * ) This private function receives a x - modem record to the pointer and returns non - zero on success .
// We should allow for resend, but we don't.