;
; alternate 16 bit x/y/zmodem crc routine, smaller and slower
; than normally used table driven macro
;
	page	64,132
	TITLE YAM BIOS/DOS Support Functions for IBM PC,XT,AT
	SUBTTL Copyright 1997 Omen Technology Inc
	name B
; Copyright 1987, 1997 Omen Technology Inc All Rights Reserved
;
;  rev Mar 24 97 caf


	if	lprog
X	equ	6		;offset of arguments
	else
X	equ	4		;offset of arguments
	endif


	if	ldata
Y	equ	2		;extra offset due to long pointer
	else
Y	equ	0
	endif


DGROUP	group _DATA
_DATA	segment	word public 'DATA'
	assume	ds:DGROUP

_DATA	ends

IGROUP	group	_TEXT
_TEXT	segment word public 'CODE'
	assume	cs:_TEXT

	public	_updcrc

;
;
;
;	unsigned updcrc(char, oldcrc)
;
;	At start of packet, oldcrc is set to initial value
;		oldcrc=0;
;
;	crc is accumulated by:
;		oldcrc=updcrc(char, oldcrc);
;
;	at end of packet,
;		oldcrc=updcrc(0,updcrc(0,oldcrc));
;		send(oldcrc>>8); send(oldcrc);
;
;	on receive, the return value of updcrc is checked after the
;	last call (with the second CRC byte); 0 indicates no error detected
;
	if lprog
_updcrc	proc	far
	else
_updcrc	proc	near
	endif
	push	bp		; save frame pointer
	mov	bp,sp		; stack pointer to frame pointer
	mov	ax,[bp+X]	; get char
	mov	bx,[bp+2+X]	; get oldcrc
	mov	cx,8		; The generator is X^16 + X^12 + X^5 + 1
updloop:			; as recommended by CCITT.
	rol	al,1            ; An alternate generator which is often
	rcl	bx,1            ; used in synchronous transmission protocols
	jnb	skipit          ; is X^16 + X^15 + X^2 + 1. This may be
				; used by substituting XOR 8005H for
	xor	bx,1021H	; XOR 1021H in the adjacent code.
skipit:	loop	updloop
	mov	ax,bx		; mov to accumulator for return
	pop	bp
	ret			; return with latest crc in ax
_updcrc	endp


_TEXT	ends
	end
