home *** CD-ROM | disk | FTP | other *** search
- PRODUCT : TURBO BASIC@>( )NUMBER : 360
- VERSION : 1.0
- OS : PC-DOS
- DATE : July 22, 1987@>( )PAGE : @value(page)/5
-
- TITLE : FILE HANDLES
-
- $INCLUDE "REGNAMES.INC" ' This file should be on your Turbo
- Basic disk.
-
- Begin:
- CLS
- OPEN "Test1" FOR OUTPUT AS #1
-
- CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
- Hour%, Minute%, Second% )
- CALL Print.Stats
- CALL Set.File.Date.and.Time ( 1, 1987, 6, 30,_
- 12, 30, 55 )
- CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
- Hour%, Minute%, Second% )
- PRINT
- CALL Print.Stats
-
- CLOSE
- KILL "Test1"
- END
-
-
- ZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
- 3 3
- 3 FNFileHandleAddress% : 3
- 3 3
- 3 Returns a file handle based upon the number of the file 3
- 3 passed into the function. The function searches through Turbo3
- 3 Basic's linked list of file handles for the corresponding 3
- 3 file number passed in the function. You will know which file 3
- 3 number to pass in through the syntax of the OPEN statement 3
- 3 that you used on the file. See the program FILEEX.BAS for an 3
- 3 example of how to use this function along with DOS function 3
- 3 call 87 ( 57 hex ). 3
- 3 3
- 3 Turbo Basic's linked list of file handles is stored in 3
- 3 the string data segment area. Two bytes at offsets 6 & 7 3
- 3 are a pointer to the first node of the linked list. Each 3
- 3 node in the linked list has the following format: 3
- 3 3
- 3 3
- 3 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 3
- 3 | Pointer to next node | 2 Bytes 3
- 3 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 3
- 3 | Pointer to previous node | " " 3
- 3 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 3
- 3 | File Number | " " 3
- 3 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 3
- 3 | DOS File Handle | " " 3
- 3 DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD 3
- 3 3
- 3 Please keep in mind that the information is stored in 3
- 3 byte-reverse notation. This was written on 6/4/87 for 3
- 3 Turbo Basic 1.00. 3
- 3 3
- @DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY
- DEF FNFileHandleAddress%(FileNumber%)
- LOCAL Segment%,Ofs%,Done%
- DEF SEG
- Segment% = PEEK(0) + (256 * PEEK(1)) ' Get the string
- segment.
- DEF SEG = Segment%
- Ofs% = PEEK(6) + (256 * PEEK(7)) ' Peek at the first file
- number.
- Done% = 1
- WHILE Done% = 1
- IF (PEEK(Ofs%+4) + (256 * PEEK(Ofs%+5))) = FileNumber% THEN
- FNFileHandleAddress% = PEEK(Ofs%+6) + (256 * PEEK(Ofs%+7))
- Done% = 0
- ELSEIF (PEEK(Ofs%) + (256 * PEEK(Ofs%+1))) = 0 THEN
- FNFileHandleAddress% = 0 ' File number not
- found.
- Done% = 0
- ELSE
- Ofs% = PEEK(Ofs%) + (256 * PEEK(Ofs%+1)) ' Traverse the
- linked list.
- END IF
- WEND
- END DEF
-
-
- ZDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
- 3 3
- 3 Get.File.Date.and.Time 3
- 3 3
- 3 Uses DOS Function call 87 ( hex 57 ) to retrieve 3
- 3 a file's time and date statistics. To accomplish this, 3
- 3 the file handle must be first retrieved from Turbo Basic's 3
- 3 linked list structure of file handles. If the file handle 3
- 3 is present in the linked list, the statistics concerning it 3
- 3 are returned. If not, all variables passed to the procedure 3
- 3 Get.File.Date.and.Time are set to zero. 3
- 3 3
- 3 Written on 6/4/87 for Turbo Basic version 1.00. 3
- 3 3
- @DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDY
- SUB Get.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
- Hour%, Minute%, Second% )
-
- FH% = FNFileHandleAddress% ( FileNumber% ) ' Get the File
- Handle.
- IF ( FH% ) THEN
- REG %AX,&H5700 ' DOS Function Call 87 -- see p.319
- REG %BX,FH% ' of Peter Norton's Programmer's Guide to
- ' the IBM PC.
- REG %DX,0
- REG %CX,0
- CALL INTERRUPT &H21
-
- Year% = 1980 + FNShr% ( REG (%DX), 9 )
- Month% = ( REG(%DX) AND &HLE0 ) \ 32
- Date% = REG(%DX) AND &HLF
- Weekday% = REG(%DX) AND &H1F
- Hour% = FNShr% ( REG(%CX), 11 )
- Minute% = FNShr% ( REG(%CX), 5 ) AND &H3F
- Second% = FNShl% ( ( REG(%CX) AND &HLF ) , 1 )
- ELSE
- Year% = 0 ' If the File Handle was not found,
- Month% = 0 ' set all variables to zero.
- Date% = 0
- Weekday% = 0
- Hour% = 0
- Minute% = 0
- Second% = 0
- END IF
-
- END SUB
-
-
- SUB Set.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
- Hour%, Minute%, Second% )
-
- FH% = FNFileHandleAddress% ( FileNumber% ) ' Get the File
- Handle.
- IF ( FH% ) THEN
- REG %AX,&H5701
- REG %BX,FH%
- REG %DX, (Year% - 1980%) * 512% + Month% * 32% + Date%
- REG %CX, FNShl% ( Hour%, 11 )
- REG %CX, REG(%CX) + FNShl% ( Minute%, 5 )
- REG %CX, REG(%CX) + ( Second% \ 2 )
- CALL INTERRUPT &H21
- ELSE
- PRINT "File number: ";FileNumber%;" associated handle not
- found."
- END IF
-
- END SUB
-
-
- SUB Print.Stats
- SHARED Year%, Month%, Date%, Hour%, Minute%, Second%
- PRINT "Year = "; Year%
- PRINT "Month = "; Month%
- PRINT "Day = "; Date%
- PRINT "Hour = "; Hour%
- PRINT "Minute = "; Minute%
- PRINT "Seconds = "; Second%
- END SUB
-
-
- DEF FNHi% ( AnyInt% )
- FNHi% = AnyInt% AND &HFF00
- END DEF
-
- DEF FNLow% ( AnyInt% )
- FNLow% = AnyInt% AND &H00FF
- END DEF
-
- DEF FNShl% ( AnyInt%, Bits% )
- FNShl% = AnyInt% * ( 2% ^ Bits% )
- END DEF
-
- DEF FNShr% ( AnyInt%, Bits% )
- FNShr% = AnyInt% \ ( 2% ^ Bits% )
- END DEF
-