TITLE "Convert Standard to P2DOS Time" ;================================================================= ; Copyright (C) 1989 by Harold F. Bower. Permission granted to ; Alpha Systems Corp. to distribute with The Libraries, Version 4 ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Date : 13 Sep 88 ; Version : 1.1 ; Module : D2PTIM ; Abstract: Portions of this code were extracted from DATE.ASM provided ; with the P2DOS diskette, by H.A.J. Ten Brugge. This module ; converts from DateStamper(tm) "type" date/time string to the ; 5-byte date/time string required for CP/M+. Strings are: ; ; Universal Time String : YY MM DD HH MM SS (all BCD) ; ; CP/M+ (P2DOS) Time String : nnnn HH MM SS ; nnnn = binary number of days since start (1 = 1 Jan 1978) ; HH MM SS = time in BCD ; Revisions: ; 1.1 - 30 Jun 91 - Corrected register usage, added cmts. HG ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PUBLIC U2PTIM ;..From DSLIB/SYSLIB Get.. EXT BCD2BIN ; Get this module from library VER EQU 10 ;===================================================================== ; Convert Universal T&D to addrsd buffer in CP/M+ (P2DOS) form. ; ; Enter: DE = Address of start of Universal T&D string ; HL = Address of buffer to receive CP/M+ (P2DOS) T&D ; Exit : A = 0, Zero Flag Set (Z), Time string (less sec) set if Ok ; A = FF, Zero Reset (NZ), Dest Date nulled on Error ; DE --> Seconds byte in Universal field (not moved) ; HL --> Seconds byte in CP/M+ (P2DOS) field (not filled) ; BC - Not Defined ; Uses : All primary registers ;===================================================================== U2PTIM: PUSH HL ; Save destination address LD A,(DE) ; Get BCD Year LD B,A ; ..to B INC DE ; ...advance to Month LD A,(DE) ; Get BCD Month OR B ; Test No Date if YY=MM=00 JR Z,NODATE ; ..Jump to error exit if Invalid stamp LD A,B ; Get BCD Year again from B CALL BCD2BIN ; Convert year to Binary CP 78 ; Is it 1978..1999? JR NC,YR19 ; ..jump if so ADD A,100 ; Else put in range 2000..2077 YR19: LD BC,1900 ; Set Base Century ADD A,C ; Add current year to Base LD C,A LD A,00 ADC A,B LD B,A LD A,(DE) ; Get BCD Month INC DE CALL BCD2BIN ; ..convert to Binary LD H,A LD A,(DE) ; Get Day INC DE ; Point to U-Hrs PUSH DE ; ..and save on stack CALL BCD2BIN ; ..convert Day to Binary LD L,A ; Day to L (binary) ; Check validity of day, month, year. (CHKDAT..From DATE.ASM) ; Enter: L = binary day ; H = binary month ; BC = binary year LD A,H DEC A ; Convert valid Month to 0-11 range CP 12 ; Is it a valid Month? JR NC,BADDAT ; ..jump error if invalid PUSH HL ; Save month and day LD E,A LD D,0 LD HL,DM ; Set lookup table for months ADD HL,DE LD D,(HL) ; Get days in this month POP HL CP 1 ; Is this February? (2-1) CALL Z,LEAPYR ; Check for leap year if Feb JR NZ,CHKDT0 ; ..jump if Not Feb and/or Not Leap Year INC D ; else make 29 days CHKDT0: LD A,L ; Check for day within range DEC A ; Have day > 0, check for <= max day CP D JR NC,BADDAT ; ..anything else is error ; Calculate 16-bit Binary Date since 1978 in Days ; Entry: BC = Year (1978..2077) ; H = Month (1..12) ; L = Days (1..31) ; Exit : DE = Days First day (0001H) : Su 01 Jan 1978 ; Last day (8EADH) : 31 Dec 2077 PUSH HL ; Save Month (H) and Day (L) LD H,0 ; Null out Month leaving just days EX DE,HL ; ..move to DE LD L,C ; Move current Year to HL LD H,B LD BC,1978 ; Start with base year in BC DAYS0: OR A SBC HL,BC ; Is this the starting year? ADD HL,BC JR Z,DAYS1 ; ..jump if so with Final Days total in DE PUSH HL LD HL,365 ; Add days in non-leap year ADD HL,DE ; ..to total Days count in DE EX DE,HL ; ...and put new Days total in DE POP HL CALL LEAPYR ; Is this a Leap Year? INC BC ; ..(advance to next year) JR NZ,DAYS0 ; ..loop if not Leap INC DE ; Else add a day JR DAYS0 ; ..then loop ; Error routines. Set Date to 0000 and move irrelevant time BADDAT: POP DE ; Restore Universal string (--> Hrs) NODATE: POP HL ; Restore Destination Address for P2DOS Date LD BC,0000 ; Set Null date for error CALL SAVEM ; Save Null date & move Time DEC A ; Set error flags (A=FF, Zero Clear (NZ)) RET ; DE=Binary Day total (Year & Day only). Mo & Da on stack, BC=Current Year DAYS1: POP HL ; Restore Mo & Da EX DE,HL ; Binary date to HL, Mo & Da to DE PUSH HL ; ..and save Binary date LD HL,DM ; Address days-of-month table LD E,1 DAYS2: LD A,D ; Check for matching month CP E JR Z,DAYS4 ; ..exit when match LD A,(HL) ; Get days in this month EX (SP),HL ; Put table on stack, Binary date to HL ADD A,L ; Add this month's days to cum bin date LD L,A LD A,00 ADC A,H LD H,A LD A,E ; Check this month CP 2 ; ..for Feb CALL Z,LEAPYR ; If so, Is it a Leap Year? JR NZ,DAYS3A ; ..jump if Not Leap Year and/or Not Feb INC HL ; Else bump Cum Bin date by 29 Feb DAYS3A: EX (SP),HL ; Put Cum Bin date to stack, Month table to HL INC HL ; Point to next month INC E ; Bump index counter JR DAYS2 ; ..and loop DAYS4: POP BC ; Exit here..Put Cum Binary Date to BC POP DE ; Restore Universal string (--> Hrs) POP HL ; ..and Destination addr from stack SAVEM: LD (HL),C ; Put binary date in string INC HL LD (HL),B INC HL EX DE,HL ; Pointers to correct regs LDI ; Move BCD Hours.. LDI ; ..and BCD Minutes XOR A ; Set OK flags and return RET ;..... ; Calculate Leap Year correction ; Enter: BC = Binary year ; Exit : Z = 1 (set) Correction necessary ; Z = 0 (clear, NZ) No correction needed LEAPYR: BIT 0,C ; Check Leap Year of x0, x4, x8, xC RET NZ BIT 1,C RET ;..... ; Days-in-Month table DM: DEFB 31,28,31,30,31,30,31,31,30,31,30,31 END