;; **** DEBUG MACRO LIBRARY ****
;;	Routines	Length (Bytes)
;;	EXIT		275, 263+ (if argument specified)
;;	PRINT		19+
;;	PRINTC		17+
;;	REGS		241

	IF1
	.PRINTX ! DEBUG MACRO Library Included !
	ENDIF


;; PRINT -- PRINT STRING IN ARGUMENT LIST
;;	E.G., PRINT <THIS IS A TEST>
;;	STRING IS FOLLOWED BY A <CR> <LF>
PRINT	MACRO	TEXT
	LOCAL	PRNT,STR
	JMP	PRNT
STR:	DB	'&TEXT'
	DB	0DH,0AH,'$'
PRNT:	PUSH	PSW
	PUSH	B
	PUSH	D
	PUSH	H
	MVI	C,9
	LXI	D,STR
	CALL	5
	POP	H
	POP	D
	POP	B
	POP	PSW

	ENDM

;; PRINTC -- PRINT CHARS IN ARGUMENT LIST
;;	E.G., PRINTC <'THIS IS A TEST',0DH,0AH>
;;	CHARS ARE NOT FOLLOWED BY A <CR> <LF>
PRINTC	MACRO	TEXT
	LOCAL	PRNT,STR
	JMP	PRNT
STR:	DB	TEXT
	DB	'$'
PRNT:	PUSH	PSW
	PUSH	B
	PUSH	D
	PUSH	H
	MVI	C,9
	LXI	D,STR
	CALL	5
	POP	H
	POP	D
	POP	B
	POP	PSW

	ENDM

;; REGS -- PRINT VALUES OF ALL REGISTERS ON ONE LINE
REGS	MACRO
	LOCAL	PRNTA,PRNTA0,PRNTA1,REGS1
	JMP	REGS1
PRNTA:	PUSH	PSW
	PUSH	B
	PUSH	D
	PUSH	H
	PUSH	PSW	; SAVE A
	RLC		; EXCHANGE NYBBLES
	RLC
	RLC
	RLC
	CALL	PRNTA0	; PRINT HIGH NYBBLE OF A AS HEX
	POP	PSW	; GET A
	CALL	PRNTA0	; PRINT LOW NYBBLE OF A AS HEX
	MVI	E,' '	; PRINT <SP>
	MVI	C,2
	CALL	5
	POP	H
	POP	D
	POP	B
	POP	PSW
	RET
PRNTA0:	ANI	0FH	; LOW-ORDER NYBBLE FIRST
	ADI	'0'	; CONVERT TO ASCII
	CPI	'9'+1	; A-F?
	JC	PRNTA1
	ADI	7	; CONVERT TO A-F
PRNTA1:	MOV	E,A	; CHAR IN E
	MVI	C,2	; PRINT
	CALL	5
	RET
REGS1:	PUSH	B	; SAVE BC
	PUSH	PSW	; SAVE A
	POP	B	; GET OLD PSW IN BC
	PUSH	B	; PLACE BACK ON STACK
	PRINTC	<'A= '>
	MOV	A,B	; HIGH FIRST
	CALL	PRNTA
	PRINTC	<'  Flags= '>
	MOV	A,C	; LOW
	CALL	PRNTA
	PRINTC	<'  BC= '>
	POP	PSW	; RESTORE A
	POP	B	; RESTORE BC
	PUSH	PSW	; SAVE A
	MOV	A,B
	CALL	PRNTA
	MOV	A,C
	CALL	PRNTA
	PRINTC	<'  DE= '>
	MOV	A,D
	CALL	PRNTA
	MOV	A,E
	CALL	PRNTA
	PRINTC	<'  HL= '>
	MOV	A,H
	CALL	PRNTA
	MOV	A,L
	CALL	PRNTA
	PRINTC	<0DH,0AH>
	POP	PSW	; RESTORE A

	ENDM

;; EXIT -- PRINT REGISTER VALUES AND RETURN TO CP/M
;;   OPTIONAL MESSAGE MAY BE PRINTED
EXIT	MACRO	MESSAGE
	IFB	<MESSAGE>
	PRINT	<Exit to CP/M>
	ELSE
	PRINT	<MESSAGE>
	ENDIF
	REGS
	JMP	0	; RETURN TO CP/M

	ENDM

