TITLE "Convert Standard to MS-DOS Time 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 : D2MTIM ; Abstract: This code is based on code fragments provided by ; Bridger Mitchell. It is used to convert from DateStamper(tm) ; "type" date/time string to a 4-byte MS-DOS Date/Time string. ; Valid dates are 1 Jan 1980 thru 31 Dec 2077 to retain ; compatibility with the other time conversion routines. ; Time strings are as: ; ; 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 ; ; YYYYYYY = 0-19 equate to 1980-1999, ; 20-97 equate to 2000-2077; 98-127 are 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 U2MTIM ;..From DSLIB/SYSLIB Get.. EXT BCD2BIN ; Convert byte in A from BCD to Binary ; disturbing No registers ;=============================================================== ; Convert Universal T&D to addressed buffer in MS-DOS form ; ; Enter: DE = Address of start of Universal T&D string ; HL = Address of buffer to receive MS-DOS T&D ; Exit : A = 0, Zero Flag Set (Z), Time string (less sec) set ; A = FF, Zero Reset (NZ), Dest Date nulled on Error ; DE --> Seconds byte in Universal field (not converted) ; HL --> High-order Time Byte MS-DOS field (low-order ; byte has seconds field nulled) ; BC - Not defined ; Uses : All primary registers ;=============================================================== U2MTIM: LD B,5 ; Convert basic 5 bytes PUSH DE ; Save input pointer U2MLOP: LD A,(DE) ; Get first BCD byte CALL BCD2BIN ; ..and convert to Binary LD (DE),A ; Put Binary byte back INC DE DJNZ U2MLOP ; ..looping til done POP DE ; Restore input pointer EX DE,HL ; Put U-Time addr in HL, M-Time addr in DE INC HL ; Advance to Month byte LD A,(HL) ; Get Universal Month byte DEC HL ; ..back down to Year OR (HL) ; Check Month in A = Year in (HL) = 0 JR Z,ERROR ; ..Jump to error if YY=MM=0 LD A,(HL) ; Get Year byte again CP 78 ; Is it 21st Century? JR NC,CEN20 ; ..jump if still 20th century ADD A,100 ; Else compensate to 21st CEN20: SUB 80 ; Subtract MS-DOS Offset from 1980 JP M,ERROR ; ..jump to error if year < 1980 ADD A,A ; Shift Year to Bits 7-1, B0=0 LD C,A ; ..and save in C INC HL LD A,(HL) ; Get Universal Month byte BIT 3,A JR Z,LMONTH ; ..jump if Month < Aug SET 0,C ; Else show month >= Aug LMONTH: AND 00000111B ; Mask off MSB of Month RRCA ; ..and shift to B7-5 RRCA ; (3 rotates right = << 5 RRCA INC HL ; Advance to Day byte OR (HL) ; ..and logically add Day bits INC DE ; Advance destination to Date Word INC DE LD (DE),A ; Save converted Low-order byte in MS-DOS form INC DE ; ..advance to High-order byte LD A,C ; Get High-order Byte LD (DE),A ; ..and save DEC DE ; Back down to Time Word DEC DE DEC DE INC HL ; Point to Hours byte LD A,(HL) ; ..and get it ADD A,A ; Shift Bits 0-4 to 3-7 with 0 fill ADD A,A ADD A,A LD C,A ; ..save result for a while INC HL ; Point to Minutes LD A,(HL) ; ..and get bits AND 00111000B ; Mask off 3 most significant bits RRCA ; ..and move to Bit 0-2 positions RRCA RRCA OR C ; Logically add to shifted Hours bits LD C,A ; Save High order completed byte LD A,(HL) ; Re-get Minutes INC HL ; ..and advance to Seconds for exit AND 00000111B ; Put least significant bits.. RRCA ; ..to High-order positions RRCA ; ..<< 5 by going circular 3 right RRCA ; Hi-order byte in C, Lo-order in A EX DE,HL ; Swap pointers back to original positions LD (HL),A ; Save low-order byte of Time Word INC HL ; ..and advance to High-order byte LD (HL),C ; Save High-order byte of Time Word INC HL ; ..and advance MS pointer to end of Date INC HL XOR A ; Set OK flags and return RET ERROR: LD BC,5 ; Advance Universal time to exit conditions ADD HL,BC EX DE,HL ; Swap regs to exit locations XOR A ; Set null for MS-DOS fill LD B,4 ERLOOP: LD (HL),A ; Fill MS-DOS time string with Nulls INC HL ; ..advance to next DJNZ ERLOOP ; Loop til done DEC HL ; ..and back up to exit pointer conditions DEC A ; Set A = 0FFH for error RET END