%include "inc:util.imp"
%include "iffinc.imp"

!Little utility subtracts two IFF files for comparison purposes
!J. Butler Mar 87

%begin
%record (iffhdr fm) iff1, iff2, iffout
%owninteger rc,a1,a2
%string (255) param,f1,f2

%routine iff sub(%record (iffhdr fm) %name iffhdr, %integer a1, a2, b)
   !perform the subtraction
   %integer i
   %for i=0,1,iffhdr_wid*iffhdr_ht-1 %cycle
      byteinteger(b+i) = byteinteger(a1+i)-byteinteger(a2+i)
   %repeat
%end

param = cli param
printline("Parameters?") %and %return %unless param -> f1.(",").f2 %and %c
f2 -> f2.("/").param
a1=0; a2=0
rc = iff readin(f1, iff1, a1)
rc = iff readin(f2, iff2, a2)
!If we opened the file successfully...
printline("IFF connect: ".iff error(rc)) %and %stop %if rc#0
printline("Size mismatch") %unless iff1_wid=iff2_wid %and iff1_ht=iff2_ht

iffout=iff1
iff1_mapaddr=0
iff sub(iff1, a1, a2, a2)
rc = iff writeout(param, iffout, a2)
heapput(a1); heapput(a2)
printline(iff error(rc)) %if rc#0
%endofprogram
