; 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