	.title	idadas
;
; Idadas converts internal date into ASCII date
; call idadas( date, byte(10) )
; 
;
;
	.dsabl	gbl
	.globl	idadmy
	.globl	r5idmy, day, month, year, months, bad

	.psect	user$i
idadas::
	tst	(r5)+

	mov	(r5)+,r5idmy+2		; copy address of date
	mov	r5,-(sp)		; save r5
	mov	#r5idmy,r5

	call	idadmy			; convert to d,m,y
	mov	(sp)+,r5		; restore r5
	mov	(r5)+,r1		; set up o/p pointer
	bcs	30$			; return immediately if error

	mov	day,r0			; number => ascii
	beq	30$
	call	numasc
	movb	#'-,(r1)+		; put in delimiter

	mov	month,r0		; get month
	dec	r0
	asl	r0			; *4
	asl	r0
	add	#months,r0		; table of months
	mov	#4,r2

20$:	movb	(r0)+,(r1)+		; copy month and delimiter
	sob	r2,20$

	mov	year,r0			; copy year
;	add	#72.,r0			; convert to year + 72.
	call	numasc
	clrb	(r1)+			; null terminate
	return

30$:	mov	#bad,r0			;   -Bad-
40$:	movb	(r0)+,(r1)+
	bne	40$
	return

;
; numasc converts number to ASCII
; r0 = number to convert
; r1=>string area
;
;
numasc:
	mov	r5,-(sp)		; save r5

	mov	r0,r3			; number to convert
	cmp	r3,#10.

10$:	mov	#divtab,r4		; divide table

	clr	digit
20$:	tst	@r4			; done ??
	beq	40$
	clr	r2
	div	(r4)+,r2
	bgt	30$
	tst	digit
	beq	20$

30$:	inc	digit
	add	#'0,r2
	movb	r2,(r1)+
	br	20$

40$:	add	#'0,r3
	movb	r3,(r1)+

	mov	(sp)+,r5
	return

	.psect	user$d,d
digit:	.word
divtab:	.word	1000., 100., 10., 0.

	.end
