home *** CD-ROM | disk | FTP | other *** search
- {$title:'MANDEM.PAS Version 2.00' $pagesize:55 $linesize:96}
- {$symtab- $debug-}
- program mandem(input,output);
- const lm=' ';
- type chunk=record
- val1,val2,val3,val4:lstring(23);
- littlechunk : array[0..319,0..199] of byte;
- end;
- band=record
- frequency:word;
- color_ind:integer;
- end;
- color_bands=array [0..255] of band;
- function writfil(var fnam:lstring;count:word;buffer:adsmem):word;extern;
- function readfil(var fnam:lstring;count:word;buffer:adsmem):word;extern;
- function allmqq(wants:word):adsmem;extern;
- function egamove(mode:integer;buf1,buf2:adsmem):word;extern;
- label 13;
- var adchunk:ads of chunk;
- bfa:ads of byte;
- answ:char;
- r0:word;
- {$page+}
- procedure load_mand;
- var pfname:lstring(65);
- cb:color_bands;
- x,y,y0,binx,binx0:integer;
- w,res,limit:word;
- color:array[0..15] of byte;
- begin
- writeln('Enter Mandelbrot picture filespec:');
- readln(pfname);
- res:=readfil(pfname,sizeof(adchunk^),adchunk);
- if res=#ffff then
- begin writeln('File not read.');return end;
- writeln('Analyzing Mandelbrot picture array...');
- for x:=0 to 255 do
- cb[x].frequency:=0;
- for x:=0 to 319 do
- for y:=0 to 199 do
- begin
- binx:=ord(adchunk^.littlechunk[x,y]);
- cb[binx].frequency:=cb[binx].frequency+1
- end;
- cb[255].color_ind:=0;
- limit:=(64000 - cb[255].frequency) div 15;
- binx0:=1;
- while binx0<16 do
- begin
- y0:=0;w:=0;binx:=1;
- for x:=0 to 254 do
- begin
- cb[x].color_ind:=7;
- w:=w+cb[x].frequency;
- if w>=limit then
- begin
- for y:=y0 to x do
- cb[y].color_ind:=binx mod 16;
- binx:=binx+1;y0:=x+1;w:=0
- end
- end;
- limit:=limit div 2;binx0:=binx;
- end;
- for x:=0 to 15 do color[x]:=wrd(x);
- writeln('Creating display buffer...');
- for y:=0 to 199 do
- begin
- x:=0;
- while x<=319 do
- begin
- binx0:=ord(adchunk^.littlechunk[x,y]);
- binx:=ord(adchunk^.littlechunk[x+1,y]);
- bfa^:=16*color[cb[binx0].color_ind]+
- color[cb[binx].color_ind];
- x:=x+2;bfa.r:=bfa.r+1
- end
- end;
- writeln('Cancel display by pressing ESC.');
- w:=0;while w<15000 do w:=w+1;
- bfa.r:=r0;res:=egamove(13,bfa,bfa);
- case res of
- 0:writeln('Display generated successfully.');
- 1:writeln('EGA not attached.');
- 2:writeln('Illegal mode invoked.');
- otherwise writeln('Unknown error',res,' occured.')
- end;
- end;{load_mand}
- {$page+}
- procedure load_dump;
- var pfdump:lstring(65);
- w,res:word;
- begin
- writeln('Enter screen dump filespec:');
- readln(pfdump);
- res:=readfil(pfdump,32000,bfa);
- if res<>#ffff then writeln('File ',pfdump,' read.')
- else begin writeln('Read error occured.');return end;
- writeln('Cancel display by pressing ESC.');
- w:=0;while w<15000 do w:=w+1;
- bfa.r:=r0;res:=egamove(13,bfa,bfa);
- case res of
- 0:writeln('Display generated successfully.');
- 1:writeln('EGA not attached.');
- 2:writeln('Illegal mode invoked.');
- otherwise writeln('Unknown error',res,' occured.')
- end;
- end;{load_dump}
- procedure save_dump;
- var pfdump:lstring(65);
- res:word;
- begin
- writeln('Enter screen dump filespec:');
- readln(pfdump);
- res:=writfil(pfdump,32000,bfa);
- if res<>#ffff then writeln('File ',pfdump,' written.')
- else writeln('Write error occured.')
- end;{save_dump}
- {$page+}
- begin
- adchunk:=allmqq(sizeof(adchunk^));
- bfa:=allmqq(32000);r0:=bfa.r;
- if (adchunk.r<=1) or (bfa.r<=1) then
- begin writeln('Insufficient memory.');goto 13 end;
- repeat
- writeln(lm,'Select one of the following:');
- writeln(lm,'m: Load Mandelbrot pic file.');
- writeln(lm,'l: Load Screen dump file.');
- writeln(lm,'s: Save Screen dump file.');
- writeln(lm,'x: Exit program.');
- writeln;
- write(lm,':');
- readln(answ);
- case answ of
- 'm':load_mand;
- 'l':load_dump;
- 's':save_dump;
- 'x':break;
- otherwise
- end
- until not true;
- 13:writeln('Exiting program.')
- end.{mandem}
-