title MSDOS 2.00 Function Library for Lattice C
include mc.ash
.model small
;;
;;	FILE:	_PARITY.ASM
;;
;;FUNCTION:	Compute the parity for a 
;;	character, install in bit 7.
;;
;;
;;CALL:
;;	c= _parity(c,parflg)
;;	char c;
;;	int parflg;
;;
;;	Parflg:	0	no parity
;;		1	odd parity
;;		2	even parity
;;		3	zero parity
;;		4	mark parity
;;
;;RETURN:	Character with correct
;;	parity in C. If no parity is selected,
;;	then C is untouched, otherwise the 
;;	calulated parity replaces bit 7. (Bits
;;	0 - 6 are used in calculation.)
;;
;;
;;CAUTIONS:	parflg is masked wiht 0x03.
;;		the upper bits of C are left
;;		intact.
;;
;;
;;ASSUMPTIONS:
;;
;;LONG	32 bits (4 bytes)
;;INT	16 bits (2 bytes)
;;CHAR	 8 bits (1 byte)
;;

.code
;
;Jump table for parity types.
;
partbl label word
	dw	none		;0 
	dw	odd		;1 
	dw	evn		;2 
	dw	zero		;3
	dw	mark		;4
	dw	none		;5 illegal
	dw	none		;6
	dw	none		;7

func _parity 
	mov	ax,arg0		;AL == char,
	mov	ah,0
	mov	bx,arg1		;BX == type
	and	bx,7		;bound it,
	shl	bx,1		;word ptr,
	jmp	word ptr cs:partbl[bx]

zero:	and	al,7fh
	jmp	none

mark:	or	al,80h
	jmp	none

odd:	and	al,7fh		;strip and test
	jpo	none		;if odd, exit,
	or	al,80h		;else set bit,
	jmp	none

evn:	and	al,7fh		;strip/test,
	jpe	none		;OK if even,
	or	al,80h		;else make odd,
	jmp	none

none:

endf _parity 

	end

