!**************************************************************** !* * !* GRAPH: Suite of routines provide LEVEL1: routines * !* but output to an IFF file * !* * !* Version 1.7 16 Mar 1987 - JHB * !* * !**************************************************************** %include "inc:util.imp" %include "iffinc.imp" !------------------------------------------------------- !%include "level1:graphinc.imp" minus the EXTGRAPH stuff and the comments & consts %option "-low" @16_E30000 %integer %array colour map(0:255) @16_7F400 %short %integer mouse x @16_7F402 %short %integer mouse y %dynamic %volatile %byte %integer %function %spec mouse buttons %c %alias "FRED_GRAPHICS_MOUSEB" %dynamic %volatile %integer %function %spec rel mouse x %c %alias "FRED_GRAPHICS_MOUSEX" %dynamic %volatile %integer %function %spec rel mouse y %c %alias "FRED_GRAPHICS_MOUSEY" %dynamic %volatile %integer %function %spec mouse but %c %alias "FRED_GRAPHICS_MOUSEB" %dynamic %routine %spec vline %alias "FRED_GRAPHICS_VLINE" (%integer x, y0, y1) %dynamic %routine %spec hline %alias "FRED_GRAPHICS_HLINE" (%integer x0, x1, y) %dynamic %routine %spec offset %alias "FRED_GRAPHICS_OFFSET" (%integer x, y) %dynamic %routine %spec colour %alias "FRED_GRAPHICS_COLOUR" (%integer colour) %dynamic %routine %spec enable %alias "FRED_GRAPHICS_ENABLE" (%integer planes) %dynamic %routine %spec update colour map %alias "FRED_GRAPHICS_UPCMAP" %c (%half %integer %name new map) %dynamic %routine %spec clear %alias "FRED_GRAPHICS_CLEAR" %dynamic %routine %spec half clear %alias "FRED_GRAPHICS_HCLEAR" (%integer h) %dynamic %routine %spec line %alias "FRED_GRAPHICS_LINE" %c (%integer x0, y0, x1, y1) %dynamic %routine %spec fill %alias "FRED_GRAPHICS_FILL" %c (%integer x0, y0, x1, y1) %dynamic %routine %spec col fill %alias "FRED_GRAPHICS_CFILL" %c (%integer x0, y0, x1, y1, %byte %integer %name b) %dynamic %routine %spec b w fill %alias "FRED_GRAPHICS_BWFILL" %c (%integer x0, y0, x1, y1, %byte %integer %name b, t) %dynamic %routine %spec triangle %alias "FRED_GRAPHICS_TRIANGLE" %c (%integer x0, y0, x1, y1, x2, y2) %dynamic %routine %spec trapeze %alias "FRED_GRAPHICS_TRAPEZE" %c (%integer x00, x01, y0, x10, x11, y1) %dynamic %routine %spec plot %alias "FRED_GRAPHICS_PLOT" (%integer x, y) %dynamic %routine %spec paint %alias "FRED_GRAPHICS_PAINT" %c (%integer %name s, %integer x0, y0, x1, y1, offset, stride) %dynamic %routine %spec textat %alias "FRED_GRAPHICS_TEXTAT" (%integer x,y) %dynamic %routine %spec showsymbol %alias "FRED_GRAPHICS_SHOWSYM" %c (%integer k) %dynamic %routine %spec showstring %alias "FRED_GRAPHICS_SHOWSTR" %c (%string(255) s) %dynamic %routine %spec font %alias "FRED_GRAPHICS_FONT" (%integer f) %dynamic %volatile %integer %function %spec font height %alias "FRED_GRAPHICS_FONTHT" %dynamic %volatile %integer %function %spec font depth %alias "FRED_GRAPHICS_FONTDP" %dynamic %volatile %integer %function %spec max font width %c %alias "FRED_GRAPHICS_FONTWX" %dynamic %volatile %integer %function %spec min font width %c %alias "FRED_GRAPHICS_FONTWN" %dynamic %volatile %integer %function %spec string width %c %alias "FRED_GRAPHICS_STRNGW" (%string(255) s) %dynamic %volatile %integer %function %spec char height %c %alias "FRED_GRAPHICS_CHARHT" (%integer c) %dynamic %volatile %integer %function %spec char depth %c %alias "FRED_GRAPHICS_CHARDP" (%integer c) %dynamic %volatile %integer %function %spec char width %c %alias "FRED_GRAPHICS_CHARWD" (%integer c) %dynamic %volatile %integer %function %spec text x pos %c %alias "FRED_GRAPHICS_XPOS" %dynamic %volatile %integer %function %spec text y pos %c %alias "FRED_GRAPHICS_YPOS" %dynamic %routine %spec show i %alias "FRED_GRAPHICS_SHOWI" (%integer n,p) %dynamic %routine %spec show r %alias "FRED_GRAPHICS_SHOWR" (%real x, %integer n,m) %dynamic %routine %spec show f %alias "FRED_GRAPHICS_SHOWF" (%real x, %integer n) %dynamic %routine %spec shex1 %alias "FRED_GRAPHICS_SHEX1" (%integer x) %dynamic %routine %spec shex2 %alias "FRED_GRAPHICS_SHEX2" (%integer x) %dynamic %routine %spec shex4 %alias "FRED_GRAPHICS_SHEX4" (%integer x) %dynamic %routine %spec shex %alias "FRED_GRAPHICS_SHEX" (%integer x) !------------------------------------------------------- %ownrecord (iffhdr fm) iffh %constinteger left=0, right=1, iff screen=1, iff file=2, maxwid=688, maxht=512, scrnwid=688, scrnht=512 %routine bulkfill(%integer bytes, %name from, %byte filler) !Fill BYTES bytes from FROM with FILLER %return %if bytes = 0 from=filler %and %return %if bytes=1 *subq.l #1, d0 f loop: *move.b d1, (a0)+ *subq.l #1,d0 *bne f loop %end %routine quick move(%integer bytes, %bytename from, to) !Clever dicks who think *dbra is better here should remember it has !a 16 bit argument. (I didn't). Note it won't move overlapping areas. f loop: *move.b (a0)+, (a1)+ *Subq.l #1, d0 *bne f loop %end %routine error(%string (255) s) %integer i i = outstream selectoutput(0); printline(s); selectoutput(i) %end %routine restrict x(%integername a) error("Plotting out of x area: ".itos(a,-1)) %unless 0<=a<=687 a=0 %if a<0; a=687 %if a>687 %end %routine restrict y(%integername a) error("Plotting out of y area: ".itos(a,-1)) %unless 0<=a<=1023 a=0 %if a<0; a=1023 %if a>1023 %end %routine swap(%integername a, b) %integer t t=a; a=b; b=t %end %external %byte %integer %function iff mouse buttons %c %alias "IFF_GRAPHICS_MOUSEB" %result=0 %if iffh_context_screen=0 %result=mouse but %end %external %integer %function iff rel mouse x %alias "IFF_GRAPHICS_MOUSEX" %result=0 %if iffh_context_screen=0 %result=rel mouse x %end %external %integer %function iff rel mouse y %alias "IFF_GRAPHICS_MOUSEY" %result=0 %if iffh_context_screen=0 %result=rel mouse y %end %external %integer %function iff mouse but %alias "IFF_GRAPHICS_MOUSEB" %result=0 %if iffh_context_screen=0 %result = mouse but %end %dynamic %routine iff vline %alias "IFF_GRAPHICS_VLINE" (%integer x, y0, y1) { Draws vertical line from (x, y0) to (x, y1). } %integer ad, y !t!error("Vline ".itos(x,3).itos(y0,3).itos(y1,3)) %if iffh_context_screen#0 %start vline(x, y0, y1) %finish %if iffh_context_file#0 %start swap(y0,y1) %if y1>y0 restrict x(x); restrict y(y0); restrict y(y1) y0 = 1023 - y0; y1 = 1023 - y1 {and the "<" 2 lines up} ad = iffh_context_imaddr + x + y0 * 688 %for y = 0, 1, y1-y0+1 %cycle byteinteger(ad) = iffh_context_colour; ad = ad + 688 %repeat %finish %end %dynamic %routine iff hline %alias "IFF_GRAPHICS_HLINE" (%integer x0, x1, y) { Draws horizontal line from (x0, y) to (x1, y). } %integer ad, x !t!error("Hline ".itos(x0,3).itos(x1,3).itos(y,3)) %if iffh_context_screen#0 %start hline(x0, x1, y) %finish %if iffh_context_file#0 %start restrict x(x0); restrict x(x1); restrict y(y) swap(x0, x1) %if x1=x1 X = x1-x0 Y = y1-y0 yn = 0 d = 2*Y - X store(x0, y0) %return %if X=0 %if sign(Y) # sign(X) %start ;!negative gradient %for xn=1,1,X %cycle %if d<0 %start yn = yn - 1 d = d + 2*Y + 2*X %else d = d + 2*Y %finish store(x0+xn, y0+yn) %repeat %else %for xn=1,1,X %cycle %if d>0 %start yn = yn + 1 d = d + 2*Y - 2*X %else d = d + 2*Y %finish store(x0+xn, y0+yn) %repeat %finish %else swap(x0, x1) %and swap(y0, y1) %if y0>=y1 X = x1-x0 Y = y1-y0 xn = 0 d = 2*X - Y store(x0, y0) %return %if Y=0 %if sign(Y) # sign(X) %start ;!negative gradient %for yn=1,1,Y %cycle %if d<0 %start xn = xn - 1 d = d + 2*X + 2*Y %else d = d + 2*X %finish store(x0+xn, y0+yn) %repeat %else %for yn=1,1,Y %cycle %if d>0 %start xn = xn + 1 d = d + 2*X - 2*Y %else d = d + 2*X %finish store(x0+xn, y0+yn) %repeat %finish %finish %end %dynamic %routine iff line %alias "IFF_GRAPHICS_LINE" (%integer x0, y0, x1, y1) { Draws arbitrary line from (x0, y0) to (x1, y1). } %integer xn,yn,d,X,Y !octant 4 = octant 0 drawn backwards. ditto 3/7, 2/6, 1/5 !t!error("Line ".itos(x0,3).itos(y0,3).itos(x1,3).itos(y1,3)) %if iffh_context_file#0 %start %if x0=x1 %then iff vline(x0, y0, y1) %elsestart %if y0=y1 %then iff hline(x0, x1, y0) %elsestart restrict x(x0); restrict y(y0) restrict x(x1); restrict y(y1) %if |y1-y0| <= |x1-x0| %start swap(x0,x1) %and swap(y0,y1) %if x0>=x1 X = x1-x0 Y = y1-y0 yn = 0 d = 2*Y - X iff plot(x0, y0) %if sign(Y) # sign(X) %start ;!negative gradient %for xn=1,1,X %cycle %if d<0 %start yn = yn - 1 d = d + 2*Y + 2*X %else d = d + 2*Y %finish iff plot(x0+xn, y0+yn) %repeat %else %for xn=1,1,X %cycle %if d>0 %start yn = yn + 1 d = d + 2*Y - 2*X %else d = d + 2*Y %finish iff plot(x0+xn, y0+yn) %repeat %finish %else swap(x0, x1) %and swap(y0, y1) %if y0>=y1 X = x1-x0 Y = y1-y0 xn = 0 d = 2*X - Y iff plot(x0, y0) %if sign(Y) # sign(X) %start ;!negative gradient %for yn=1,1,Y %cycle %if d<0 %start xn = xn - 1 d = d + 2*X + 2*Y %else d = d + 2*X %finish iff plot(x0+xn, y0+yn) %repeat %else %for yn=1,1,Y %cycle %if d>0 %start xn = xn + 1 d = d + 2*X - 2*Y %else d = d + 2*X %finish iff plot(x0+xn, y0+yn) %repeat %finish %finish %finish %finish %finish %if iffh_context_screen#0 %start line(x0, y0, x1, y1) %finish %end %dynamic %routine iff fill %alias "IFF_GRAPHICS_FILL" (%integer x0, y0, x1, y1) { Draws filled orthogonal box with diagonal corners at (x0, y0, x1, y1). } %integer i, j, ix !t!error("Fill ".itos(x0,3).itos(y0,3).itos(x1,3).itos(y1,3)) %if iffh_context_screen#0 %start fill(x0, y0, x1, y1) %finish %if iffh_context_file#0 %start restrict x(x0); restrict y(y0) restrict x(x1); restrict y(y1) swap(y0, y1) %if y1>y0 swap(x0, x1) %if x1