Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.94 KB | None | 0 0
  1.  DP = destination pointer
  2.   SP = source pointer
  3.   Source and Dest are the two buffers
  4.  
  5.  
  6.   SP:=0;
  7.   DP:=0;
  8.   repeat
  9.     Com:=Source[SP];
  10.     inc(SP);
  11.     b7:=Com shr 7;  {b7 is bit 7 of Com}
  12.     case b7 of
  13.       0 : begin  {copy command (2)}
  14.             {Count is bits 4-6 + 3}
  15.             Count:=(Com and $7F) shr 4 + 3;
  16.             {Position is bits 0-3, with bits 0-7 of next byte}
  17.             Posit:=(Com and $0F) shl 8+Source[SP];
  18.             Inc(SP);
  19.             {Starting pos=Cur pos. - calculated value}
  20.             Posit:=DP-Posit;
  21.             for i:=Posit to Posit+Count-1 do
  22.             begin
  23.               Dest[DP]:=Dest[i];
  24.               Inc(DP);
  25.             end;
  26.           end;
  27.       1 : begin
  28.             {Check bit 6 of Com}
  29.             b6:=(Com and $40) shr 6;
  30.             case b6 of
  31.               0 : begin  {Copy as is command (1)}
  32.                     Count:=Com and $3F;  {mask 2 topmost bits}
  33.                     if Count=0 then break; {EOF marker}
  34.                     for i:=1 to Count do
  35.                     begin
  36.                       Dest[DP]:=Source[SP];
  37.                       Inc(DP);
  38.                       Inc(SP);
  39.                     end;
  40.                   end;
  41.               1 : begin  {large copy, very large copy and fill commands}
  42.                     {Count = (bits 0-5 of Com) +3}
  43.                     {if Com=FEh then fill, if Com=FFh then very large copy}
  44.                     Count:=Com and $3F;
  45.                     if Count<$3E then {large copy (3)}
  46.                     begin
  47.                       Inc(Count,3);
  48.                       {Next word = pos. from start of image}
  49.                       Posit:=Word(Source[SP]);
  50.                       Inc(SP,2);
  51.                       for i:=Posit to Posit+Count-1 do
  52.                       begin
  53.                         Dest[DP]:=Dest[i];
  54.                         Inc(DP);
  55.                       end;
  56.                     end
  57.                     else if Count=$3F then   {very large copy (5)}
  58.                     begin
  59.                       {next 2 words are Count and Pos}
  60.                       Count:=Word(Source[SP]);
  61.                       Posit:=Word(Source[SP+2]);
  62.                       Inc(SP,4);
  63.                       for i:=Posit to Posit+Count-1 do
  64.                       begin
  65.                         Dest[DP]:=Dest[i];
  66.                         Inc(DP);
  67.                       end;
  68.                     end else
  69.                     begin   {Count=$3E, fill (4)}
  70.                       {Next word is count, the byte after is color}
  71.                       Count:=Word(Source[SP]);
  72.                       Inc(SP,2);
  73.                       b:=Source[SP];
  74.                       Inc(SP);
  75.                       for i:=0 to Count-1 do
  76.                       begin
  77.                         Dest[DP]:=b;
  78.                         inc(DP);
  79.                       end;
  80.                     end;
  81.                   end;
  82.             end;
  83.           end;
  84.     end;
  85.   until false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement