
; -----------------------------------------------------------------------------
;			       AsciiHexToBinary
; -----------------------------------------------------------------------------
; DESCRIPTION:	This subroutine converts an ASCII hex digit in the accumulator
;		to its binary equivalent.  It returns with the carry bit
;		cleared on success, or set if the input was not a valid hex
;		digit.
;
; NOTE:		As written, accepts only upper-case hex digits.  Uncomment the
;		ANL instruction if you want to accept lower-case digits also.
;
; REVISIONS:	29 Jun 07 - RAC - Genesis
; -----------------------------------------------------------------------------

AsciiHexToBinary:
	add	a,#256-'0'		; Convert 0-9
	jnc	FixCarry		; Result < 0 - bad input
	cjne	a,#10,$+3		; Result >= 10?
	jc	FixCarry		; No - we're done
;	anl	a,#NOT 20h		; Yes - convert to upper case
	subb	a,#7			; Convert A-F
	cjne	a,#10,$+3		; Is result < 10?
	jc	CarryOk			; Yes - that's bad
	cjne	a,#16,$+3		; No - check for result >= 16
FixCarry:
	cpl	c			; Fix the carry bit
CarryOk:
	ret				; Return
