home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
c_all592.arj
/
TI360.ASC
< prev
next >
Wrap
Text File
|
1991-08-27
|
8KB
|
331 lines
PRODUCT : TURBO BASIC NUMBER : 360
VERSION : 1.0
OS : PC-DOS
DATE : July 22, 1987 PAGE : 1/5
TITLE : FILE HANDLES
This program demonstrates how to retrieve a file handle from
within a Turbo Basic program.
$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
PRODUCT : TURBO BASIC NUMBER : 360
VERSION : 1.0
OS : PC-DOS
DATE : July 22, 1987 PAGE : 2/5
TITLE : FILE HANDLES
┌───────────────────────────────────────────────────────────────┐
│ │
│ FNFileHandleAddress% : │
│ │
│ Returns a file handle based upon the number of the file │
│ passed into the function. The function searches through Turbo│
│ Basic's linked list of file handles for the corresponding │
│ file number passed in the function. You will know which file │
│ number to pass in through the syntax of the OPEN statement │
│ that you used on the file. See the program FILEEX.BAS for an │
│ example of how to use this function along with DOS function │
│ call 87 ( 57 hex ). │
│ │
│ Turbo Basic's linked list of file handles is stored in │
│ the string data segment area. Two bytes at offsets 6 & 7 │
│ are a pointer to the first node of the linked list. Each │
│ node in the linked list has the following format: │
│ │
│ │
│ ────────────────────────────── │
│ | Pointer to next node | 2 Bytes │
│ ────────────────────────────── │
│ | Pointer to previous node | " " │
│ ────────────────────────────── │
│ | File Number | " " │
│ ────────────────────────────── │
│ | DOS File Handle | " " │
│ ────────────────────────────── │
│ │
│ Please keep in mind that the information is stored in │
│ byte-reverse notation. This was written on 6/4/87 for │
│ Turbo Basic 1.00. │
│ │
└───────────────────────────────────────────────────────────────┘
PRODUCT : TURBO BASIC NUMBER : 360
VERSION : 1.0
OS : PC-DOS
DATE : July 22, 1987 PAGE : 3/5
TITLE : FILE HANDLES
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
┌───────────────────────────────────────────────────────────────┐
│ │
│ Get.File.Date.and.Time │
│ │
│ Uses DOS Function call 87 ( hex 57 ) to retrieve │
│ a file's time and date statistics. To accomplish this, │
│ the file handle must be first retrieved from Turbo Basic's │
│ linked list structure of file handles. If the file handle │
│ is present in the linked list, the statistics concerning it │
│ are returned. If not, all variables passed to the procedure │
│ Get.File.Date.and.Time are set to zero. │
│ │
│ Written on 6/4/87 for Turbo Basic version 1.00. │
│ │
└───────────────────────────────────────────────────────────────┘
PRODUCT : TURBO BASIC NUMBER : 360
VERSION : 1.0
OS : PC-DOS
DATE : July 22, 1987 PAGE : 4/5
TITLE : FILE HANDLES
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%
PRODUCT : TURBO BASIC NUMBER : 360
VERSION : 1.0
OS : PC-DOS
DATE : July 22, 1987 PAGE : 5/5
TITLE : FILE HANDLES
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