ùúùú  ¬  ¬  ¬  ¬  ¬  ¬  ¬  ¬  ¬  ¬****************************************************************************
*									   *
*	Convert HEX string to binary.					   *
*									   *
*	Inputs:		a0 = Pointer to string				   *
*	Outputs:	Z = Success/Failure, d1 = Result		   *
*									   *
****************************************************************************
HexStrToBin:
	move.l	a0,a1			; Save pointer in a1
	moveq	#8,d0			; 8 = MaxLength
.Loop1:
	tst.b	(a0)+			; Check for end of string
	dbeq	d0,.Loop1
	bne.b	.Error			; Error if end not found

	moveq	#0,d1			; Clear Result
.Loop:
	move.b	(a1)+,d0		; Get character
	beq.b	.End			; Quit if zero byte

	rol.l	#4,d1			; Rotate Result

	cmp.b	#'0',d0			; Check if ASCII '0'
	blt.b	.Not09
	cmp.b	#'9',d0			; to ASCII '9'
	bgt.b	.Not09

	sub.b	#'0',d0			; Subtract to get hex number
	or.b	d0,d1			; Put the number in the result
	bra.b	.Loop

.Not09:
	bset	#5,d0			; Convert to lowercase

	cmp.b	#'a',d0			; Check if ASCII 'a'
	blt.b	.Error			; to ASCII 'f'
	cmp.b	#'f',d0			; Otherwise the character is not
	bgt.b	.Error			; allowed.

	sub.b	#'f'-$f,d0		; Subtract to get hex number
	or.b	d0,d1			; Put the number to the result
	bra.b	.Loop

.Error:
	moveq	#-1,d0	
.End:
	rts
