home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / turbopas / sfmsrc.arc / SFMVARS.INC < prev   
Text File  |  1987-11-15  |  16KB  |  427 lines

  1. {                          Super File Manager
  2.  
  3.                               SFMVARS.INC
  4.  
  5.                            by David Steiner
  6.                               2035 J Apt. 6
  7.                               Lincoln, NE
  8.  
  9.   This include file is for declaring the majority of the program's
  10.     global variables, constants and types.  Also included are a
  11.     couple of routines that need to come before all of the others,
  12.     and don't fit in the second include file.
  13.  
  14. }
  15.  
  16.  
  17. CONST
  18.   version     = 'v1.01';
  19.   MaxFiles    = 512;
  20.   MinStack    = 512;     { Set aside to insure against heap/stack collision }
  21.   KiloByte    = 1024.0;  { Formal definition, maybe you'd rather it was 1000 }
  22.   WindowLen   = 17;
  23.   DelChar     = #229;    { DOS character to signal deleted file }
  24.   NulChar     = #000;
  25.   PtrChar     = #175;    { Pointer character in directory windows }
  26.  
  27.   horzlin     = #205;    { These characters make up the window }
  28.   vertlin     = #179;    {   borders.                          }
  29.   int1        = #209;
  30.   int2        = #216;
  31.   int3        = #207;
  32.   corn1       = #213;
  33.   corn2       = #184;
  34.   corn3       = #212;
  35.   corn4       = #190;
  36.   tleft       = #198;
  37.   trght       = #181;
  38.   lbrk        = #219  {#181};
  39.   rbrk        = #219  {#198};
  40.  
  41.   Rbit        = $01;   { These are masks for the bits in the file's }
  42.   Hbit        = $02;   {   attribute byte: read-only, hidden, sys,  }
  43.   Sbit        = $04;   {   volume label, directory and archive.     }
  44.   Vbit        = $08;
  45.   Dbit        = $10;
  46.   Abit        = $20;
  47.  
  48.   MakeNoise   : boolean  = true;   { Typed constant so Int10 can access flag }
  49.   cursornum   : integer  = $0607;  { Default CGA cursor }
  50.  
  51.  
  52. TYPE
  53.  
  54.   {
  55.   This 'variant record' allows accessing full and half registers
  56.     without two separate variable declarations.
  57.   }
  58.   Reg_T    = record case boolean of
  59.                true  : (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : integer);
  60.                false : (AL,AH,BL,BH,CL,CH,DL,DH          : byte);
  61.              end;
  62.  
  63.  
  64.   {
  65.   The archaic DOS File Control Block.
  66.   }
  67.   FCB_T   = record
  68.                Drive      : byte;
  69.                Name       : array[1..8] of char;
  70.                Ext        : array[1..3] of char;
  71.                BlockNum,
  72.                RecSize    : integer;
  73.                Size       : array[0..1] of integer;
  74.                Date       : integer;
  75.                Reserved2  : array[0..9] of byte;
  76.                SeqNum     : byte;
  77.                RandomNum  : array[0..3] of byte;
  78.             end;
  79.  
  80.  
  81.   {
  82.   DOS Extended File Control Block.
  83.   }
  84.   ExtFCB_T = record
  85.                ExtFlag    : byte;
  86.                Reserved   : array[0..4] of byte;
  87.                FileAttr,
  88.                Drive      : byte;
  89.                Name       : array[1..8] of char;
  90.                Ext        : array[1..3] of char;
  91.                BlockNum,
  92.                RecSize    : integer;
  93.                Size       : array[0..1] of integer;
  94.                Date       : integer;
  95.                Reserved2  : array[0..9] of byte;
  96.                SeqNum     : byte;
  97.                RandomNum  : array[0..3] of byte;
  98.              end;
  99.  
  100.  
  101.   {
  102.   The entries in a directory follow the specifications of the
  103.     following record.  By using this record we can read from disk
  104.     into a memory area reserved for an array of Entry_T.
  105.   }
  106.   Entry_T = record
  107.               Name        : array[1..8] of char;
  108.               Ext         : array[1..3] of char;
  109.               Attr        : byte;
  110.               Reserved    : array[0..9] of byte;
  111.               Time,
  112.               Date,
  113.               Cluster     : integer;
  114.               Size        : array[0..1] of integer;
  115.             end;
  116.  
  117.  
  118.   {
  119.   This record outlines the table at an address returned by DOS function
  120.     request $32.  This is a non-documented function, but is supported
  121.     from DOS v2.0 through v3.2 and seems very reliable.
  122.   }
  123.   DskTbl_T= record
  124.               DRIVE1,
  125.               DRIVE2      : byte;
  126.               SECTORSIZE  : integer;
  127.               CLUSTERSIZE,
  128.               NHEADS      : byte;
  129.               BOOTSIZE    : integer;
  130.               NFATS       : byte;
  131.               ROOTENTRIES,
  132.               DATASECTOR,
  133.               MAXCLUSTER  : integer;
  134.               FATSIZE     : byte;
  135.               ROOTSECTOR  : integer;
  136.               DEVDRIVER   : array[0..1] of integer;
  137.               FATATTR     : byte;
  138.             end;
  139.  
  140.   {
  141.   String types for use in procedure declarations.
  142.   }
  143.   str4        = string[ 4];
  144.   str6        = string[ 6];
  145.   str10       = string[10];
  146.   str11       = string[11];
  147.   str80       = string[80];
  148.  
  149.   {
  150.   Types for passing addresses between procedures.
  151.   }
  152.   Addr_T      = ^integer;
  153.   DskTblptr   = ^DskTbl_T;
  154.  
  155.   EntryArr_T  = array[1..MaxFiles] of Entry_T;
  156.   MarkedArr_T = array[1..MaxFiles] of boolean;
  157.  
  158.  
  159. VAR
  160.  
  161.   SavedPath  : str80;
  162.  
  163.   {
  164.   Coordinates for specifying the current window
  165.   }
  166.   X1, X2, Y1, Y2 : integer;
  167.  
  168.   {
  169.   Colors to be used by program, they are set in procedure Colors.
  170.   }
  171.   PATTR, NATTR, HATTR, HATTR2, BNATTR, BHATTR : integer;
  172.   MATTR                                       : array[1..2] of integer;
  173.  
  174.   Color,
  175.   ShowAll,
  176.   FATsaved,
  177.   FuncKey    : boolean;
  178.   FATptr,
  179.   HeapStart  : Addr_T;
  180.  
  181.   DiskTable  : array[1..2] of ^DskTbl_T;
  182.   Path       : array[1..2] of str80;
  183.   HelpScreen,
  184.   Loaded,
  185.   Saved,
  186.   NoSave     : array[1..2] of boolean;
  187.   Drive      : array[1..2] of integer;
  188.   TopEntry,
  189.   CurLin,
  190.   CurEntry,
  191.   MaxEntry   : array[1..2] of integer;
  192.   DiskFree,
  193.   DirSize,
  194.   FATbytes   : array[1..2] of real;
  195.   Entry      : array[1..2] of EntryArr_T;
  196.   Marked     : array[1..2] of MarkedArr_T;
  197.  
  198.   {
  199.   Store the directory mask as entered and as converted by DOS.
  200.   }
  201.   Mask,
  202.   ConvMask   : array[1..2] of string[12];
  203.  
  204.  
  205.  
  206. procedure Noise( freq, dur : integer );
  207. begin
  208.   if MakeNoise then
  209.   begin
  210.     Sound( freq );
  211.     Delay( dur );
  212.   end;
  213.   NoSound;
  214. end;
  215.  
  216.  
  217.   {
  218.   The following section takes over BIOS interrupt $10, function
  219.     request $0E (Write Character as TeleType).  This is done
  220.     in order to prevent DOS from destroying our screen when it
  221.     prints the message for changing disks on a one floppy
  222.     system.  The interrupt handler basically just forces the
  223.     function request to conform to the current window settings.
  224.     After Int10 is turned on calls to interrupt 10 will be directed
  225.     to these routines rather than the BIOS.
  226.   Don't forget to make sure the original interrupt handler is restored
  227.     before the program exits.  See procedures AbortProgram and
  228.     AbortOnError in the sfmSCRN.inc file.
  229.   }
  230.  
  231. const
  232.   DataSeg     : integer  =  0;
  233.   Int10char   : char     = #0;  { Temporary storage for character to print }
  234.  
  235.   OldInt10    : array[0..1] of integer  = (0,0);
  236.  
  237. procedure Int10;
  238.   {
  239.   The beep code below is not my own, I converted it from a sample
  240.     program from 'The Complete Guide to IBM PC AT Assembly Language'
  241.     by Harley Hahn.  If you are looking for a good Assembly reference
  242.     I've been pretty happy with this one (I don't have an AT either).
  243.     The beep emulates the above Noise procedure by putting the
  244.     frequency in CX and the duration (in milleseconds) in BX.
  245.  
  246.   OUTLINE OF INT10:
  247.  
  248.      Check if interrupt call was for 'Write Character as Teletype'
  249.      if not
  250.      (
  251.        call the normal BIOS
  252.        exit
  253.      )
  254.      otherwise
  255.      (
  256.        if the character to be printed is
  257.                 a Linefeed : make a short beep
  258.          a Carriage Return : print a Space instead
  259.              anything else : print the character using Turbo's Write
  260.        exit
  261.      )
  262.   }
  263. begin
  264.   {                  ;  These lines are not entered by us, they
  265.      PUSH    BP      ;    are placed at the start of every subroutine
  266.      MOV     BP, SP  ;    by Turbo Pascal.  You must therefore account
  267.      PUSH    SP      ;    for them before executing an IRET instruction.
  268.   }
  269.   Inline(
  270.     $80/$FC/$0E            {        CMP     AH, $0E                       }
  271.     /$74/$0A               {        JE      gotit                         }
  272.                            {        ;                                     }
  273.     /$9C                   {        PUSHF                                 }
  274.     /$2E/$FF/$1E/>OLDINT10 {CS:     CALL    FAR [>OldInt10] ; Call BIOS   }
  275.                            {        ;                                     }
  276.     /$89/$EC               {        MOV     SP, BP   ; Code to exit       }
  277.     /$5D                   {        POP     BP                            }
  278.     /$CF                   {        IRET                                  }
  279.                            {        ;                                     }
  280.                            {        ;  Only enter here if BIOS function   }
  281.                            {        ;    request was $0E, otherwise we    }
  282.                            {        ;    let the BIOS procede normally    }
  283.                            {        ;    with the above PUSHF and CALL.   }
  284.                            {        ;                                     }
  285.     /$50                   {gotit:  PUSH    AX  ; Save all registers      }
  286.     /$53                   {        PUSH    BX  ;   so we can use Turbo   }
  287.     /$51                   {        PUSH    CX  ;   code below.           }
  288.     /$52                   {        PUSH    DX                            }
  289.     /$57                   {        PUSH    DI                            }
  290.     /$56                   {        PUSH    SI                            }
  291.     /$06                   {        PUSH    ES                            }
  292.     /$1E                   {        PUSH    DS                            }
  293.                            {        ;                                     }
  294.     /$2E/$A2/>INT10CHAR    {CS:     MOV     [>Int10char], AL ; Get char   }
  295.                            {        ;                                     }
  296.                            {        ;  Now we replace linefeed characters }
  297.                            {        ;    with a short beep if the         }
  298.                            {        ;    MakeNoise flag is set.           }
  299.                            {        ;                                     }
  300.     /$3C/$0A               {        CMP     AL, 10                        }
  301.     /$75/$36               {        JNE     nobeep                        }
  302.     /$2E/$A0/>MAKENOISE    {CS:     MOV     AL, [>MakeNoise]              }
  303.     /$3C/$00               {        CMP     AL, $00                       }
  304.     /$74/$2E               {        JE      nobeep                        }
  305.                            {        ;                                     }
  306.     /$B9/$E8/$03           {        MOV     CX, 1000 ; Frequency          }
  307.     /$BB/$64/$00           {        MOV     BX, 100  ; Duration (millsecs)}
  308.                            {        ;                                     }
  309.     /$B0/$B6               {        MOV     AL, $B6  ; Prepare timer      }
  310.     /$E6/$43               {        OUT     $43, AL                       }
  311.                            {        ;                                     }
  312.     /$BA/$12/$00           {        MOV     DX, $0012 ; Calculate freq.   }
  313.     /$B8/$DC/$34           {        MOV     AX, $34DC                     }
  314.     /$F7/$F1               {        DIV     CX                            }
  315.                            {        ;                                     }
  316.     /$E6/$42               {        OUT     $42, AL  ; Send freq to timer }
  317.     /$EB/$00               {        JMP     SHORT j1                      }
  318.     /$88/$E0               {j1:     MOV     AL, AH                        }
  319.     /$E6/$42               {        OUT     $42, AL                       }
  320.                            {        ;                                     }
  321.     /$E4/$61               {        IN      AL, $61  ; Save current timer }
  322.     /$88/$C4               {        MOV     AH, AL   ;   setting          }
  323.                            {        ;                                     }
  324.     /$0C/$03               {        OR      AL, $03  ; Turn on speaker    }
  325.     /$E6/$61               {        OUT     $61, AL                       }
  326.                            {        ;                                     }
  327.     /$B9/$D4/$01           {l1:     MOV     CX, 468  ; Delay              }
  328.     /$E2/$FE               {l2:     LOOP    l2                            }
  329.     /$4B                   {        DEC     BX                            }
  330.     /$75/$F8               {        JNZ     l1                            }
  331.                            {        ;                                     }
  332.     /$88/$E0               {        MOV     AL, AH   ; Turn off speaker   }
  333.     /$E6/$61               {        OUT     $61, AL                       }
  334.                            {nobeep:                                       }
  335.                            {        ;                                     }
  336.                            {        ;  The following two lines set the    }
  337.                            {        ;    data segment to allow access to  }
  338.                            {        ;    variables in the common area of  }
  339.                            {        ;    the program.                     }
  340.                            {        ;                                     }
  341.     /$2E/$A1/>DATASEG      {CS:     MOV     AX, [>DataSeg]                }
  342.     /$8E/$D8               {        MOV     DS, AX                        }
  343.   );
  344.  
  345.   case Int10char of             { Not much here, but it does the job }
  346.     #10  : { Already beeped };
  347.     #13  : write( ' ' );
  348.     else   write( Int10char );
  349.   end;
  350.  
  351.   InLine(
  352.     $1F                    {        POP     DS  ; Restore all registers  }
  353.     /$07                   {        POP     ES                           }
  354.     /$5E                   {        POP     SI                           }
  355.     /$5F                   {        POP     DI                           }
  356.     /$5A                   {        POP     DX                           }
  357.     /$59                   {        POP     CX                           }
  358.     /$5B                   {        POP     BX                           }
  359.     /$58                   {        POP     AX                           }
  360.                            {        ;                                    }
  361.     /$89/$EC               {        MOV     SP, BP   ; Code to exit      }
  362.     /$5D                   {        POP     BP                           }
  363.     /$CF                   {        IRET                                 }
  364.   );
  365. end;
  366.  
  367. procedure Int10ON;
  368.   {
  369.   Direct interrupt 10 calls through our procedure, Int10.
  370.   }
  371. var
  372.   Regs : reg_T;
  373. begin
  374.   DataSeg := Dseg;
  375.   with Regs do
  376.   begin
  377.     AH := $35;             { DOS function $35 - Get Interrupt Vector Address }
  378.     AL := $10;             {      getting $10 - BIOS Video interrupt }
  379.     MsDos( Regs );
  380.     OldInt10[1] := ES;
  381.     OldInt10[0] := BX;
  382.     AH := $25;             { DOS function $25 - Set Interrupt Vector Address }
  383.     AL := $10;             {      setting $10 - BIOS Video interrupt }
  384.     DS := Cseg;
  385.     DX := ofs( Int10 );
  386.     MsDos( Regs );
  387.   end;
  388. end;
  389.  
  390. procedure Int10OFF;
  391.   {
  392.   Restores the original address for interrupt 10.
  393.   }
  394. var
  395.   Regs : reg_T;
  396. begin
  397.   with Regs do
  398.   begin
  399.     AH := $25;            { DOS function $25 - Set Interrupt Vector Address }
  400.     AL := $10;            {      setting $10 - BIOS Video interrupt }
  401.     DS := OldInt10[1];
  402.     DX := OldInt10[0];
  403.     MsDos( Regs );
  404.   end;
  405. end;
  406.  
  407. function HexStr( num : integer ) : str4;
  408.   {
  409.   Convert integer to its four character hex representation
  410.      (padded with zeros).
  411.   }
  412. var
  413.   tstr : string[4];
  414.   i, j : integer;
  415. begin
  416.   tstr[0] := #4;
  417.   for i := 0 to 3 do
  418.   begin
  419.     j := ord('0') + ( (num SHR (4*i)) AND $0F );
  420.     if j < 58 then
  421.       tstr[4-i] := chr( j )
  422.     else
  423.       tstr[4-i] := chr( j + 7 );
  424.   end;
  425.   HexStr := tstr;
  426. end;
  427.