unit TextOut;

{$mode delphi}

interface
uses Classes, SysUtils,Graphics,
        Forms,Dialogs, Controls, extctrls;

procedure TextoutExec;
procedure Drop(s:ansistring);
var
   ConsoleInputRequest:boolean=false;
   CharacterInputRequest:boolean=false;


implementation
uses TextFrm;

var
cache:array[0..65535]of ansistring;
point0:word=0;
point1:word=0;
len:integer=0;

procedure TextoutExec;
var
  s,t:AnsiString;
  c:PAnsiChar;
  p0,p1,p2:word;
  len:integer;
begin
    if point0=point1 then exit;
     p0:=point0;
     p1:=point1;
     p2:=p1;
     len:=0;
     while p2<>p0 do
             begin
               len:=len+length(cache[p2]);
               inc(p2);
             end;
     setlength(s,len+1);
      //c:=Pchar(s);
     c:=@s[1];
     while p1<>p0 do
          begin
            c:=StrEcopy(c,PChar(cache[p1]));
            cache[p1]:='';
            inc(p1);
          end;
     t:=s;
     point1:=p0;
     TextForm.AppendString(t);

end;

//var DropCriticalSection: TRTLCriticalSection;

procedure drop(s:ansistring);
begin
    //EnterCriticalSection(DropCriticalSection);
    while word(point0+1)=point1 do (TThread.CurrentThread).Yield;
    cache[point0]:=s;
    inc(point0);
    //LeaveCriticalSection(DropCriticalSection);
end;

initialization
    //InitCriticalSection(DropCriticalSection);
finalization
    //DoneCriticalSection(DropCriticalSection);
end.

