Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DP = destination pointer
- SP = source pointer
- Source and Dest are the two buffers
- SP:=0;
- DP:=0;
- repeat
- Com:=Source[SP];
- inc(SP);
- b7:=Com shr 7; {b7 is bit 7 of Com}
- case b7 of
- 0 : begin {copy command (2)}
- {Count is bits 4-6 + 3}
- Count:=(Com and $7F) shr 4 + 3;
- {Position is bits 0-3, with bits 0-7 of next byte}
- Posit:=(Com and $0F) shl 8+Source[SP];
- Inc(SP);
- {Starting pos=Cur pos. - calculated value}
- Posit:=DP-Posit;
- for i:=Posit to Posit+Count-1 do
- begin
- Dest[DP]:=Dest[i];
- Inc(DP);
- end;
- end;
- 1 : begin
- {Check bit 6 of Com}
- b6:=(Com and $40) shr 6;
- case b6 of
- 0 : begin {Copy as is command (1)}
- Count:=Com and $3F; {mask 2 topmost bits}
- if Count=0 then break; {EOF marker}
- for i:=1 to Count do
- begin
- Dest[DP]:=Source[SP];
- Inc(DP);
- Inc(SP);
- end;
- end;
- 1 : begin {large copy, very large copy and fill commands}
- {Count = (bits 0-5 of Com) +3}
- {if Com=FEh then fill, if Com=FFh then very large copy}
- Count:=Com and $3F;
- if Count<$3E then {large copy (3)}
- begin
- Inc(Count,3);
- {Next word = pos. from start of image}
- Posit:=Word(Source[SP]);
- Inc(SP,2);
- for i:=Posit to Posit+Count-1 do
- begin
- Dest[DP]:=Dest[i];
- Inc(DP);
- end;
- end
- else if Count=$3F then {very large copy (5)}
- begin
- {next 2 words are Count and Pos}
- Count:=Word(Source[SP]);
- Posit:=Word(Source[SP+2]);
- Inc(SP,4);
- for i:=Posit to Posit+Count-1 do
- begin
- Dest[DP]:=Dest[i];
- Inc(DP);
- end;
- end else
- begin {Count=$3E, fill (4)}
- {Next word is count, the byte after is color}
- Count:=Word(Source[SP]);
- Inc(SP,2);
- b:=Source[SP];
- Inc(SP);
- for i:=0 to Count-1 do
- begin
- Dest[DP]:=b;
- inc(DP);
- end;
- end;
- end;
- end;
- end;
- end;
- until false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement