	.title	bday
;
; call bday( date, date-1 )
; 
	.dsabl	gbl
	.globl	idadmy, dmyida, leap
	.globl	r5idmy, r5dmyi, day, month, year, tbnday

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

	mov	(r5)+,r5idmy+2		; copy 1st date address
	mov	(r5)+,r5dmyi+8.		; copy 2nd date address
	mov	#r5idmy,r5
	call	idadmy			; convert to day, month, year

; decrease day
	dec	day			; dec day
	bgt	60$			; br, if > 0

	cmp	month,#3		; march ??
	beq	40$			; yep, special

;month backwards
	dec	month			; dec month
	ble	30$			; br, if less than 0

20$:	mov	month,r1		; get max days for previous month
	dec	r1
	asl	r1
	mov	tbnday(r1),day		; set days to max for this month
	br	60$

; year backwards
30$:	mov	#12.,month		; set month 12
	dec	year			; dec year
	br	20$			; and set day

40$:	mov	#2,month		; must be feb, whether or not leap
	mov	year,r4
	call	leap			; leap year ??
	bcc	50$			; br, if false
	mov	#29.,day		; set day and month to 29/2
	br	60$

50$:	mov	#28.,day		; set day and month to 28/2

60$:	mov	#r5dmyi,r5
	call	dmyida			; convert day month year to internal

	return

	.end
