;
; SYSLIB Module Name:  SLADC
; Author:  Richard Conn
; SYSLIB Version Number:  2.0
; Module Version Number:  1.0
; Module Entry Points:
;	LA3DC		LADC
; Module External References:
;	LOUT
;

;
;  LA3DC --
;	PRINT REG A AS 3 DECIMAL CHARACTERS ON LST:
;
	EXT	LOUT

LA3DC::
	PUSH	PSW	; SAVE A
	PUSH	PSW
	XRA	A	; TURN OFF LEADING <SP> FLAG
	STA	LSFLG
	JMP	PADC1
;
;  LADC --
;	PRINT REG A AS DECIMAL CHARACTERS W/LEADING SP IN 3-CHAR FIELD ON LST:
;
LADC::
	PUSH	PSW	; SAVE A
	PUSH	PSW
	MVI	A,1	; TURN ON LEADING <SP> FLAG
	STA	LSFLG
;  PRINT ROUTINE
PADC1:	POP	PSW	; GET A
	PUSH	B	; SAVE BC
	MVI	B,100	; PRINT HUNDREDS
	CALL	PAC	; PRINT A CHAR
	MVI	B,10	; PRINT TENS
	CALL	PAC
	ADI	'0'	; CONVERT TO ASCII
	CALL	LOUT	; PRINT
	POP	B	; RESTORE BC
	POP	PSW	; RESTORE A
	RET

;  BUFFER
LSFLG:	DS	1	; LEADING <SP> FLAG

;  PRINT RESULT OF DIVISION OF A BY B W/LEADING <SP> (INTEGER DIVISION)
PAC:	MVI	C,0	; SET COUNT
PACL:	SUB	B	; COMPUTE COUNT
	JC	PACD
	INR	C	; INCR COUNT
	JMP	PACL
PACD:	ADD	B	; ADD B BACK IN
	PUSH	PSW	; SAVE A
	MOV	A,C	; GET COUNT
	ORA	A	; ZERO?
	JNZ	PACD1
	LDA	LSFLG	; CHECK FOR LEADING <SP>
	ORA	A	; 0 MEANS NO
	JZ	PACD1
	MVI	A,' '	; PRINT <SP>
	CALL	LOUT
	POP	PSW	; RESTORE A
	RET
PACD1:	XRA	A	; A=0
	STA	LSFLG	; TURN OFF LEADING <SP> FLAG
	MOV	A,C	; GET COUNT
	ADI	'0'	; CONVERT TO DECIMAL
	CALL	LOUT	; PRINT IT
	POP	PSW	; RESTORE A
	RET

	END
