Turbopower TPCRT "Savewindow" and "Restorewindow" lazarus / 21-General ---------------------------------------------------------------------- Atreyu · 2021-01-02 06:26 I'm porting an MS-DOS text based application which was written using some routines from the old Turbopower TPCRT unit... So far I have managed to rewrite/kludge some of this unit to make the old code compile on FP. But now I am stuck on one function that saves a "window" of the screen to an allocated Char array and a procedure which restores the screen from the Char array. I believe the code is referencing the BIOS video Ram area ($B800). The "Movescreen" command is part of old assembler object code from the TPCRT unit... the only indication of what it does is the comment "Move Length words from Source to Dest without snow". The only snow I can possibly think of is old CGA video cards from the days of IBM XT's that had flickering problems. Thats how old all of this stuff is... Can someone advise how to fix the old stuff below so it uses the Videobuf array of the FP video unit? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  BufPtr = ^BufferArray;  BufferArray = array[0..MaxInt] of Char; {$I DBCRT.INC} function SaveWindow(XLow, YLow, XHigh, YHigh : Byte; Allocate : Boolean;                      var Covers : Pointer) : Boolean;    {-Allocate buffer space if requested and save window contents}  var    CoversP : BufPtr absolute Covers;    WordsPerRow : Word;    BufBytes : Word;    SrcPos : Word;    DestPos : Word;    Row : Word;  begin    {assume success}    SaveWindow := True;     {compute number of words to move per row}    WordsPerRow := Succ(XHigh-XLow);     if Allocate then begin      {compute bytes needed for screen buffer}      BufBytes := (WordsPerRow*Succ(YHigh-YLow)) shl 1;       {make sure enough memory is available}      if MaxAvail < LongInt(BufBytes) then begin        SaveWindow := False;        Exit;      end      else        {allocate the screen buffer}        GetMem(CoversP, BufBytes);    end;     {save current contents to the screen buffer}    DestPos := 0;    SrcPos := (Pred(YLow)*ScreenWidth+Pred(XLow)) shl 1;    for Row := YLow to YHigh do begin      MoveScreen(Mem[VideoSegment:SrcPos], CoversP^[DestPos], WordsPerRow);      Inc(SrcPos, ScreenWidth shl 1);      Inc(DestPos, WordsPerRow shl 1);    end;  end; procedure RestoreWindow(XLow, YLow, XHigh, YHigh : Byte;                          Deallocate : Boolean; var Covers : Pointer);    {-Restore screen contents and deallocate buffer space if requested}  var    CoversP : BufPtr absolute Covers;  WordsPerRow : Word;    SrcPos : Word;    DestPos : Word;    Row : Word;  begin    {compute number of words to move per row}    WordsPerRow := Succ(XHigh-XLow);     {Restore current contents to the screen buffer}    DestPos := 0;    SrcPos := (Pred(YLow)*ScreenWidth+Pred(XLow)) shl 1;    for Row := YLow to YHigh do begin      MoveScreen(CoversP^[DestPos], Mem[VideoSegment:SrcPos], WordsPerRow);      Inc(SrcPos, ScreenWidth shl 1);      Inc(DestPos, WordsPerRow shl 1);    end;     {deallocate buffer space if requested}    if Deallocate then begin      FreeMem(CoversP, (WordsPerRow*Succ(YHigh-YLow)) shl 1);      CoversP := nil;    end;  end; Thanks again guys, Atreyu [Edited to add code tags - please see How to use the Forum.] ---------------------------------------------------------------------- PascalDragon · 2021-01-02 09:28 It should be enough to change the code as follows (not tested, but it should at least point you in the right direction): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function SaveWindow(...): Boolean;// ...begin  // ...  DestPos := 0;  // VideoBuf is a pointer to an array of Words, so the "shl 1" is not needed  SrcPos := Pred(YLow)*ScreenWidth+Pred(XLow);  for Row := YLow to YHigh do begin    Move(VideoBuf^[SrcPos], CoversP^[DestPos], WordsPerRow * SizeOf(Word));    MoveScreen(Mem[VideoSegment:SrcPos], CoversP^[DestPos], WordsPerRow);    Inc(SrcPos, ScreenWidth);    Inc(DestPos, WordsPerRow shl 1);  end;    // ...end; procedure RestoreWindow(...);// ...begin  // ...  DestPos := 0;  // same as above (though it would be better to swap the names of Src and Dest...)  SrcPos := Pred(YLow)*ScreenWidth+Pred(XLow);  for Row := YLow to YHigh do begin    MoveScreen(CoversP^[DestPos], VideoBuf^[SrcPos], WordsPerRow * SizeOf(Word));    Inc(SrcPos, ScreenWidth);    Inc(DestPos, WordsPerRow shl 1);  end;    // ...end;