home *** CD-ROM | disk | FTP | other *** search
- ; --------------------------------------------------------------
- ; FUNCTION NAME: FILETIME - Gets or sets the DOS time on a file
- ; --------------------------------------------------------------
- ; Copyright(c) 1988-1990 -- James Occhiogrosso
-
- INCLUDE DEVELOP.MAC ; Developer's Library macro file
-
- PUBLIC FILETIME ; Declare function name
- ; Declare Clipper EXTERNALS
- EXTRN __PARINFO:FAR ; Get Clipper parameter information
- EXTRN __PARC:FAR ; Get a Clipper string
- EXTRN __RETC:FAR ; Return a string to Clipper
-
- CODESEG SEGMENT 'CODE'
- ASSUME CS:CODESEG
-
-
- FILETIME PROC FAR
-
- JMP BEGIN ; Jump around data area
-
- FILE_HANDLE DB 0 ; Store file handle here
- GET_TIME DB '00:00:00', 0 ; Store Clipper return time
- SET_FLAG DB 0 ; Set to 1 for setting time
-
- BEGIN:
- PUSH_REGS ; Save Clipper registers
-
- PUSH DS ; Save Clippers data segment
- PUSH CS ;
- POP DS ; Set up our data segment
- MOV BX, OFFSET FILE_HANDLE ; Get address of first data
- MOV AX, 0
- MOV CX, 11 ; Set to loop 11 times
- NEXT: MOV [BX], AL ; Clear a byte of data area
- ADD BX, 1 ; Increment the address
- LOOP NEXT
- POP DS ; Restore data segment
-
- P_TYPE 1 ; Get parameter type to AX
- CMP AX, 1 ; Character string passed?
- JNE RET_NULL_1 ; No! Return null time
-
- P_COUNT ; Yes! Get parameters passed
- CMP AX, 02 ; If no second parameter,
- JNE OPEN_FILE ; get file time and return
- P_TYPE 2 ; Else, get its type
- CMP AX, 1 ; Is it a string?
- JNE RET_NULL_1 ; No! Return null time
- MOV CS:SET_FLAG, 1 ; Yes! Set the flag
- PUSH DS ; Save the data segment
- JMP OPEN_FILE ; Jump around null return
-
-
- RET_NULL_1:
- JMP EXIT_TIME ; RET_NULL labels used for
- ; direct jump to exit point
- RET_NULL_2: ; due to an error condition.
- JMP CLOSE_FILE
-
-
- OPEN_FILE:
- GET_PARC 1 ; Address of passed filename
- MOV DS, DX ; Get filename segment
- MOV DX, AX ; Get filename offset
- SUB AL, AL ; Set for read only mode
- MOV AH, 3Dh ; Open file request
- INT 21h
- JC RET_NULL_1 ; On error, return null time
- MOV CS:FILE_HANDLE, AL ; Save the file handle
-
- GET_THE_TIME:
- PUSH CS ; Move data segment to CS
- POP DS ; for our data
- SUB BH, BH ; Zero out BX for handle
- MOV BL, FILE_HANDLE ; Get the DOS handle
- MOV AH, 57h ; DOS date/time function
- SUB AL, AL ; Get file date/time
- INT 21h
- JC RET_NULL_2 ; Return null time
-
- MOV AL, CL ; Move time to AL (seconds)
- AND AL, 00011111b ; Mask out unused bits
- ADD AL, AL ; DOS resolves 2 seconds
- AAM ; Adjust MS/LS digits
- ADD AX, 3030h ; Convert to ASCII
- MOV BX, OFFSET GET_TIME ; Get return time address
- MOV [BX+6], AH ; Save seconds digit (tens)
- MOV [BX+7], AL ; Save seconds digit (ones)
-
- MOV AX, CX ; Restore original time
- AND AX, 0000011111100000b ; Mask out the unused bits
- MOV CL, 5 ; Constant for shift
- SHR AX, CL ; Shift minute bits
- AAM ; Adjust MS/LS digits
- ADD AX, 3030h ; Convert AX to ASCII
- MOV [BX+3], AH ; Save minutes digit (tens)
- MOV [BX+4], AL ; Save minutes digits (ones)
-
- MOV AL, CH ; Restore original time
- AND AL, 11111000b ; Mask out the unused bits
- MOV CL, 3 ; Constant for shift
- SHR AL, CL ; Shift hour bits
- AAM ; Adjust MS/LS digits
- ADD AX, 3030h ; Convert to ASCII
- MOV [BX], AH ; Save hour MS digit (tens)
- MOV [BX+1], AL ; Save hour LS digit (ones)
- MOV AL, ':' ; Put colons in time string
- MOV [BX+2], AL
- MOV [BX+5], AL
-
- SET_THE_TIME:
- MOV AL, CS:SET_FLAG ; Check the flag
- CMP AL, 0 ; Is it set?
- JE CLOSE_FILE ; No! We are done
- POP DS ; Yes! Recover data segment,
- MOV CS:SET_FLAG, 0 ; reset the flag, and
- GET_PARC 2 ; get passed time string
- MOV DS, DX ; Get passed segment into DS
- MOV BX, AX ; and offset into BX
-
- MOV AX, WORD PTR [BX] ; Get the hours digits
- XCHG AH, AL ; Put them in correct order
- SUB AX, 3030h ; Remove ASCII bias
- AAD ; Adjust from ASCII
- MOV CL, 11 ; Shift constant
- SHL AX, CL ; Shift year left 9 bytes
- PUSH AX ; Save the hours value
-
- MOV AX, WORD PTR [BX+3] ; Get the minutes digits
- XCHG AH, AL ; Put them in correct order
- SUB AX, 3030h ; Remove ASCII bias
- AAD ; Adjust from ASCII
- MOV CL, 5 ; Shift constant
- SHL AX, CL ; Shift month left 5 bytes
- PUSH AX ; Save the minutes value
-
- MOV AX, WORD PTR [BX+6] ; Get the seconds digits
- XCHG AH, AL ; Put them in correct order
- SUB AX, 3030h ; Remove ASCII bias
- AAD ; Adjust from ASCII
- SHR AX, 1 ; Divide by 2 for DOS
-
- POP BX ; Get back minutes value
- ADD AX, BX ; Add it in
- POP BX ; Get back hours value
- ADD AX, BX ; Add it in
- PUSH AX ; Store new time
-
- SUB BH, BH ; Clear upper handle byte
- MOV BL, FILE_HANDLE ; Get the DOS handle
- MOV AH, 57h ; DOS set file date/time
- SUB AL, AL ; Date/time DOS request
- INT 21h
- MOV AL, 1 ; Set date/time DOS value
- POP CX ; Get new time back
- INT 21h ; Set new time
-
- CLOSE_FILE:
- MOV BH, 0
- MOV BL, FILE_HANDLE ; Get the DOS handle
- MOV AX, 3E00h ; DOS request to close file
- INT 21h
-
-
- EXIT_TIME:
- MOV AL, CS:SET_FLAG ; Get the set flag
- CMP AL, 0 ; Is it zero?
- JE AROUND2 ; Yes! Jump around next line
- POP DS ; Error condition, fix stack
- AROUND2:
- POP_REGS ; Restore all registers
- MOV AX, CS ; Segment of return time
- MOV BX, OFFSET CS:GET_TIME ; Offset of return time
- RET_STRING AX BX ; Return time string
-
- FILETIME ENDP ; End of procedure
-
- CODESEG ENDS ; End of code segment
- END ; End of assembly
-
-