View Issue Details

IDProjectCategoryView StatusLast Update
0008076FPCRTLpublic2009-03-16 18:44
ReporterAmadeusz S?awi?skiAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version2.2.4Fixed in Version2.2.4 
Summary0008076: crt problem using gotoxy, write and SCREENWIDTH
DescriptionWhe using this code I expect to get a yellow line on themost right of the terminal window, but it 'draws' it frome the lefttop to downright:

for i := 1 to SCREENHEIGHT do
begin
textbackground(YELLOW);
gotoxy(SCREENWIDTH, i);
write(' ');
end;

When using this things seems to work correctly but the line is 'doublespaced'

for i := 1 to SCREENHEIGHT do
begin
textbackground(YELLOW);
gotoxy(SCREENWIDTH-1, i);
write(' '); {here write two spaces}
end;
Additional InformationUsing Mac OS X v 10.4.8 Intel version

compiling using version from this package: fpc-2.1.1-20061015-i386.pkg

terminal version 1.5

TagsNo tags attached.
Fixed in Revision11690
FPCOldBugId0
FPCTarget2.2.2
Attached Files

Activities

Jonas Maebe

2007-01-05 23:18

manager   ~0010682

This patch to rtl/unix/crt.pp fixes it, but I'm not going to apply it because I have no idea whether it doesn't break any other things:

Index: crt.pp
===================================================================
--- crt.pp (revision 5819)
+++ crt.pp (working copy)
@@ -430,8 +430,8 @@
       ConsoleBuf^[idx+CurrX].ch:=s[i];
       ConsoleBuf^[idx+CurrX].attr:=TextAttr;
       inc(CurrX);
- if CurrX>ScreenWidth then
- CurrX:=ScreenWidth;
+// if CurrX>ScreenWidth then
+// CurrX:=ScreenWidth;
     end;
 end;

Florian

2007-01-05 23:37

administrator   ~0010683

I don't think that the patch is good, it could lead to an buffer overrun of ConsoleBuf, no?

Something like windows does seems more appropriate to me:
  if CurrX > WindMaxX then begin
    CurrX := WindMinX;
    Inc(CurrY);
  end; { if }
  While CurrY > WindMaxY do begin
    RemoveLine(1);
    Dec(CurrY);
  end; { while }

I wonder also were the unix crt unit takes care of the wind* values.

Jonas Maebe

2007-01-06 13:08

manager   ~0010696

I don't know, but the crt unit is everything but my domain.

Florian

2007-01-17 08:49

administrator   ~0010909

This applies to linux too. The fix is however unclear. At least the complete unix code doesn't look well.

Peter Vreman

2007-03-29 09:39

administrator   ~0012024

The unix CRT unit relies on correct detection of the screenwidth and screenheight. Without correct information about that it is impossible to keep track of the cursor movement in the internal buffer and the physical tty console.

The code works fine with linux console,xterm and konsole.

Jonas Maebe

2007-03-29 09:56

manager   ~0012026

Screenwidth and height are correctly detected. The problem is that the crt unit contains a bug which causes it not to properly keep track of the cursor position (namely if you write a character at the screen border, because then the cursor moves to the next line while the cursor-tracking code truncates the position to the edge of the screen -- see the patch I posted for where this code is).

And for me this program fails on both Linux and Mac OS X:

uses crt;

var
 i :longint;

begin
  writeln(screenwidth,' x ',screenheight);
  for i := 1 to SCREENHEIGHT do
    begin
      textbackground(YELLOW);
      gotoxy(SCREENWIDTH, i);
      write(' ');
   end;
end.


It writes the first yellow block at the right edge of the terminal window, but the rest forms a diagonal line over the screen instead of a straight line at the right edge of the window (below the first block). As for the dimensions it writes out, those are correct in both cases: 80x24.

Marco van de Voort

2007-09-16 17:44

manager   ~0014685

Jonas' example:
- same on FreeBSD textmode console
. Works fine in xterm.

Jonas: doesn't your patch allow curx to become > screenwidth? Probably it should wrap around.

Jonas Maebe

2007-09-16 17:53

manager   ~0014686

As I mentioned I have no idea about possible negative side effects, and I won't apply it.

Michael Van Canneyt

2008-05-22 20:15

administrator   ~0019591

Applied modified version of patch.

Windmax etc. is taken care of in DoWrite.

Part of the problem is GotoXY which tries to be too smart:
CurrX is used as the 'old' coordinate to 'improve' escape
sequences.

if CurrX doesn't change (as per the old code), then chances
are that gotoxy emits a wrong escape sequence, resulting in
a wrong cursor position. I fixed it by making CurrX:=$FF in case
of overflow. (as done in some other cases). After patch,
the program runs fine on KConsole, X term and Linux console

Issue History

Date Modified Username Field Change
2007-01-05 21:50 Amadeusz S?awi?ski New Issue
2007-01-05 23:18 Jonas Maebe Note Added: 0010682
2007-01-05 23:37 Florian Note Added: 0010683
2007-01-05 23:37 Florian Status new => assigned
2007-01-05 23:37 Florian Assigned To => Jonas Maebe
2007-01-06 13:08 Jonas Maebe Note Added: 0010696
2007-01-06 13:08 Jonas Maebe FPCOldBugId => 0
2007-01-06 13:08 Jonas Maebe FPCTarget => -
2007-01-06 13:08 Jonas Maebe Assigned To Jonas Maebe =>
2007-01-06 13:08 Jonas Maebe Status assigned => confirmed
2007-01-17 08:48 Florian Status confirmed => assigned
2007-01-17 08:48 Florian Assigned To => Michael Van Canneyt
2007-01-17 08:49 Florian FPCTarget - => 2.2.0
2007-01-17 08:49 Florian Note Added: 0010909
2007-03-29 09:39 Peter Vreman Note Added: 0012024
2007-03-29 09:56 Jonas Maebe Note Added: 0012026
2007-09-16 11:08 Florian FPCTarget 2.2.0 => 2.2.2
2007-09-16 17:44 Marco van de Voort Note Added: 0014685
2007-09-16 17:53 Jonas Maebe Note Added: 0014686
2008-04-13 11:35 Florian Target Version => 2.2.2
2008-04-13 11:56 Florian Fixed in Version => 2.3.1
2008-04-13 11:57 Florian Status assigned => resolved
2008-04-13 11:57 Florian Resolution open => fixed
2008-04-13 11:57 Florian Status resolved => assigned
2008-04-13 11:57 Florian Fixed in Version 2.3.1 =>
2008-05-22 20:15 Michael Van Canneyt Fixed in Revision => 11040
2008-05-22 20:15 Michael Van Canneyt Status assigned => resolved
2008-05-22 20:15 Michael Van Canneyt Note Added: 0019591
2008-09-01 23:31 Jonas Maebe Fixed in Version => 2.3.1
2008-09-01 23:31 Jonas Maebe Fixed in Revision 11040 => 11690
2008-09-01 23:31 Jonas Maebe Fixed in Version 2.3.1 => 2.2.3
2008-09-01 23:31 Jonas Maebe Target Version 2.2.2 => 2.2.4
2009-03-16 18:44 Jonas Maebe Status resolved => closed