>Mask Michel Grimminck "Hourglass_Smash": " at line "; 'Version$="1.10":version= (Version$) init: main: lastmove= ( A$= A$<>"" key:lastmove= X,Y,B: B<>0 lastmove= -lastmove)>6*60*100 joke:B=0:lastmove= B<>0 B>0 testbutton: A$<>"none" key:B=0 B>0 X>XS/2-32 X<(XS/2-32+MX) selectmask:B=0 B>0 X>=PX+16 X<=PX+32 Y>=Yd0 Y<=Yd1 B>1 X>=PX X<=PX+48 Y1 X>=PX X<=PX+48 Y>Yd1 M0-=1: changeM0:B=0 B=1 X>=PX X<=PX+48 Y=PX X<=PX+48 Y>Yd1 M0+=1: changeM0:B=0 B=1 XYS/2 makesection:B=0 B=4 XYS/2 (-1) gsline:B=0 B=4 XYS/2 setxy B=2 makeMask(Type,Mcurrent): update(Mcurrent) ( Dcurrent=(Y-Yd0)/(Yd1-Yd0): printD B=2 makeMask(Type,Mcurrent): update(Mcurrent) Y0=Y: X,Y,B: B>0 PX+24,Y Y<>Y0 inversegetbxy(X,Y, ((X-ZOOM!0)/Xc*SFX)+SFX Yt=(ZOOM!12-Y)/Yc*SFY+SFY getxy(X,Y, .2Xt= ((X-SFX)/SFX)*Xc+ZOOM!0: Xt<0 Xt=ZOOM!0 /6Yt=ZOOM!12+1- ((Y-YS/2)/SFY)*Yc: Yt<0 Yt=ZOOM!4 getbxy(X,Y, 32Xt= ((X-SFX)/SFX)*Xc+ZOOM!0: Xt<0 Xt=ZOOM!0 42Yt= (ZOOM!12+1- (Y/SFY)*Yc): Yt<0 Yt=ZOOM!4 setxy getxy(X,Y,Xt,Yt) Xt>=0 Xt=0 Yt=PX X=PX-1 Y>=PY+YS/2 Y=PY+YS/2-1 Y<=YS/2 Y=YS/2+1 X<>Xold Y<>Yold X0,Y0,Xold,Yold: X,Y,X0,Y0:Xold=X:Yold=Y (-1) = "Shift was released, operation aborted": X,Y,X0,Y0: X,Y,X0,Y0 getxy(X0,Y0,Xt0,Yt0) getxy(X,Y,Xt,Yt) O1A%=Xt:B%=Yt: ReadRGB: 2:L%(R%)=RGB?R%: P3A%=Xt0:B%=Yt0: ReadRGB: 2:M%(R%)=RGB?R%: M%()=M%()-L%() ((Xt0-Xt)^2+(Yt0-Yt)^2)+1 DX=(Xt0-Xt)/L:DY=(Yt0-Yt)/L L:X%=Xt+T%*DX:Y%=Yt+T%*DY U, AD%=MASK(Mcurrent)+!MainX*Y%+X%:?AD%=0 V$ A%=!MainData+!MainLine*Y%+3*X% R%=0 2:A%?R%=L%(R%)+T%*M%(R%)/L: displayMainOrig(1): update(Mcurrent) makesection X0=X:Y0=Y Xold=X0:Yold=Y0: X,Y,0,0 X,Y,B X>=PX X=PX-1 Y>=PY+YS/2 Y=PY+YS/2-1 Y<=YS/2 Y=YS/2+1 X<>Xold Y<>Yold X0,Y0,Xold-X0,Yold-Y0: X0,Y0,X-X0,Y-Y0:Xold=X:Yold=Y X0,Y0,X-X0,Y-Y0 X= M%/8/4 Max%=M%/8/4-1 T%=L%:H%=1 AD%=MASK(M1%):P%=0 !MainY-1:AD%=MASK(M1%)+!MainX*Y% !MainX-1 AD%?X%=1 T%!(4*P%)=X%+65536*Y%: P%<(Max%-1) P%+=1 DX%=!MainX P%=Max%-1 "Not all seeds are used" ;P%; " seeds used" 8C%=1:COL%=2:AD%=MASK(Mcurrent):DPT%=1400: seededfill A%=AD%: Filter update(Mcurrent) fill(X%,Y%,DPT%,COL%) P%,DX%,T%,H%,A%,B%,L%,M%,TN% C%=COLOR P%=1:DX%=!MainX mc_maxblock: error$: mc_assign(M%): error$: T%=L%:H%=1 1T%!0=X%+65536*Y%:A%=AD%+!MainX*Y%+X%:?A%=COL% seededfill !FillAD=AD%:!FillKL=COL% P%*4*5 >=M% mc_release(L%): "Operation failed due to memory problems": H%=0 TN%=L% TN%=L%+M%-P%*4*4 !FillStoreAD=TN%:A%=T% !FillNP=0:B%=P%: Fill T%=TN%:P%=!FillNP DPT%-=1:H%=1-H% P%=0 DPT%<0 mc_release(L%): error$: "V","v" : version "D","d" : zoomtoc "C","c" : unzoomtoc "Z","z" : "X","x" : unzoom "0" : printbutton("0", "1" : printbutton("1", "andnot" : andnot: printbutton("andnot", "=","copy" : copy: printbutton("copy", "A","a","and" : printbutton("and", "O","o","or" : printbutton("or", "E","e","eor" : printbutton("eor", "N","n","not" : printbutton("not", "S","s","save": save: printbutton("save", "1","grey" : cleartypes: printbutton("grey", ):Type=0: makeMask(Type,Mcurrent): update(Mcurrent) "2","rgb" : cleartypes: printbutton("rgb", ):Type=1: makeMask(Type,Mcurrent): update(Mcurrent) "3","color" : cleartypes: printbutton("color", ):Type=2: makeMask(Type,Mcurrent): update(Mcurrent) "edge:grey" : cleartypes: printbutton("edge:grey", ):Type=3: makeMask(Type,Mcurrent): update(Mcurrent) "hue" : cleartypes: printbutton("hue", ):Type=4: makeMask(Type,Mcurrent): update(Mcurrent) "save:pic" : clearsave:SaveType$="save:pic": printbutton("save:pic", X,Y,B: "save:smpic" : clearsave:SaveType$="save:smpic": printbutton("save:smpic", X,Y,B: "save:mask" : clearsave:SaveType$="save:mask": printbutton("save:mask", X,Y,B: "black","white","red","green","blue","purple","cyan","yellow","cgrey","darkred","darkblue": setmaskcolor(A$): displayMain(Mcurrent) "noise" : noise(noise): printbutton("noise", "noise:1","noise:2","noise:3","noise:4","noise:5","noise:6","noise:8" :noise= A$,1)): clearnoise: printbutton(A$, X,Y,B: "dilation" : dilation: printbutton("dilation", "dilation:1","dilation:3","dilation:5","dilation:6","dilation:8" :dilation= A$,1)): cleardilation: printbutton(A$, X,Y,B: "load","l","L": load: printbutton("load", "load:mask","load:pic","load:back" : printbutton(LoadType$, printbutton(A$, ):LoadType$=A$: X,Y,B: mc_showmap "T": tidymem "seed" : seed: printbutton("seed", "large" : large: printbutton("large", "invall" : inverse("all"): printbutton(A$, "invmask" : inverse("mask"): printbutton(A$, " : speedtest "erase" : erase: printbutton(A$, "24bit" : 24bit: printbutton(A$, "changecolor" : changecolor: printbutton(A$, "changegrey" : changegrey: printbutton(A$, "correctcol" : correctcol: printbutton(A$, "gamma" : gamma: printbutton(A$, "sceleton" : sceleton(1): update(Mcurrent): printbutton(A$, "pal" :!pal=1-!pal: setuppal( displayMainOrig(1): update(Mcurrent): printbutton("pal",-!pal) "=":T%= checkpal: ;Colors?T%;: "morph","m","M": transform: printbutton("morph", "dma" :dma=1-dma: printbutton("dma",dma-1): X,Y,B: "fastdisplay" :FD=1-FD: printbutton("fastdisplay",-FD): displayMainOrig(1): X,Y,B: "flipy" : flipy: printbutton(A$, displayMainOrig(1) "flipx" : flipx: printbutton(A$, displayMainOrig(1) "contrast" : contrast: printbutton(A$, displayMainOrig(1) "sharp" : sharp: printbutton(A$, displayMainOrig(1) "loadmap" : loadmap: printbutton(A$, "\" : compress "|" : testmem "J" : "K" : lines "tundo" :undo= undo: printbutton("tundo",undo): X,Y,B: "undo" : undo: printbutton(A$, dmaon U%,F%,L% "OS_File",5,".MaskBackup" U%,,F%,,L%:F%=(F% >>8) L%<>!MainL "Unable to undo": printDiskAccess( "OS_File",255,".MaskBackup",MAIN printDiskAccess( displayMainOrig(1) backup undo printDiskAccess( 'CH%= (".MaskBackup") "OS_GBPB",&02,CH%,MAIN,!MainL "SetType .MaskBackup 690" printDiskAccess( OX,OY,X0,Y0,B0,X,Y,B,R,S,ROT,XL,YL,DX,DY RECTANGLEFILL SFX,YS/2+SFY,PX-SFX*2,PY-SFY*2 "Let's not waste those "; (12*index+.5);" mips...." (1)<.45 lines: OX=PX/2:OY=PY/2+YS/2 R=0:S=0.003:ROT=.015 (1)<.3 ROT=ROT*1.5:S=S*1.5 X0,Y0,B0 (50)+120 (50)+120 (1)*(PX-SFX-XL)+SFX -OX (1)*(PY-SFY-YL)+SFY+YS/2 -OY %%DX=( (1)-.5)*R-S*(X+XL/2)-Y*ROT-1 &#DY=( (1)-.5)*R-S*(Y+YL/2)+X*ROT X+=OX:Y+=OY (X+DX)>SFX (Y+DY)>(YS/2+SFY) (X+DX+XL+SFX)"" X<>X0 Y<>Y0 B<>0 displayMainOrig(1) lines T%,L,K,G,M,M2,OX,OY,B,X0,X1,Y0,Y1,VX0,VY0,VX1,VY1,C,CO T%=0 9:X0(T%)=PX/2:Y0(T%)=YS/2+PY/2:K(T%)= L=1.8: INVLOED X,Y K=.5: VERKLEINING G=.99: AFREMMING M=.01:M2=.2: OX,OY,B CO=C:C=(C+1) K(C): X0(C),Y0(C),X1(C),Y1(C) :5X0(C)=(X0(C)+X0*L)/(1+L):Y0(C)=(Y0(C)+Y0*L)/(1+L) ;5X1(C)=(X0(C)+X1*L)/(1+L):Y1(C)=(Y0(C)+Y1*L)/(1+L) X0(C),Y0(C),X1(C),Y1(C):K(C)= =GVX0=G*(VX0+ rnd):VX1=G*(VX1+ rnd):VY0=G*(VY0+ rnd):VY1=G*(VY1+ >)X1=(X1+M*X0)/(1+M):Y1=(Y1+M*Y0)/(1+M) ?'X0+=VX0:Y0+=VY0:X1+=VX1:Y1+=VY1:U= X0<4 X0>=1276:VX0=-VX0:X0+=VX0:U= Y0<4 Y0>=956:VY0=-VY0:Y0+=VY0:U= X1<4 X1>=1276:VX1=-VX1:X1+=VX1:U= Y1<4 Y1>=956:VY1=-VY1:Y1+=VY1:U= X,Y,B (0)<>"" X<>OX Y<>OY B<>0 K(C) X0(C),Y0(C),X1(C),Y1(C) =(6+2*4)*( (1)-.5) testmem mc_showmap P.R%= ensuremem( mc_free+150*1024, ,2,0,0,0) "Result:";R% mc_showmap restoremem mc_showmap compress A%=MASK(Mcurrent) CompressBitfield update(Mcurrent) CALL DeCompressBitfield PROCupdate(Mcurrent) sharp !Main24= "Operation not implemented for <24 bit files": b,T%= ensuremem(!MainN+4, ,Mcurrent,0,0,0) "Not enough memory for operation": restoremem: d5MAD= mc_assign(!MainN+4): MAD= error$: MTEMP=MAD "Strength (def.=0.5)";S S=0 S=.5 (S)>5 i) "illegal strength. Aborted" j3 T%= mc_release(MAD): error$: restoremem l m backup M=1+4*S p6MX%=!MainLine:!sharpS=S*1024:!sharpM=M*1024:B%=MX% C%=0 "Processing colour:";C% Y%=1 !MainY-2:!sharpMask=MASK(Mcurrent)+Y%*!MainX:A%=!MainData+!MainLine*Y%+C%:!sharpStore=MAD+Y%*!MainX sharpen Y%=1 !MainY-2:!sharpMask=MASK(Mcurrent)+Y%*!MainX:A%=!MainData+!MainLine*Y%+C%:!sharpStore=MAD+Y%*!MainX sharpback "Memory stuff" {/T%= mc_release(MAD): error$: restoremem "Ready": printtime transform T$="" ensuremem(!MainL+256 + MaskAmount+16, ,0,0,0,0) tridata= :OldMask=Mcurrent restoremem: "Not enough memory available for operation": DSEC= mc_assign(!MainL +256): SEC= restoremem: error$: "Secondary picture (RETURN for none)";S$ S$<>"" 7 "OS_File",5,S$ U%,,F%,,L%:F%=(F% >>8) M F%<>&690 "Not a clear file. Transforming aborted": relsec: X L%>(!MainL+40) "Second picture has an unequal size. Aborted": relsec: printDiskAccess( "OS_File",255,S$,SEC printDiskAccess( hB$="": S$<>"" !Main24= "Interpolate with secondary picture? (Yes/No/Abort)";B$:B$= B$,1) B$="A" B$="a" "Operation aborted.": relsec: B$="Y" B$="y" int= int= "Number of steps (default=1)";: Step Step=0 Step=1 Step<0 Step<> (Step) Step>500 "Illegal number of steps. Transforming aborted": relsec: F$="": Step>1 int "Filename"; . int= " (or RETURN not to save)"; F$="" int "Aborted:Must have a filename to interpolate": relsec: F$<>"" 6 "OS_File",5,F$ U%,,F%,,L%:F%=(F% >>8) L U%=1 "'"F$"' already exists as a file. Aborted.": relsec: "Cdir "+F$ "Cdir "+F$+".spr" F$<>"" ; "Load point file (or RETURN not to load):";T$ T$<>"" : "OS_File",5,T$ U%,,F%,,L%:F%=(F% >>8) Z F%<>&FFD U%<>1 "illegal file, ignored. (press key)",~F%:B$= :T$="" % T$<>"" loadtrans(T$) Ktridata= mc_assign(MaskAmount+16): tridata= relsec: error$: /MASK(0)=tridata:OldMask=Mcurrent:Mcurrent=0 $templ=!MainData+!MainLine*!MainY X=!MainX:Y=!MainY S$<>"" initmain(SEC) ` !MainX<>X !MainY<>Y "The secondary image has wrong size. Aborted.": relsec: \ !Main24= int= "Secondary image must be 24bpp to interpolate": relsec: H temp=MAIN:MAIN=SEC: displayMainOrig(0):MAIN=temp: initmain(MAIN) "Please select points with the mouse, menu to end" T$="" T$<>"" U%=5 draw(U%): S$="" A%=MAIN:B%=templ:C%=SEC: COPYMEM X,Y,B: X0 B$<>"" "\ZXDCzxdc ",B$)<=1 X=X0:Y=Y0+4000*(X>PX):B$= testbutton B$<>"none" (XPY Y=YS/2 Y0-=YS/2 getbxy(X0,Y0,X0,Y0) B=1 { D=4000: ((X(T%,S%)-X0)^2+(Y(T%,S%)-Y0)^2)=PX X=PX-1 Y>=YS/2 Y-=YS/2 Y>=PY Y=PY-1 getbxy(X,Y,X,Y) V X<>Xold Y<>Yold draw(N):X(N,S%)=X:Y(N,S%)=Y: draw(N):Xold=X:Yold=Y 8 N+=1:S%=1: N>50 N=50: "No more points" N=5 "Too little points. Aborted.": relsec:: S$<>"" A%=MAIN:B%=templ:C%=SEC: COPYMEM F$<>"" savetrans(F$+".Points") N-=1: "Sorting points" 6 X(1,R%)=0:Y(1,R%)=0:X(2,R%)=!MainX-.5:Y(2,R%)=0 F X(3,R%)=!MainX-.5:Y(3,R%)=!MainY-.5:X(4,R%)=0:Y(4,R%)=!MainY-.5 I A=X(T,S%)*X(T,S%)+Y(T,S%)*Y(T,S%): AMIN CH J-=H J1=J+1: J1>H J1-=H ' NO= orient(HULL(J),I(K),HULL(J1)) USED(J)= USED(J)= J TRI+=1:T(TRI,0)=HULL(J):T(TRI,1)=I(K):T(TRI,2)=HULL(J1) L0=J:P0=HULL(J) L1=J:P1=HULL(J1) JN+=1:O=NO L0>0 L1>0 (L1L0) 1 H+=1: L1+1 -1:HULL(T)=HULL(T-1): HULL(L1)=I(K) L1>(L0+1) < H-=L1-L0-1: T=L0+1 H:HULL(T)=HULL(T+L1-L0-1): L0>L1 L1=1 H=L0+1 < L1>1 H=L0-L1+2: H:HULL(T)=HULL(T+L1-1): K+=1 "Optimizing triangulation: pass=";P F%= H1=1 TRI: H2=1 TRI: optimize(H1,H2): P+=1 P>20 TRI: showline(T(T,0),T(T,1)): showline(T(T,1),T(T,2)): showline(T(T,2),T(T,0)) Init triangle table inittridata dotransformation(0) int= F$<>"" CH%= (F$+".000") . writestring(CH%,"Run "+CurrentFile$) #CH%,0 " "SetType "+F$+".000 FEB" int MAIN,SEC S%=1-S% inittridata printDiskAccess( "Cdir "+F$+".sec" "Cdir "+F$+".mix" & "OS_File",255,S$,MAIN printDiskAccess( (? A%=MAIN:B%=!MainData+!MainLine*!MainY:C%=SEC: COPYMEM dotransformation(1) MAIN,SEC CH%= (F$+".mix.000") ,0 writestring(CH%,"Run "+CurrentFile$) #CH%,0 /( "SetType "+F$+".mix.000 FEB" 09 B$=F$+".mix."+ ("0000"+ (Step+1)),3):CH%= 1& writestring(CH%,"Run "+S$) #CH%,0 4 "SetType "+B$+" FEB" NR=1 Step 6" "Mixing nr:";NR Mu=1-NR/(Step+1) 8) C$=F$+"."+ ("0000"+ (NR)),3) 9$ "OS_File",255,C$,MAIN :4 initmain(MAIN):Da%=!MainData:N%=!MainN ;- C$=F$+".sec."+ ("0000"+ (NR)),3) <# "OS_File",255,C$,SEC initmain(SEC) >: A%=Da%:B%=!MainData:C%=1024*Mu:D%=1024*(1-Mu) @0 initmain(MAIN): displayMainOrig(1) A- C$=F$+".mix."+ ("0000"+ (NR)),3) CH%= C, "OS_GBPB",&02,CH%,MAIN,!MainL E" "SetType "+C$+" 690" H)T%= mc_release(SEC): error$: I-T%= mc_release(tridata): error$: Mcurrent=OldMask restoremem initmain(MAIN): "Ready.": printtime inittridata "filling triangles" AD%=tridata TV COL%=T: setline(T(T,0),T(T,1)): setline(T(T,1),T(T,2)): setline(T(T,2),T(T,0)) X%=0:Y%=0 V3 2:X%+=X(T(T,K),S%):Y%+=Y(T(T,K),S%): W( X%=X%/3:Y%=Y%/3:C%=0:AD%=tridata fill(X%,Y%,1500,T) T%=1 !MainN-1: AD%?T%=0 AD%?T%=AD%?(T%-1) relsec mc_release(SEC) error$: tridata<> mc_release(tridata) error$: d Mcurrent=OldMask: restoremem savetrans(T$) U%,CH% #CH%,N-5 U%=5 #CH%,X(U%,0),Y(U%,0),X(U%,1),Y(U%,1) loadtrans(T$) U%,CH% #CH%,N:N+=5 U%=5 #CH%,X(U%,0),Y(U%,0),X(U%,1),Y(U%,1) dotransformation(dir) initmain(MAIN) {0LI%=!MainLine:X=!MainX:Y=!MainY:D%=!MainData initmain(SEC):T%=1:To%=-1:L%=5:Da%=!MainData:ml%=!MainLine !_DA=Da%:!_ML=ml% !Main24= !_bpp=3 !_bpp=1 "Hourglass_On" NR=1 Step int Mu=NR/(Step+1) Mu=NR/Step dir Mu=1-Mu M1=1-Mu !_Mu1=M1*MLacc:!_Xmax=X "Transforming....";: Step>1 "(Picture nr:";NR;")" !MainN>7E4*index dmaoff 2X%=0: triangle=1 TRI:!_tri=triangle: newtri T=triangle "" CH%= "OS_GBPB",&02,CH%,MAIN,LI%*Y+D%-MAIN "SetType "+C$+" 690" "Hourglass_Off" gettrianglenr(X%,Y%,T%) intri(T%) TRI: T%<>I% intri(I%) intri(T%) 'A0%= orient2(X%,Y%,T(T%,0),T(T%,1)) 'A1%= orient2(X%,Y%,T(T%,1),T(T%,2)) A0%<>A1% 'A2%= orient2(X%,Y%,T(T%,2),T(T%,0)) A0%<>A2% optimize(T0,T1) (T0)= (T1) TEL+=1 A0=-1:A1=-1:B0=-1:B1=-1 T(T0,I)=T(T1,J) A0>-1 B0=-1 B0=I:A1=J T(T0,I)=T(T1,J) A0=-1 B0=-1 A0=I:B1=J A0=-1 B0=-1 C0=-1:C1=-1 A0<>T B0<>T C0=T A1<>T B1<>T C1=T C0=-1 C1=-1 "ERROR": orient(T(T0,C0),T(T0,A0),T(T1,C1))<> orient(T(T1,C1),T(T1,A1),T(T0,C0)) min( angle(T(T0,C0),T(T1,C1),T(T1,A1)) , angle(T(T0,C0),T(T0,A0),T(T1,C1)) ) min( angle(T(T0,A0),T(T0,B0),T(T0,C0)) , angle(T(T1,A1),T(T1,B1),T(T1,C1)) ) R10 J=1/J J=J*MLacc B angle(P0,P1,P2) A,B,C,A1,A2,A3 dist(P0,P1):B= dist(P1,P2):C= dist(P2,P0) A<1 A=1: "Warning: arcsine out of range" B<1 B=1: "Warning: arcsine out of range" C<1 C=1: "Warning: arcsine out of range" )T=(A*A-B*B-C*C)/(2*B*C): T<-1 T=-1 T>1 )T=(B*B-C*C-A*A)/(2*C*A): T<-1 T=-1 T>1 )T=(C*C-A*A-B*B)/(2*A*B): T<-1 T=-1 T>1 min(A1, min(A2,A3)) dist(P0,P1) ((X(P0,S%)-X(P1,S%))^2+(Y(P0,S%)-Y(P1,S%))^2) handlezoom A$=B$:dontdismask= Stemp=MAIN:MAIN=SEC: initmain(SEC): displayMainOrig(0):MAIN=temp: initmain(MAIN) T%=5 N-1: draw(T%): flipy !Main24= !MainX/2 E A%=!MainData+3*X%+0:B%=!MainData+!MainLine-3-3*X%: flipy E A%=!MainData+3*X%+1:B%=!MainData+!MainLine-2-3*X%: flipy E A%=!MainData+3*X%+2:B%=!MainData+!MainLine-1-3*X%: flipy M !MainX/2:A%=!MainData+X%:B%=!MainData+!MainLine-1-X%: flipy: flipx mc_assign(!MainLine+4) !MainY/2:AD%=!MainData+Y*!MainLine:AD1%=!MainData+(!MainY-Y-1)*!MainLine BU%= 0 X%=0 !MainLine-1 : AD%?X%,AD1%?X%: 2 A%=AD%:B%=AD%+!MainLine-1:C%=BU%: COPYMEM 4 A%=AD1%:B%=AD1%+!MainLine-1:C%=AD%: COPYMEM 3 A%=BU%:B%=BU%+!MainLine-1:C%=AD1%: COPYMEM BU%<> BU%= mc_release(BU%): BU%= error$: showline(P0,P1) X0,Y0,X1,Y1 inversegetbxy(X(P0,1-S%),Y(P0,1-S%),X0,Y0) inversegetbxy(X(P1,1-S%),Y(P1,1-S%),X1,Y1) window(1) X0,Y0+YS/2,X1,Y1+YS/2 inversegetbxy(X(P0,S%),Y(P0,S%),X0,Y0) inversegetbxy(X(P1,S%),Y(P1,S%),X1,Y1) window(0) X0,Y0,X1,Y1 setline(P0,P1) line(X(P0,S%),Y(P0,S%),X(P1,S%),Y(P1,S%)) dist(P0,P1) ((X(P0,S%)-X(P1,S%))^2+(Y(P0,S%)-Y(P1,S%))^2) orient(T0,T1,T2) *UO=(X(T1,S%)-X(T0,S%))*(Y(T2,S%)-Y(T0,S%))-(X(T2,S%)-X(T0,S%))*(Y(T1,S%)-Y(T0,S%)) orient2(X%,Y%,T1,T2) /=O=(X(T1,S%)-X%)*(Y(T2,S%)-Y%)-(X(T2,S%)-X%)*(Y(T1,S%)-Y%) 0 =O>=0 draw(Q%) X0,Y0,X1,Y1 inversegetbxy(X(Q%,0),Y(Q%,0),X0,Y0) inversegetbxy(X(Q%,1),Y(Q%,1),X1,Y1) window(0) X1,Y1,10 X0,Y0,X1,Y1 window(1) X0,Y0+YS/2,10 X0,Y0+YS/2,X1,Y1+YS/2 window(NR) 24,SFX;SFY+YS/2*NR;PX-SFX;PY+YS/2*NR-SFY; checkpal A%,B%,F%,T% 4:Colors!T%=0: F.A%=MASK(Mcurrent):B%=Colors: CheckPalette G7double=0:Gaps=0: Colors?T%=3 double+=1 Colors?T%=0 Gaps+=1 =double>0 sceleton(TI%) 255:Colors?T%=0: Colors?255=1:Colors?0=1 P7T1=(T% 1)=1:T2=(T% 2)=2:T3=(T% 4)=4:T4=(T% QAT5=(T% 16)=16:T6=(T% 32)=32:T7=(T% 64)=64:T8=(T% 128)=128 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 Colors?T%=1 (T1+T2+T3+T4+T5+T6+T7+T8)=-1 Colors?T%=1 (T1+T2+T3+T4+T5+T6+T7+T8)<-4 Colors?T%=0 :Colors?255=1:Colors?0=1 DX%=!MainX !MainY-2:AD%=MASK(Mcurrent)+!MainX*Y% !MainX-2:A%=AD%+X%: ?A%=1 hS C%=(A%?1>0)+2*(A%?(1-DX%)>0)+4*(A%?(-DX%)>0)+8*(A%?(-1-DX%)>0)+16*(A%?-1>0) i? C%+=32*(A%?(-1+DX%)>0)+64*(A%?DX%>0)+128*(A%?(1+DX%)>0) ?A%=3-Colors?-C% k A%=MASK(Mcurrent): Filter changecolor !Main24= s[ T%= checkpal: "OPERATION FAILED:Not able to change palette.":fail= t "Use Current selected point or new point (C/N/A)" B$<>"N" B$<>"C" B$<>"c" B$<>"n" "Operation aborted": B$="N" B$="n" y, "Please enter red value:";: z. "Please enter green value:";: {- "Please enter blue value:";: | }) A%=Xcurrent:B%=Ycurrent: ReadRGB R=RGB?0:G=RGB?1:B=RGB?2 backup R+G+B=0 R=1:G=1:B=1 #GR=(R+G+B):R=R/GR:G=G/GR:B=B/GR "Busy..." !MainN>5E4*index !Main24= dmaoff !Main24= 8 !MainEntry-1: Colors?T%<>1 Colors?T%=0 A A=!MainData:N=!MainN:!MainData=!MainPal:!MainN=!MainEntry AD%=Colors AD%=MASK(Mcurrent) !MainN-1 AD%?T%=1 > A%=!MainData+T%*3:R0=A%?0:G0=A%?1:B0=A%?2:GR0=R0+G0+B0 " R0=R*GR0:G0=G*GR0:B0=B*GR0 R0>255 R0=255 G0>255 G0=255 B0>255 B0=255 A%?0=R0:A%?1=G0:A%?2=B0 !Main24= !MainData=A:!MainN=N dmaon "Ready" displayMainOrig(1): update(Mcurrent) changegrey testpalette: fail : "By which factor has the grey-value to be multiplied"; F<0 "What is a negative grey-value suppossed to mean?": backup F>255 "That much? Ok. but it will all turn white" "Busy..." !Main24= 4:Table!T%=Colors!T%: 255:G0=F*T%: G0>255 G0=255 : maps?(4+T%)=G0:maps?(260+T%)=G0:maps?(516+T%)=G0: generalcorrectcolor "Ready" displayMainOrig(1): update(Mcurrent) correctcol testpalette: fail : "By which factor has the red-value to be multiplied"; R<0 "What is a negative red-value suppossed to mean?": "By which factor has the green-value to be multiplied"; G<0 "What is a negative green-value suppossed to mean?": "By which factor has the blue-value to be multiplied"; B<0 "What is a negative blue-value suppossed to mean?": backup "Busy..." !Main24= 4:Table!T%=Colors!T%: E%=0 255:R%=R*E%:G%=G*E%:B%=B*E% R%<0 R%=0 G%<0 G%=0 B%<0 B%=0 R%>255 R%=255 G%>255 G%=255 B%>255 B%=255 6 maps?(4+E%)=R%:maps?(260+E%)=G%:maps?(516+E%)=B% generalcorrectcolor fail : "Ready" displayMainOrig(1): update(Mcurrent) testpalette fail= !Main24= [ T%= checkpal: "OPERATION FAILED:Not able to change palette.":fail= generalcorrectcolor fail= !Main24= [ T%= checkpal: "OPERATION FAILED:Not able to change palette.":fail= !Main24= 4:Table!T%=Colors!T%: !Main24 F A%=maps+4:C%=MASK(Mcurrent): TransFormColor:A%+=256: 6 !MainEntry-1: Table?T%<>1 Table?T%=0 A A=!MainData:N=!MainN:!MainData=!MainPal:!MainN=!MainEntry = A%=maps+4:C%=Table: TransFormColor:A%+=256: !MainData=A:!MainN=N gamma testpalette: fail : "gamma factor"; G<=.001 G>100 "Illegal gamma. Aborted.": backup !Main24= 4:Table!T%=Colors!T%: 255:G0=255*(T%/255)^(1/G) : maps?(4+T%)=G0:maps?(260+T%)=G0:maps?(516+T%)=G0: "maps?4=0:maps?260=0:maps?516=0 generalcorrectcolor fail "Ready" - displayMainOrig(1): update(Mcurrent) loadmap testpalette: fail : B$=M$ "Load map:Filename ('','last','other')";M$ M$="last" M$="LAST" M$="Last" M$=B$ M$="" M$=".Maps.MyMap": "Default map:'"M$"' taken." M$,1)=":" M$=".Maps."+ M$,2) "OS_File",5,M$ U%,,F%,,L%:F%=(F% >>8) U%<>1 "This file does not exist": L%<>832 "This file is not a color-map. Its length is not 832 bytes.": F%<>&FFD "Warning:incorrect file-type" "OS_File",255,M$,maps !maps<>&BD2A275D "Warning:incorrect indentifier" backup name(maps+4,60) .A%=maps+64:B%=maps+832:C%=maps+4: COPYMEM generalcorrectcolor fail - displayMainOrig(1): update(Mcurrent) 24bit !Main24= "Picture is already in 24 bit format": "T%=MAIN: ?T%<>0 T%+=1: :M=T% (M-MAIN+4*!MainX*!MainY+4+7*mc_page) >mc_amount "Not enough memory for operation": T%=1 T%<=MaxMask% * A%=MASK(T%): CompressBitfield printDiskAccess( 3 CH%= (".MaskSwap"+ (T%)) 1 "OS_GBPB",&02,CH%,A%,MaskAmount/8+1 printDiskAccess( 8 R%= mc_release(MASK(T%)): error$: OldMask%=MaxMask% mc_assign(M-MAIN+3*!MainX*!MainY+4): B O=MAIN:MAIN= mc_reallocate(MAIN): MAIN= error$: # O<>MAIN initmain(MAIN) / N%= mc_assign(M-MAIN+3*!MainX*!MainY+4) error$: "Converting....": (M-MAIN) 4:N%!T%=MAIN!T%: 8O=N%+M-MAIN:O!1=M!1:O!5=M!5:O!9=M!9:O!13=24:AD%=O+17 A%=0:B%=AD%: ConvertTo24 !Main24= !MainData=O+17 !MainLine=3*!MainX mc_release(MAIN)= error$: #2MAIN=N%:!MainL=!MainData-MAIN+!MainLine*!MainY "reallocating..." %8MAIN= mc_reallocate(MAIN): MAIN= error$: !MainData=MAIN+O+17-N% T%=1 8:MASK(T%)= mc_assign(1): MASK(T%)= error$: assignmasks T%=1 min(MaxMask%,OldMask%) printDiskAccess( "OS_File",255,".MaskSwap"+ (T%),MASK(T%) printDiskAccess( .& A%=MASK(T%): DeCompressBitfield displayMask(M%,M%-M0+1): version T$=" Version:"+Version$+" "+"Author:Michel Grimminck Email:grimmink@phys.uva.nl Smail:Westerstraat 155 Amsterdam " 78T$=T$+"Current image contains "+ (!MainN)+" pixels " !Main24= T$=T$+"of 3 bytes per pixel" T$=T$+"of one byte/pixel" T$=T$+" " (T$): T$,T%,57): contrast !Main24= "Not implemented for <=8 bpp files": getboundaries X0=0 Y0=0 X1=!MainX-1 Y1=!MainY "Erase/contrast cannot handle edges": A*data= mc_assign(3*(X1-X0+1)*(Y1-Y0+1)) data= "not enough memory for operation": "Contrast factor";CF Y%=Y0 Y1:AD%=data+3*(X1-X0+1)*(Y%-Y0):ADL%=!MainData+Y%*!MainLine X%=3*X0 3*X1+2:AD%?(X%-X0)=ADL%?X% erase fail= mc_release(data): error$: fail= Y%=Y0 Y1:AD%=data+3*(X1-X0+1)*(Y%-Y0):ADL%=!MainData+Y%*!MainLine X%=3*X0 3*X1+2:N=(1-CF)*ADL%?X%+CF*AD%?(X%-X0) N<0 N>255 N=255 ADL%?X%=N "Ready." S0T%= mc_release(data): error$: erase X0,Y0,X1,Y1 fail= !Main24= "Not implemented for <=8 bpp files": getboundaries X0=0 Y0=0 X1=!MainX-1 Y1=!MainY "Erase cannot handle edges": \9T%= ensuremem((X1-X0+3)*(Y1-Y0+3)*4, ,Mcurrent,0,0,0) "Erase:not enough memory for operation": restoremem: ^UGS%= mc_assign((X1-X0+3)*(Y1-Y0+3)*4): GS%= error$:fail= restoremem: IM%=(X1-X0+1)*(Y1-Y0+1)*.07 IM%<40 IM%=40 IM%>1500 cK "This is going to take a very long time. Are you sure?(Y/N)" B$= B$<>"Y" B$<>"y" f9 T%= mc_release(GS%): error$: g8 "Erase aborted":fail= restoremem: backup "Copying color";C%;" data" DY%=(X1-X0+3)*4 (Y1-Y0+2):B%=Y%+Y0-1:AD%=GS%+DY%*Y%:M%=MASK(Mcurrent)+!MainX*B%+X0-1 (X1-X0+2):A%=X%+X0-1: M%?X%=0 ReadRGB:AD%!(X%*4)=256*RGB?C% AD%!(X%*4)=0 "Doing ";IM%;" Gauss-Seidel iterations in color ";C% IM%>150*(index^.333) dmaoff F%=DY% (Y1-Y0)+1:A%=GS%+DY%*Y%:B%=MASK(Mcurrent)+!MainX*(Y%+Y0-1)+X0-1 D%=(X1-X0)+1: GaussSeidel { I%+=1 dmaon "Copying color";C%;" back to picture" (Y1-Y0+2):B%=Y%+Y0-1:AD%=GS%+DY%*Y%:M%=MASK(Mcurrent)+!MainX*B%+X0-1:S%=!MainData+!MainLine*B%+(X0-1)*3 (X1-X0+2):A%=X%-X0-1: M%?X%=1 S%?(X%*3+C%)=AD%!(X%*4)/256 "Ready" mc_release(GS%): error$: restoremem displayMainOrig(1) update(Mcurrent) speedtest "Doing speedtests" A%=MASK(Mcurrent) T%=0 CompressBitfield: DeCompressBitfield: "Time to compress+decompress:"; /100/T%*1000;" ms" displayMask(Mcurrent,Mcurrent-M0+1): "Black mask:";( -TI%)/100/(T%-1) displayMain(Mcurrent): "Black main:";( -TI%)/100/(T%-1) &P%=BinaryInstr:[OPT 0: R3,R5,R7:] BA%=MASK(Mcurrent):B%=MASK(Mcurrent):C%=MASK(Mcurrent): Binary displayMask(Mcurrent,Mcurrent-M0+1): "White mask:";( -TI%)/100/(T%-1) displayMain(Mcurrent): "White main:";( -TI%)/100/(T%-1) inverse(option$) fail= option$="all" AD%=!MainData !Main24= ? 255:Colors?T%=255-T%: :A%=Colors:C%=0: B%=0 TransFormColor: 3 T%=!MainPal !MainData-1:?T%=255-?T%: option$="mask" 255:maps?(4+T%)=255-T%:maps?(260+T%)=255-T%:maps?(516+T%)=255-T%: generalcorrectcolor fail : displayMainOrig(1) update(Mcurrent) noise(D%) DX%=!MainX !MainY-2:A%=MASK(Mcurrent)+DX%*Y%: Neighbours2: A%=MASK(Mcurrent): Filter update(Mcurrent) dilation DX%=!MainX:D%=dilation !MainY-2:A%=MASK(Mcurrent)+!MainX*Y%: Neighbours: A%=MASK(Mcurrent): Filter2 Filter update(Mcurrent) clearnoise printbutton("noise:1", printbutton("noise:2", printbutton("noise:3", printbutton("noise:4", printbutton("noise:5", printbutton("noise:6", printbutton("noise:8", cleardilation printbutton("dilation:1", printbutton("dilation:3", printbutton("dilation:5", printbutton("dilation:6", printbutton("dilation:8", cleartypes printbutton("grey", printbutton("rgb", printbutton("color", printbutton("edge:grey", printbutton("hue", clearsave printbutton("save:pic", printbutton("save:smpic", printbutton("save:mask", update(M%) displayMask(M%,M%-M0+1): displayMain(M%): printtime printtime 40,0);" ";: 40,0) changeM0 M0<1 M0=1 (M0+2)>MaxMask% M0=MaxMask%-2 clearD: printD YY%=0 displayMask(YY%+M0,YY%+1): showMaskRect X,Y,B: -T%)>12 large ensuremem(MaskAmount, ,Mcurrent,0,0,0) "Large: not enough memory for operation": restoremem: QM1%=0:MASK(0)= mc_assign(MaskAmount): MASK(0)= error$: restoremem: "Please enter a minimal thickness (pixels)"; S%:S%= (S%/2) S%>200 "Don't you think that is rather big?": restoremem: %P%=BinaryInstr:[OPT 0:MOV R3,R5:] ;A%=MASK(0):B%=MASK(Mcurrent):C%=MASK(Mcurrent): Binary K=Mcurrent:Mcurrent=M1% R%=1 noise(8): Mcurrent=K: seedintern mc_release(MASK(0)): error$: restoremem update(Mcurrent) "And: Please select first mask":M1%= input "And: Please select second mask":M2%= input "Doing operation:z=x and y" &P%=BinaryInstr:[OPT 0: R3,R5,R6:] 8A%=MASK(Mcurrent):B%=MASK(M1%):C%=MASK(M2%): Binary update(Mcurrent) andnot "And Not: Please select first mask":M1%= input "And Not: Please select second mask":M2%= input "Doing operation:z=x andnot y" &P%=BinaryInstr:[OPT 0: R3,R5,R7:] 3A%=MASK(M2%):B%=MASK(M2%):C%=MASK(M2%): Binary &P%=BinaryInstr:[OPT 0: R3,R5,R6:] 8A%=MASK(Mcurrent):B%=MASK(M1%):C%=MASK(M2%): Binary &P%=BinaryInstr:[OPT 0: R3,R5,R7:] 3A%=MASK(M2%):B%=MASK(M2%):C%=MASK(M2%): Binary update(Mcurrent) "Or: Please select first mask":M1%= input "Or: Please select second mask":M2%= input "Doing operation:z=x or y" %'P%=BinaryInstr:[OPT 0: R R3,R5,R6:] &8A%=MASK(Mcurrent):B%=MASK(M1%):C%=MASK(M2%): Binary update(Mcurrent) "Exclusive or: Please select first mask":M1%= input "Exclusive or: Please select second mask":M2%= input "Doing operation:z=x eor y" .&P%=BinaryInstr:[OPT 0: R3,R5,R6:] /8A%=MASK(Mcurrent):B%=MASK(M1%):C%=MASK(M2%): Binary update(Mcurrent) "Not:Please select a mask":M1%= input "Doing operation:z=not x" 6&P%=BinaryInstr:[OPT 0: R3,R5,R7:] 78A%=MASK(Mcurrent):B%=MASK(M1%):C%=MASK(M1%): Binary update(Mcurrent) "Copy: Please select a mask":M1%= input "Doing operation:z=x" >%P%=BinaryInstr:[OPT 0:MOV R3,R5:] ?8A%=MASK(Mcurrent):B%=MASK(M1%):C%=MASK(M1%): Binary update(Mcurrent) update(Mcurrent) A%,B%,C% I%P%=BinaryInstr:[OPT 0:MOV R3,#0:] JBA%=MASK(Mcurrent):B%=MASK(Mcurrent):C%=MASK(Mcurrent): Binary N%P%=BinaryInstr:[OPT 0:MOV R3,R7:] OBA%=MASK(Mcurrent):B%=MASK(Mcurrent):C%=MASK(Mcurrent): Binary update(Mcurrent) input X,Y,B: X,Y,B: B>1 X>=PX X<=PX+48 Y1 X>=PX X<=PX+48 Y>Yd1 M0-=1: changeM0:B=0 B=1 X>=PX X<=PX+48 Y=PX X<=PX+48 Y>Yd1 M0+=1: changeM0:B=0 (Y/YS*3)+(M0-1) selectmask c+M%=3- (Y/YS*3)+(M0-1): M%>MaxMask% Mcurrent=M% showMaskRect displayMain(Mcurrent) makeMask(TYPE%,NR%) =0:A%=Xcurrent:B%=Ycurrent: ReadRGB "Hourglass_Start",100 TYPE% n9 A%=MASK(NR%):B%=RGB?0+RGB?1+RGB?2:C%=768*Dcurrent !Main24 Calc(0) q r_ A%=Colors:A=!MainData:!MainData=!MainPal:N=!MainN:!MainN=!MainEntry:!Main24= Calc(0) sB !Main24= :!MainN=N:!MainData=A:B%=MASK(Mcurrent): SetMask t v/ A%=MASK(NR%):B%=RGB?0:C%=RGB?1:D%=RGB?2 E%=Dcurrent^2*3*255*255 !Main24= Calc(1) z {_ A%=Colors:A=!MainData:!MainData=!MainPal:N=!MainN:!MainN=!MainEntry:!Main24= Calc(1) |B !Main24= :!MainN=N:!MainData=A:B%=MASK(Mcurrent): SetMask } Z=Dcurrent^2 /3 - TR=RGB?0:TG=RGB?1:TB=RGB?2:T=TR+TG+TB A%=T:B%=Z*65536 !Main24= C%=MASK(NR%): Calc(2) _ C%=Colors:A=!MainData:!MainData=!MainPal:N=!MainN:!MainN=!MainEntry:!Main24= Calc(2) H !Main24= :!MainN=N:!MainData=A:A%=C%:B%=MASK(Mcurrent): SetMask "Hourglass_Off" !Main24= "Not implemented for 24 bpp files": C=Dcurrent* W3=2/3* (3):P2= X=RGB?0-.5*RGB?1-.5*RGB?2 Y=W3*RGB?1-W3*RGB?2 Y=0 T=- *(X<0) T= (X/Y): X<0 !MainEntry-1 9 R=!MainPal+3*B%:G=!MainPal+3*B%+1:B=!MainPal+3*B%+2 X=?R-.5*?G-.5*?B Y=W3*?G-W3*?B Y=0 H=- *(X<0) H= (X/Y): X<0 (H-T): H>P2 H-=P2 H=P2-H H140000*index : "This will take a long time. Are you sure?(Y/N)" !MainN>140000*index ^ B$= B$<>"Y" B$<>"y" "Edge aborted": "Ok. busy for some time...." !MainN>14000*index dmaoff #C%=(Dcurrent*600)^2:!EdgeVal=C% !MainY-2:AD%=MASK(Mcurrent)+!MainX*B%:!EdgeAd=AD%: Edge: dmaon type2 "Hourglass_On":Z=Dcurrent^2 /3 )TR=RGB?0:TG=RGB?1:TB=RGB?2:T=TR+TG+TB =Button(T%,0) X<=Button(T%,2) Y>=Button(T%,1) Y<=Button(T%,3) S=T% S>=0 printbutton(Button$(S), S=-1 ="none" =Button$(S) defaults mode:mode= "FX 4 1" .mapsize=6144 : Size of main fixed buffer PL 16,MASK(8),OldMask(8),Button(90,3),ButtonP$(90),Button$(90) ButtonType(90),C%(2,2,2),L%(2),M%(2),Colors 256,Table 256,R(15),G(15),B(15) X(50,1),Y(50,1),I(50),T(100,2),USED(40),HULL(40),maps mapsize K(10),X0(10),Y0(10),X1(10),Y1(10) maskstatus(8),temp(8),M(3) button=0:on=1:off=0:M$="" FD=deffd:dontdismask= =PL!0=149:PL!4=-1: "OS_ReadVduVariables",PL,PL+8:EE%=PL!8 "OS_ReadModeVariable",mode,3 ,,T%: T%<>63 mode=15: mode: "This program must run in a 256 color mode. Change !Defaults-file": "OS_ReadModeVariable",mode,4 ,,FX "OS_ReadModeVariable",mode,5 ,,FY "OS_ReadModeVariable",mode,7 ,,ScrMem% "OS_ReadModeVariable",mode,11 ,,XW:XW+=1 "OS_ReadModeVariable",mode,12 ,,YW:YW+=1 +SFX=1<>FX)-2:YMmax=(PY >>FY)-2 )XMmaxM=(MX >>FX)-2:YMmaxM=(MY >>FY)-2 Determen arm speed: =0:T%=0: :T%+=1: >=10:index=T%/2100 'dma=defdma:!pal=defpal: setuppal( defdma=2 % index<.6 dma=off dma=on 0,0,PX,PY: 0,YS/2,PX,PY .MaxMask%=3:Mcurrent=2:Type=2: showMaskRect 7Xmenu=XS/2-32+MX+20: Xmenu,0,1500,3000 mc_init( -48*1024,4096): error$ -MAIN= mc_assign(1):: MAIN= error$ 8:MASK(T%)= mc_assign(1): MASK(T%)= error$ >SaveType$="save:smpic":Xcurrent=0:Ycurrent=0:Dcurrent=0.25 LoadType$="load:pic" printXY: printD Y=YS*47/50 21+128 makebutton(Xmenu+32,Y,"Grey","grey") makebutton(Xmenu+128,Y,"RGB","rgb") makebutton(Xmenu+208,Y,"Color","color") makebutton(Xmenu+32,Y-3/50*YS,"Hue","hue") makebutton(Xmenu+128,Y-3/50*YS,"Edge","edge:grey") printbutton("color", printline(Xmenu+0*SFX,Y-5/50*YS+SFY*3,XS) Xmenu+1,Y YB=40/50*YS makebutton(Xmenu+12,YB,"NOT","not") makebutton(Xmenu+78,YB,"=","copy") makebutton(Xmenu+114,YB,"AND","and") makebutton(Xmenu+182,YB,"0","0") makebutton(Xmenu+216,YB,"1","1") makebutton(Xmenu+252,YB,"LARGE","large") makebutton(Xmenu+12,YB-3/50*YS,"EOR","eor") makebutton(Xmenu+80,YB-3/50*YS,"OR","or") makebutton(Xmenu+132,YB-3/50*YS,"ANDNOT","andnot") makebutton(Xmenu+248,YB-3/50*YS,"SEED","seed") makebutton(Xmenu+12,YB-6/50*YS,"NOISE:","noise") makebutton(Xmenu+126,YB-6/50*YS,"1","noise:1") makebutton(Xmenu+158,YB-6/50*YS,"2","noise:2") makebutton(Xmenu+190,YB-6/50*YS,"3","noise:3") makebutton(Xmenu+222,YB-6/50*YS,"4","noise:4") makebutton(Xmenu+254,YB-6/50*YS,"5","noise:5") makebutton(Xmenu+286,YB-6/50*YS,"6","noise:6") makebutton(Xmenu+318,YB-6/50*YS,"8","noise:8") ;%noise=1: printbutton("noise:1", makebutton(Xmenu+12,YB-9/50*YS,"DILATION:","dilation") makebutton(Xmenu+176,YB-9/50*YS,"1","dilation:1") makebutton(Xmenu+208,YB-9/50*YS,"3","dilation:3") makebutton(Xmenu+240,YB-9/50*YS,"5","dilation:5") makebutton(Xmenu+272,YB-9/50*YS,"6","dilation:6") makebutton(Xmenu+272+32,YB-9/50*YS,"8","dilation:8") B+dilation=1: printbutton("dilation:1", printline(Xmenu+0*SFX,YB-11/50*YS+SFY*4,XS) Xmenu+1,YB YF=YB-13/50*YS makebutton(Xmenu+16,YF,"LOAD:","load") makebutton(Xmenu+112,YF,"pic","load:pic") makebutton(Xmenu+176,YF,"mask","load:mask") makebutton(Xmenu+256,YF,"back","load:back") printbutton(LoadType$, makebutton(Xmenu+16,YF-YS*3/50,"SAVE:","save") makebutton(Xmenu+112,YF-YS*3/50,"pic","save:pic") makebutton(Xmenu+176,YF-YS*3/50,"smpic","save:smpic") makebutton(Xmenu+270,YF-YS*3/50,"mask","save:mask") printbutton(SaveType$, printline(Xmenu+0*SFX,YF-5/50*YS+SFY*4,XS) Xmenu+1,YF U%=-32+16 Ypic=YF-YS*7/50 makebutton(Xmenu+16,Ypic,"map","loadmap") makebutton(Xmenu+86,Ypic,"InvM","invmask") makebutton(Xmenu+170,Ypic," ","flipy") makebutton(Xmenu+224,Ypic," ","flipx") makebutton(Xmenu+278,Ypic,"24b","24bit") makebutton(Xmenu+170,Ypic-YS*3/50,"Gam","gamma") makebutton(Xmenu+240,Ypic-YS*3/50,"Filt","correctcol") makebutton(Xmenu+100,Ypic-YS*3/50,"Col","changecolor") makebutton(Xmenu+16,Ypic-YS*3/50,"grey","changegrey") makebutton(Xmenu+16,Ypic-YS*6/50,"Morph","morph") makebutton(Xmenu+116,Ypic-YS*6/50,"Erase","erase") makebutton(Xmenu+216,Ypic-YS*6/50,"contrast","contrast") makebutton(Xmenu+16,Ypic-YS*9/50,"sharp","sharp") makebutton(Xmenu+116,Ypic-YS*9/50,"undo","undo") Y=Ypic-12/50*YS makebutton(Xmenu+U%+32,Y,"b","black") makebutton(Xmenu+U%+64,Y,"w","white") makebutton(Xmenu+U%+96,Y,"r","red") makebutton(Xmenu+U%+128,Y,"g","green") makebutton(Xmenu+U%+160,Y,"b","blue") makebutton(Xmenu+U%+192,Y,"p","purple") makebutton(Xmenu+U%+224,Y,"c","cyan") makebutton(Xmenu+U%+256,Y,"y","yellow") makebutton(Xmenu+U%+288,Y,"g","cgrey") makebutton(Xmenu+U%+320,Y,"R","darkred") makebutton(Xmenu+U%+352,Y,"B","darkblue") printline(Xmenu+0*SFX,Ypic-14/50*YS+SFY*4,XS) Yo=Y-4/50*YS makebutton(Xmenu+16,Yo,"DMA","dma") printbutton("dma",dma-1) makebutton(Xmenu+88,Yo,"FD","fastdisplay") printbutton("fastdisplay",-FD) makebutton(Xmenu+144,Yo,"pal","pal") printbutton("pal",-!pal) makebutton(Xmenu+216,Yo,"undo","tundo") printbutton("tundo",undo) Xmenu+1,Ypic y(MaskColor$="": setmaskcolor("black") makebutton2(0,YS/2-8*SFY,"zoom","D") makebutton2(16*5,YS/2-8*SFY,"unzoom","C") makebutton2(16*12,YS/2-8*SFY,"mask","Z") makebutton2(16*17,YS/2-8*SFY,"X","X") makebutton2(16*19,YS/2-8*SFY," makebutton2(16*21,YS/2-8*SFY," makebutton2(16*23,YS/2-8*SFY," makebutton2(16*25,YS/2-8*SFY," loadClear(".Demo2") setmaskcolor(A$) MaskColor$<>"" printbutton(MaskColor$, MaskColor$=A$ "black" :?MaskColor=0 ! "white" :?MaskColor=255 "red" :?MaskColor=16 # "darkred" :?MaskColor=4 "green" :?MaskColor=64 ! "blue" :?MaskColor=128 # "darkblue" :?MaskColor=8 $ "purple":?MaskColor=128+16 $ "cyan" :?MaskColor=128+64 # "yellow":?MaskColor=64+16 $ "cgrey" :?MaskColor=4+8+32 printbutton(MaskColor$, showMaskRect T%=0 2:M%=3-T%: (M%+M0-1)<>Mcurrent XS/2-32,T%*YS/3,MX,MY (M%+M0-1)>MaxMask% XS/2-32,T%*YS/3,MX,MY printXY A%,B% %A%=Xcurrent:B%=Ycurrent: ReadRGB 5:Y=YS*0.6/10 Xmenu,Y-16*SFY,500,16*SFY:: Xmenu+32,Y: "Position:"; Xcurrent;","; Ycurrent Xmenu+32,Y-8*SFY: "Color:";RGB?0;",";RGB?1;",";RGB?2 printDiskAccess( clearD PX+16,0,16,YS showArrows printD Dcurrent<0 Dcurrent=0 Dcurrent>1 Dcurrent=1 PX+16,Yd0,16,Yd1-Yd0 PX+16,Yd0,16,(Yd1-Yd0)*Dcurrent printDiskAccess(A%) Xmenu+32,YS*0.4/10: XS-15,15,10 dmaoff dma=off "OS_UpdateMEMC",0,1024 dmaon "OS_UpdateMEMC",1024,1024 loadClear(C$) "OS_File",5,C$ U%,,F%,,L%:F%=(F% >>8) F%<>&690 F%<>&FF9 "Not a clear or sprite file": %OLDMAIN=MAIN:MAINL=!MainL:FLAG%= mc_amount< (L%*1.33+9*mc_page) "Not enough memory for image": %OldMask()=MASK():MAXMASK=MaxMask% 8:MASK(T%)= mc_reassign(MASK(T%),1): MASK(T%)= error$: MAIN= mc_reassign(MAIN,L%): MAIN= error$="Not enough continious memory." "Tidying memory": tidymem:MAIN= mc_assign(L%) MAIN= error$: loadmask= :fail= F%=&690 loadtype690 F%=&FF9 loadtypeFF9 loadtype690 printDiskAccess( "OS_File",255,C$,MAIN printDiskAccess( takecareofnew takecareofnew CurrentFile$=C$ (C$) +1: T%-=1: C$,T%,1)="." T%=0 C$,T%,1)=":" FileName$= C$,T%+1) initmain(MAIN) 6ZOOM!0=0:ZOOM!4=0:ZOOM!8=!MainX-1:ZOOM!12=!MainY-1 initzoom MaskAmount=!MainX*!MainY assignmasks MaxMask%<=0 displayMainOrig(1) loadmask= loadmask= loadspritemask displayMask(M%,M%-M0+1): displayMainOrig(1) loadmask= displayMain(Mcurrent) loadtypeFF9 printDiskAccess( readbuffer(12): !maps<>1 "Warning: more than one sprite in this file" readbuffer(44):S=maps ,M=S!40: "OS_ReadModeVariable",M,3 1:BPP=1 3:BPP=2 15:BPP=4 63:BPP=8 "illegal spritefile. Loading aborted":fail= 1E4 X<=0 XL>mapsize "illegal spritefile. Loading aborted":fail= name(S+4,12) N%=S!36:M%=S?24/8:MO%=S?24 (N%-44-XL*Y)>=0 N%-=XL*Y:loadmask= loadmask= readbuffer(N%-44) converting to clear-format: T%=1 (S$):MAIN?(T%-1)= S$,T%)): :MAIN?(T%-1)=0 m=T%-1+MAIN m!1=100*version m!5=X m!9=Y m!13=8 p=m+17 Q%=0 767 4:p!Q%=0: Taking care of the palette: (N%-44)>0 (N%-44)<2048 Q%=0 (2^BPP-1) : 2: j=maps?(8*(Q% 63)+1+C%) ' C%=1 (Q% 64)<>0 j+=128 ( C%=2 (Q% 128)<>0 j+=128 p?(3*Q%+C%)=j (N%-44)=0 A%=0 255: getRGB8 , C%=0 2:p?(3*A%+C%)=rgb!(4*C%) !6 Q%=0 C%=0 2:p?(3*Q%+C%)=240-32*Q%: p!(3* 7)=&000000 p!(3* 8)=&994400 p!(3* 9)=&00EEEE p!(3*10)=&00CC00 p!(3*11)=&0000DD p!(3*12)=&99EEEE p!(3*13)=&008855 p!(3*14)=&00BBFF p!(3*15)=&FFBB00 p!(3*0)=&FFFFFF p!(3*1)=&BBBBBB p!(3*2)=&777777 p!(3*3)=&000000 p!(3*0)=&FFFFFF p!(3*1)=&000000 "illegal spritefile. Loading aborted":fail= (N%-44)=2048 Q%=0 (2^BPP-1) : 2: j=maps?(8*Q%+1+C%) p?(3*Q%+C%)=j : 256 palette entries loading in the sprite: = D=p+256*3:P%=mapsize/XL:W%=0 C=63 V%=0 @0 W%=0 readbuffer(XL* min(P%,Y-V%)) A8 A%=maps+M%+XL*W%:B%=A%+X-1:C%=D+V%*X: COPYMEM W%+=1: W%=P% W%=0 C D C<63 FL MAIN= mc_reassign(MAIN,X*Y+D-MAIN): MAIN= error$:fail= B%=2^BPP-1 V%=0 I0 W%=0 readbuffer(XL* min(P%,Y-V%)) J* S%=D+V%*X:O%=maps+XL*W%:bit%=MO% KR X%=0 X-1:byte%=bit%/8:S%?X%=((O%?byte%) >> (bit% B%:bit%+=BPP: W%+=1: W%=P% W%=0 M N loadmask= printDiskAccess( takecareofnew loadspritemask printDiskAccess( B%=2^BPP-1:W%=0 V%=0 X0 W%=0 readbuffer(XL* min(P%,Y-V%)) Y7 S%=MASK(Mcurrent)+V%*X:O%=maps+XL*W%:bit%=MO% ZZ X%=0 X-1:byte%=bit%/8:S%?X%=-((((O%?byte%) >> (bit% B%)<>0):bit%+=BPP: W%+=1: W%=P% W%=0 \ printDiskAccess( readbuffer(AA%) B,C%,D%,E% AA%<=mapsize d" "OS_GBPB",4,CH%,maps,AA% e f( "OS_GBPB",4,CH%,maps,mapsize-1 g "OS_Args",0,CH% ,,FP h9 "OS_GBPB",3,CH%,maps+mapsize-1,1,FP+AA%-mapsize i initzoom m:X=ZOOM!8-ZOOM!0+1:Y=ZOOM!12-ZOOM!4+1:!ZOOMX=X:!ZOOMY=Y n%Xc=X/ (PX/SFX-1):Yc=Y/ (PY/SFY-1) o1Xcm=!MainX/ (MX/SFX-1):Ycm=!MainY/ (MY/SFY-1) initmain(MAIN) t"T%=MAIN: ?T%<>0 T%+=1: :M=T% !MainX=M!5 !MainY=M!9 !MainN=M!5*M!9 M!13<=8 !Main24= !MainPal=M+17 !MainEntry=2^M!13 |! !MainData=M+17+3*(2^M!13) !MainLine=!MainX ~ !Main24= !MainData=M+17 !MainLine=3*!MainX *!MainL=!MainData-MAIN+!MainLine*!MainY ,X0=ZOOM!0:Y0=ZOOM!4:X1=ZOOM!8:Y1=ZOOM!12 DX=X1-X0:DY=Y1-Y0:U=5 ":X0-=DX/U:X1-=DX/U ":X0+=DX/U:X1+=DX/U ":Y0+=DY/U:Y1+=DY/U ":Y0-=DY/U:Y1-=DY/U X0<0 X1-=X0:X0=0 X1>!MainX-1 X0-=X1-!MainX+1:X1=!MainX-1 Y0<0 Y1-=Y0:Y0=0 Y1>!MainY-1 Y0-=Y1-!MainY+1:Y1=!MainY-1 255:B$= zoomtoxy unzoomtoc L=.2:Q=L X0=(1+Q)*ZOOM!0-Q*ZOOM!8 Y0=(1+Q)*ZOOM!4-Q*ZOOM!12 X1=(1+Q)*ZOOM!8-Q*ZOOM!0 Y1=(1+Q)*ZOOM!12-Q*ZOOM!4 X0<0 X0=0 X1>!MainX-1 X1=!MainX-1 Y0<0 Y0=0 Y1>!MainY-1 Y1=!MainY-1 zoomtoxy 255:B$= zoomtoc L=.2:Q=-L X0=(1+Q)*ZOOM!0-Q*ZOOM!8 Y0=(1+Q)*ZOOM!4-Q*ZOOM!12 X1=(1+Q)*ZOOM!8-Q*ZOOM!0 Y1=(1+Q)*ZOOM!12-Q*ZOOM!4 zoomtoxy 255:B$= unzoom %X0=0:Y0=0:X1=!MainX-1:Y1=!MainY-1 zoomtoxy 255:B$= getboundaries zoomtoxy ,ZOOM!0=X0:ZOOM!4=Y0:ZOOM!8=X1:ZOOM!12=Y1 (X=ZOOM!8-ZOOM!0+1:Y=ZOOM!12-ZOOM!4+1 !ZOOMX=X:!ZOOMY=Y %Xc=X/ (PX/SFX-1):Yc=Y/ (PY/SFY-1) displayMainOrig(1) dontdismask= displayMain(Mcurrent) dontdismask= assignmasks Mcurrent<=0 Mcurrent=1 ;Reserve%= mc_assign(10*1024): No error handling needed T%=0: :T%+=1 1MASK(T%)= mc_reassign(MASK(T%),MaskAmount+16) T%=8 MASK(T%)= MASK(T%)= MaxMask%=T%-1 MaxMask%=8 MASK(T%)= MASK(T%)= mc_assign(1): MASK(T%)= error$: MaxMask%>=4 MASK(MaxMask%)= mc_reassign(MASK(MaxMask%),1):MaxMask%-=1: MASK(MaxMask%+1)= error$: MaxMask%>=5 MASK(MaxMask%)= mc_reassign(MASK(MaxMask%),1):MaxMask%-=1: MASK(MaxMask%+1)= error$: Mcurrent>MaxMask% Mcurrent=MaxMask% T%=MaxMask%-3: T%<0 T%=0 !Yd0=8*SFY*T%:Yd1=YS-8*SFY-Yd0 showMaskRect: clearD: printD MaxMask%<=0 "Not enough memory. Load another object to avoid crashing!" Reserve%>0 mc_release(Reserve%): error$: tidymem T%,R%,FLAG,O T%=0: FLAG= @ O=MAIN:MAIN= mc_reallocate(MAIN): MAIN= error$: O<>MAIN FLAG= initmain(MAIN) O=MASK(R%) G MASK(R%)= mc_reallocate(MASK(R%)): MASK(R%)= error$: MASK(R%)<>O FLAG= T%+=1 T%=8 FLAG= showArrows (M0+3)<=MaxMask% T%=M0+3 MaxMask%: PX+16,(-2+8*(1+T%-M0-3))*SFY: M0>1 M0-1: PX+16,YS-1-8*(T%)*SFY: (139): 0,0)" " 0,0); LoadType$ "load:pic" : "Load picture:filename"; "load:mask" : "Load mask:filename"; "load:back" : "Load background:filename"; "Bug in load procedure": S$="" "Loading aborted": "OS_File",5,S$ U%,,F%,,L%:F%=(F% >>8) U%<>1 "File not found": F%<>&690 F%<>&FF9 "Not a clear or sprite file": LoadType$="load:mask": loadmask: LoadType$="load:back": loadback: loadClear(S$) loadmask #CH%:C%+=1: C%=500 T%=0 C%=500 "This file does not look like a clear file": #CH%: readnumber readnumber readnumber X<>!MainX Y<>!MainY "The mask has not the right size": #CH%: readnumber: T%<>1 "This is not a mask file ( >2 colors)": #CH%: 6:T%= #CH%: printDiskAccess( "OS_GBPB",4,CH%,MASK(Mcurrent),!MainN printDiskAccess( update(Mcurrent) loadback !Main24= "the operation is only implemented for 24 bit files": #CH%:C%+=1: C%=500 T%=0 C%=500 "This file does not look like a clear file": #CH%: readnumber readnumber readnumber X<>!MainX Y<>!MainY "The picture has not the right size": #CH%: readnumber: T%<>24 "Operation not implemented for <24 bit files": #CH%: printDiskAccess( "AD%=!MainData: T%=0 !MainN-1 #CH%:G%= #CH%:B%= MASK(Mcurrent)?T%=0 AD%?(T%*3)=R%:AD%?(T%*3+1)=B%:AD%?(T%*3+2)=G% printDiskAccess( displayMainOrig(1) savemask ' A$="Mask of '"+FileName$+"'" "Saving mask of ";!MainN+24+ (A$);" bytes" printDiskAccess( #CH%, A$,T%,1)): #CH%,0: writenumber(100* (Version$)) writenumber(!MainX): writenumber(!MainY) writenumber(1) #CH%,0: #CH%,0: #CH%,0 #CH%,255: #CH%,255: #CH%,255 "OS_GBPB",2,CH%,MASK(Mcurrent),!MainN "SetType "+S$+" 690" printDiskAccess( writenumber(R%) #CH%, R% 255:R%=R% >>8: writestring(CH%,S$) (S$): #CH%, S$,T%)): readnumber #CH% *256 #CH% *65536 #CH% *65536*256 okToSave(S$) U%,F%,L% "OS_File",5,S$ U%,,F%,,L%:F%=(F% >>8) U%=2 S$;" is a directory, saving aborted":= U%=1 F%<>&690 OJ "File already exists with type &";~F%;" Are you sure (Y/N)" P< A$= A$<>"Y" A$<>"y" "Saving aborted":= = R SaveType$ "save:pic" : "Save picture:filename"; "save:smpic" : "Save small picture:filename"; "save:mask" : "Save mask:filename"; "Bug in save procedure": S$="" "Saving aborted": okToSave(S$)= SaveType$="save:pic" X0=0:Y0=0:X1=!MainX-1:Y1=!MainY-1 SaveType$="save:smpic" getboundaries: Y0>Y1 X0>X1 SaveType$="save:mask" savemask: d"T%=MAIN: ?T%<>0 T%+=1: :M=T% M!5=X1-X0+1:M!9=Y1-Y0+1 "Saving ";M!5*M!9*!MainLine/!MainX+!MainData-MAIN;" bytes" g3A%=?MaskColor: getRGB8:R=rgb!0:G=rgb!4:B=rgb!8 !Main24= i0 C%=0:U=1E6: 2^M!13-1 :AD%=M+17+3*T% jD V=(AD%?0-R)*(AD%?0-R)+(AD%?1-G)*(AD%?1-G)+(AD%?2-B)*(AD%?2-B) V=bsize% y& "OS_GBPB",2,CH%,BU%,!_bp !_bp=0 }! "OS_GBPB",2,CH%,BU%,!_bp ! E%=CH%:B%=X0:F%=X1:!_bp=0 i Y%=Y0 Y1:ADmain%=!MainData+!MainLine*Y%:ADmask%=MASK(Mcurrent)+!MainX*Y%:A%=ADmask%:D%=ADmain% writerow & (!_bp +!MainLine) >=bsize% & "OS_GBPB",2,CH%,BU%,!_bp !_bp=0 " "OS_GBPB",2,CH%,BU%,!_bp "SetType "+S$+" 690" printDiskAccess( BU%<> BU%<>Colors :T%= mc_release(BU%): error$: getboundaries B%,C%,D% Y0=-1:Y1=0:X0=-1:X1=0 !MainY-1 AD%=MASK(Mcurrent)+!MainX*Y% (B%=AD%:C%=!MainX-1:D%=1:M%= TestGT0 Y0=-1 Y0=Y% Y1=Y% !MainX-1 AD%=MASK(Mcurrent)+X% :B%=AD%:D%=!MainX:C%=(!MainY-1)*D%:M%= TestGT0 X0=-1 X0=X% X1=X% displayMainOrig(p) L1,L2,S0%,C%,H%,T%,Y%,D%,B% :S0%=EE%+ ((YS/2-PY)/SFY)*XW+1: p=0 S0%=S0%+ (YS/2/SFY)*XW H%=0:C%=Xc *2^18+1 mc_assign(4*XW/2+8): !_L1= error$: mc_assign(4*XW/2+8): !_L2= error$: 4*XW/2+4 4:T%!L1=&808080:T%!L2=&808080: !_L1=L1+4:!_L2=L2+4 FD=off YMmax:D%=S0%+XW*Y%+.5:B%=Y%*Yc+ZOOM!4 DisplayMain: L1,L2:!_L1=L1+4:!_L2=L2+4: YMmax:D%=S0%+XW*Y%+.5:B%=Y%*Yc+ZOOM!4:H%=!MainX*B% DisplayMainFast: L1,L2:!_L1=L1+4:!_L2=L2+4: mc_release(L1): error$: mc_release(L2): error$: displayMain(MASK) B%,C%,D%,H%,S0% :S0%=EE%+ ((YS-PY)/SFY)*XW+1:L0%=EE%+ ((YS/2-PY)/SFY)*XW+1 4C%=Xc *2^18+1:!_MASK=MASK(MASK):!_XW=XW:!_S0=S0% YMmax:H%=D%*Yc+ZOOM!4:B%=L0%+XW*D%: DisplayMainMask: displayMask(M%,NR%) A%,B%,C%,D%,S0% NR%<1 NR%>3 M%<1 M%>MaxMask% @S0%=EE%+ (NR%*YS/3+.999)-MY)/SFY+.999)*XW+(XS/2-32)/SFX+1 LC%=XMmaxM:D%=Xcm*2^18+1:!_S0=S0%:!_XW=XW:!_MASK=MASK(M%):!_DY=Ycm*2^18+1 !_Y=0 "A%=YMmaxM+1:B%=0: DisplayMask setuppal(Q%) !pal 0:P$="brtt" 1:P$="rrbg" Q% : "Palette set to:"P$ &R()=0:G()=0:B()=0:R=2:G=1:B=2:TI=1 4:M=16>>Q:A$= P$,Q,1) M)=M A$="t" U=1<=31 T%.!Defaults") T%=1 #CHANNEL): A$=":" A$= #CHANNEL) A$="=" V$="": #CHANNEL): A<>34 V$=V$+ C%=(A<32 ) C%=( A<=32 A=34) A<>34 (V$)-1) 1:mode=V: V<0 V>127 "Illegal mode": "on":defdma=1 "off":defdma=0 "auto":defdma=2 I "Error in !Defauls file:dma option unknown":defdma=2:B$= "off":deffd=0 "on":deffd=1 Q "Error in !Defaults file:FastDisplay option unknown":deffd=0:B$= 4:defpal=V: V<>0 V<>1 "Error in !Defaults file:palette option unknown":defpal=0:B$= "off":undo= "on":undo= L "Error in !Defaults file:Undo option unknown":undo= #CHANNEL swap_init Swap$(8),SwapLock(8),SwapLength(8),SwapAd(8) Swap$()="InMemory" SwapLock()= swap_ensure(S%(0),S%(1),S%(2),S%(3)) S%(3) S%(T%)>=0 SwapLock(S%(T%))= S%(T%)>=0 Swap$(S%(T%)) "InMemory": 9 "Crunched": swap_makefree(MaskAmount): uncrunch 6 "OnDisc" : swap_makefree(SwapLength(S%(T%)) swap_makefree(amount) S%(3) enough *larg= mc_maxblock: larg= error$: block= mc_usage(MASK(1)) amount<=larg : Memory can be assigned amount<=free tidymem #. larg= mc_maxblock: larg= error$: $G amount<=larg : Memory can be assigned after tidymem % ensuremem(amount,main,M(0),M(1),M(2),M(3)) larg,free,block maskstatus()=0 enough= not enough space, so make space: T%=1 MaxMask%:maskstatus(T%)=0: 0=free to use T%=0 3:maskstatus(M(T%))=1: : 1=not free to use /9left=0: T%=1 MaxMask%: maskstatus(T%)=0 left+=1 maxfree=free+left*block main= maxfree+= mc_usage(MAIN) amount > maxfree :memory definitly can not be made free maskstatus(T%)=0 7B A%=MASK(T%): CompressBitfield: PRINT"Compressed mask:";T% 8D MASK(T%)= mc_reassign(A%,MaskAmount/8+16): error$: 9G maskstatus(T%)=2 : 2=bitfield compressed. free+=block ; < T%+=1 T%>MaxMask% amount<=free >*larg= mc_maxblock: larg= error$: enough= All masks are compressed and there is still not enough memory restoremem T%,FLAG% FLAG%= T%=1 MaxMask% maskstatus(T%)=2 FLAG%= I5 (MaskAmount+16) > mc_maxblock tidymem J7 MASK(T%)= mc_reassign(MASK(T%),MaskAmount+16) K& PRINT"Decompressing nr:";T% MASK(T%)= "Due to memory problems, masks are lost. (sorry).":MaxMask%=T%-1 A%=MASK(T%): DeCompressBitfield FLAG% : tidymem mc_init(amount,page) A%,B%,C% inits memory controller, giving it 'amount' bytes off memory. readcopymem:mc_page=page mc_page<16 mc_page=256 W#mc_amount=- (-amount/page)*page mc_memory mc_amount YCmc_max=amount/mc_page-1: mc_map mc_max+5:mc_map+=1:mc_map?-1= ZEA%=mc_map:B%=mc_map+mc_max+2:C%=0: VULMEM:?(mc_map+mc_max+1)=255 error$="No error" mc_restore(ad,amount) T1,T2 mc_nr(ad): a&T2= mc_nr(ad+amount-1): mc_getnr: T%=T1 mc_map?T%<>0 error$="memory is occupied":= mc_map?T%=nr mc_assign(amount) A%,B%,C%,T% amount> mc_free error$="Not enough memory, "+ (amount- mc_free)+" Bytes too little.":= mc_getnr: m,mc_ad= mc_bestfit(amount): mc_ad= mc_nr(mc_ad)= oKA%=mc_map+ mc_nr(mc_ad):B%=mc_map+ mc_nr(mc_ad+amount-1):C%=nr: VULMEM =mc_ad mc_free T%,F%:F%=0 T%=0 mc_max: mc_map?T%=0 F%+=1 :=F%*mc_page mc_maxblock T%,F% mc_largest=-1:T%=0 {+F%=0: mc_map?T%=0:T%+=1:F%+=1: :T%+=1 F%>mc_largest mc_largest=F% T%>mc_max =mc_largest*mc_page mc_getnr A%,B%,C%,D%,F%,T%,M%:M%=1 "A%=mc_max:B%=mc_map:C%=M%:D%= mc_getnr M%+=1 M%>=255 M%>=255 error$="Too many handles":= =M%-1 mc_nr(ad) nr%=(ad-mc_memory)/mc_page nr%<0 nr%>mc_max error$="handle is outside range":= mc_showmap T%,N% T%=0 mc_max:N%=mc_map?T% N%>0 (48+N%); mc_bestfit(amount) T%,best,len mc_smallest=1E8:best=0:T%=0 mc_map?T%<>0:T%+=1: T%<=mc_max + len=0: mc_map?T%=0:len+=1:T%+=1: S (len*mc_page >= amount) (lenmc_max mc_smallest=1E8 error$="Not enough continious memory.":= =mc_memory+best*mc_page mc_release(handle) A%,B%,C%,T%,nr Gnr=mc_map? mc_nr(handle): nr=0 error$="Handle does not exist":= *A%=mc_map:B%=mc_max:C%=nr: mc_release mc_usage(handle) T%,U%,nr -U%=0:nr=mc_map? mc_nr(handle): T%=0 mc_max: mc_map?T%=nr U%+=1 =U%*mc_page mc_reallocate(handle) nr,amount,T% ,amount= mc_usage(handle): amount= mc_reassign(handle,amount): mc_reassign(handle,amount) A%,B%,C%,T%,nr,ad,a mc_usage(handle): amounthandle mc_nr(handle)<> A%=handle:B%=handle+a-1:C%=ad: FASTCOPYMEM readcopymem COPYMEM 280 CALL COPYMEM (BeginLoad,EindLoad,BeginSave,-,-,0,0,0,0,0,0,0,0,0,0,0) Verplaats een stuk geheugen. Van BeginLoad tot EindLoad naar BeginSave CALL VULMEM (Beginadres,Eindadres,Waarde,0,0,0,0,0,0,0,0,0,0,0,0,0) PASS=0 P%=COPYMEM [OPT PASS CMP R0,R2 BLS Anderevolgorde .COPYMEMLOOP LDRB R3,[R0],#1 STRB R3,[R2],#1 CMP R0,R1 BLE COPYMEMLOOP MOV PC,R14 .Anderevolgorde SUB R3,R2,R0 $ADD R3,R3,R1 ;R3=EindSave .COPYLOOP2 LDRB R4,[R1],#-1 STRB R4,[R3],#-1 CMP R1,R0 BPL COPYLOOP2 MOV PC,R14 .FASTCOPYMEM CMP R0,R2 BLS AnderevolgordeF .FASTCOPYMEMLOOP LDR R3,[R0],#4 STR R3,[R2],#4 CMP R0,R1 BLE FASTCOPYMEMLOOP MOV PC,R14 .AnderevolgordeF #MOV R1,R1,LSR#2:MOV R1,R1,LSL#2 SUB R3,R2,R0 $ADD R3,R3,R1 ;R3=EindSave .FASTCOPYLOOP2 LDR R4,[R1],#-4 STR R4,[R3],#-4 CMP R1,R0 BPL FASTCOPYLOOP2 MOV PC,R14 .VULMEM STRB R2,[R0],#1 CMP R0,R1 BLE VULMEM MOV PC,R14 .mc_getnr LDRB R4,[R1,R0] CMP R4,R2:MVNEQ R3,#0 SUBS R0,R0,#1 BPL mc_getnr MOV R0,R3 MOV PC,R14 .mc_release MOV R4,#0 LDRB R3,[R0,R1] CMP R3,R2 STREQB R4,[R0,R1] SUBS R1,R1,#1 BPL mc_release MOV PC,R14