;
; SYSLIB Module Name:  SMA2HC
; Author:  Richard Conn
; SYSLIB Version Number:  2.0
; Module Version Number:  1.0
; Module Entry Points:
;	MA2HC
; Module External References:
;	EN
;
;
;  MA2HC --
;	STORE REG A AS 2 HEXADECIMAL CHARACTERS IN MEMORY PTED TO BY DE;
; ON INPUT, A=VALUE AND HL=PTR TO 2-BYTE BUFFER
; ON RETURN, DE PTS TO NEXT BYTE AFTER BUFFER
;
	EXT	EN

MA2HC::
	XCHG		; PTR IN HL INSTEAD
	PUSH	PSW	; SAVE A
	PUSH	PSW
	CALL	EN	; EXCHANGE NYBBLES
	CALL	PAHC	; PRINT LOW-ORDER NYBBLE AS HEX
	POP	PSW	; GET A
	CALL	PAHC	; PRINT LOW-ORDER NYBBLE AS HEX
	POP	PSW	; RESTORE A
	XCHG		; POINTER BACK IN DE
	RET
PAHC:	ANI	0FH	; MASK FOR LOW NYBBLE
	CPI	10	; LETTER OR DIGIT?
	JC	PADIG	; DIGIT IF CARRY
	ADI	'A'-10	; CONVERT TO 'A'-'F'
	JMP	PUT	; PUT IN MEMORY
PADIG:	ADI	'0'	; CONVERT TO '0'-'9'
PUT:	MOV	M,A	; CHAR IN MEMORY
	INX	H	; PT TO NEXT LOCATION
	RET

	END
