home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pctech
/
1986_08
/
mandel87.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-05-06
|
7KB
|
163 lines
Program Mandelbrot87;
type
reg = array[0..11] of byte;
const
xmin = -2.0;
xrange = 2.6;
ymin = -1.3;
yrange = 2.6;
crt_index_reg = $03D4; { Port # of Index register of 6845 }
crt_data_reg = $03D5; { Port # of Input register of 6845 }
mode_select_reg = $03D8; { Port # of video mode select register }
color_select_reg = $03D9; { Port # of video color select register }
var
c,j,k,n : integer;
x,y,dx,dy : real;
crt_mode_set : byte absolute $0000:$0465;
crt_palette : byte absolute $0000:$0466;
{ Used by BIOS to maintain values of mode & color regs }
screen : array[1..16384] of byte absolute $B800:$0000;
label
quit;
{-------- CLEARS SCREEN --------------------------------------------}
Procedure ClearScreen;
begin
port[mode_select_reg] := 0; { Disables video to prevent snow }
FillChar(screen,16384,0); { Fills screen with chr 0 attribute 0 }
port[mode_select_reg] := 9; { Enables video to see screen }
end;
{-------- SET 6845 CRT CONTROLLER TO LO-RES MODE --------------------}
Procedure LoRes;
const
regdata : reg = (113,80,90,10,127,6,100,112,2,1,32,0);
var
i : byte;
begin
crt_mode_set := 0;
crt_palette := 0;
port[color_select_reg] := 0;
for i := 0 to 11 do
begin
port[crt_index_reg] := i;
port[crt_data_reg] := regdata[i];
end;
ClearScreen;
crt_mode_set := 9;
end;
{-------- SET 6845 CRT CONTROLLER TO 80x25 TEXT SCREEN -------------}
Procedure TextScreen;
const
regdata : reg = (113,80,90,10,31,6,25,28,2,7,6,7);
var
i : byte;
begin
for i := 0 to 11 do
begin
port[crt_index_reg] := i;
port[crt_data_reg] := regdata[i];
end;
crt_mode_set := 41;
ClrScr;
end;
{-------- PLOTS POINT AT (x,y) in COLOR c --------------------------}
Procedure Point(x,y,c:integer);
begin
inline($B8/$00/$02/ { MOV AX,0200H 0200 -> AX }
$30/$FF/ { XOR BH,BH 0 -> BH }
$8A/$56/$08/ { MOV DL,[BP+8] x -> DL }
$D0/$EA/ { SHR DL,1 x/2->DL,rem->CF }
$8A/$76/$06/ { MOV DH,[BP+6] y -> DH }
$CD/$10/ { INT 10H locates cursor }
$B8/$00/$08/ { MOV AX,0800H 0800 -> AX }
$CD/$10/ { INT 10H read attribute }
$8A/$5E/$04/ { MOV BL,[BP+4] c -> BL }
$73/$05/ { JNC +5 x even => CF=0 }
$25/$00/$F0/ { AND AH,F0H discard old fg }
$EB/$0B/ { JMP +11 Jmp to col asmb }
$D0/$E3/ { SHL BL,1 x even so }
$D0/$E3/ { SHL BL,1 c is bg }
$D0/$E3/ { SHL BL,1 shift bg }
$D0/$E3/ { SHL BL,1 left 4 bits }
$25/$00/$0F/ { AND AH,0FH discard old bg }
$00/$E3/ { ADD BL,AH assemble color }
$B8/$DE/$09/ { MOV AX,09DE chr ▐ to AH }
$B9/$01/$00/ { MOV CX,01 one to write }
$CD/$10); { INT 10H write chr, attr }
end;
{-------- DETERMINE NUMBER OF ITERATIONS AT (x,y) ------------------}
Function Iterate(x,y:real):integer;
var
scratch : integer;
begin
Inline(
$B9/$3F/$00/ { MOV CX,3FH # iterates -> CX }
$9B/$D9/$E8/ { FLD1 1 to 8087 Stack }
$9B/$D8/$C0/ { FADD ST(0),ST(0) 2 on Stack }
$9B/$D8/$C0/ { FADD ST(0),ST(0) 4 on Stack }
$9B/$DD/$46/$0C/ { FLD QWORD PTR [BP+12] x to Stack }
$9B/$DD/$46/$04/ { FLD QWORD PTR [BP+4] y to Stack }
$9B/$D9/$C1/ { FLD ST(1) Copy x }
$9B/$D9/$C1/ { FLD ST(1) Copy y }
{ HERE: Loop label }
$9B/$D9/$C1/ { FLD ST(1) Copy x }
$9B/$D8/$C8/ { FMUL ST(0),ST(0) x*x }
$9B/$D9/$C1/ { FLD ST(1) Copy y }
$9B/$D8/$C8/ { FMUL ST(0),ST(0) y*y }
$9B/$DE/$E9/ { FSUBP ST(1),ST(0) x*x - y*y }
$9B/$D8/$C4/ { FADD ST(0),ST(4) x*x - y*y + x }
$9B/$D9/$CA/ { FXCH ST(2) new x <-> old x }
$9B/$DE/$C9/ { FMULP ST(1),ST(0) x*y }
$9B/$D8/$C0/ { FADD ST(0),ST(0) 2*x*y }
$9B/$D8/$C2/ { FADD ST(0),ST(2) 2*x*y + y }
$9B/$D9/$C1/ { FLD ST(1) Copy x }
$9B/$D8/$C8/ { FMUL ST(0),ST(0) x*x }
$9B/$D9/$C1/ { FLD ST(1) Copy y }
$9B/$D8/$C8/ { FMUL ST(0),ST(0) y*y }
$9B/$DE/$C1/ { FADDP ST(1),ST(0) x*x + y*y }
$9B/$D8/$DD/ { FCOMP ST(5) Greater than 4? }
$9B/$DD/$7E/$FC/ { FSTSW [BP-4] Status to Scratch}
$9B/ { FWAIT 8087 Done? }
$8A/$66/$FD/ { MOV AH,[BP-3] Status to AH }
$9E/ { SAHF Status to Flags }
$77/$02/ { JA QUIT x*x+y*y > 4? }
$E2/$C3/ { LOOP HERE No then Loop }
{ QUIT: Yes }
$89/$4E/$14); { MOV [BP+20],CX Return # iterates}
end;
{-------- MAIN PROGRAM BEGINS --------------------------------------}
begin
LoRes; { Switch to LoRes mode }
dx := xrange/159; dy := yrange/99; { Scale world to screen }
y := ymin + yrange; { Maximum y to top of screen }
for j := 0 to 99 do { 100 rows on LoRes screen }
begin
x := xmin; { Minimum x to left of screen}
for k := 0 to 159 do { 160 columns on LoRes screen}
begin
n := Iterate(x,y); { Determine number of iterations }
c := n div 8; { Determine color number 0..7 }
if n mod 8 > 3 then c := c+8;
{ If remainder = 4..7 then bright }
Point(k,j,c); { Plot point on screen }
if keypressed then goto quit;
{ Press any key to interrupt/quit }
x := x + dx; { Update x coordinate of point }
end; { Loop until finished with row }
y := y - dy; { Update y coordinate of point }
end; { Loop until finished with screen }
quit: repeat until keypressed; { Hold picture until key pressed }
TextScreen; { Restore normal text screen }
end.