Home » CEEFAX disks » telesoftware6.adl » 09-04-88/T\OSB21

09-04-88/T\OSB21

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » CEEFAX disks » telesoftware6.adl
Filename: 09-04-88/T\OSB21
Read OK:
File size: 3733 bytes
Load address: 0000
Exec address: FFFFFFFF
Duplicates

There is 1 duplicate copy of this file in the archive:

File contents
OSBITS - An Exploration of the BBC Micro at Machine Level

By Programmer

..........................................................


Part 21: Real Numbers Explore the Mandelbrot Set


In the last module I introduced the idea of splitting up a
word (in that case it was 4 bytes as used by BASIC integers)
such that the lower few bytes were in fact representing
fractional parts of 1.  This module exploits that idea in
order to perform some pretty hairy computation in order to
plot a crude diagram showing the Mandelbrot Set.

The Mandelbrot Set illustrates the performance of the
function z=z+c where both z and c are complex numbers.  This
means they have a real part and an imaginary part and the
imaginary part is a multiple (or fraction) of the square
root of -1.  Mathematicians call that quantity i while
engineers usually call it j.  (i to an electrical engineer
denotes current, as in Ohm's Law v=ir.)

So essentially we take z=z+c, starting with z=0 and keep
putting it into the equation.  Obviously the first time
around z will equal c.  If we keep doing this so called
iterative process and check on the size of z as we do it we
can see how the function behaves.

In order to draw the Mandelbrot Set we simply carry out this
iteration using screen co-ordinates to represent values of
c.  Since c has these real and imaginary parts we can plot
real values along the x axis and imaginary ones up the y
axis.  The colour of the pixel plotted at that point is used
to tell us how the size of the function behaves.

We are interested in whether or not the size of the function
increases without limit.  For our purposes 'without limit'
means only that it reaches 2 because if it reaches 2 it
will, I am reliably informed, reach infinity!  Different
colour values tell us how many iterations it took for the
function to reach 2 in size.  If after a certain number of
iterations it has not yet reached 2 then the pixel is
coloured black and that value of c is part of the Mandelbrot
Set.  This is all named after a Belgian mathematician named
Benoit B Mandelbrot who discovered this particular behaviour
of complex numbers.

Mandelbrot also discovered fractals and the boundary of the
black area in the middle of our eventual diagram is a
fractal.  If we blow it up ever larger we reveal more and
more detail.  Now you can imagine that since many iterations
are taking place at each pixel on the screen the whole
process can take a long time.  I have drawn blow-ups of
areas of the boundary that took over 48 hours to plot on a
BBC micro in BASIC.  (I've also done it in FORTRAN on a
32016 second processor in an hour but that's down to the
power of the machinery and of FORTRAN rather than any fancy
coding of mine.)

The algorithm is like this:

Map out values of c covering the range -2.25-1.5i to
0.75+1.5i across the screen area.  This means that the
graphics origin (0,0) represents -2.25-1.5i and (1024,1024)
represents 0.75+1.5i and each pixel on the screen would
represent a value of c.

Work your way over the screen and for each pixel:

Set a counter at zero, set z equal to zero (0+0i)

Loop start

Calculate size of z, if > 2 then colour the pixel according
to the value in the counter and move on to next pixel

If the counter has reached a preset value colour the pixel
black and move on to the next pixel

If neither condition is met then recalculate z=z+c using the
previous value of z and go back to the start of the loop

In practice the tendency is to calculate the new value of
the size squared, which is the sum of the real part squared
and the imaginary part squared.  There is no point in taking
a spurious square root.  So the size variable being used is
the square and it is therefore compared with 4 rather than
2.  Also the actual order of carrying out the tests will
vary from the straight algorithm.  In the module program,
for example, the counter is decremented at the end of the
loop rather than the beginning so the test is carried out
there.  Also the size is tested as soon after it is
calculated as feasible bearing in mind the length of the
branch needed after the test.  Because of this branch length
problem the code here actually tests in a rather odd place,
during the calculation of the new value of y.

The Mandelbrot set calculation is suited to limited
fixed-point arithmetic because it works within a limited
range of numbers and because, being a graphic, it is perhaps
more tolerant of poor accuracy in the calculations.  I will
admit this in advance, my fixed-point routine is not
amazingly accurate, but your trade-off is speed against
precision.  So, before we look at the code I shall explain
the fixed-point method used here.

If we take a four byte word and put the 'binary' point in
the middle we then have a fixed point number.  If you look
at the algorithms for arithmetic I listed in the last module
you will find that a constant factor was involved in
changing the numbers into the fixed point representation. 
It was 10000 last time but in the program in this module I
will use 65536.  This puts the binary point exactly in the
middle of the number so that the top two bytes are the
integer part and the lower two bytes are the fractional
part.  In this way we can represent numbers up to 65536 and
as small as 1.526E-5 (which is 0.00001526).

In order to carry out the necessary multiplications I have
modified the multi-byte multiplication routine used in
module 13 to produce a five byte result instead of four. 
This is because we have to divide the result of a fixed
point multiplication by the relevant factor.  It looks like
this:

Here is a six byte number. The binary point is represented
by a plus sign.

  ------------------------------------+------------------
  | byte 5 | byte 4 | byte 3 | byte 2 | byte 1 | byte 0 |
  ------------------------------------+------------------

If we multiply a four byte number x

  ------------------------------------+------------------
  |        |        | xxxxxx | xxxxxx | xxxxxx | xxxxxx |
  ------------------------------------+------------------

by a four byte number y

  ------------------------------------+------------------
  |        |        | yyyyyy | yyyyyy | yyyyyy | yyyyyy |
  ------------------------------------+------------------

we can get a eight byte number xy, part of which is here.

  ------------------------------------+------------------
  | xyxyxy | xyxyxy | xyxyxy | xyxyxy | xyxyxy | xyxyxy |
  ------------------------------------+------------------

To divide by 65536 we simply discard bytes 0 and 1 and read
from byte 2 to byte 5.

  ------------------+------------------
  | byte 5 | byte 4 | byte 3 | byte 2 |
  ------------------+------------------

And this essentially is how the multiplication routine
works.  Now I know from experience that we will not be
multiplying any numbers to give products greater than 255 so
we can use a 5 byte representation.  This results in one
byte above the binary point in the result, like this.

           ---------+------------------
           | byte 4 | byte 3 | byte 2 |
           ---------+------------------

In order to cope with 2's complement negatives you have to
also pad out the higher bytes in the numbers to be
multiplied and in the result with &FF if necessary.  That is
why you see checks for negative and &FFs being put into 5th
bytes in the fixed point multiplication routine.

The routine lies between lines 3780 and 4580 in the module
program.

And so to the code itself.

You will find that this code is almost a straight line, with
only two subroutines, the Mandelbrot routine itself and the
multiplying routine.  This was done partly for speed, but
also partly because by its nature this is a linear process
rather than a multi-branched one, and so subroutines might
not have clarified much.

At the start of the assembly I test to see if your program
is running in a second processor or in the BBC Micro itself,
the I/O processor.  This is because the program uses Mode 2
graphics and will not fit in memory easily.  With a second
processor that is no problem but in the micro itself you
must be in Mode 7 to assemble and must clear the BASIC
variable workspace (with a NEW) before you can run the final
code.  The first few lines of the program take care of that
and will tell you what is going on.  The code is executed by
pressing function key 0: function key 1 is available to list
the program in Mode 3.  In the micro the code is assembled
at &1300, in a 'safe' part of the disc workspace.  In a
second processor it can just be put alongside the
BASIC/Assembler using DIM.  If you have a BBC Master without
a second processor you will have to change this part of the
code to force the use of DIM because the value of PAGE is
&E00.  [You can also use shadow memory by using Mode 130
instead of Mode 2.]

We set the mode as 2 and this gives us increments of 8
graphics units per pixel on the x axis and 4 on the y.  If
you want to change to Mode 0 or Mode 1 you have to modify
these variables accordingly.  The horizontal increments will
be 2 and 4 for Modes 0 and 1 respectively.

For speed I am using zero page workspace for the
multiplying routines, and that is set next.

In the assembler itself Mode 2 is set up followed by a VDU5
equivalent (both done using OSWRCH) so that the text cursor
is removed.  I know that there is a VDU23 instruction to
switch off the cursor, but VDU5 is quicker and easier.

The next section is a plotting loop that uses two words of
memory labelled 'x_coord' and 'y_coord' to set the position
of the pixel being plotted currently.  The Mandelbrot
subroutine uses a GCOL equivalent to set the colour before
the pixel is plotted using a PLOT 69 equivalent (plot a
point).  For convenience I am using a 1024 units square area
of the screen.

Since the numerical area covered is 3 units along both axes
the increment per graphics unit is 3/1024.  Since our fixed
point representation effectively multiplies that by 65536
(which is 256*256) the increment in fixed point is in fact
&C0 in both directions.  This figure is put into memory at
labels h_inc and v_inc during the assembly.

I have in fact eased the difficulty of this program greatly
by assuming it will only be plotting the whole set.  You
could modify it to plot a smaller section at the risk of
greater inacuracy with very small numbers but you will have
to change the increments and the plot starting points
manually, as it were, to do this.  Simply, to find the four
byte fixed point equivalent of a number, just multiply it by
65536.

The complex numbers are broken down into real and imaginary
parts.  Their labels here are x and y for the components of
z (since z is usually written x+iy) and c_real and c_imag
for c.  These are the calculations we must make:

    size = x^2 + y^2  (remember size is itself a square)

    New value of x = x^2 - y^2 + c_real

    New value of y = 2 * x * y + c_imag

From line 1050 the code computes the value of c_real, based
upon the current position on the screen.  By using the X
register counting down from 4 and offset against 'h_inc-1'
we can use a BNE to test the loop during the transfer of
bytes into multiplication workspace.  You will see that most
of the transfers are done this way.

In line 1310 -2.25 is added in the calculation of c_real. 
-2.25 is the starting point of that axis.  In our fixed
point representation the number to be added is -2.25 * 65536
and that (in 2's complement negative) is &FFFDC000.

From line 1420 c_imag is calculated and you will note that
in line 1680 -1.5 is added in, this is &FFFE8000 in our
fixed point.

Just prior to the start of the main iteration loop the
counter is initialised (we count down as usual in order to
use a BNE/BEQ trap at the end of the loop) and x and y are
initialised at zero, because z is zero as we start
iterating.

x squared and y squared are calculated simply by multiplying
each with itself.  The size is then calculated by adding the
two results.  Ideally we should test the size now, but there
is too much code between here and the nearest point to put
the other end of the branch.  Remember a branch can only be
+127 or -128 bytes.  We will find the test shortly.

In the calculations for the new x and y you will notice that
while x needs x^2 and y^2, y needs x and y, so we must
calculate the new y before we calculate the new x.  From
line 2540 the code calculates the new y.  In the middle of
this there is the earliest spot for the size test, which is
why it appears at line 2850.  The reason for putting the
test as early as possible is that it will trap on size over
most of the screen so by trapping here, rather than at the
end of the loop, we save executing code unnecessarily, which
saves time albeit only a small amount.

We finish calculating the new y and then calculate the new
x ready for the next iteration.

The counter is decremented for the next iteration, but if
that will take us past our iterations limit, in this case
32, we exit instead, using a BEQ in line 3410.

At 'size_out' is the code that uses GCOL (VDU 18) to set the
pixel colour.  Rather than waste time and effort on a
division I have simply masked off all but the last three
bits of the size, which gives values from 0 to 7.  If the
iterations limit is exceeded then we reach 'count_out' and
set the colour to black (GCOL 0,0).

After some variable and workspace setting we finally come to
the fixed point multiplication code.  You will notice that
we test for a negative number and if we find one we make it
up to five bytes before the multiplication, since we want a
good five byte result.  The same applies to the result.  The
loop is executed 40 times because 5 bytes is 40 bits.

Plotting the Mandelbrot set on a 3MHz 6502 second processor
from BASIC using floating point takes me over 45 minutes,
this routine using fixed point machine code arithmetic takes
only 22 minutes.  If I could speed up the multiplications I
could probably get it even faster.  Fair takes your breath
away dunnit?

The alternative to fixed point, a little slower but more
precise, is floating point.  That's for next time.
00000000  4f 53 42 49 54 53 20 2d  20 41 6e 20 45 78 70 6c  |OSBITS - An Expl|
00000010  6f 72 61 74 69 6f 6e 20  6f 66 20 74 68 65 20 42  |oration of the B|
00000020  42 43 20 4d 69 63 72 6f  20 61 74 20 4d 61 63 68  |BC Micro at Mach|
00000030  69 6e 65 20 4c 65 76 65  6c 0d 0d 42 79 20 50 72  |ine Level..By Pr|
00000040  6f 67 72 61 6d 6d 65 72  0d 0d 2e 2e 2e 2e 2e 2e  |ogrammer........|
00000050  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 2e  |................|
*
00000080  2e 2e 2e 2e 0d 0d 0d 50  61 72 74 20 32 31 3a 20  |.......Part 21: |
00000090  52 65 61 6c 20 4e 75 6d  62 65 72 73 20 45 78 70  |Real Numbers Exp|
000000a0  6c 6f 72 65 20 74 68 65  20 4d 61 6e 64 65 6c 62  |lore the Mandelb|
000000b0  72 6f 74 20 53 65 74 0d  0d 0d 49 6e 20 74 68 65  |rot Set...In the|
000000c0  20 6c 61 73 74 20 6d 6f  64 75 6c 65 20 49 20 69  | last module I i|
000000d0  6e 74 72 6f 64 75 63 65  64 20 74 68 65 20 69 64  |ntroduced the id|
000000e0  65 61 20 6f 66 20 73 70  6c 69 74 74 69 6e 67 20  |ea of splitting |
000000f0  75 70 20 61 0d 77 6f 72  64 20 28 69 6e 20 74 68  |up a.word (in th|
00000100  61 74 20 63 61 73 65 20  69 74 20 77 61 73 20 34  |at case it was 4|
00000110  20 62 79 74 65 73 20 61  73 20 75 73 65 64 20 62  | bytes as used b|
00000120  79 20 42 41 53 49 43 20  69 6e 74 65 67 65 72 73  |y BASIC integers|
00000130  29 0d 73 75 63 68 20 74  68 61 74 20 74 68 65 20  |).such that the |
00000140  6c 6f 77 65 72 20 66 65  77 20 62 79 74 65 73 20  |lower few bytes |
00000150  77 65 72 65 20 69 6e 20  66 61 63 74 20 72 65 70  |were in fact rep|
00000160  72 65 73 65 6e 74 69 6e  67 0d 66 72 61 63 74 69  |resenting.fracti|
00000170  6f 6e 61 6c 20 70 61 72  74 73 20 6f 66 20 31 2e  |onal parts of 1.|
00000180  20 20 54 68 69 73 20 6d  6f 64 75 6c 65 20 65 78  |  This module ex|
00000190  70 6c 6f 69 74 73 20 74  68 61 74 20 69 64 65 61  |ploits that idea|
000001a0  20 69 6e 0d 6f 72 64 65  72 20 74 6f 20 70 65 72  | in.order to per|
000001b0  66 6f 72 6d 20 73 6f 6d  65 20 70 72 65 74 74 79  |form some pretty|
000001c0  20 68 61 69 72 79 20 63  6f 6d 70 75 74 61 74 69  | hairy computati|
000001d0  6f 6e 20 69 6e 20 6f 72  64 65 72 20 74 6f 0d 70  |on in order to.p|
000001e0  6c 6f 74 20 61 20 63 72  75 64 65 20 64 69 61 67  |lot a crude diag|
000001f0  72 61 6d 20 73 68 6f 77  69 6e 67 20 74 68 65 20  |ram showing the |
00000200  4d 61 6e 64 65 6c 62 72  6f 74 20 53 65 74 2e 0d  |Mandelbrot Set..|
00000210  0d 54 68 65 20 4d 61 6e  64 65 6c 62 72 6f 74 20  |.The Mandelbrot |
00000220  53 65 74 20 69 6c 6c 75  73 74 72 61 74 65 73 20  |Set illustrates |
00000230  74 68 65 20 70 65 72 66  6f 72 6d 61 6e 63 65 20  |the performance |
00000240  6f 66 20 74 68 65 0d 66  75 6e 63 74 69 6f 6e 20  |of the.function |
00000250  7a 3d 7a 2b 63 20 77 68  65 72 65 20 62 6f 74 68  |z=z+c where both|
00000260  20 7a 20 61 6e 64 20 63  20 61 72 65 20 63 6f 6d  | z and c are com|
00000270  70 6c 65 78 20 6e 75 6d  62 65 72 73 2e 20 20 54  |plex numbers.  T|
00000280  68 69 73 0d 6d 65 61 6e  73 20 74 68 65 79 20 68  |his.means they h|
00000290  61 76 65 20 61 20 72 65  61 6c 20 70 61 72 74 20  |ave a real part |
000002a0  61 6e 64 20 61 6e 20 69  6d 61 67 69 6e 61 72 79  |and an imaginary|
000002b0  20 70 61 72 74 20 61 6e  64 20 74 68 65 0d 69 6d  | part and the.im|
000002c0  61 67 69 6e 61 72 79 20  70 61 72 74 20 69 73 20  |aginary part is |
000002d0  61 20 6d 75 6c 74 69 70  6c 65 20 28 6f 72 20 66  |a multiple (or f|
000002e0  72 61 63 74 69 6f 6e 29  20 6f 66 20 74 68 65 20  |raction) of the |
000002f0  73 71 75 61 72 65 0d 72  6f 6f 74 20 6f 66 20 2d  |square.root of -|
00000300  31 2e 20 20 4d 61 74 68  65 6d 61 74 69 63 69 61  |1.  Mathematicia|
00000310  6e 73 20 63 61 6c 6c 20  74 68 61 74 20 71 75 61  |ns call that qua|
00000320  6e 74 69 74 79 20 69 20  77 68 69 6c 65 0d 65 6e  |ntity i while.en|
00000330  67 69 6e 65 65 72 73 20  75 73 75 61 6c 6c 79 20  |gineers usually |
00000340  63 61 6c 6c 20 69 74 20  6a 2e 20 20 28 69 20 74  |call it j.  (i t|
00000350  6f 20 61 6e 20 65 6c 65  63 74 72 69 63 61 6c 20  |o an electrical |
00000360  65 6e 67 69 6e 65 65 72  0d 64 65 6e 6f 74 65 73  |engineer.denotes|
00000370  20 63 75 72 72 65 6e 74  2c 20 61 73 20 69 6e 20  | current, as in |
00000380  4f 68 6d 27 73 20 4c 61  77 20 76 3d 69 72 2e 29  |Ohm's Law v=ir.)|
00000390  0d 0d 53 6f 20 65 73 73  65 6e 74 69 61 6c 6c 79  |..So essentially|
000003a0  20 77 65 20 74 61 6b 65  20 7a 3d 7a 2b 63 2c 20  | we take z=z+c, |
000003b0  73 74 61 72 74 69 6e 67  20 77 69 74 68 20 7a 3d  |starting with z=|
000003c0  30 20 61 6e 64 20 6b 65  65 70 0d 70 75 74 74 69  |0 and keep.putti|
000003d0  6e 67 20 69 74 20 69 6e  74 6f 20 74 68 65 20 65  |ng it into the e|
000003e0  71 75 61 74 69 6f 6e 2e  20 20 4f 62 76 69 6f 75  |quation.  Obviou|
000003f0  73 6c 79 20 74 68 65 20  66 69 72 73 74 20 74 69  |sly the first ti|
00000400  6d 65 0d 61 72 6f 75 6e  64 20 7a 20 77 69 6c 6c  |me.around z will|
00000410  20 65 71 75 61 6c 20 63  2e 20 20 49 66 20 77 65  | equal c.  If we|
00000420  20 6b 65 65 70 20 64 6f  69 6e 67 20 74 68 69 73  | keep doing this|
00000430  20 73 6f 20 63 61 6c 6c  65 64 0d 69 74 65 72 61  | so called.itera|
00000440  74 69 76 65 20 70 72 6f  63 65 73 73 20 61 6e 64  |tive process and|
00000450  20 63 68 65 63 6b 20 6f  6e 20 74 68 65 20 73 69  | check on the si|
00000460  7a 65 20 6f 66 20 7a 20  61 73 20 77 65 20 64 6f  |ze of z as we do|
00000470  20 69 74 20 77 65 0d 63  61 6e 20 73 65 65 20 68  | it we.can see h|
00000480  6f 77 20 74 68 65 20 66  75 6e 63 74 69 6f 6e 20  |ow the function |
00000490  62 65 68 61 76 65 73 2e  0d 0d 49 6e 20 6f 72 64  |behaves...In ord|
000004a0  65 72 20 74 6f 20 64 72  61 77 20 74 68 65 20 4d  |er to draw the M|
000004b0  61 6e 64 65 6c 62 72 6f  74 20 53 65 74 20 77 65  |andelbrot Set we|
000004c0  20 73 69 6d 70 6c 79 20  63 61 72 72 79 20 6f 75  | simply carry ou|
000004d0  74 20 74 68 69 73 0d 69  74 65 72 61 74 69 6f 6e  |t this.iteration|
000004e0  20 75 73 69 6e 67 20 73  63 72 65 65 6e 20 63 6f  | using screen co|
000004f0  2d 6f 72 64 69 6e 61 74  65 73 20 74 6f 20 72 65  |-ordinates to re|
00000500  70 72 65 73 65 6e 74 20  76 61 6c 75 65 73 20 6f  |present values o|
00000510  66 0d 63 2e 20 20 53 69  6e 63 65 20 63 20 68 61  |f.c.  Since c ha|
00000520  73 20 74 68 65 73 65 20  72 65 61 6c 20 61 6e 64  |s these real and|
00000530  20 69 6d 61 67 69 6e 61  72 79 20 70 61 72 74 73  | imaginary parts|
00000540  20 77 65 20 63 61 6e 20  70 6c 6f 74 0d 72 65 61  | we can plot.rea|
00000550  6c 20 76 61 6c 75 65 73  20 61 6c 6f 6e 67 20 74  |l values along t|
00000560  68 65 20 78 20 61 78 69  73 20 61 6e 64 20 69 6d  |he x axis and im|
00000570  61 67 69 6e 61 72 79 20  6f 6e 65 73 20 75 70 20  |aginary ones up |
00000580  74 68 65 20 79 0d 61 78  69 73 2e 20 20 54 68 65  |the y.axis.  The|
00000590  20 63 6f 6c 6f 75 72 20  6f 66 20 74 68 65 20 70  | colour of the p|
000005a0  69 78 65 6c 20 70 6c 6f  74 74 65 64 20 61 74 20  |ixel plotted at |
000005b0  74 68 61 74 20 70 6f 69  6e 74 20 69 73 20 75 73  |that point is us|
000005c0  65 64 0d 74 6f 20 74 65  6c 6c 20 75 73 20 68 6f  |ed.to tell us ho|
000005d0  77 20 74 68 65 20 73 69  7a 65 20 6f 66 20 74 68  |w the size of th|
000005e0  65 20 66 75 6e 63 74 69  6f 6e 20 62 65 68 61 76  |e function behav|
000005f0  65 73 2e 0d 0d 57 65 20  61 72 65 20 69 6e 74 65  |es...We are inte|
00000600  72 65 73 74 65 64 20 69  6e 20 77 68 65 74 68 65  |rested in whethe|
00000610  72 20 6f 72 20 6e 6f 74  20 74 68 65 20 73 69 7a  |r or not the siz|
00000620  65 20 6f 66 20 74 68 65  20 66 75 6e 63 74 69 6f  |e of the functio|
00000630  6e 0d 69 6e 63 72 65 61  73 65 73 20 77 69 74 68  |n.increases with|
00000640  6f 75 74 20 6c 69 6d 69  74 2e 20 20 46 6f 72 20  |out limit.  For |
00000650  6f 75 72 20 70 75 72 70  6f 73 65 73 20 27 77 69  |our purposes 'wi|
00000660  74 68 6f 75 74 20 6c 69  6d 69 74 27 0d 6d 65 61  |thout limit'.mea|
00000670  6e 73 20 6f 6e 6c 79 20  74 68 61 74 20 69 74 20  |ns only that it |
00000680  72 65 61 63 68 65 73 20  32 20 62 65 63 61 75 73  |reaches 2 becaus|
00000690  65 20 69 66 20 69 74 20  72 65 61 63 68 65 73 20  |e if it reaches |
000006a0  32 20 69 74 0d 77 69 6c  6c 2c 20 49 20 61 6d 20  |2 it.will, I am |
000006b0  72 65 6c 69 61 62 6c 79  20 69 6e 66 6f 72 6d 65  |reliably informe|
000006c0  64 2c 20 72 65 61 63 68  20 69 6e 66 69 6e 69 74  |d, reach infinit|
000006d0  79 21 20 20 44 69 66 66  65 72 65 6e 74 0d 63 6f  |y!  Different.co|
000006e0  6c 6f 75 72 20 76 61 6c  75 65 73 20 74 65 6c 6c  |lour values tell|
000006f0  20 75 73 20 68 6f 77 20  6d 61 6e 79 20 69 74 65  | us how many ite|
00000700  72 61 74 69 6f 6e 73 20  69 74 20 74 6f 6f 6b 20  |rations it took |
00000710  66 6f 72 20 74 68 65 0d  66 75 6e 63 74 69 6f 6e  |for the.function|
00000720  20 74 6f 20 72 65 61 63  68 20 32 20 69 6e 20 73  | to reach 2 in s|
00000730  69 7a 65 2e 20 20 49 66  20 61 66 74 65 72 20 61  |ize.  If after a|
00000740  20 63 65 72 74 61 69 6e  20 6e 75 6d 62 65 72 20  | certain number |
00000750  6f 66 0d 69 74 65 72 61  74 69 6f 6e 73 20 69 74  |of.iterations it|
00000760  20 68 61 73 20 6e 6f 74  20 79 65 74 20 72 65 61  | has not yet rea|
00000770  63 68 65 64 20 32 20 74  68 65 6e 20 74 68 65 20  |ched 2 then the |
00000780  70 69 78 65 6c 20 69 73  0d 63 6f 6c 6f 75 72 65  |pixel is.coloure|
00000790  64 20 62 6c 61 63 6b 20  61 6e 64 20 74 68 61 74  |d black and that|
000007a0  20 76 61 6c 75 65 20 6f  66 20 63 20 69 73 20 70  | value of c is p|
000007b0  61 72 74 20 6f 66 20 74  68 65 20 4d 61 6e 64 65  |art of the Mande|
000007c0  6c 62 72 6f 74 0d 53 65  74 2e 20 20 54 68 69 73  |lbrot.Set.  This|
000007d0  20 69 73 20 61 6c 6c 20  6e 61 6d 65 64 20 61 66  | is all named af|
000007e0  74 65 72 20 61 20 42 65  6c 67 69 61 6e 20 6d 61  |ter a Belgian ma|
000007f0  74 68 65 6d 61 74 69 63  69 61 6e 20 6e 61 6d 65  |thematician name|
00000800  64 0d 42 65 6e 6f 69 74  20 42 20 4d 61 6e 64 65  |d.Benoit B Mande|
00000810  6c 62 72 6f 74 20 77 68  6f 20 64 69 73 63 6f 76  |lbrot who discov|
00000820  65 72 65 64 20 74 68 69  73 20 70 61 72 74 69 63  |ered this partic|
00000830  75 6c 61 72 20 62 65 68  61 76 69 6f 75 72 0d 6f  |ular behaviour.o|
00000840  66 20 63 6f 6d 70 6c 65  78 20 6e 75 6d 62 65 72  |f complex number|
00000850  73 2e 0d 0d 4d 61 6e 64  65 6c 62 72 6f 74 20 61  |s...Mandelbrot a|
00000860  6c 73 6f 20 64 69 73 63  6f 76 65 72 65 64 20 66  |lso discovered f|
00000870  72 61 63 74 61 6c 73 20  61 6e 64 20 74 68 65 20  |ractals and the |
00000880  62 6f 75 6e 64 61 72 79  20 6f 66 20 74 68 65 0d  |boundary of the.|
00000890  62 6c 61 63 6b 20 61 72  65 61 20 69 6e 20 74 68  |black area in th|
000008a0  65 20 6d 69 64 64 6c 65  20 6f 66 20 6f 75 72 20  |e middle of our |
000008b0  65 76 65 6e 74 75 61 6c  20 64 69 61 67 72 61 6d  |eventual diagram|
000008c0  20 69 73 20 61 0d 66 72  61 63 74 61 6c 2e 20 20  | is a.fractal.  |
000008d0  49 66 20 77 65 20 62 6c  6f 77 20 69 74 20 75 70  |If we blow it up|
000008e0  20 65 76 65 72 20 6c 61  72 67 65 72 20 77 65 20  | ever larger we |
000008f0  72 65 76 65 61 6c 20 6d  6f 72 65 20 61 6e 64 0d  |reveal more and.|
00000900  6d 6f 72 65 20 64 65 74  61 69 6c 2e 20 20 4e 6f  |more detail.  No|
00000910  77 20 79 6f 75 20 63 61  6e 20 69 6d 61 67 69 6e  |w you can imagin|
00000920  65 20 74 68 61 74 20 73  69 6e 63 65 20 6d 61 6e  |e that since man|
00000930  79 20 69 74 65 72 61 74  69 6f 6e 73 0d 61 72 65  |y iterations.are|
00000940  20 74 61 6b 69 6e 67 20  70 6c 61 63 65 20 61 74  | taking place at|
00000950  20 65 61 63 68 20 70 69  78 65 6c 20 6f 6e 20 74  | each pixel on t|
00000960  68 65 20 73 63 72 65 65  6e 20 74 68 65 20 77 68  |he screen the wh|
00000970  6f 6c 65 0d 70 72 6f 63  65 73 73 20 63 61 6e 20  |ole.process can |
00000980  74 61 6b 65 20 61 20 6c  6f 6e 67 20 74 69 6d 65  |take a long time|
00000990  2e 20 20 49 20 68 61 76  65 20 64 72 61 77 6e 20  |.  I have drawn |
000009a0  62 6c 6f 77 2d 75 70 73  20 6f 66 0d 61 72 65 61  |blow-ups of.area|
000009b0  73 20 6f 66 20 74 68 65  20 62 6f 75 6e 64 61 72  |s of the boundar|
000009c0  79 20 74 68 61 74 20 74  6f 6f 6b 20 6f 76 65 72  |y that took over|
000009d0  20 34 38 20 68 6f 75 72  73 20 74 6f 20 70 6c 6f  | 48 hours to plo|
000009e0  74 20 6f 6e 20 61 0d 42  42 43 20 6d 69 63 72 6f  |t on a.BBC micro|
000009f0  20 69 6e 20 42 41 53 49  43 2e 20 20 28 49 27 76  | in BASIC.  (I'v|
00000a00  65 20 61 6c 73 6f 20 64  6f 6e 65 20 69 74 20 69  |e also done it i|
00000a10  6e 20 46 4f 52 54 52 41  4e 20 6f 6e 20 61 0d 33  |n FORTRAN on a.3|
00000a20  32 30 31 36 20 73 65 63  6f 6e 64 20 70 72 6f 63  |2016 second proc|
00000a30  65 73 73 6f 72 20 69 6e  20 61 6e 20 68 6f 75 72  |essor in an hour|
00000a40  20 62 75 74 20 74 68 61  74 27 73 20 64 6f 77 6e  | but that's down|
00000a50  20 74 6f 20 74 68 65 0d  70 6f 77 65 72 20 6f 66  | to the.power of|
00000a60  20 74 68 65 20 6d 61 63  68 69 6e 65 72 79 20 61  | the machinery a|
00000a70  6e 64 20 6f 66 20 46 4f  52 54 52 41 4e 20 72 61  |nd of FORTRAN ra|
00000a80  74 68 65 72 20 74 68 61  6e 20 61 6e 79 20 66 61  |ther than any fa|
00000a90  6e 63 79 0d 63 6f 64 69  6e 67 20 6f 66 20 6d 69  |ncy.coding of mi|
00000aa0  6e 65 2e 29 0d 0d 54 68  65 20 61 6c 67 6f 72 69  |ne.)..The algori|
00000ab0  74 68 6d 20 69 73 20 6c  69 6b 65 20 74 68 69 73  |thm is like this|
00000ac0  3a 0d 0d 4d 61 70 20 6f  75 74 20 76 61 6c 75 65  |:..Map out value|
00000ad0  73 20 6f 66 20 63 20 63  6f 76 65 72 69 6e 67 20  |s of c covering |
00000ae0  74 68 65 20 72 61 6e 67  65 20 2d 32 2e 32 35 2d  |the range -2.25-|
00000af0  31 2e 35 69 20 74 6f 0d  30 2e 37 35 2b 31 2e 35  |1.5i to.0.75+1.5|
00000b00  69 20 61 63 72 6f 73 73  20 74 68 65 20 73 63 72  |i across the scr|
00000b10  65 65 6e 20 61 72 65 61  2e 20 20 54 68 69 73 20  |een area.  This |
00000b20  6d 65 61 6e 73 20 74 68  61 74 20 74 68 65 0d 67  |means that the.g|
00000b30  72 61 70 68 69 63 73 20  6f 72 69 67 69 6e 20 28  |raphics origin (|
00000b40  30 2c 30 29 20 72 65 70  72 65 73 65 6e 74 73 20  |0,0) represents |
00000b50  2d 32 2e 32 35 2d 31 2e  35 69 20 61 6e 64 20 28  |-2.25-1.5i and (|
00000b60  31 30 32 34 2c 31 30 32  34 29 0d 72 65 70 72 65  |1024,1024).repre|
00000b70  73 65 6e 74 73 20 30 2e  37 35 2b 31 2e 35 69 20  |sents 0.75+1.5i |
00000b80  61 6e 64 20 65 61 63 68  20 70 69 78 65 6c 20 6f  |and each pixel o|
00000b90  6e 20 74 68 65 20 73 63  72 65 65 6e 20 77 6f 75  |n the screen wou|
00000ba0  6c 64 0d 72 65 70 72 65  73 65 6e 74 20 61 20 76  |ld.represent a v|
00000bb0  61 6c 75 65 20 6f 66 20  63 2e 0d 0d 57 6f 72 6b  |alue of c...Work|
00000bc0  20 79 6f 75 72 20 77 61  79 20 6f 76 65 72 20 74  | your way over t|
00000bd0  68 65 20 73 63 72 65 65  6e 20 61 6e 64 20 66 6f  |he screen and fo|
00000be0  72 20 65 61 63 68 20 70  69 78 65 6c 3a 0d 0d 53  |r each pixel:..S|
00000bf0  65 74 20 61 20 63 6f 75  6e 74 65 72 20 61 74 20  |et a counter at |
00000c00  7a 65 72 6f 2c 20 73 65  74 20 7a 20 65 71 75 61  |zero, set z equa|
00000c10  6c 20 74 6f 20 7a 65 72  6f 20 28 30 2b 30 69 29  |l to zero (0+0i)|
00000c20  0d 0d 4c 6f 6f 70 20 73  74 61 72 74 0d 0d 43 61  |..Loop start..Ca|
00000c30  6c 63 75 6c 61 74 65 20  73 69 7a 65 20 6f 66 20  |lculate size of |
00000c40  7a 2c 20 69 66 20 3e 20  32 20 74 68 65 6e 20 63  |z, if > 2 then c|
00000c50  6f 6c 6f 75 72 20 74 68  65 20 70 69 78 65 6c 20  |olour the pixel |
00000c60  61 63 63 6f 72 64 69 6e  67 0d 74 6f 20 74 68 65  |according.to the|
00000c70  20 76 61 6c 75 65 20 69  6e 20 74 68 65 20 63 6f  | value in the co|
00000c80  75 6e 74 65 72 20 61 6e  64 20 6d 6f 76 65 20 6f  |unter and move o|
00000c90  6e 20 74 6f 20 6e 65 78  74 20 70 69 78 65 6c 0d  |n to next pixel.|
00000ca0  0d 49 66 20 74 68 65 20  63 6f 75 6e 74 65 72 20  |.If the counter |
00000cb0  68 61 73 20 72 65 61 63  68 65 64 20 61 20 70 72  |has reached a pr|
00000cc0  65 73 65 74 20 76 61 6c  75 65 20 63 6f 6c 6f 75  |eset value colou|
00000cd0  72 20 74 68 65 20 70 69  78 65 6c 0d 62 6c 61 63  |r the pixel.blac|
00000ce0  6b 20 61 6e 64 20 6d 6f  76 65 20 6f 6e 20 74 6f  |k and move on to|
00000cf0  20 74 68 65 20 6e 65 78  74 20 70 69 78 65 6c 0d  | the next pixel.|
00000d00  0d 49 66 20 6e 65 69 74  68 65 72 20 63 6f 6e 64  |.If neither cond|
00000d10  69 74 69 6f 6e 20 69 73  20 6d 65 74 20 74 68 65  |ition is met the|
00000d20  6e 20 72 65 63 61 6c 63  75 6c 61 74 65 20 7a 3d  |n recalculate z=|
00000d30  7a 2b 63 20 75 73 69 6e  67 20 74 68 65 0d 70 72  |z+c using the.pr|
00000d40  65 76 69 6f 75 73 20 76  61 6c 75 65 20 6f 66 20  |evious value of |
00000d50  7a 20 61 6e 64 20 67 6f  20 62 61 63 6b 20 74 6f  |z and go back to|
00000d60  20 74 68 65 20 73 74 61  72 74 20 6f 66 20 74 68  | the start of th|
00000d70  65 20 6c 6f 6f 70 0d 0d  49 6e 20 70 72 61 63 74  |e loop..In pract|
00000d80  69 63 65 20 74 68 65 20  74 65 6e 64 65 6e 63 79  |ice the tendency|
00000d90  20 69 73 20 74 6f 20 63  61 6c 63 75 6c 61 74 65  | is to calculate|
00000da0  20 74 68 65 20 6e 65 77  20 76 61 6c 75 65 20 6f  | the new value o|
00000db0  66 0d 74 68 65 20 73 69  7a 65 20 73 71 75 61 72  |f.the size squar|
00000dc0  65 64 2c 20 77 68 69 63  68 20 69 73 20 74 68 65  |ed, which is the|
00000dd0  20 73 75 6d 20 6f 66 20  74 68 65 20 72 65 61 6c  | sum of the real|
00000de0  20 70 61 72 74 20 73 71  75 61 72 65 64 0d 61 6e  | part squared.an|
00000df0  64 20 74 68 65 20 69 6d  61 67 69 6e 61 72 79 20  |d the imaginary |
00000e00  70 61 72 74 20 73 71 75  61 72 65 64 2e 20 20 54  |part squared.  T|
00000e10  68 65 72 65 20 69 73 20  6e 6f 20 70 6f 69 6e 74  |here is no point|
00000e20  20 69 6e 20 74 61 6b 69  6e 67 0d 61 20 73 70 75  | in taking.a spu|
00000e30  72 69 6f 75 73 20 73 71  75 61 72 65 20 72 6f 6f  |rious square roo|
00000e40  74 2e 20 20 53 6f 20 74  68 65 20 73 69 7a 65 20  |t.  So the size |
00000e50  76 61 72 69 61 62 6c 65  20 62 65 69 6e 67 20 75  |variable being u|
00000e60  73 65 64 20 69 73 0d 74  68 65 20 73 71 75 61 72  |sed is.the squar|
00000e70  65 20 61 6e 64 20 69 74  20 69 73 20 74 68 65 72  |e and it is ther|
00000e80  65 66 6f 72 65 20 63 6f  6d 70 61 72 65 64 20 77  |efore compared w|
00000e90  69 74 68 20 34 20 72 61  74 68 65 72 20 74 68 61  |ith 4 rather tha|
00000ea0  6e 0d 32 2e 20 20 41 6c  73 6f 20 74 68 65 20 61  |n.2.  Also the a|
00000eb0  63 74 75 61 6c 20 6f 72  64 65 72 20 6f 66 20 63  |ctual order of c|
00000ec0  61 72 72 79 69 6e 67 20  6f 75 74 20 74 68 65 20  |arrying out the |
00000ed0  74 65 73 74 73 20 77 69  6c 6c 0d 76 61 72 79 20  |tests will.vary |
00000ee0  66 72 6f 6d 20 74 68 65  20 73 74 72 61 69 67 68  |from the straigh|
00000ef0  74 20 61 6c 67 6f 72 69  74 68 6d 2e 20 20 49 6e  |t algorithm.  In|
00000f00  20 74 68 65 20 6d 6f 64  75 6c 65 20 70 72 6f 67  | the module prog|
00000f10  72 61 6d 2c 0d 66 6f 72  20 65 78 61 6d 70 6c 65  |ram,.for example|
00000f20  2c 20 74 68 65 20 63 6f  75 6e 74 65 72 20 69 73  |, the counter is|
00000f30  20 64 65 63 72 65 6d 65  6e 74 65 64 20 61 74 20  | decremented at |
00000f40  74 68 65 20 65 6e 64 20  6f 66 20 74 68 65 0d 6c  |the end of the.l|
00000f50  6f 6f 70 20 72 61 74 68  65 72 20 74 68 61 6e 20  |oop rather than |
00000f60  74 68 65 20 62 65 67 69  6e 6e 69 6e 67 20 73 6f  |the beginning so|
00000f70  20 74 68 65 20 74 65 73  74 20 69 73 20 63 61 72  | the test is car|
00000f80  72 69 65 64 20 6f 75 74  0d 74 68 65 72 65 2e 20  |ried out.there. |
00000f90  20 41 6c 73 6f 20 74 68  65 20 73 69 7a 65 20 69  | Also the size i|
00000fa0  73 20 74 65 73 74 65 64  20 61 73 20 73 6f 6f 6e  |s tested as soon|
00000fb0  20 61 66 74 65 72 20 69  74 20 69 73 0d 63 61 6c  | after it is.cal|
00000fc0  63 75 6c 61 74 65 64 20  61 73 20 66 65 61 73 69  |culated as feasi|
00000fd0  62 6c 65 20 62 65 61 72  69 6e 67 20 69 6e 20 6d  |ble bearing in m|
00000fe0  69 6e 64 20 74 68 65 20  6c 65 6e 67 74 68 20 6f  |ind the length o|
00000ff0  66 20 74 68 65 0d 62 72  61 6e 63 68 20 6e 65 65  |f the.branch nee|
00001000  64 65 64 20 61 66 74 65  72 20 74 68 65 20 74 65  |ded after the te|
00001010  73 74 2e 20 20 42 65 63  61 75 73 65 20 6f 66 20  |st.  Because of |
00001020  74 68 69 73 20 62 72 61  6e 63 68 20 6c 65 6e 67  |this branch leng|
00001030  74 68 0d 70 72 6f 62 6c  65 6d 20 74 68 65 20 63  |th.problem the c|
00001040  6f 64 65 20 68 65 72 65  20 61 63 74 75 61 6c 6c  |ode here actuall|
00001050  79 20 74 65 73 74 73 20  69 6e 20 61 20 72 61 74  |y tests in a rat|
00001060  68 65 72 20 6f 64 64 20  70 6c 61 63 65 2c 0d 64  |her odd place,.d|
00001070  75 72 69 6e 67 20 74 68  65 20 63 61 6c 63 75 6c  |uring the calcul|
00001080  61 74 69 6f 6e 20 6f 66  20 74 68 65 20 6e 65 77  |ation of the new|
00001090  20 76 61 6c 75 65 20 6f  66 20 79 2e 0d 0d 54 68  | value of y...Th|
000010a0  65 20 4d 61 6e 64 65 6c  62 72 6f 74 20 73 65 74  |e Mandelbrot set|
000010b0  20 63 61 6c 63 75 6c 61  74 69 6f 6e 20 69 73 20  | calculation is |
000010c0  73 75 69 74 65 64 20 74  6f 20 6c 69 6d 69 74 65  |suited to limite|
000010d0  64 0d 66 69 78 65 64 2d  70 6f 69 6e 74 20 61 72  |d.fixed-point ar|
000010e0  69 74 68 6d 65 74 69 63  20 62 65 63 61 75 73 65  |ithmetic because|
000010f0  20 69 74 20 77 6f 72 6b  73 20 77 69 74 68 69 6e  | it works within|
00001100  20 61 20 6c 69 6d 69 74  65 64 0d 72 61 6e 67 65  | a limited.range|
00001110  20 6f 66 20 6e 75 6d 62  65 72 73 20 61 6e 64 20  | of numbers and |
00001120  62 65 63 61 75 73 65 2c  20 62 65 69 6e 67 20 61  |because, being a|
00001130  20 67 72 61 70 68 69 63  2c 20 69 74 20 69 73 20  | graphic, it is |
00001140  70 65 72 68 61 70 73 0d  6d 6f 72 65 20 74 6f 6c  |perhaps.more tol|
00001150  65 72 61 6e 74 20 6f 66  20 70 6f 6f 72 20 61 63  |erant of poor ac|
00001160  63 75 72 61 63 79 20 69  6e 20 74 68 65 20 63 61  |curacy in the ca|
00001170  6c 63 75 6c 61 74 69 6f  6e 73 2e 20 20 49 20 77  |lculations.  I w|
00001180  69 6c 6c 0d 61 64 6d 69  74 20 74 68 69 73 20 69  |ill.admit this i|
00001190  6e 20 61 64 76 61 6e 63  65 2c 20 6d 79 20 66 69  |n advance, my fi|
000011a0  78 65 64 2d 70 6f 69 6e  74 20 72 6f 75 74 69 6e  |xed-point routin|
000011b0  65 20 69 73 20 6e 6f 74  0d 61 6d 61 7a 69 6e 67  |e is not.amazing|
000011c0  6c 79 20 61 63 63 75 72  61 74 65 2c 20 62 75 74  |ly accurate, but|
000011d0  20 79 6f 75 72 20 74 72  61 64 65 2d 6f 66 66 20  | your trade-off |
000011e0  69 73 20 73 70 65 65 64  20 61 67 61 69 6e 73 74  |is speed against|
000011f0  0d 70 72 65 63 69 73 69  6f 6e 2e 20 20 53 6f 2c  |.precision.  So,|
00001200  20 62 65 66 6f 72 65 20  77 65 20 6c 6f 6f 6b 20  | before we look |
00001210  61 74 20 74 68 65 20 63  6f 64 65 20 49 20 73 68  |at the code I sh|
00001220  61 6c 6c 20 65 78 70 6c  61 69 6e 0d 74 68 65 20  |all explain.the |
00001230  66 69 78 65 64 2d 70 6f  69 6e 74 20 6d 65 74 68  |fixed-point meth|
00001240  6f 64 20 75 73 65 64 20  68 65 72 65 2e 0d 0d 49  |od used here...I|
00001250  66 20 77 65 20 74 61 6b  65 20 61 20 66 6f 75 72  |f we take a four|
00001260  20 62 79 74 65 20 77 6f  72 64 20 61 6e 64 20 70  | byte word and p|
00001270  75 74 20 74 68 65 20 27  62 69 6e 61 72 79 27 20  |ut the 'binary' |
00001280  70 6f 69 6e 74 20 69 6e  0d 74 68 65 20 6d 69 64  |point in.the mid|
00001290  64 6c 65 20 77 65 20 74  68 65 6e 20 68 61 76 65  |dle we then have|
000012a0  20 61 20 66 69 78 65 64  20 70 6f 69 6e 74 20 6e  | a fixed point n|
000012b0  75 6d 62 65 72 2e 20 20  49 66 20 79 6f 75 20 6c  |umber.  If you l|
000012c0  6f 6f 6b 0d 61 74 20 74  68 65 20 61 6c 67 6f 72  |ook.at the algor|
000012d0  69 74 68 6d 73 20 66 6f  72 20 61 72 69 74 68 6d  |ithms for arithm|
000012e0  65 74 69 63 20 49 20 6c  69 73 74 65 64 20 69 6e  |etic I listed in|
000012f0  20 74 68 65 20 6c 61 73  74 20 6d 6f 64 75 6c 65  | the last module|
00001300  0d 79 6f 75 20 77 69 6c  6c 20 66 69 6e 64 20 74  |.you will find t|
00001310  68 61 74 20 61 20 63 6f  6e 73 74 61 6e 74 20 66  |hat a constant f|
00001320  61 63 74 6f 72 20 77 61  73 20 69 6e 76 6f 6c 76  |actor was involv|
00001330  65 64 20 69 6e 0d 63 68  61 6e 67 69 6e 67 20 74  |ed in.changing t|
00001340  68 65 20 6e 75 6d 62 65  72 73 20 69 6e 74 6f 20  |he numbers into |
00001350  74 68 65 20 66 69 78 65  64 20 70 6f 69 6e 74 20  |the fixed point |
00001360  72 65 70 72 65 73 65 6e  74 61 74 69 6f 6e 2e 20  |representation. |
00001370  0d 49 74 20 77 61 73 20  31 30 30 30 30 20 6c 61  |.It was 10000 la|
00001380  73 74 20 74 69 6d 65 20  62 75 74 20 69 6e 20 74  |st time but in t|
00001390  68 65 20 70 72 6f 67 72  61 6d 20 69 6e 20 74 68  |he program in th|
000013a0  69 73 20 6d 6f 64 75 6c  65 20 49 0d 77 69 6c 6c  |is module I.will|
000013b0  20 75 73 65 20 36 35 35  33 36 2e 20 20 54 68 69  | use 65536.  Thi|
000013c0  73 20 70 75 74 73 20 74  68 65 20 62 69 6e 61 72  |s puts the binar|
000013d0  79 20 70 6f 69 6e 74 20  65 78 61 63 74 6c 79 20  |y point exactly |
000013e0  69 6e 20 74 68 65 0d 6d  69 64 64 6c 65 20 6f 66  |in the.middle of|
000013f0  20 74 68 65 20 6e 75 6d  62 65 72 20 73 6f 20 74  | the number so t|
00001400  68 61 74 20 74 68 65 20  74 6f 70 20 74 77 6f 20  |hat the top two |
00001410  62 79 74 65 73 20 61 72  65 20 74 68 65 0d 69 6e  |bytes are the.in|
00001420  74 65 67 65 72 20 70 61  72 74 20 61 6e 64 20 74  |teger part and t|
00001430  68 65 20 6c 6f 77 65 72  20 74 77 6f 20 62 79 74  |he lower two byt|
00001440  65 73 20 61 72 65 20 74  68 65 20 66 72 61 63 74  |es are the fract|
00001450  69 6f 6e 61 6c 0d 70 61  72 74 2e 20 20 49 6e 20  |ional.part.  In |
00001460  74 68 69 73 20 77 61 79  20 77 65 20 63 61 6e 20  |this way we can |
00001470  72 65 70 72 65 73 65 6e  74 20 6e 75 6d 62 65 72  |represent number|
00001480  73 20 75 70 20 74 6f 20  36 35 35 33 36 20 61 6e  |s up to 65536 an|
00001490  64 0d 61 73 20 73 6d 61  6c 6c 20 61 73 20 31 2e  |d.as small as 1.|
000014a0  35 32 36 45 2d 35 20 28  77 68 69 63 68 20 69 73  |526E-5 (which is|
000014b0  20 30 2e 30 30 30 30 31  35 32 36 29 2e 0d 0d 49  | 0.00001526)...I|
000014c0  6e 20 6f 72 64 65 72 20  74 6f 20 63 61 72 72 79  |n order to carry|
000014d0  20 6f 75 74 20 74 68 65  20 6e 65 63 65 73 73 61  | out the necessa|
000014e0  72 79 20 6d 75 6c 74 69  70 6c 69 63 61 74 69 6f  |ry multiplicatio|
000014f0  6e 73 20 49 20 68 61 76  65 0d 6d 6f 64 69 66 69  |ns I have.modifi|
00001500  65 64 20 74 68 65 20 6d  75 6c 74 69 2d 62 79 74  |ed the multi-byt|
00001510  65 20 6d 75 6c 74 69 70  6c 69 63 61 74 69 6f 6e  |e multiplication|
00001520  20 72 6f 75 74 69 6e 65  20 75 73 65 64 20 69 6e  | routine used in|
00001530  0d 6d 6f 64 75 6c 65 20  31 33 20 74 6f 20 70 72  |.module 13 to pr|
00001540  6f 64 75 63 65 20 61 20  66 69 76 65 20 62 79 74  |oduce a five byt|
00001550  65 20 72 65 73 75 6c 74  20 69 6e 73 74 65 61 64  |e result instead|
00001560  20 6f 66 20 66 6f 75 72  2e 20 0d 54 68 69 73 20  | of four. .This |
00001570  69 73 20 62 65 63 61 75  73 65 20 77 65 20 68 61  |is because we ha|
00001580  76 65 20 74 6f 20 64 69  76 69 64 65 20 74 68 65  |ve to divide the|
00001590  20 72 65 73 75 6c 74 20  6f 66 20 61 20 66 69 78  | result of a fix|
000015a0  65 64 0d 70 6f 69 6e 74  20 6d 75 6c 74 69 70 6c  |ed.point multipl|
000015b0  69 63 61 74 69 6f 6e 20  62 79 20 74 68 65 20 72  |ication by the r|
000015c0  65 6c 65 76 61 6e 74 20  66 61 63 74 6f 72 2e 20  |elevant factor. |
000015d0  20 49 74 20 6c 6f 6f 6b  73 20 6c 69 6b 65 0d 74  | It looks like.t|
000015e0  68 69 73 3a 0d 0d 48 65  72 65 20 69 73 20 61 20  |his:..Here is a |
000015f0  73 69 78 20 62 79 74 65  20 6e 75 6d 62 65 72 2e  |six byte number.|
00001600  20 54 68 65 20 62 69 6e  61 72 79 20 70 6f 69 6e  | The binary poin|
00001610  74 20 69 73 20 72 65 70  72 65 73 65 6e 74 65 64  |t is represented|
00001620  0d 62 79 20 61 20 70 6c  75 73 20 73 69 67 6e 2e  |.by a plus sign.|
00001630  0d 0d 20 20 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |..  ------------|
00001640  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00001650  2d 2d 2d 2d 2d 2d 2d 2d  2b 2d 2d 2d 2d 2d 2d 2d  |--------+-------|
00001660  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 0d 20 20 7c 20  |-----------.  | |
00001670  62 79 74 65 20 35 20 7c  20 62 79 74 65 20 34 20  |byte 5 | byte 4 |
00001680  7c 20 62 79 74 65 20 33  20 7c 20 62 79 74 65 20  || byte 3 | byte |
00001690  32 20 7c 20 62 79 74 65  20 31 20 7c 20 62 79 74  |2 | byte 1 | byt|
000016a0  65 20 30 20 7c 0d 20 20  2d 2d 2d 2d 2d 2d 2d 2d  |e 0 |.  --------|
000016b0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
000016c0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2b 2d 2d 2d  |------------+---|
000016d0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 0d  |---------------.|
000016e0  0d 49 66 20 77 65 20 6d  75 6c 74 69 70 6c 79 20  |.If we multiply |
000016f0  61 20 66 6f 75 72 20 62  79 74 65 20 6e 75 6d 62  |a four byte numb|
00001700  65 72 20 78 0d 0d 20 20  2d 2d 2d 2d 2d 2d 2d 2d  |er x..  --------|
00001710  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00001720  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2b 2d 2d 2d  |------------+---|
00001730  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 0d  |---------------.|
00001740  20 20 7c 20 20 20 20 20  20 20 20 7c 20 20 20 20  |  |        |    |
00001750  20 20 20 20 7c 20 78 78  78 78 78 78 20 7c 20 78  |    | xxxxxx | x|
00001760  78 78 78 78 78 20 7c 20  78 78 78 78 78 78 20 7c  |xxxxx | xxxxxx ||
00001770  20 78 78 78 78 78 78 20  7c 0d 20 20 2d 2d 2d 2d  | xxxxxx |.  ----|
00001780  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
000017a0  2b 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |+---------------|
000017b0  2d 2d 2d 0d 0d 62 79 20  61 20 66 6f 75 72 20 62  |---..by a four b|
000017c0  79 74 65 20 6e 75 6d 62  65 72 20 79 0d 0d 20 20  |yte number y..  |
000017d0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
000017f0  2d 2d 2d 2d 2b 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----+-----------|
00001800  2d 2d 2d 2d 2d 2d 2d 0d  20 20 7c 20 20 20 20 20  |-------.  |     |
00001810  20 20 20 7c 20 20 20 20  20 20 20 20 7c 20 79 79  |   |        | yy|
00001820  79 79 79 79 20 7c 20 79  79 79 79 79 79 20 7c 20  |yyyy | yyyyyy | |
00001830  79 79 79 79 79 79 20 7c  20 79 79 79 79 79 79 20  |yyyyyy | yyyyyy |
00001840  7c 0d 20 20 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  ||.  ------------|
00001850  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00001860  2d 2d 2d 2d 2d 2d 2d 2d  2b 2d 2d 2d 2d 2d 2d 2d  |--------+-------|
00001870  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 0d 0d 77 65 20  |-----------..we |
00001880  63 61 6e 20 67 65 74 20  61 20 65 69 67 68 74 20  |can get a eight |
00001890  62 79 74 65 20 6e 75 6d  62 65 72 20 78 79 2c 20  |byte number xy, |
000018a0  70 61 72 74 20 6f 66 20  77 68 69 63 68 20 69 73  |part of which is|
000018b0  20 68 65 72 65 2e 0d 0d  20 20 2d 2d 2d 2d 2d 2d  | here...  ------|
000018c0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
000018d0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2b 2d  |--------------+-|
000018e0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
000018f0  2d 0d 20 20 7c 20 78 79  78 79 78 79 20 7c 20 78  |-.  | xyxyxy | x|
00001900  79 78 79 78 79 20 7c 20  78 79 78 79 78 79 20 7c  |yxyxy | xyxyxy ||
00001910  20 78 79 78 79 78 79 20  7c 20 78 79 78 79 78 79  | xyxyxy | xyxyxy|
00001920  20 7c 20 78 79 78 79 78  79 20 7c 0d 20 20 2d 2d  | | xyxyxy |.  --|
00001930  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
*
00001950  2d 2d 2b 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |--+-------------|
00001960  2d 2d 2d 2d 2d 0d 0d 54  6f 20 64 69 76 69 64 65  |-----..To divide|
00001970  20 62 79 20 36 35 35 33  36 20 77 65 20 73 69 6d  | by 65536 we sim|
00001980  70 6c 79 20 64 69 73 63  61 72 64 20 62 79 74 65  |ply discard byte|
00001990  73 20 30 20 61 6e 64 20  31 20 61 6e 64 20 72 65  |s 0 and 1 and re|
000019a0  61 64 0d 66 72 6f 6d 20  62 79 74 65 20 32 20 74  |ad.from byte 2 t|
000019b0  6f 20 62 79 74 65 20 35  2e 0d 0d 20 20 2d 2d 2d  |o byte 5...  ---|
000019c0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2b  |---------------+|
000019d0  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
000019e0  2d 2d 0d 20 20 7c 20 62  79 74 65 20 35 20 7c 20  |--.  | byte 5 | |
000019f0  62 79 74 65 20 34 20 7c  20 62 79 74 65 20 33 20  |byte 4 | byte 3 |
00001a00  7c 20 62 79 74 65 20 32  20 7c 0d 20 20 2d 2d 2d  || byte 2 |.  ---|
00001a10  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2b  |---------------+|
00001a20  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |----------------|
00001a30  2d 2d 0d 0d 41 6e 64 20  74 68 69 73 20 65 73 73  |--..And this ess|
00001a40  65 6e 74 69 61 6c 6c 79  20 69 73 20 68 6f 77 20  |entially is how |
00001a50  74 68 65 20 6d 75 6c 74  69 70 6c 69 63 61 74 69  |the multiplicati|
00001a60  6f 6e 20 72 6f 75 74 69  6e 65 0d 77 6f 72 6b 73  |on routine.works|
00001a70  2e 20 20 4e 6f 77 20 49  20 6b 6e 6f 77 20 66 72  |.  Now I know fr|
00001a80  6f 6d 20 65 78 70 65 72  69 65 6e 63 65 20 74 68  |om experience th|
00001a90  61 74 20 77 65 20 77 69  6c 6c 20 6e 6f 74 20 62  |at we will not b|
00001aa0  65 0d 6d 75 6c 74 69 70  6c 79 69 6e 67 20 61 6e  |e.multiplying an|
00001ab0  79 20 6e 75 6d 62 65 72  73 20 74 6f 20 67 69 76  |y numbers to giv|
00001ac0  65 20 70 72 6f 64 75 63  74 73 20 67 72 65 61 74  |e products great|
00001ad0  65 72 20 74 68 61 6e 20  32 35 35 20 73 6f 0d 77  |er than 255 so.w|
00001ae0  65 20 63 61 6e 20 75 73  65 20 61 20 35 20 62 79  |e can use a 5 by|
00001af0  74 65 20 72 65 70 72 65  73 65 6e 74 61 74 69 6f  |te representatio|
00001b00  6e 2e 20 20 54 68 69 73  20 72 65 73 75 6c 74 73  |n.  This results|
00001b10  20 69 6e 20 6f 6e 65 0d  62 79 74 65 20 61 62 6f  | in one.byte abo|
00001b20  76 65 20 74 68 65 20 62  69 6e 61 72 79 20 70 6f  |ve the binary po|
00001b30  69 6e 74 20 69 6e 20 74  68 65 20 72 65 73 75 6c  |int in the resul|
00001b40  74 2c 20 6c 69 6b 65 20  74 68 69 73 2e 0d 0d 20  |t, like this... |
00001b50  20 20 20 20 20 20 20 20  20 20 2d 2d 2d 2d 2d 2d  |          ------|
00001b60  2d 2d 2d 2b 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |---+------------|
00001b70  2d 2d 2d 2d 2d 2d 0d 20  20 20 20 20 20 20 20 20  |------.         |
00001b80  20 20 7c 20 62 79 74 65  20 34 20 7c 20 62 79 74  |  | byte 4 | byt|
00001b90  65 20 33 20 7c 20 62 79  74 65 20 32 20 7c 0d 20  |e 3 | byte 2 |. |
00001ba0  20 20 20 20 20 20 20 20  20 20 2d 2d 2d 2d 2d 2d  |          ------|
00001bb0  2d 2d 2d 2b 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |---+------------|
00001bc0  2d 2d 2d 2d 2d 2d 0d 0d  49 6e 20 6f 72 64 65 72  |------..In order|
00001bd0  20 74 6f 20 63 6f 70 65  20 77 69 74 68 20 32 27  | to cope with 2'|
00001be0  73 20 63 6f 6d 70 6c 65  6d 65 6e 74 20 6e 65 67  |s complement neg|
00001bf0  61 74 69 76 65 73 20 79  6f 75 20 68 61 76 65 20  |atives you have |
00001c00  74 6f 0d 61 6c 73 6f 20  70 61 64 20 6f 75 74 20  |to.also pad out |
00001c10  74 68 65 20 68 69 67 68  65 72 20 62 79 74 65 73  |the higher bytes|
00001c20  20 69 6e 20 74 68 65 20  6e 75 6d 62 65 72 73 20  | in the numbers |
00001c30  74 6f 20 62 65 0d 6d 75  6c 74 69 70 6c 69 65 64  |to be.multiplied|
00001c40  20 61 6e 64 20 69 6e 20  74 68 65 20 72 65 73 75  | and in the resu|
00001c50  6c 74 20 77 69 74 68 20  26 46 46 20 69 66 20 6e  |lt with &FF if n|
00001c60  65 63 65 73 73 61 72 79  2e 20 20 54 68 61 74 20  |ecessary.  That |
00001c70  69 73 0d 77 68 79 20 79  6f 75 20 73 65 65 20 63  |is.why you see c|
00001c80  68 65 63 6b 73 20 66 6f  72 20 6e 65 67 61 74 69  |hecks for negati|
00001c90  76 65 20 61 6e 64 20 26  46 46 73 20 62 65 69 6e  |ve and &FFs bein|
00001ca0  67 20 70 75 74 20 69 6e  74 6f 20 35 74 68 0d 62  |g put into 5th.b|
00001cb0  79 74 65 73 20 69 6e 20  74 68 65 20 66 69 78 65  |ytes in the fixe|
00001cc0  64 20 70 6f 69 6e 74 20  6d 75 6c 74 69 70 6c 69  |d point multipli|
00001cd0  63 61 74 69 6f 6e 20 72  6f 75 74 69 6e 65 2e 0d  |cation routine..|
00001ce0  0d 54 68 65 20 72 6f 75  74 69 6e 65 20 6c 69 65  |.The routine lie|
00001cf0  73 20 62 65 74 77 65 65  6e 20 6c 69 6e 65 73 20  |s between lines |
00001d00  33 37 38 30 20 61 6e 64  20 34 35 38 30 20 69 6e  |3780 and 4580 in|
00001d10  20 74 68 65 20 6d 6f 64  75 6c 65 0d 70 72 6f 67  | the module.prog|
00001d20  72 61 6d 2e 0d 0d 41 6e  64 20 73 6f 20 74 6f 20  |ram...And so to |
00001d30  74 68 65 20 63 6f 64 65  20 69 74 73 65 6c 66 2e  |the code itself.|
00001d40  0d 0d 59 6f 75 20 77 69  6c 6c 20 66 69 6e 64 20  |..You will find |
00001d50  74 68 61 74 20 74 68 69  73 20 63 6f 64 65 20 69  |that this code i|
00001d60  73 20 61 6c 6d 6f 73 74  20 61 20 73 74 72 61 69  |s almost a strai|
00001d70  67 68 74 20 6c 69 6e 65  2c 20 77 69 74 68 0d 6f  |ght line, with.o|
00001d80  6e 6c 79 20 74 77 6f 20  73 75 62 72 6f 75 74 69  |nly two subrouti|
00001d90  6e 65 73 2c 20 74 68 65  20 4d 61 6e 64 65 6c 62  |nes, the Mandelb|
00001da0  72 6f 74 20 72 6f 75 74  69 6e 65 20 69 74 73 65  |rot routine itse|
00001db0  6c 66 20 61 6e 64 20 74  68 65 0d 6d 75 6c 74 69  |lf and the.multi|
00001dc0  70 6c 79 69 6e 67 20 72  6f 75 74 69 6e 65 2e 20  |plying routine. |
00001dd0  20 54 68 69 73 20 77 61  73 20 64 6f 6e 65 20 70  | This was done p|
00001de0  61 72 74 6c 79 20 66 6f  72 20 73 70 65 65 64 2c  |artly for speed,|
00001df0  20 62 75 74 0d 61 6c 73  6f 20 70 61 72 74 6c 79  | but.also partly|
00001e00  20 62 65 63 61 75 73 65  20 62 79 20 69 74 73 20  | because by its |
00001e10  6e 61 74 75 72 65 20 74  68 69 73 20 69 73 20 61  |nature this is a|
00001e20  20 6c 69 6e 65 61 72 20  70 72 6f 63 65 73 73 0d  | linear process.|
00001e30  72 61 74 68 65 72 20 74  68 61 6e 20 61 20 6d 75  |rather than a mu|
00001e40  6c 74 69 2d 62 72 61 6e  63 68 65 64 20 6f 6e 65  |lti-branched one|
00001e50  2c 20 61 6e 64 20 73 6f  20 73 75 62 72 6f 75 74  |, and so subrout|
00001e60  69 6e 65 73 20 6d 69 67  68 74 0d 6e 6f 74 20 68  |ines might.not h|
00001e70  61 76 65 20 63 6c 61 72  69 66 69 65 64 20 6d 75  |ave clarified mu|
00001e80  63 68 2e 0d 0d 41 74 20  74 68 65 20 73 74 61 72  |ch...At the star|
00001e90  74 20 6f 66 20 74 68 65  20 61 73 73 65 6d 62 6c  |t of the assembl|
00001ea0  79 20 49 20 74 65 73 74  20 74 6f 20 73 65 65 20  |y I test to see |
00001eb0  69 66 20 79 6f 75 72 20  70 72 6f 67 72 61 6d 0d  |if your program.|
00001ec0  69 73 20 72 75 6e 6e 69  6e 67 20 69 6e 20 61 20  |is running in a |
00001ed0  73 65 63 6f 6e 64 20 70  72 6f 63 65 73 73 6f 72  |second processor|
00001ee0  20 6f 72 20 69 6e 20 74  68 65 20 42 42 43 20 4d  | or in the BBC M|
00001ef0  69 63 72 6f 20 69 74 73  65 6c 66 2c 0d 74 68 65  |icro itself,.the|
00001f00  20 49 2f 4f 20 70 72 6f  63 65 73 73 6f 72 2e 20  | I/O processor. |
00001f10  20 54 68 69 73 20 69 73  20 62 65 63 61 75 73 65  | This is because|
00001f20  20 74 68 65 20 70 72 6f  67 72 61 6d 20 75 73 65  | the program use|
00001f30  73 20 4d 6f 64 65 20 32  0d 67 72 61 70 68 69 63  |s Mode 2.graphic|
00001f40  73 20 61 6e 64 20 77 69  6c 6c 20 6e 6f 74 20 66  |s and will not f|
00001f50  69 74 20 69 6e 20 6d 65  6d 6f 72 79 20 65 61 73  |it in memory eas|
00001f60  69 6c 79 2e 20 20 57 69  74 68 20 61 20 73 65 63  |ily.  With a sec|
00001f70  6f 6e 64 0d 70 72 6f 63  65 73 73 6f 72 20 74 68  |ond.processor th|
00001f80  61 74 20 69 73 20 6e 6f  20 70 72 6f 62 6c 65 6d  |at is no problem|
00001f90  20 62 75 74 20 69 6e 20  74 68 65 20 6d 69 63 72  | but in the micr|
00001fa0  6f 20 69 74 73 65 6c 66  20 79 6f 75 0d 6d 75 73  |o itself you.mus|
00001fb0  74 20 62 65 20 69 6e 20  4d 6f 64 65 20 37 20 74  |t be in Mode 7 t|
00001fc0  6f 20 61 73 73 65 6d 62  6c 65 20 61 6e 64 20 6d  |o assemble and m|
00001fd0  75 73 74 20 63 6c 65 61  72 20 74 68 65 20 42 41  |ust clear the BA|
00001fe0  53 49 43 0d 76 61 72 69  61 62 6c 65 20 77 6f 72  |SIC.variable wor|
00001ff0  6b 73 70 61 63 65 20 28  77 69 74 68 20 61 20 4e  |kspace (with a N|
00002000  45 57 29 20 62 65 66 6f  72 65 20 79 6f 75 20 63  |EW) before you c|
00002010  61 6e 20 72 75 6e 20 74  68 65 20 66 69 6e 61 6c  |an run the final|
00002020  0d 63 6f 64 65 2e 20 20  54 68 65 20 66 69 72 73  |.code.  The firs|
00002030  74 20 66 65 77 20 6c 69  6e 65 73 20 6f 66 20 74  |t few lines of t|
00002040  68 65 20 70 72 6f 67 72  61 6d 20 74 61 6b 65 20  |he program take |
00002050  63 61 72 65 20 6f 66 20  74 68 61 74 0d 61 6e 64  |care of that.and|
00002060  20 77 69 6c 6c 20 74 65  6c 6c 20 79 6f 75 20 77  | will tell you w|
00002070  68 61 74 20 69 73 20 67  6f 69 6e 67 20 6f 6e 2e  |hat is going on.|
00002080  20 20 54 68 65 20 63 6f  64 65 20 69 73 20 65 78  |  The code is ex|
00002090  65 63 75 74 65 64 20 62  79 0d 70 72 65 73 73 69  |ecuted by.pressi|
000020a0  6e 67 20 66 75 6e 63 74  69 6f 6e 20 6b 65 79 20  |ng function key |
000020b0  30 3a 20 66 75 6e 63 74  69 6f 6e 20 6b 65 79 20  |0: function key |
000020c0  31 20 69 73 20 61 76 61  69 6c 61 62 6c 65 20 74  |1 is available t|
000020d0  6f 20 6c 69 73 74 0d 74  68 65 20 70 72 6f 67 72  |o list.the progr|
000020e0  61 6d 20 69 6e 20 4d 6f  64 65 20 33 2e 20 20 49  |am in Mode 3.  I|
000020f0  6e 20 74 68 65 20 6d 69  63 72 6f 20 74 68 65 20  |n the micro the |
00002100  63 6f 64 65 20 69 73 20  61 73 73 65 6d 62 6c 65  |code is assemble|
00002110  64 0d 61 74 20 26 31 33  30 30 2c 20 69 6e 20 61  |d.at &1300, in a|
00002120  20 27 73 61 66 65 27 20  70 61 72 74 20 6f 66 20  | 'safe' part of |
00002130  74 68 65 20 64 69 73 63  20 77 6f 72 6b 73 70 61  |the disc workspa|
00002140  63 65 2e 20 20 49 6e 20  61 0d 73 65 63 6f 6e 64  |ce.  In a.second|
00002150  20 70 72 6f 63 65 73 73  6f 72 20 69 74 20 63 61  | processor it ca|
00002160  6e 20 6a 75 73 74 20 62  65 20 70 75 74 20 61 6c  |n just be put al|
00002170  6f 6e 67 73 69 64 65 20  74 68 65 0d 42 41 53 49  |ongside the.BASI|
00002180  43 2f 41 73 73 65 6d 62  6c 65 72 20 75 73 69 6e  |C/Assembler usin|
00002190  67 20 44 49 4d 2e 20 20  49 66 20 79 6f 75 20 68  |g DIM.  If you h|
000021a0  61 76 65 20 61 20 42 42  43 20 4d 61 73 74 65 72  |ave a BBC Master|
000021b0  20 77 69 74 68 6f 75 74  0d 61 20 73 65 63 6f 6e  | without.a secon|
000021c0  64 20 70 72 6f 63 65 73  73 6f 72 20 79 6f 75 20  |d processor you |
000021d0  77 69 6c 6c 20 68 61 76  65 20 74 6f 20 63 68 61  |will have to cha|
000021e0  6e 67 65 20 74 68 69 73  20 70 61 72 74 20 6f 66  |nge this part of|
000021f0  20 74 68 65 0d 63 6f 64  65 20 74 6f 20 66 6f 72  | the.code to for|
00002200  63 65 20 74 68 65 20 75  73 65 20 6f 66 20 44 49  |ce the use of DI|
00002210  4d 20 62 65 63 61 75 73  65 20 74 68 65 20 76 61  |M because the va|
00002220  6c 75 65 20 6f 66 20 50  41 47 45 20 69 73 0d 26  |lue of PAGE is.&|
00002230  45 30 30 2e 20 20 5b 59  6f 75 20 63 61 6e 20 61  |E00.  [You can a|
00002240  6c 73 6f 20 75 73 65 20  73 68 61 64 6f 77 20 6d  |lso use shadow m|
00002250  65 6d 6f 72 79 20 62 79  20 75 73 69 6e 67 20 4d  |emory by using M|
00002260  6f 64 65 20 31 33 30 0d  69 6e 73 74 65 61 64 20  |ode 130.instead |
00002270  6f 66 20 4d 6f 64 65 20  32 2e 5d 0d 0d 57 65 20  |of Mode 2.]..We |
00002280  73 65 74 20 74 68 65 20  6d 6f 64 65 20 61 73 20  |set the mode as |
00002290  32 20 61 6e 64 20 74 68  69 73 20 67 69 76 65 73  |2 and this gives|
000022a0  20 75 73 20 69 6e 63 72  65 6d 65 6e 74 73 20 6f  | us increments o|
000022b0  66 20 38 0d 67 72 61 70  68 69 63 73 20 75 6e 69  |f 8.graphics uni|
000022c0  74 73 20 70 65 72 20 70  69 78 65 6c 20 6f 6e 20  |ts per pixel on |
000022d0  74 68 65 20 78 20 61 78  69 73 20 61 6e 64 20 34  |the x axis and 4|
000022e0  20 6f 6e 20 74 68 65 20  79 2e 20 20 49 66 0d 79  | on the y.  If.y|
000022f0  6f 75 20 77 61 6e 74 20  74 6f 20 63 68 61 6e 67  |ou want to chang|
00002300  65 20 74 6f 20 4d 6f 64  65 20 30 20 6f 72 20 4d  |e to Mode 0 or M|
00002310  6f 64 65 20 31 20 79 6f  75 20 68 61 76 65 20 74  |ode 1 you have t|
00002320  6f 20 6d 6f 64 69 66 79  0d 74 68 65 73 65 20 76  |o modify.these v|
00002330  61 72 69 61 62 6c 65 73  20 61 63 63 6f 72 64 69  |ariables accordi|
00002340  6e 67 6c 79 2e 20 20 54  68 65 20 68 6f 72 69 7a  |ngly.  The horiz|
00002350  6f 6e 74 61 6c 20 69 6e  63 72 65 6d 65 6e 74 73  |ontal increments|
00002360  20 77 69 6c 6c 0d 62 65  20 32 20 61 6e 64 20 34  | will.be 2 and 4|
00002370  20 66 6f 72 20 4d 6f 64  65 73 20 30 20 61 6e 64  | for Modes 0 and|
00002380  20 31 20 72 65 73 70 65  63 74 69 76 65 6c 79 2e  | 1 respectively.|
00002390  0d 0d 46 6f 72 20 73 70  65 65 64 20 49 20 61 6d  |..For speed I am|
000023a0  20 75 73 69 6e 67 20 7a  65 72 6f 20 70 61 67 65  | using zero page|
000023b0  20 77 6f 72 6b 73 70 61  63 65 20 66 6f 72 20 74  | workspace for t|
000023c0  68 65 0d 6d 75 6c 74 69  70 6c 79 69 6e 67 20 72  |he.multiplying r|
000023d0  6f 75 74 69 6e 65 73 2c  20 61 6e 64 20 74 68 61  |outines, and tha|
000023e0  74 20 69 73 20 73 65 74  20 6e 65 78 74 2e 0d 0d  |t is set next...|
000023f0  49 6e 20 74 68 65 20 61  73 73 65 6d 62 6c 65 72  |In the assembler|
00002400  20 69 74 73 65 6c 66 20  4d 6f 64 65 20 32 20 69  | itself Mode 2 i|
00002410  73 20 73 65 74 20 75 70  20 66 6f 6c 6c 6f 77 65  |s set up followe|
00002420  64 20 62 79 20 61 20 56  44 55 35 0d 65 71 75 69  |d by a VDU5.equi|
00002430  76 61 6c 65 6e 74 20 28  62 6f 74 68 20 64 6f 6e  |valent (both don|
00002440  65 20 75 73 69 6e 67 20  4f 53 57 52 43 48 29 20  |e using OSWRCH) |
00002450  73 6f 20 74 68 61 74 20  74 68 65 20 74 65 78 74  |so that the text|
00002460  20 63 75 72 73 6f 72 0d  69 73 20 72 65 6d 6f 76  | cursor.is remov|
00002470  65 64 2e 20 20 49 20 6b  6e 6f 77 20 74 68 61 74  |ed.  I know that|
00002480  20 74 68 65 72 65 20 69  73 20 61 20 56 44 55 32  | there is a VDU2|
00002490  33 20 69 6e 73 74 72 75  63 74 69 6f 6e 20 74 6f  |3 instruction to|
000024a0  0d 73 77 69 74 63 68 20  6f 66 66 20 74 68 65 20  |.switch off the |
000024b0  63 75 72 73 6f 72 2c 20  62 75 74 20 56 44 55 35  |cursor, but VDU5|
000024c0  20 69 73 20 71 75 69 63  6b 65 72 20 61 6e 64 20  | is quicker and |
000024d0  65 61 73 69 65 72 2e 0d  0d 54 68 65 20 6e 65 78  |easier...The nex|
000024e0  74 20 73 65 63 74 69 6f  6e 20 69 73 20 61 20 70  |t section is a p|
000024f0  6c 6f 74 74 69 6e 67 20  6c 6f 6f 70 20 74 68 61  |lotting loop tha|
00002500  74 20 75 73 65 73 20 74  77 6f 20 77 6f 72 64 73  |t uses two words|
00002510  20 6f 66 0d 6d 65 6d 6f  72 79 20 6c 61 62 65 6c  | of.memory label|
00002520  6c 65 64 20 27 78 5f 63  6f 6f 72 64 27 20 61 6e  |led 'x_coord' an|
00002530  64 20 27 79 5f 63 6f 6f  72 64 27 20 74 6f 20 73  |d 'y_coord' to s|
00002540  65 74 20 74 68 65 20 70  6f 73 69 74 69 6f 6e 0d  |et the position.|
00002550  6f 66 20 74 68 65 20 70  69 78 65 6c 20 62 65 69  |of the pixel bei|
00002560  6e 67 20 70 6c 6f 74 74  65 64 20 63 75 72 72 65  |ng plotted curre|
00002570  6e 74 6c 79 2e 20 20 54  68 65 20 4d 61 6e 64 65  |ntly.  The Mande|
00002580  6c 62 72 6f 74 0d 73 75  62 72 6f 75 74 69 6e 65  |lbrot.subroutine|
00002590  20 75 73 65 73 20 61 20  47 43 4f 4c 20 65 71 75  | uses a GCOL equ|
000025a0  69 76 61 6c 65 6e 74 20  74 6f 20 73 65 74 20 74  |ivalent to set t|
000025b0  68 65 20 63 6f 6c 6f 75  72 20 62 65 66 6f 72 65  |he colour before|
000025c0  0d 74 68 65 20 70 69 78  65 6c 20 69 73 20 70 6c  |.the pixel is pl|
000025d0  6f 74 74 65 64 20 75 73  69 6e 67 20 61 20 50 4c  |otted using a PL|
000025e0  4f 54 20 36 39 20 65 71  75 69 76 61 6c 65 6e 74  |OT 69 equivalent|
000025f0  20 28 70 6c 6f 74 20 61  0d 70 6f 69 6e 74 29 2e  | (plot a.point).|
00002600  20 20 46 6f 72 20 63 6f  6e 76 65 6e 69 65 6e 63  |  For convenienc|
00002610  65 20 49 20 61 6d 20 75  73 69 6e 67 20 61 20 31  |e I am using a 1|
00002620  30 32 34 20 75 6e 69 74  73 20 73 71 75 61 72 65  |024 units square|
00002630  20 61 72 65 61 0d 6f 66  20 74 68 65 20 73 63 72  | area.of the scr|
00002640  65 65 6e 2e 0d 0d 53 69  6e 63 65 20 74 68 65 20  |een...Since the |
00002650  6e 75 6d 65 72 69 63 61  6c 20 61 72 65 61 20 63  |numerical area c|
00002660  6f 76 65 72 65 64 20 69  73 20 33 20 75 6e 69 74  |overed is 3 unit|
00002670  73 20 61 6c 6f 6e 67 20  62 6f 74 68 20 61 78 65  |s along both axe|
00002680  73 0d 74 68 65 20 69 6e  63 72 65 6d 65 6e 74 20  |s.the increment |
00002690  70 65 72 20 67 72 61 70  68 69 63 73 20 75 6e 69  |per graphics uni|
000026a0  74 20 69 73 20 33 2f 31  30 32 34 2e 20 20 53 69  |t is 3/1024.  Si|
000026b0  6e 63 65 20 6f 75 72 20  66 69 78 65 64 0d 70 6f  |nce our fixed.po|
000026c0  69 6e 74 20 72 65 70 72  65 73 65 6e 74 61 74 69  |int representati|
000026d0  6f 6e 20 65 66 66 65 63  74 69 76 65 6c 79 20 6d  |on effectively m|
000026e0  75 6c 74 69 70 6c 69 65  73 20 74 68 61 74 20 62  |ultiplies that b|
000026f0  79 20 36 35 35 33 36 0d  28 77 68 69 63 68 20 69  |y 65536.(which i|
00002700  73 20 32 35 36 2a 32 35  36 29 20 74 68 65 20 69  |s 256*256) the i|
00002710  6e 63 72 65 6d 65 6e 74  20 69 6e 20 66 69 78 65  |ncrement in fixe|
00002720  64 20 70 6f 69 6e 74 20  69 73 20 69 6e 20 66 61  |d point is in fa|
00002730  63 74 0d 26 43 30 20 69  6e 20 62 6f 74 68 20 64  |ct.&C0 in both d|
00002740  69 72 65 63 74 69 6f 6e  73 2e 20 20 54 68 69 73  |irections.  This|
00002750  20 66 69 67 75 72 65 20  69 73 20 70 75 74 20 69  | figure is put i|
00002760  6e 74 6f 20 6d 65 6d 6f  72 79 20 61 74 0d 6c 61  |nto memory at.la|
00002770  62 65 6c 73 20 68 5f 69  6e 63 20 61 6e 64 20 76  |bels h_inc and v|
00002780  5f 69 6e 63 20 64 75 72  69 6e 67 20 74 68 65 20  |_inc during the |
00002790  61 73 73 65 6d 62 6c 79  2e 0d 0d 49 20 68 61 76  |assembly...I hav|
000027a0  65 20 69 6e 20 66 61 63  74 20 65 61 73 65 64 20  |e in fact eased |
000027b0  74 68 65 20 64 69 66 66  69 63 75 6c 74 79 20 6f  |the difficulty o|
000027c0  66 20 74 68 69 73 20 70  72 6f 67 72 61 6d 20 67  |f this program g|
000027d0  72 65 61 74 6c 79 0d 62  79 20 61 73 73 75 6d 69  |reatly.by assumi|
000027e0  6e 67 20 69 74 20 77 69  6c 6c 20 6f 6e 6c 79 20  |ng it will only |
000027f0  62 65 20 70 6c 6f 74 74  69 6e 67 20 74 68 65 20  |be plotting the |
00002800  77 68 6f 6c 65 20 73 65  74 2e 20 20 59 6f 75 0d  |whole set.  You.|
00002810  63 6f 75 6c 64 20 6d 6f  64 69 66 79 20 69 74 20  |could modify it |
00002820  74 6f 20 70 6c 6f 74 20  61 20 73 6d 61 6c 6c 65  |to plot a smalle|
00002830  72 20 73 65 63 74 69 6f  6e 20 61 74 20 74 68 65  |r section at the|
00002840  20 72 69 73 6b 20 6f 66  0d 67 72 65 61 74 65 72  | risk of.greater|
00002850  20 69 6e 61 63 75 72 61  63 79 20 77 69 74 68 20  | inacuracy with |
00002860  76 65 72 79 20 73 6d 61  6c 6c 20 6e 75 6d 62 65  |very small numbe|
00002870  72 73 20 62 75 74 20 79  6f 75 20 77 69 6c 6c 20  |rs but you will |
00002880  68 61 76 65 0d 74 6f 20  63 68 61 6e 67 65 20 74  |have.to change t|
00002890  68 65 20 69 6e 63 72 65  6d 65 6e 74 73 20 61 6e  |he increments an|
000028a0  64 20 74 68 65 20 70 6c  6f 74 20 73 74 61 72 74  |d the plot start|
000028b0  69 6e 67 20 70 6f 69 6e  74 73 0d 6d 61 6e 75 61  |ing points.manua|
000028c0  6c 6c 79 2c 20 61 73 20  69 74 20 77 65 72 65 2c  |lly, as it were,|
000028d0  20 74 6f 20 64 6f 20 74  68 69 73 2e 20 20 53 69  | to do this.  Si|
000028e0  6d 70 6c 79 2c 20 74 6f  20 66 69 6e 64 20 74 68  |mply, to find th|
000028f0  65 20 66 6f 75 72 0d 62  79 74 65 20 66 69 78 65  |e four.byte fixe|
00002900  64 20 70 6f 69 6e 74 20  65 71 75 69 76 61 6c 65  |d point equivale|
00002910  6e 74 20 6f 66 20 61 20  6e 75 6d 62 65 72 2c 20  |nt of a number, |
00002920  6a 75 73 74 20 6d 75 6c  74 69 70 6c 79 20 69 74  |just multiply it|
00002930  20 62 79 0d 36 35 35 33  36 2e 0d 0d 54 68 65 20  | by.65536...The |
00002940  63 6f 6d 70 6c 65 78 20  6e 75 6d 62 65 72 73 20  |complex numbers |
00002950  61 72 65 20 62 72 6f 6b  65 6e 20 64 6f 77 6e 20  |are broken down |
00002960  69 6e 74 6f 20 72 65 61  6c 20 61 6e 64 20 69 6d  |into real and im|
00002970  61 67 69 6e 61 72 79 0d  70 61 72 74 73 2e 20 20  |aginary.parts.  |
00002980  54 68 65 69 72 20 6c 61  62 65 6c 73 20 68 65 72  |Their labels her|
00002990  65 20 61 72 65 20 78 20  61 6e 64 20 79 20 66 6f  |e are x and y fo|
000029a0  72 20 74 68 65 20 63 6f  6d 70 6f 6e 65 6e 74 73  |r the components|
000029b0  20 6f 66 0d 7a 20 28 73  69 6e 63 65 20 7a 20 69  | of.z (since z i|
000029c0  73 20 75 73 75 61 6c 6c  79 20 77 72 69 74 74 65  |s usually writte|
000029d0  6e 20 78 2b 69 79 29 20  61 6e 64 20 63 5f 72 65  |n x+iy) and c_re|
000029e0  61 6c 20 61 6e 64 20 63  5f 69 6d 61 67 0d 66 6f  |al and c_imag.fo|
000029f0  72 20 63 2e 20 20 54 68  65 73 65 20 61 72 65 20  |r c.  These are |
00002a00  74 68 65 20 63 61 6c 63  75 6c 61 74 69 6f 6e 73  |the calculations|
00002a10  20 77 65 20 6d 75 73 74  20 6d 61 6b 65 3a 0d 0d  | we must make:..|
00002a20  20 20 20 20 73 69 7a 65  20 3d 20 78 5e 32 20 2b  |    size = x^2 +|
00002a30  20 79 5e 32 20 20 28 72  65 6d 65 6d 62 65 72 20  | y^2  (remember |
00002a40  73 69 7a 65 20 69 73 20  69 74 73 65 6c 66 20 61  |size is itself a|
00002a50  20 73 71 75 61 72 65 29  0d 0d 20 20 20 20 4e 65  | square)..    Ne|
00002a60  77 20 76 61 6c 75 65 20  6f 66 20 78 20 3d 20 78  |w value of x = x|
00002a70  5e 32 20 2d 20 79 5e 32  20 2b 20 63 5f 72 65 61  |^2 - y^2 + c_rea|
00002a80  6c 0d 0d 20 20 20 20 4e  65 77 20 76 61 6c 75 65  |l..    New value|
00002a90  20 6f 66 20 79 20 3d 20  32 20 2a 20 78 20 2a 20  | of y = 2 * x * |
00002aa0  79 20 2b 20 63 5f 69 6d  61 67 0d 0d 46 72 6f 6d  |y + c_imag..From|
00002ab0  20 6c 69 6e 65 20 31 30  35 30 20 74 68 65 20 63  | line 1050 the c|
00002ac0  6f 64 65 20 63 6f 6d 70  75 74 65 73 20 74 68 65  |ode computes the|
00002ad0  20 76 61 6c 75 65 20 6f  66 20 63 5f 72 65 61 6c  | value of c_real|
00002ae0  2c 20 62 61 73 65 64 0d  75 70 6f 6e 20 74 68 65  |, based.upon the|
00002af0  20 63 75 72 72 65 6e 74  20 70 6f 73 69 74 69 6f  | current positio|
00002b00  6e 20 6f 6e 20 74 68 65  20 73 63 72 65 65 6e 2e  |n on the screen.|
00002b10  20 20 42 79 20 75 73 69  6e 67 20 74 68 65 20 58  |  By using the X|
00002b20  0d 72 65 67 69 73 74 65  72 20 63 6f 75 6e 74 69  |.register counti|
00002b30  6e 67 20 64 6f 77 6e 20  66 72 6f 6d 20 34 20 61  |ng down from 4 a|
00002b40  6e 64 20 6f 66 66 73 65  74 20 61 67 61 69 6e 73  |nd offset agains|
00002b50  74 20 27 68 5f 69 6e 63  2d 31 27 0d 77 65 20 63  |t 'h_inc-1'.we c|
00002b60  61 6e 20 75 73 65 20 61  20 42 4e 45 20 74 6f 20  |an use a BNE to |
00002b70  74 65 73 74 20 74 68 65  20 6c 6f 6f 70 20 64 75  |test the loop du|
00002b80  72 69 6e 67 20 74 68 65  20 74 72 61 6e 73 66 65  |ring the transfe|
00002b90  72 20 6f 66 0d 62 79 74  65 73 20 69 6e 74 6f 20  |r of.bytes into |
00002ba0  6d 75 6c 74 69 70 6c 69  63 61 74 69 6f 6e 20 77  |multiplication w|
00002bb0  6f 72 6b 73 70 61 63 65  2e 20 20 59 6f 75 20 77  |orkspace.  You w|
00002bc0  69 6c 6c 20 73 65 65 20  74 68 61 74 20 6d 6f 73  |ill see that mos|
00002bd0  74 0d 6f 66 20 74 68 65  20 74 72 61 6e 73 66 65  |t.of the transfe|
00002be0  72 73 20 61 72 65 20 64  6f 6e 65 20 74 68 69 73  |rs are done this|
00002bf0  20 77 61 79 2e 0d 0d 49  6e 20 6c 69 6e 65 20 31  | way...In line 1|
00002c00  33 31 30 20 2d 32 2e 32  35 20 69 73 20 61 64 64  |310 -2.25 is add|
00002c10  65 64 20 69 6e 20 74 68  65 20 63 61 6c 63 75 6c  |ed in the calcul|
00002c20  61 74 69 6f 6e 20 6f 66  20 63 5f 72 65 61 6c 2e  |ation of c_real.|
00002c30  20 0d 2d 32 2e 32 35 20  69 73 20 74 68 65 20 73  | .-2.25 is the s|
00002c40  74 61 72 74 69 6e 67 20  70 6f 69 6e 74 20 6f 66  |tarting point of|
00002c50  20 74 68 61 74 20 61 78  69 73 2e 20 20 49 6e 20  | that axis.  In |
00002c60  6f 75 72 20 66 69 78 65  64 0d 70 6f 69 6e 74 20  |our fixed.point |
00002c70  72 65 70 72 65 73 65 6e  74 61 74 69 6f 6e 20 74  |representation t|
00002c80  68 65 20 6e 75 6d 62 65  72 20 74 6f 20 62 65 20  |he number to be |
00002c90  61 64 64 65 64 20 69 73  20 2d 32 2e 32 35 20 2a  |added is -2.25 *|
00002ca0  20 36 35 35 33 36 0d 61  6e 64 20 74 68 61 74 20  | 65536.and that |
00002cb0  28 69 6e 20 32 27 73 20  63 6f 6d 70 6c 65 6d 65  |(in 2's compleme|
00002cc0  6e 74 20 6e 65 67 61 74  69 76 65 29 20 69 73 20  |nt negative) is |
00002cd0  26 46 46 46 44 43 30 30  30 2e 0d 0d 46 72 6f 6d  |&FFFDC000...From|
00002ce0  20 6c 69 6e 65 20 31 34  32 30 20 63 5f 69 6d 61  | line 1420 c_ima|
00002cf0  67 20 69 73 20 63 61 6c  63 75 6c 61 74 65 64 20  |g is calculated |
00002d00  61 6e 64 20 79 6f 75 20  77 69 6c 6c 20 6e 6f 74  |and you will not|
00002d10  65 20 74 68 61 74 0d 69  6e 20 6c 69 6e 65 20 31  |e that.in line 1|
00002d20  36 38 30 20 2d 31 2e 35  20 69 73 20 61 64 64 65  |680 -1.5 is adde|
00002d30  64 20 69 6e 2c 20 74 68  69 73 20 69 73 20 26 46  |d in, this is &F|
00002d40  46 46 45 38 30 30 30 20  69 6e 20 6f 75 72 0d 66  |FFE8000 in our.f|
00002d50  69 78 65 64 20 70 6f 69  6e 74 2e 0d 0d 4a 75 73  |ixed point...Jus|
00002d60  74 20 70 72 69 6f 72 20  74 6f 20 74 68 65 20 73  |t prior to the s|
00002d70  74 61 72 74 20 6f 66 20  74 68 65 20 6d 61 69 6e  |tart of the main|
00002d80  20 69 74 65 72 61 74 69  6f 6e 20 6c 6f 6f 70 20  | iteration loop |
00002d90  74 68 65 0d 63 6f 75 6e  74 65 72 20 69 73 20 69  |the.counter is i|
00002da0  6e 69 74 69 61 6c 69 73  65 64 20 28 77 65 20 63  |nitialised (we c|
00002db0  6f 75 6e 74 20 64 6f 77  6e 20 61 73 20 75 73 75  |ount down as usu|
00002dc0  61 6c 20 69 6e 20 6f 72  64 65 72 20 74 6f 0d 75  |al in order to.u|
00002dd0  73 65 20 61 20 42 4e 45  2f 42 45 51 20 74 72 61  |se a BNE/BEQ tra|
00002de0  70 20 61 74 20 74 68 65  20 65 6e 64 20 6f 66 20  |p at the end of |
00002df0  74 68 65 20 6c 6f 6f 70  29 20 61 6e 64 20 78 20  |the loop) and x |
00002e00  61 6e 64 20 79 20 61 72  65 0d 69 6e 69 74 69 61  |and y are.initia|
00002e10  6c 69 73 65 64 20 61 74  20 7a 65 72 6f 2c 20 62  |lised at zero, b|
00002e20  65 63 61 75 73 65 20 7a  20 69 73 20 7a 65 72 6f  |ecause z is zero|
00002e30  20 61 73 20 77 65 20 73  74 61 72 74 0d 69 74 65  | as we start.ite|
00002e40  72 61 74 69 6e 67 2e 0d  0d 78 20 73 71 75 61 72  |rating...x squar|
00002e50  65 64 20 61 6e 64 20 79  20 73 71 75 61 72 65 64  |ed and y squared|
00002e60  20 61 72 65 20 63 61 6c  63 75 6c 61 74 65 64 20  | are calculated |
00002e70  73 69 6d 70 6c 79 20 62  79 20 6d 75 6c 74 69 70  |simply by multip|
00002e80  6c 79 69 6e 67 0d 65 61  63 68 20 77 69 74 68 20  |lying.each with |
00002e90  69 74 73 65 6c 66 2e 20  20 54 68 65 20 73 69 7a  |itself.  The siz|
00002ea0  65 20 69 73 20 74 68 65  6e 20 63 61 6c 63 75 6c  |e is then calcul|
00002eb0  61 74 65 64 20 62 79 20  61 64 64 69 6e 67 20 74  |ated by adding t|
00002ec0  68 65 0d 74 77 6f 20 72  65 73 75 6c 74 73 2e 20  |he.two results. |
00002ed0  20 49 64 65 61 6c 6c 79  20 77 65 20 73 68 6f 75  | Ideally we shou|
00002ee0  6c 64 20 74 65 73 74 20  74 68 65 20 73 69 7a 65  |ld test the size|
00002ef0  20 6e 6f 77 2c 20 62 75  74 20 74 68 65 72 65 0d  | now, but there.|
00002f00  69 73 20 74 6f 6f 20 6d  75 63 68 20 63 6f 64 65  |is too much code|
00002f10  20 62 65 74 77 65 65 6e  20 68 65 72 65 20 61 6e  | between here an|
00002f20  64 20 74 68 65 20 6e 65  61 72 65 73 74 20 70 6f  |d the nearest po|
00002f30  69 6e 74 20 74 6f 20 70  75 74 0d 74 68 65 20 6f  |int to put.the o|
00002f40  74 68 65 72 20 65 6e 64  20 6f 66 20 74 68 65 20  |ther end of the |
00002f50  62 72 61 6e 63 68 2e 20  20 52 65 6d 65 6d 62 65  |branch.  Remembe|
00002f60  72 20 61 20 62 72 61 6e  63 68 20 63 61 6e 20 6f  |r a branch can o|
00002f70  6e 6c 79 20 62 65 0d 2b  31 32 37 20 6f 72 20 2d  |nly be.+127 or -|
00002f80  31 32 38 20 62 79 74 65  73 2e 20 20 57 65 20 77  |128 bytes.  We w|
00002f90  69 6c 6c 20 66 69 6e 64  20 74 68 65 20 74 65 73  |ill find the tes|
00002fa0  74 20 73 68 6f 72 74 6c  79 2e 0d 0d 49 6e 20 74  |t shortly...In t|
00002fb0  68 65 20 63 61 6c 63 75  6c 61 74 69 6f 6e 73 20  |he calculations |
00002fc0  66 6f 72 20 74 68 65 20  6e 65 77 20 78 20 61 6e  |for the new x an|
00002fd0  64 20 79 20 79 6f 75 20  77 69 6c 6c 20 6e 6f 74  |d y you will not|
00002fe0  69 63 65 20 74 68 61 74  0d 77 68 69 6c 65 20 78  |ice that.while x|
00002ff0  20 6e 65 65 64 73 20 78  5e 32 20 61 6e 64 20 79  | needs x^2 and y|
00003000  5e 32 2c 20 79 20 6e 65  65 64 73 20 78 20 61 6e  |^2, y needs x an|
00003010  64 20 79 2c 20 73 6f 20  77 65 20 6d 75 73 74 0d  |d y, so we must.|
00003020  63 61 6c 63 75 6c 61 74  65 20 74 68 65 20 6e 65  |calculate the ne|
00003030  77 20 79 20 62 65 66 6f  72 65 20 77 65 20 63 61  |w y before we ca|
00003040  6c 63 75 6c 61 74 65 20  74 68 65 20 6e 65 77 20  |lculate the new |
00003050  78 2e 20 20 46 72 6f 6d  0d 6c 69 6e 65 20 32 35  |x.  From.line 25|
00003060  34 30 20 74 68 65 20 63  6f 64 65 20 63 61 6c 63  |40 the code calc|
00003070  75 6c 61 74 65 73 20 74  68 65 20 6e 65 77 20 79  |ulates the new y|
00003080  2e 20 20 49 6e 20 74 68  65 20 6d 69 64 64 6c 65  |.  In the middle|
00003090  20 6f 66 0d 74 68 69 73  20 74 68 65 72 65 20 69  | of.this there i|
000030a0  73 20 74 68 65 20 65 61  72 6c 69 65 73 74 20 73  |s the earliest s|
000030b0  70 6f 74 20 66 6f 72 20  74 68 65 20 73 69 7a 65  |pot for the size|
000030c0  20 74 65 73 74 2c 20 77  68 69 63 68 20 69 73 0d  | test, which is.|
000030d0  77 68 79 20 69 74 20 61  70 70 65 61 72 73 20 61  |why it appears a|
000030e0  74 20 6c 69 6e 65 20 32  38 35 30 2e 20 20 54 68  |t line 2850.  Th|
000030f0  65 20 72 65 61 73 6f 6e  20 66 6f 72 20 70 75 74  |e reason for put|
00003100  74 69 6e 67 20 74 68 65  0d 74 65 73 74 20 61 73  |ting the.test as|
00003110  20 65 61 72 6c 79 20 61  73 20 70 6f 73 73 69 62  | early as possib|
00003120  6c 65 20 69 73 20 74 68  61 74 20 69 74 20 77 69  |le is that it wi|
00003130  6c 6c 20 74 72 61 70 20  6f 6e 20 73 69 7a 65 20  |ll trap on size |
00003140  6f 76 65 72 0d 6d 6f 73  74 20 6f 66 20 74 68 65  |over.most of the|
00003150  20 73 63 72 65 65 6e 20  73 6f 20 62 79 20 74 72  | screen so by tr|
00003160  61 70 70 69 6e 67 20 68  65 72 65 2c 20 72 61 74  |apping here, rat|
00003170  68 65 72 20 74 68 61 6e  20 61 74 20 74 68 65 0d  |her than at the.|
00003180  65 6e 64 20 6f 66 20 74  68 65 20 6c 6f 6f 70 2c  |end of the loop,|
00003190  20 77 65 20 73 61 76 65  20 65 78 65 63 75 74 69  | we save executi|
000031a0  6e 67 20 63 6f 64 65 20  75 6e 6e 65 63 65 73 73  |ng code unnecess|
000031b0  61 72 69 6c 79 2c 20 77  68 69 63 68 0d 73 61 76  |arily, which.sav|
000031c0  65 73 20 74 69 6d 65 20  61 6c 62 65 69 74 20 6f  |es time albeit o|
000031d0  6e 6c 79 20 61 20 73 6d  61 6c 6c 20 61 6d 6f 75  |nly a small amou|
000031e0  6e 74 2e 0d 0d 57 65 20  66 69 6e 69 73 68 20 63  |nt...We finish c|
000031f0  61 6c 63 75 6c 61 74 69  6e 67 20 74 68 65 20 6e  |alculating the n|
00003200  65 77 20 79 20 61 6e 64  20 74 68 65 6e 20 63 61  |ew y and then ca|
00003210  6c 63 75 6c 61 74 65 20  74 68 65 20 6e 65 77 0d  |lculate the new.|
00003220  78 20 72 65 61 64 79 20  66 6f 72 20 74 68 65 20  |x ready for the |
00003230  6e 65 78 74 20 69 74 65  72 61 74 69 6f 6e 2e 0d  |next iteration..|
00003240  0d 54 68 65 20 63 6f 75  6e 74 65 72 20 69 73 20  |.The counter is |
00003250  64 65 63 72 65 6d 65 6e  74 65 64 20 66 6f 72 20  |decremented for |
00003260  74 68 65 20 6e 65 78 74  20 69 74 65 72 61 74 69  |the next iterati|
00003270  6f 6e 2c 20 62 75 74 20  69 66 0d 74 68 61 74 20  |on, but if.that |
00003280  77 69 6c 6c 20 74 61 6b  65 20 75 73 20 70 61 73  |will take us pas|
00003290  74 20 6f 75 72 20 69 74  65 72 61 74 69 6f 6e 73  |t our iterations|
000032a0  20 6c 69 6d 69 74 2c 20  69 6e 20 74 68 69 73 20  | limit, in this |
000032b0  63 61 73 65 0d 33 32 2c  20 77 65 20 65 78 69 74  |case.32, we exit|
000032c0  20 69 6e 73 74 65 61 64  2c 20 75 73 69 6e 67 20  | instead, using |
000032d0  61 20 42 45 51 20 69 6e  20 6c 69 6e 65 20 33 34  |a BEQ in line 34|
000032e0  31 30 2e 0d 0d 41 74 20  27 73 69 7a 65 5f 6f 75  |10...At 'size_ou|
000032f0  74 27 20 69 73 20 74 68  65 20 63 6f 64 65 20 74  |t' is the code t|
00003300  68 61 74 20 75 73 65 73  20 47 43 4f 4c 20 28 56  |hat uses GCOL (V|
00003310  44 55 20 31 38 29 20 74  6f 20 73 65 74 20 74 68  |DU 18) to set th|
00003320  65 0d 70 69 78 65 6c 20  63 6f 6c 6f 75 72 2e 20  |e.pixel colour. |
00003330  20 52 61 74 68 65 72 20  74 68 61 6e 20 77 61 73  | Rather than was|
00003340  74 65 20 74 69 6d 65 20  61 6e 64 20 65 66 66 6f  |te time and effo|
00003350  72 74 20 6f 6e 20 61 0d  64 69 76 69 73 69 6f 6e  |rt on a.division|
00003360  20 49 20 68 61 76 65 20  73 69 6d 70 6c 79 20 6d  | I have simply m|
00003370  61 73 6b 65 64 20 6f 66  66 20 61 6c 6c 20 62 75  |asked off all bu|
00003380  74 20 74 68 65 20 6c 61  73 74 20 74 68 72 65 65  |t the last three|
00003390  0d 62 69 74 73 20 6f 66  20 74 68 65 20 73 69 7a  |.bits of the siz|
000033a0  65 2c 20 77 68 69 63 68  20 67 69 76 65 73 20 76  |e, which gives v|
000033b0  61 6c 75 65 73 20 66 72  6f 6d 20 30 20 74 6f 20  |alues from 0 to |
000033c0  37 2e 20 20 49 66 20 74  68 65 0d 69 74 65 72 61  |7.  If the.itera|
000033d0  74 69 6f 6e 73 20 6c 69  6d 69 74 20 69 73 20 65  |tions limit is e|
000033e0  78 63 65 65 64 65 64 20  74 68 65 6e 20 77 65 20  |xceeded then we |
000033f0  72 65 61 63 68 20 27 63  6f 75 6e 74 5f 6f 75 74  |reach 'count_out|
00003400  27 20 61 6e 64 0d 73 65  74 20 74 68 65 20 63 6f  |' and.set the co|
00003410  6c 6f 75 72 20 74 6f 20  62 6c 61 63 6b 20 28 47  |lour to black (G|
00003420  43 4f 4c 20 30 2c 30 29  2e 0d 0d 41 66 74 65 72  |COL 0,0)...After|
00003430  20 73 6f 6d 65 20 76 61  72 69 61 62 6c 65 20 61  | some variable a|
00003440  6e 64 20 77 6f 72 6b 73  70 61 63 65 20 73 65 74  |nd workspace set|
00003450  74 69 6e 67 20 77 65 20  66 69 6e 61 6c 6c 79 20  |ting we finally |
00003460  63 6f 6d 65 20 74 6f 0d  74 68 65 20 66 69 78 65  |come to.the fixe|
00003470  64 20 70 6f 69 6e 74 20  6d 75 6c 74 69 70 6c 69  |d point multipli|
00003480  63 61 74 69 6f 6e 20 63  6f 64 65 2e 20 20 59 6f  |cation code.  Yo|
00003490  75 20 77 69 6c 6c 20 6e  6f 74 69 63 65 20 74 68  |u will notice th|
000034a0  61 74 0d 77 65 20 74 65  73 74 20 66 6f 72 20 61  |at.we test for a|
000034b0  20 6e 65 67 61 74 69 76  65 20 6e 75 6d 62 65 72  | negative number|
000034c0  20 61 6e 64 20 69 66 20  77 65 20 66 69 6e 64 20  | and if we find |
000034d0  6f 6e 65 20 77 65 20 6d  61 6b 65 20 69 74 0d 75  |one we make it.u|
000034e0  70 20 74 6f 20 66 69 76  65 20 62 79 74 65 73 20  |p to five bytes |
000034f0  62 65 66 6f 72 65 20 74  68 65 20 6d 75 6c 74 69  |before the multi|
00003500  70 6c 69 63 61 74 69 6f  6e 2c 20 73 69 6e 63 65  |plication, since|
00003510  20 77 65 20 77 61 6e 74  20 61 0d 67 6f 6f 64 20  | we want a.good |
00003520  66 69 76 65 20 62 79 74  65 20 72 65 73 75 6c 74  |five byte result|
00003530  2e 20 20 54 68 65 20 73  61 6d 65 20 61 70 70 6c  |.  The same appl|
00003540  69 65 73 20 74 6f 20 74  68 65 20 72 65 73 75 6c  |ies to the resul|
00003550  74 2e 20 20 54 68 65 0d  6c 6f 6f 70 20 69 73 20  |t.  The.loop is |
00003560  65 78 65 63 75 74 65 64  20 34 30 20 74 69 6d 65  |executed 40 time|
00003570  73 20 62 65 63 61 75 73  65 20 35 20 62 79 74 65  |s because 5 byte|
00003580  73 20 69 73 20 34 30 20  62 69 74 73 2e 0d 0d 50  |s is 40 bits...P|
00003590  6c 6f 74 74 69 6e 67 20  74 68 65 20 4d 61 6e 64  |lotting the Mand|
000035a0  65 6c 62 72 6f 74 20 73  65 74 20 6f 6e 20 61 20  |elbrot set on a |
000035b0  33 4d 48 7a 20 36 35 30  32 20 73 65 63 6f 6e 64  |3MHz 6502 second|
000035c0  20 70 72 6f 63 65 73 73  6f 72 0d 66 72 6f 6d 20  | processor.from |
000035d0  42 41 53 49 43 20 75 73  69 6e 67 20 66 6c 6f 61  |BASIC using floa|
000035e0  74 69 6e 67 20 70 6f 69  6e 74 20 74 61 6b 65 73  |ting point takes|
000035f0  20 6d 65 20 6f 76 65 72  20 34 35 20 6d 69 6e 75  | me over 45 minu|
00003600  74 65 73 2c 0d 74 68 69  73 20 72 6f 75 74 69 6e  |tes,.this routin|
00003610  65 20 75 73 69 6e 67 20  66 69 78 65 64 20 70 6f  |e using fixed po|
00003620  69 6e 74 20 6d 61 63 68  69 6e 65 20 63 6f 64 65  |int machine code|
00003630  20 61 72 69 74 68 6d 65  74 69 63 20 74 61 6b 65  | arithmetic take|
00003640  73 0d 6f 6e 6c 79 20 32  32 20 6d 69 6e 75 74 65  |s.only 22 minute|
00003650  73 2e 20 20 49 66 20 49  20 63 6f 75 6c 64 20 73  |s.  If I could s|
00003660  70 65 65 64 20 75 70 20  74 68 65 20 6d 75 6c 74  |peed up the mult|
00003670  69 70 6c 69 63 61 74 69  6f 6e 73 20 49 0d 63 6f  |iplications I.co|
00003680  75 6c 64 20 70 72 6f 62  61 62 6c 79 20 67 65 74  |uld probably get|
00003690  20 69 74 20 65 76 65 6e  20 66 61 73 74 65 72 2e  | it even faster.|
000036a0  20 20 46 61 69 72 20 74  61 6b 65 73 20 79 6f 75  |  Fair takes you|
000036b0  72 20 62 72 65 61 74 68  0d 61 77 61 79 20 64 75  |r breath.away du|
000036c0  6e 6e 69 74 3f 0d 0d 54  68 65 20 61 6c 74 65 72  |nnit?..The alter|
000036d0  6e 61 74 69 76 65 20 74  6f 20 66 69 78 65 64 20  |native to fixed |
000036e0  70 6f 69 6e 74 2c 20 61  20 6c 69 74 74 6c 65 20  |point, a little |
000036f0  73 6c 6f 77 65 72 20 62  75 74 20 6d 6f 72 65 0d  |slower but more.|
00003700  70 72 65 63 69 73 65 2c  20 69 73 20 66 6c 6f 61  |precise, is floa|
00003710  74 69 6e 67 20 70 6f 69  6e 74 2e 20 20 54 68 61  |ting point.  Tha|
00003720  74 27 73 20 66 6f 72 20  6e 65 78 74 20 74 69 6d  |t's for next tim|
00003730  65 2e 0d                                          |e..|
00003733
09-04-88/T\OSB21.m0
09-04-88/T\OSB21.m1
09-04-88/T\OSB21.m2
09-04-88/T\OSB21.m4
09-04-88/T\OSB21.m5