Unit Tools;

Interface

procedure sin_gen(var table:Array of word;period,amplitude,offset:word);
Procedure Draw_Ansi(Name:String);


Implementation

procedure sin_gen(var table:Array of word;period,amplitude,offset:word);
{precalculates a sine table of the length period,
 stores it in the Array table.
 The "Height" in the variable Amplitude and the 
 position of the null point in offset are required for this}
Var i:Word;
Begin
  for i:=0 to period-1 do
    table[i]:=round(sin(i*2*pi/period)*amplitude)+offset;
End;

Procedure Draw_Ansi(Name:String);
{outputs an Ansi file on the screen (requires ANSI.SYS !)}
Var Ansi:File;                  {Ansi file}
    StdOut:File;                {standard output file (Int 21h)}
    Buffer:Pointer;             {buffer for screen}
    Size:Word;                  {file size}
Begin
  Assign(Ansi,Name);            {open Ansi file}
  Assign(StdOut,'CON');         {open output file}

  Reset(Ansi,1);                {initialize Ansi file with block size 1 byte.}
  Size:=FileSize(Ansi);         {define size (in bytes)}
  Reset(Ansi,Size);             {initialize file with this size again}
  Reset(StdOut,Size);           {initialize output file}

  GetMem(Buffer,Size);          {allocate buffer}
  BlockRead(Ansi,Buffer^,1);    {read file ...}
  BlockWrite(StdOut,Buffer^,1); {... and output}
  FreeMem(Buffer,Size);         {free buffer}
  Close(Ansi);                  {close files}
  Close(StdOut);
End;

Begin
End.
