;************************************************************************ ; File DATIME.INC ver 28 Oct 84 * ;************************************************************************ ; * ; DATE1: Routine to insert date in format mm/dd/yy into buffer at HL * ; * ;************************************************************************ DATE1: CALL GET_CLOCK PUSH HL LD HL,(DATEPB) ;get days since 1/1/78 CALL CNVDAY ;convert to month,day, year POP HL LD A,(MONTHS) CALL PUTBCD LD (HL),'/' INC HL LD A,(DAYS) CALL PUTBCD LD (HL),'/' INC HL LD A,(YEARS) CALL PUTBCD RET ;************************************************************************ ; * ; DATE2: Routine to insert date in format dd mmm yy into buffer at HL * ; * ;************************************************************************ DATE2: CALL GET_CLOCK PUSH HL LD HL,(DATEPB) ;get days since 1/1/78 CALL CNVDAY ;convert to month,day, year POP HL LD A,(DAYS) CALL PUTBCD LD (HL),' ' INC HL PUSH HL LD A,(MONTHS) AND 10H ;see if greater than 9 LD A,(MONTHS) JR Z,DAT_J1 AND 0FH ;get lower tens digit ADD A,10 ;and add ten to it DAT_J1: DEC A ;make it an offset LD B,A ;multiply by three SLA A ;and do a table lookup ADD A,B ;into the month string LD D,0 ;table LD E,A LD HL,MONTAB ADD HL,DE POP DE ;output buffer address LD BC,3 LDIR EX DE,HL ;get output buffer addr in HL LD (HL),' ' INC HL LD A,(YEARS) CALL PUTBCD RET MONTAB: DB 'JanFebMarAprMayJunJulAugSepOctNovDec' ;************************************************************************ ; * ; HHMMSS: Routine to insert time in format hh:mm:ss into buffer at HL * ; * ;************************************************************************ HHMMSS: CALL GET_CLOCK LD DE,DATEPB+2 ;point to hours byte LD (DATEPB+4),A ;put seconds in date parm block LD B,2 TIME1: LD A,(DE) INC DE CALL PUTBCD ;insert hh:mm: LD (HL),':' INC HL DJNZ TIME1 LD A,(DE) CALL PUTBCD ;insert seconds RET PAGE ;************************************************************************ ; * ; HHMM: Routine to insert time in format hh:mm into buffer at HL * ; * ;************************************************************************ HHMM: CALL GET_CLOCK LD DE,DATEPB+2 ;point to hours byte LD A,(DE) INC DE CALL PUTBCD ;insert hours LD (HL),':' INC HL LD A,(DE) CALL PUTBCD ;insert minutes RET ;************************************************************************ ; Routine to convert a BCD byte into two ascii characters at HL * ;************************************************************************ PUTBCD: PUSH AF RRCA RRCA RRCA RRCA ;get high nibble CALL PUTNIB POP AF ;now low nibble CALL PUTNIB RET ; make ascii & put into buffer PUTNIB: ;make ascii & put into buffer AND 0FH OR '0' LD (HL),A INC HL ;next buffer location RET PAGE ;************************************************************************ ; * ; Routine to get date and time from cp/m+ in bdos format * ; * ;************************************************************************ GET_CLOCK: PUSH HL ; ; this bios call is needed because the bdos rdtime ; function doesn't call bios to update the clock data ; in the scb ; LD C,DRBIOS ;direct bios call LD DE,BIOSPB ;read time function CALL BDOS LD C,RDTIME ;get date/time LD DE,DATEPB ;where to put date CALL BDOS POP HL RET BIOSPB: DB 26 ;time function DB 0 ;value for A DATEPB: DS 5 ;date parameter block ;************************************************************************ ; * ; CNVDAY - Routine to convert cp/m or mp/m date from days since * ; 1/1/78 to month, day, and year in 3 BCD bytes. * ; * ;************************************************************************ YEAR EQU 365 ;leap year gets adjusted for ; ; count up until goal days exceeded ; CNVDAY: LD (GOALDAYS),HL ;save as goal to reach LD A,1 ;initial values LD (DAYS),A LD (MONTHS),A ;month counter (jan is one) LD HL,0 LD (DAYSCNT),HL ;start at zero LD DE,YEAR ;one year of days LD A,78H ;the first year (bcd) LD (YEARS),A ;save year value ; ; it's much eaiser to detect leap years in binary ; LD A,78 ;1st year (binary) LD (YEARS_BIN),A ;for leap year determination YEARLOOP: LD HL,(DAYSCNT) ADD HL,DE ;trial add one year of days CALL CKLEAP JR NZ,NO_LEAP INC HL ;was a leap year NO_LEAP: CALL CKGOAL JP NC,YEARDONE ;year over flowed LD A,(YEARS) CCF ;daa screws up if carry is set INC A ;add one to the year count DAA ;make bcd LD (YEARS),A ;save years JP Z,DONE ;exact match LD (DAYSCNT),HL ;year was ok to add LD HL,YEARS_BIN INC (HL) JR YEARLOOP ; YEARDONE: ; ; see if this is a leap year and adjust Feb if required ; CALL CKLEAP LD HL,FEB ;point to feburary LD (HL),28 JR NZ,NOT_LEAP ;no, don't adjust feb INC (HL) ;make 29 NOT_LEAP: LD DE,MONTBL ;point to month table MONTHLOOP: LD HL,(DAYSCNT) LD A,(DE) ;get month LD C,A LD B,0 ADD HL,BC CALL CKGOAL JP NC,MONTHDONE PUSH AF CCF LD A,(MONTHS) INC A ;count to next month DAA LD (MONTHS),A POP AF JR Z,DONE ;exact (on the first of the month) LD (DAYSCNT),HL INC DE ;point to next month JR MONTHLOOP MONTHDONE: ; ; continue counting until day of month attained ; LD HL,(DAYSCNT) DAYSLOOP: INC HL ;add one day CALL CKGOAL JP NC,DONE CCF ;zero carry bit so daa is screwed up LD A,(DAYS) INC A DAA LD (DAYS),A JR DAYSLOOP DONE: RET ;leave module ; ; compare count (in hl) with goal ; C if count < goal ; Z if count = goal ; CKGOAL: PUSH DE LD DE,(GOALDAYS) LD A,H CP D JR NZ,CKEND LD A,L CP E CKEND: POP DE RET ; ; check for leap year ; return z if leap year ; CKLEAP: LD A,(YEARS_BIN) ;get years AND 03H RET MONTBL: DB 31 ;jan FEB: DB 28 ;feb DB 31 ;mar DB 30 ;apr DB 31 ;may DB 30 ;jun DB 31 ;jul DB 31 ;aug DB 30 ;sep DB 31 ;oct DB 30 ;nov DB 31 ;dec ; ; these values are the output of this module ; DAYS: DS 1 ;counts days in month (bcd) MONTHS: DS 1 ;counts months in year (bcd) YEARS: DS 1 ;counts years (starts at 78) (bcd) ; ; cnvdays ram area ; YEARS_BIN: DS 1 ;years in binary (for leap year calc) DAYSCNT: DS 2 ;counts days GOALDAYS: DS 2 ;days since 1/1/78 ; ; End of file DATIME.INC * ;************************************************************************