; TimeConvA.asm  --  assembly-language code for time conversion package
; Copyright Xerox Corporation 1979

;	Last modified December 15, 1977  5:47 PM

; Outgoing procedures
.ent TimeDiv, TimeMul

; Outgoing statics
.ent monthTable

.srel

TimeDiv: .TimeDiv
TimeMul: .TimeMul
monthTable: .monthTable

.nrel


; TimeDiv(lvDividend, divisor, lvQuotient) = remainder
; Performs unsigned division of 32-bit number at @lvDividend by
; 16-bit divisor.  Puts the 32-bit quotient in @lvQuotient and
; returns the remainder.

.TimeDiv:
	sta 3 1 2
	sta 0 2 2		; Save lvDividend
	mov 2 3			; Preserve frame pointer
	mov 1 2			; Divisor
	mkzero 0 0		; High dividend ← 0
	lda 1 @2 3		; Low dividend ← lvDividend!0
	div			; Ac0←remainder, ac1←quotient
	 #77400
	sta 1 @3 3		; lvQuotient!0 ← quotient
	isz 2 3
	isz 3 3
	lda 1 @2 3		; Low dividend ← lvDividend!1
	div			; Ac0←remainder, ac1←quotient
	 #77400
	sta 1 @3 3		; lvQuotient!1 ← quotient
	mov 3 2
	lda 3 1 2
	jmp 1 3			; Return remainder in ac0


; TimeMul(addend, multiplier, lvMultiplicand)
; Multiplies the 32-bit number at @lvMultiplicand by the 16-bit multiplier,
; then adds the 16-bit addend, and puts the result back into @lvMultiplicand.

.TimeMul:
	sta 3 1 2
	mov 2 3			; Preserve frame
	mov 1 2			; Multiplier
	isz 3 3
	lda 1 @3 3		; lvMultiplicand!1
	mul			; (ac0,ac1) ← ac1*ac2 + ac0
	sta 1 @3 3		; lvMultiplicand!1 ← low product
	dsz 3 3
	lda 1 @3 3		; lvMultiplicand!0
	mul			; (ac0,ac1) ← ac1*ac2 + ac0
	sta 1 @3 3		; lvMultiplicand!0 ← high product
	mov 3 2
	lda 3 1 2
	jmp 1 3



; monthTable!i is the number of days preceding the first day of month i.
; It is assumed that this is a leap year (i.e., Feb 29 exists).

.monthTable:
	0
	31.
	60.
	91.
	121.
	152.
	182.
	213.
	244.
	274.
	305.
	335.
	366.

.end