TITLE "Convert MS-DOS 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 : M2DTIM ; Abstract: This module contains the routine M2UTIM which converts ; MicroSoft DOS Time Stamp to Standard DateStamper (Universal) ; Format entries. It is derived from code fragments provided ; by Bridger Mitchell. It converts a 4-byte MicroSoft date/time ; field to the 5-byte DateStamper(tm) "type" date/time fields. ; Valid dates are 1 Jan 1980 thru 31 Dec 2077 to retain compata- ; bility with the other time conversion routines. ; ; Universal Time String : YY MM DD HH MM (all BCD) ; YY = 78..99 are 20th century, 00..77 are 21st century ; ; MS-DOS Time String: 2 byte binary date referenced to 1980, ; 2 byte binary time (Seconds resolved to even 2) ; ; Logically, the Date and Time appear as: ; Bit 15 8 7 0 15 8 7 0 ; Time: HHHHHMMM MMMSSSSS Date: YYYYYYYM MMMDDDDD ; ; Valid years are 1980 thru 2077, others return an error ; ; In memory, the Date and Time appear as: ; Base+0 Base+1 Base+2 Base+3 ; Time: MMMSSSSS HHHHHMMM Date: MMMDDDDD YYYYYYYM ; ; Date word = 0000H = Null date ; Revisions: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PUBLIC M2UTIM ; Let this be the external name ;..From DSLIB/SYSLIB Get.. EXT BIN2BCD ; Convert Binary byte in A to ; BCD disturbing NO registers ;===================================================================== ; Convert MS-DOS Time to Universal Time string ; Enter: HL = Points to MS-DOS Time/Date String ; DE = Addr of destination Universal T&D entry ; Exit : A = 0, Zero Flag Set (Z) if Ok ; A <> 0, Zero Flag Clear (NZ) if error, Univ date Null ; HL --> Second (hi-order) Date Byte in Source MS-DOS T&D field ; DE --> Seconds Byte in Dest Universal T&D (not filled) ; BC - Destroyed ; Uses : All primary registers ;===================================================================== M2UTIM: PUSH DE ; Save destination pointer for exit INC HL ; ..and advance to Date INC HL LD C,(HL) ; Get MS-DOS Source word INC HL LD B,(HL) LD A,B ; Is it valid? OR C JR Z,ERROR ; ..jump error exit if invalid LD A,B ; Convert Years to U-format SRL A ; >> 1 CP 98 ; Is it in range 1980-2077? JR NC,ERROR ; ..go error if not SUB 20 ; Is it 20th century? JR NC,CEN21 ; ..jump if 21st century ADD A,100 ; Else get correct 20th century year CEN21: LD (DE),A ; Save Univ year in binary INC DE ; ..and advance to Month LD A,C ; Get low-order date (for Month) RR B ; Rotate Month MSB from Year to Carry RLA ; Shift Month >> 5 by going 4 left thru carry RLA RLA RLA AND 00001111B ; Mask Month bits LD (DE),A ; Save Univ month in binary INC DE ; ..and advance to Day LD A,C ; Get low-order date again (for Day) AND 00011111B ; Mask Day bits LD (DE),A ; Save Univ day in binary INC DE ; ..and advance to Hours PUSH HL ; Save source pointer DEC HL ; Back up to Source MS Time Word DEC HL LD B,(HL) ; Get High-order byte of time DEC HL LD C,(HL) ; Get Low-order Time byte POP HL ; ..restore exit pointer LD A,B ; Get Hi-order byte for Hours RRA ; Shift Hours from B3-7 to B0-4 RRA RRA AND 00011111B ; Mask Hours bits LD (DE),A ; Save Univ Hours in binary INC DE ; ..and advance to Minutes LD A,B ; Get Hi-order byte again for Minutes AND 00000111B ; Mask significant Minutes bits ;..The following neglects the seconds bits.. RL C ; Get minutes bit from low-order byte to carry RLA ; ..and shift into Minutes byte in A RL C ; Repeat until all 3 bits shifted RLA RL C RLA LD (DE),A ; Save Univ Minutes in binary ; The output date now exists in Binary in the output buffer ; Convert all 5 bytes to BCD POP DE ; Restore entry pointer to Univ output LD B,5 ; Convert 5 bytes CONV: LD A,(DE) ; Get a byte CALL BIN2BCD ; ..and convert it LD (DE),A ; Put it back INC DE DJNZ CONV ; ..looping til done XOR A ; Set OK Exit conditions RET ; ..and quit ; Exit here with pointers set and Univ Date field Nulled (except Seconds) ERROR: POP DE ; Restore destination pointer to U-Time XOR A ; Value to clear output string LD B,5 ; Do all 5 bytes ERLOOP: LD (DE),A ; Stuff a Null INC DE ; ..advance to next DJNZ ERLOOP ; Loop til done DEC A ; Set error conditions RET END