TITLE "Convert P2Dos Time to Standard - 13 Sep 88" ;================================================================= ; 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.0 ; Module : P2DTIM ; Abstract: Derived from DATE.ASM by H.A.J. Ten Brugge. This module ; contains the routine P2UTIM which converts a 4-byte P2Dos ; (CP/M+) date/time field to the 5-byte DateStamper(tm) "type" ; date/time fields. Valid dates are 1 Jan 1978 (0001H) thru 31 ; Dec 2077 (8EADH). ; ; Universal Time String : YY MM DD HH MM (all BCD) ; YY = 78..99 are 20th century, 00..77 are 21st century ; ; CP/M+ (P2DOS) Time String : nnnn HH MM ; nnnn = binary number of days since start (1 = 1 Jan 1978) ; HH MM = time in BCD ; 0000=Null date, >=8EAEH are invalid dates ; Revisions: ;===================================================================== PUBLIC P2UTIM ; Let this be the external name ;..from DSLIB/SYSLIB Get.. EXT BIN2BCD ; Use this module ;=============================================================== ; Convert CP/M+ (P2DOS) Time to Universal Time string ; Enter: HL = Points to CP/M+ (P2DOS) T&D entry ; DE = Addr of destination Universal T&D entry ; Exit : A = 0, Zero Flag Set (Z) for Ok ; Errors due only to bad entry, must check YY=MM=0 ; HL --> Byte after Minutes in Source P2DOS T&D field ; DE --> Byte after Minutes in Dest Universal T&D ; BC - Destroyed ; Uses : All primary registers ;=============================================================== P2UTIM: PUSH DE ; Save Universal T&D address on stack LD E,(HL) ; Get binary date to BC INC HL LD D,(HL) INC HL PUSH HL ; Save DTIM addr on stack as well LD A,D ; Check for No valid date (0000H) OR E LD BC,0000 ; Fill registers for possible error return JR Z,SAVDAT ; ..Jump to exit with Null Univ. Date if so LD HL,36525 ; Is date > 31 Dec 2077? SBC HL,DE JR C,SAVDAT ; ..jump to Null date exit if so LD BC,1978 ; Set beginning year EX DE,HL ; Put Binary Day/date in HL DMJ0: LD DE,365 ; Set days in normal year CALL LEAPYR ; ..check for leap year JR NZ,DMJ1 ; ..jump if not INC DE DMJ1: OR A ; When # of days left.. SBC HL,DE ; ..is less than days in year.. JR C,DMJ2 ; ..year is in HL, so exit JR Z,DMJ2 ; ...or here if last day of Year INC BC ; Bump starting year JR DMJ0 ; ..and back for another try ; When get here, binary year is in BC, remaining days in HL DMJ2: ADD HL,DE ; Compensate for above underflow LD A,1 ; Start with month # 1 (Jan) LD D,0 ; ..prepare for 16-bit math PUSH HL ; Save days remaining LD HL,DM ; ..and address month table DMJ3: LD E,(HL) ; Get days in current mo to E CP 2 ; Is it Feb? CALL Z,LEAPYR ; ..Check for leap year if Feb JR NZ,DMJ4 ; Jump if not leap year INC E ; ..else compensate DMJ4: EX (SP),HL ; Swap pointer (HL) with Days Remaining (stk) OR A SBC HL,DE ; Subtract days in Month from Remaining days JR C,DMJ5 ; ..Exit if we've gone too far JR Z,DMJ5 ; ...or just far enough (last day of month) EX (SP),HL INC HL ; Point to next month in table INC A ; .bump month counter JR DMJ3 ; ..and Try again; ; Arrive here with Remaining days (less underflow) on Stack Top, ; Relative month in A (Jan = 1), Days in that month in E, and ; Binary Year in BC. HL addresses months table and is expendable DMJ5: ADD HL,DE ; Compensate for underflow EX (SP),HL ; ..and put back on stack.. POP HL ; Restore Day in L CALL BIN2BCD ; Convert Month (in A) to BCD LD H,B ; ..moving Year to HL LD B,A LD A,L ; Convert Day LD L,C CALL BIN2BCD ; ..to BCD LD C,A LD DE,100 ; Subtract centuries, one by one.. DMJ7A: OR A SBC HL,DE JR NC,DMJ7A ; ..until we go too far ADD HL,DE ; Then correct for underflow LD A,L ; Get Years (tens and ones) CALL BIN2BCD ; ..to BCD SAVDAT: POP DE ; Get DTIM addr from stack POP HL ; Get Universal time string addr from stack LD (HL),A ; Store Years.. INC HL LD (HL),B ; ..Months INC HL LD (HL),C ; ..Days INC HL EX DE,HL ; Put U-tim addr in DE, D-Tim in HL LDI ; Move Hours & adjust ptrs LDI ; Move Minutes & adjust ptrs 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 for xx00 in lower byte RET NZ ; ..for x0, x4, x8, xC being Leap Years BIT 1,C RET ;..... ; Days-in-Month table DM: DEFB 31,28,31,30,31,30,31,31,30,31,30,31 END