home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / INTR_DMO.ZIP / PLS-UTIL.INC < prev    next >
Encoding:
Text File  |  1985-10-01  |  5.6 KB  |  199 lines

  1. { PLS-UTIL.INC  Miscelaneous global subprograms }
  2.  
  3. { Forward declaration of error handling routines which use some of the
  4.   routines in the STD-UTIL.INC file and are also used by some of these
  5.   routines. The formal definition of these forward declared procedures
  6.   is in the STD-DISP.INC Include file, which must be included at some
  7.   point following STD-UTIL.INC. }
  8.  
  9.     procedure Disp_IO_Error(device_name: File_ID); forward;
  10.  
  11.     procedure Disp_Error_Msg(err_msg: Str_80); forward;
  12.  
  13. type  NoteRecord = record
  14.                      C,CF,D,DF,E,F,FF,G,GF,A,AF,B: integer;
  15.                    end;
  16.  
  17. const  NOTES : NoteRecord =
  18.                (C:1;CF:2;D:3;DF:4;E:5;F:6;FF:7;G:8;GF:9;A:10;AF:11;B:12);
  19.  
  20.     procedure Play(note,duration: integer);
  21.  
  22.       var  frequency : real;
  23.            i         : integer;
  24.       begin
  25.         frequency := 522;              { Middle C                        }
  26.         for i := 1 to Note - 1 do      { Increase frequency Note-1 times }
  27.         frequency := frequency * 1.059463094;
  28.         Sound(Round(frequency));
  29.         Delay(duration);
  30.         NoSound;
  31.       end; { Play }
  32.  
  33.     procedure Beep;
  34.  
  35.       var  i: integer;
  36.       begin
  37.         for i := 1 to 2 do
  38.           with Notes do
  39.           begin
  40.             Play(G,50);
  41.             Play(D,50);
  42.           end;
  43.       end; { Beep }
  44.  
  45.     function Fgnd(attr: Byte): Integer;
  46.       begin
  47.         Fgnd := (attr and $0F) + ((attr and $80) div 8);
  48.       end { Fgnd };
  49.  
  50.     function Bgnd(attr: Byte): Integer;
  51.       begin
  52.         Bgnd := (attr and $70) div $10;
  53.       end { Bgnd };
  54.  
  55.     function Null_Date(cmp_date: Byte_Date): Boolean;
  56.       begin
  57.         with cmp_date do
  58.         Null_Date := ((month = ZERO) and (day = ZERO)) and (year = ZERO);
  59.       end; { Null_Date }
  60.  
  61.     function Ok: Boolean;
  62.       begin
  63.         Ok := (io_status = ZERO);
  64.       end; { Ok }
  65.  
  66.     procedure Usr_Out_Driver(out_chr: Char);
  67.       var vid_char : PC_Char;
  68.  
  69.       begin
  70.         vid_char.attribute := vid_attr; vid_char.character := out_chr;
  71.         vid_chr[cur_pos] := vid_char;
  72.         cur_pos := Succ(cur_pos);
  73.       end; { Usr_Out_Driver }
  74.  
  75.     procedure GoTo_XY(col, row: Integer);         { Used to position }
  76.       begin                                       { cur_pos for output }
  77.         GoToXY(col,row);
  78.         col := Pred(col) mod MAX_COL;
  79.         row := Pred(row) mod MAX_ROW;
  80.         cur_pos := (row * MAX_COL + col + 1);     { Calculate cur_pos as }
  81.       end; { GoTo_XY }                            { offset into video RAM }
  82.  
  83.     procedure Repeat_Char(character : Char;     { Character to be output.    }
  84.                           count     : Integer); { Number of times to output. }
  85.       var i     : Integer;
  86.  
  87.       begin
  88.         for i := 1 to count do
  89.            Write(character);
  90.       end; { Repeat_Char }
  91.  
  92.     procedure Repeat_Usr_Char(character : Char;
  93.                               count     : Integer);
  94.       var i     : Integer;
  95.  
  96.       begin
  97.         for i := 1 to count do
  98.            Write(Usr,character);
  99.       end; { Repeat_Char }
  100.  
  101.     procedure Write_Usr_Str(out_str: Str_255);
  102.       var i : Integer;
  103.       begin
  104.         for i := 1 to Length(out_str) do  { Outputs out_str via the }
  105.            Write(Usr,out_str[i]);         { Usr output device       }
  106.       end; { Write_Usr_Str }
  107.  
  108.     procedure Strip_Trailing(len : Byte);
  109.  
  110.       begin
  111.         inp_str[0] := Chr(0);       { Set inp_str length to ZERO }
  112.         while (inp_str[len] in [#0..SPACE,FILL_CHAR]) and (len > ZERO) do
  113.           len := Pred(len);
  114.         inp_str[0] := Chr(len);     { Set inp_str length to len }
  115.       end; { Strip_Trailing }
  116.  
  117.     procedure Strip_Leading(len : Byte);
  118.  
  119.       var  i         : Byte;
  120.  
  121.       begin
  122.         i := 1;
  123.         While (inp_str[i] in [#0..SPACE,FILL_CHAR]) and (i <= len) do
  124.           i := Succ(i);
  125.         inp_str := Copy(inp_str,i,len);
  126.       end; { Strip_Leading }
  127.  
  128.     procedure Strip_Inp_Str(len : Byte);
  129.  
  130.       begin
  131.         Strip_Trailing(len);
  132.         Strip_Leading(len);
  133.       end; { Strip_Inp_Str }
  134.  
  135.   function Upper_Case(str: Str_80): Str_80;
  136.       var  i  : Byte;
  137.       begin
  138.         for i := 1 to length(str) do
  139.             str[i] := UpCase(str[i]);
  140.         Upper_Case := str;
  141.       end { Upper_Case };
  142.  
  143.   function Exist(file_name: File_ID): Boolean;
  144.     var chk_file  : File;
  145.  
  146.     begin
  147.       Assign(chk_file,file_name);
  148. {$I-} Reset(chk_file); {$I+}
  149.       Exist := (IOresult = ZERO);
  150.       Close(chk_file);
  151.     end; { Exist }
  152.  
  153.   procedure Clr_Kbd_Buf;
  154.     var kbd_head  : Byte absolute $0000:$041A;
  155.     var kbd_tail  : Byte absolute $0000:$041C;
  156.  
  157.     begin
  158.       kbd_head := kbd_tail;
  159.     end; { Clr_Kbd_Buf }
  160.  
  161.   procedure Get_System_Date;
  162.     var ms_reg  : record
  163.                     ax,bx,cx,dx,bp,si,di,ds,es,flags : Integer;
  164.                   end;
  165.         num_str : Str_5;
  166.  
  167.     begin
  168.       with ms_reg do
  169.       begin
  170.         ax := $2A00;
  171.         Intr($21,ms_reg);
  172.         Str(Hi(dx):2,num_str);
  173.         sys_date := num_str + '/';
  174.         Str(Lo(dx):2,num_str);
  175.         sys_date := sys_date + num_str + '/';
  176.         Str(cx:4,num_str);
  177.         sys_date := sys_date + num_str;
  178.         for i := 1 to 4 do
  179.           if (sys_date[i] = SPACE) then
  180.             sys_date[i] := '0';
  181.       end; {with}
  182.     end; { Get_System_Date }
  183.  
  184.   procedure Chain_To(file_name: File_ID);
  185.     var chain_file : File;
  186.  
  187.     begin
  188.       if Exist(file_name) then
  189.         begin
  190.           Assign(chain_file,file_name);
  191.           chain(chain_file);
  192.         end
  193.       else
  194.         begin
  195.           io_status := $22;
  196.           Disp_IO_Error(file_name);
  197.         end;
  198.     end; { Chain_To }
  199.