; routine: bcd2jul and bin2jul ; author: Bridger Mitchell & Howard Goldstein ; date: 4/16/1988 ; BCD to Julian date routine. ; >> hl-> DateStamper bcd yr/mo/da string ; << hl = Julian date (78/01/01 == 1) ; (if yr<78 this routine wraps to next century. routine covers ; 1978/01/01-2077/12/31) ; entry bcd2jul ; extrn jbcd2bn,dpermo ; cseg bcd2jul: push af push bc push hl ld b,3 ;convert bcd yr/mo/da to bin binlp: ld a,(hl) ;at hl... call jbcd2bn ld (hl),a inc hl djnz binlp pop hl pop bc pop af ; fall thru... ; ; ; Binary to Julian Date routine. ; ; >> hl -> yr,mo,da in bin ; << hl = Julian date ; entry bin2jul ; bin2jul: push af push bc push de ld a,(hl) ;a = yr inc hl ld c,(hl) ;c = mo inc hl push hl ;save ptr to day push af ;save year ; ; set hl= initial julian value of 77/12/31 ; ld hl,0 sub 78 jr z,b2jul3 jr nc,b2jul0 add a,100 ;<78, assume next century b2jul0: ld b,a ;b = # yrs > 78 ld a,1 ;init modulo 4 counter ld de,365 ;days/yr b2jul1: add hl,de ;calc julian val. of (yr/01/01 - 1) inc a and 3 ;every 4 yrs, jr nz,b2jul2 inc hl ;..add 1 for leap year b2jul2: djnz b2jul1 ; ; hl now = # days in years before current year ; b2jul3: pop af and 3 ;if current yr == leap year jr nz,b2jul5 ld a,c cp 3 ;..and mo >= march jr c,b2jul5 inc hl ;..add the extra day (Feb 29) ; b2jul5: ld b,c ; b = month = # months +1 to sum ld de,dpermo ;point at table jr b2jul7 ; b2jul6: call addhl ;add # days in this month inc de ;bump tbl ptr b2jul7: djnz b2jul6 ; pop de ;ptr to day call addhl pop de pop bc pop af ret addhl: ld a,(de) ;add day of current month ; adda2hl:add l ld l,a ret nc inc h ret end