program loadiff;
uses crt,dos;
var wsp:longint;
g:file;
buf:array [0..4095] of byte;
color,szer,q,l,i,x,y,px,py,err,ofs:integer;
id:array [0..3] of char;
size,lop:word;
tmp,mask:byte;
bajt,pix:shortint;
xx:char;
bmhd:record
w,h,x,y:word;
nplanes:byte;
masking:byte;
compression:byte;
pad1:byte;
trclr:word;
xaspect,yaspect:byte;
pwidth,pheight:word;
end;
cmap:array [0..767] of byte;
tmsk:array [0..7] of byte;
tpixle:array [0..7] of byte;
procedure bit(b1,b2,b3,b4,b5,b6,b7,b8:byte);
var mask,b0:byte;
begin
for l:=0 to 7 do begin
mask:=tmsk[l]; b0:=0;
if (b1 and mask)>0 then b0:=b0 or 1;
if (b2 and mask)>0 then b0:=b0 or 2;
if (b3 and mask)>0 then b0:=b0 or 4;
if (b4 and mask)>0 then b0:=b0 or 8;
if bmhd.nplanes<>4 then begin
if (b5 and mask)>0 then b0:=b0 or 16;
if (b6 and mask)>0 then b0:=b0 or 32;
if (b7 and mask)>0 then b0:=b0 or 64;
if (b8 and mask)>0 then b0:=b0 or 128;
end;
tpixle[l]:=b0;
end;
end;
function mos(t:word):word;
begin
mos:=(t mod 256)*256+t div 256;
end;
procedure get;
begin
blockread(g,bajt,1,err);move(bajt,tmp,1);
end;
procedure _getid;
begin
blockread(g,id,sizeof(id),err);
end;
procedure getid;
begin
_getid;
blockread(g,buf,4,err);
size:=buf[3]+buf[2]*256+buf[1]*65536;
end;
procedure vga_off;
begin
asm
mov ax,3;
int $10;
end;
end;
procedure bitplan;
begin
ofs:=szer div bmhd.nplanes; px:=0;
for i:=0 to ofs-1 do begin
bit(buf[i],buf[ofs+i],buf[2*ofs+i],buf[3*ofs+i],buf[4*ofs+i],buf[5*ofs+i],buf[6*ofs+i],buf[7*ofs+i]);
for q:=0 to 7 do begin
mem[$a000:px+y*320]:=tpixle[q];px:=px+1;
end;
end;
fillchar(buf,sizeof(buf),0); x:=0; y:=y+1;
end;
procedure pixel(col:byte);
begin
buf[x]:=col; x:=x+1;
end;
procedure iff(name:string);
var q,e,r:integer;
begin
clrscr;
assign(g,name);reset(g,1);
getid;_getid;
if id<>'ILBM' then begin write('Not IFF.');halt; end;
while id<>'BODY' do begin
getid;
if id='BMHD' then blockread(g,bmhd,size,err);
if id='CMAP' then begin color:=size; blockread(g,cmap,size,err);end;
end;
bmhd.w:=mos(bmhd.w); szer:=bmhd.w;
bmhd.h:=mos(bmhd.h);
if (bmhd.w mod bmhd.nplanes)<>0 then szer:=((bmhd.w div bmhd.nplanes)+1)*bmhd.nplanes;
if bmhd.nplanes=4 then bmhd.w:=szer div 2;
writeln('Width x Height: ',bmhd.w,' x ',bmhd.h);
{write(id,' ', bmhd.nplanes);halt;}
repeat until keypressed;
x:=0; y:=0; py:=bmhd.h; fillchar(buf,sizeof(buf),0);
asm
mov ax,$13;
int $10;
end;
port[$3c8]:=0; for i:=0 to color-1 do port[$3c9]:=cmap[i] shr 2;
{ D E K O M P R E S J A }
while y<py do begin
get;
if bajt<0 then begin pix:=abs(bajt)+1; get;
for i:=1 to pix do begin pixel(bajt);end;
end
else begin
pix:=bajt+1;
for i:=1 to pix do begin get;pixel(bajt);end;
end;
if (x>bmhd.w-1) then bitplan;
end;
close(g);
end;
begin
tmsk[0]:=$80;
tmsk[1]:=$40;
tmsk[2]:=$20;
tmsk[3]:=$10;
tmsk[4]:=$8;
tmsk[5]:=$4;
tmsk[6]:=$2;
tmsk[7]:=$1;
iff('akt.iff');
xx:=readkey;
repeat until keypressed;
vga_off;
end.