[fpc-devel] crt unit fix

Dr. Karl-Michael Schindler schindler at physik.uni-halle.de
Tue Mar 15 08:51:18 CET 2005


There is a endian related bug in the crt unit, which breaks the  
examples ex10 and ex11 of the crt docs. The following fixes the bug and  
makes the code more obvious. I suggest to replace the following two  
routines. Tested on Mac OS X. It fixes web bug 3788 (I submitted that  
one) and 3391 as good as possible (submitted by coraxyn). Some small  
editing corrections as well.

Procedure DoEmptyLine(y,xl,xh:Longint);
{
   Write an empty line at row Y from column Xl to Xh. Memory is also  
updated.
}
Var
   len : Longint;
   blank_with_attribute : TCharAttr;
Begin
   ttyGotoXY(xl,y);
   len:=xh-xl+1;
   LineWrite(Space(len));
   blank_with_attribute.ch:=' ';
   blank_with_attribute.attr:=TextAttr;
    
FillWord(ConsoleBuf^[(y-1)*ScreenWidth+xl 
-1],len,word(blank_with_attribute));
End;

Procedure ClrScr;
{
   Clear the current window, and set the cursor on 1,1
}
Var
   CY,i      : Longint;
   oldflush  : boolean;
   blank_with_attribute : TCharAttr;

Begin
   { See if color has changed }
   if OldTextAttr<>TextAttr then
    begin
      i:=TextAttr;
      TextAttr:=OldTextAttr;
      ttyColor(i);
    end;
   oldflush:=ttySetFlush(Flushing);
   if FullWin then
    begin
      if not OutputRedir then
       ttySendStr(#27'[H'#27'[2J');
      CurrX:=1;
      CurrY:=1;
      blank_with_attribute.ch   := ' ';
      blank_with_attribute.attr := TextAttr;
       
FillWord(ConsoleBuf^,ScreenWidth*ScreenHeight,word(blank_with_attribute) 
);
    end
   else
    begin
      For Cy:=WinMinY To WinMaxY Do
       DoEmptyLine(Cy,WinMinX,WinMaxX);
      GoToXY(1,1);
    end;
   ttySetFlush(oldflush);
End;





More information about the fpc-devel mailing list