home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / c_all592.arj / TI360.ASC < prev    next >
Text File  |  1991-08-27  |  8KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  9.   VERSION  :  1.0
  10.        OS  :  PC-DOS
  11.      DATE  :  July 22, 1987                            PAGE  :  1/5
  12.  
  13.   TITLE    :  FILE HANDLES
  14.  
  15.  
  16.  
  17.  
  18.   This program demonstrates how to retrieve a file handle from
  19.   within a Turbo Basic program.
  20.  
  21.   $INCLUDE "REGNAMES.INC"  ' This file should be on your Turbo
  22.   Basic disk.
  23.  
  24.   Begin:
  25.       CLS
  26.       OPEN "Test1" FOR OUTPUT AS #1
  27.  
  28.       CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
  29.                                     Hour%, Minute%, Second% )
  30.       CALL Print.Stats
  31.       CALL Set.File.Date.and.Time ( 1, 1987, 6, 30,_
  32.                                     12, 30, 55 )
  33.       CALL Get.File.Date.and.Time ( 1, Year%, Month%, Date%,_
  34.                                     Hour%, Minute%, Second% )
  35.       PRINT
  36.       CALL Print.Stats
  37.  
  38.       CLOSE
  39.       KILL "Test1"
  40.   END
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  75.   VERSION  :  1.0
  76.        OS  :  PC-DOS
  77.      DATE  :  July 22, 1987                            PAGE  :  2/5
  78.  
  79.   TITLE    :  FILE HANDLES
  80.  
  81.  
  82.  
  83.  
  84.   ┌───────────────────────────────────────────────────────────────┐
  85.   │                                                               │
  86.   │  FNFileHandleAddress% :                                       │
  87.   │                                                               │
  88.   │  Returns a file handle based upon the number of the file      │
  89.   │  passed into the function. The function searches through Turbo│
  90.   │  Basic's linked list of file handles for the corresponding    │
  91.   │  file number passed in the function. You will know which file │
  92.   │  number to pass in through the syntax of the OPEN statement   │
  93.   │  that you used on the file. See the program FILEEX.BAS for an │
  94.   │  example of how to use this function along with DOS function  │
  95.   │  call 87 ( 57 hex ).                                          │
  96.   │                                                               │
  97.   │       Turbo Basic's linked list of file handles is stored in  │
  98.   │  the string data segment area.  Two bytes at offsets 6 & 7    │
  99.   │  are a pointer to the first node of the linked list.  Each    │
  100.   │  node in the linked list has the following format:            │
  101.   │                                                               │
  102.   │                                                               │
  103.   │      ──────────────────────────────                           │
  104.   │      | Pointer to next node       |    2 Bytes                │
  105.   │      ──────────────────────────────                           │
  106.   │      | Pointer to previous node   |    "   "                  │
  107.   │      ──────────────────────────────                           │
  108.   │      | File Number                |    "   "                  │
  109.   │      ──────────────────────────────                           │
  110.   │      | DOS File Handle            |    "   "                  │
  111.   │      ──────────────────────────────                           │
  112.   │                                                               │
  113.   │  Please keep in mind that the information is stored in        │
  114.   │  byte-reverse notation.  This was written on 6/4/87 for       │
  115.   │  Turbo Basic 1.00.                                            │
  116.   │                                                               │
  117.   └───────────────────────────────────────────────────────────────┘
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  141.   VERSION  :  1.0
  142.        OS  :  PC-DOS
  143.      DATE  :  July 22, 1987                            PAGE  :  3/5
  144.  
  145.   TITLE    :  FILE HANDLES
  146.  
  147.  
  148.  
  149.  
  150.   DEF FNFileHandleAddress%(FileNumber%)
  151.   LOCAL Segment%,Ofs%,Done%
  152.     DEF SEG
  153.     Segment% = PEEK(0) + (256 * PEEK(1))   ' Get the string
  154.   segment.
  155.     DEF SEG  = Segment%
  156.     Ofs%     = PEEK(6) + (256 * PEEK(7))   ' Peek at the first file
  157.           number.
  158.     Done%    = 1
  159.     WHILE Done% = 1
  160.       IF (PEEK(Ofs%+4) + (256 * PEEK(Ofs%+5))) = FileNumber% THEN
  161.         FNFileHandleAddress% = PEEK(Ofs%+6) + (256 * PEEK(Ofs%+7))
  162.         Done% = 0
  163.       ELSEIF (PEEK(Ofs%) + (256 * PEEK(Ofs%+1))) = 0 THEN
  164.         FNFileHandleAddress% = 0                ' File number not
  165.   found.
  166.         Done% = 0
  167.       ELSE
  168.         Ofs% = PEEK(Ofs%) + (256 * PEEK(Ofs%+1))   ' Traverse the
  169.            linked list.
  170.       END IF
  171.     WEND
  172.   END DEF
  173.  
  174.  
  175.   ┌───────────────────────────────────────────────────────────────┐
  176.   │                                                               │
  177.   │  Get.File.Date.and.Time                                       │
  178.   │                                                               │
  179.   │  Uses DOS Function call 87 ( hex 57 ) to retrieve             │
  180.   │  a file's time and date statistics.  To accomplish this,      │
  181.   │  the file handle must be first retrieved from Turbo Basic's   │
  182.   │  linked list structure of file handles.  If the file handle   │
  183.   │  is present in the linked list, the statistics concerning it  │
  184.   │  are returned.  If not, all variables passed to the procedure │
  185.   │  Get.File.Date.and.Time are set to zero.                      │
  186.   │                                                               │
  187.   │  Written on 6/4/87 for Turbo Basic version 1.00.              │
  188.   │                                                               │
  189.   └───────────────────────────────────────────────────────────────┘
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  207.   VERSION  :  1.0
  208.        OS  :  PC-DOS
  209.      DATE  :  July 22, 1987                            PAGE  :  4/5
  210.  
  211.   TITLE    :  FILE HANDLES
  212.  
  213.  
  214.  
  215.  
  216.   SUB Get.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
  217.                                Hour%, Minute%, Second% )
  218.  
  219.       FH% = FNFileHandleAddress% ( FileNumber% )  ' Get the File
  220.   Handle.
  221.       IF ( FH% ) THEN
  222.           REG %AX,&H5700 ' DOS Function Call 87 -- see p.319
  223.           REG %BX,FH%    ' of Peter Norton's Programmer's Guide to
  224.                          ' the IBM PC.
  225.           REG %DX,0
  226.           REG %CX,0
  227.           CALL INTERRUPT &H21
  228.  
  229.           Year% = 1980 + FNShr% ( REG (%DX), 9 )
  230.           Month% =  ( REG(%DX) AND &HLE0 ) \ 32
  231.           Date% =  REG(%DX) AND &HLF
  232.           Weekday% =  REG(%DX) AND &H1F
  233.           Hour% =  FNShr% ( REG(%CX), 11 )
  234.           Minute% =  FNShr% ( REG(%CX), 5 ) AND &H3F
  235.           Second% =  FNShl% ( ( REG(%CX) AND &HLF ) , 1 )
  236.       ELSE
  237.           Year% = 0       ' If the File Handle was not found,
  238.           Month% = 0      ' set all variables to zero.
  239.           Date% = 0
  240.           Weekday% = 0
  241.           Hour% = 0
  242.           Minute% = 0
  243.           Second% = 0
  244.       END IF
  245.  
  246.   END SUB
  247.  
  248.  
  249.   SUB Set.File.Date.and.Time ( FileNumber%, Year%, Month%, Date%,_
  250.                                Hour%, Minute%, Second% )
  251.  
  252.       FH% = FNFileHandleAddress% ( FileNumber% )  ' Get the File
  253.   Handle.
  254.       IF ( FH% ) THEN
  255.           REG %AX,&H5701
  256.           REG %BX,FH%
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  TURBO BASIC                            NUMBER  :  360
  273.   VERSION  :  1.0
  274.        OS  :  PC-DOS
  275.      DATE  :  July 22, 1987                            PAGE  :  5/5
  276.  
  277.   TITLE    :  FILE HANDLES
  278.  
  279.  
  280.  
  281.  
  282.           REG %DX, (Year% - 1980%) * 512% + Month% * 32% + Date%
  283.           REG %CX, FNShl% ( Hour%, 11 )
  284.           REG %CX, REG(%CX) + FNShl% ( Minute%, 5 )
  285.           REG %CX, REG(%CX) + ( Second% \ 2 )
  286.           CALL INTERRUPT &H21
  287.       ELSE
  288.           PRINT "File number: ";FileNumber%;" associated handle not
  289.           found."
  290.       END IF
  291.  
  292.   END SUB
  293.  
  294.  
  295.   SUB Print.Stats
  296.     SHARED Year%, Month%, Date%, Hour%, Minute%, Second%
  297.       PRINT "Year = "; Year%
  298.       PRINT "Month = "; Month%
  299.       PRINT "Day = "; Date%
  300.       PRINT "Hour = ";  Hour%
  301.       PRINT "Minute = "; Minute%
  302.       PRINT "Seconds = "; Second%
  303.   END SUB
  304.  
  305.  
  306.   DEF FNHi% ( AnyInt% )
  307.       FNHi% = AnyInt% AND &HFF00
  308.   END DEF
  309.  
  310.   DEF FNLow% ( AnyInt% )
  311.       FNLow% = AnyInt% AND &H00FF
  312.   END DEF
  313.  
  314.   DEF FNShl% ( AnyInt%, Bits% )
  315.       FNShl% = AnyInt% * ( 2% ^ Bits% )
  316.   END DEF
  317.  
  318.   DEF FNShr% ( AnyInt%, Bits% )
  319.       FNShr% = AnyInt% \ ( 2% ^ Bits% )
  320.   END DEF
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.