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

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

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

	mov	month,r1		; get max days for current month
	dec	r1
	asl	r1
	mov	tbnday(r1),r1		; r1 = max days for this month

; bump day
	inc	day			; bump day
	cmp	day,r1			; less than max ??
	ble	50$			; then nothing else to do

	cmp	month,#2		; feb ??
	beq	20$			; yep, special

;month roll over
	mov	#1,day			; set day to 1
	inc	month			; bump month....
	cmp	month,#12.		; end of year ??
	ble	50$			; br, if false

; year roll over
	mov	#1,month		; set month to 1
	inc	year			; bump year
	br	50$

20$:	mov	year,r4
	call	leap			; leap year ?
	bcs	40$			; br, if true so 29/2 is valid
30$:	mov	#1,day			; non leap year, set 1/3
	mov	#3,month
	br	50$

40$:	cmp	day,#29.		; but was it a leap day already ??
	bgt	30$

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

	.end
