Nigel Dore's machine-code program transforms the otherwise laborious routine of filling in irregular shapes into a quick and simple operation. Paint Routine Filling in irregular shapes on the Spectrum can be a long and laborious process, which can be avoided by using this fill routine. The program, which is entirely in machine code, will fill any enclosed area simply given one point inside of it. The machine code is approximately 500 bytes long but requires about 6K for storage of a second screen. This use of memory is no problem on a 48K Spectrum but leaves the 16K with about 2. The fill routine is entered into memory by using the program in figure 1. [This program is on Fill.tzx under the name of "codereader".] The length of the machine code means that mistakes are easily made and for that reason the pro- gram is extensively check-summed. So much so that the com- puter will tell you in which lines you have made mistakes. Having entered the program, save it before you run it, then run it. If there are no detected mistakes the Basic program will now self-destruct. [The version on the TZX will not.] If mistakes are detected then correct them and rerun the program, repeating if necessary. Once the machine code has been entered it can be Saved with the command: SAVE "fill"CODE 32000,500 and loaded with the command CLEAR 25800: LOAD "fill"CODE [This first version is called "fill 16" on the TZX, for a reason which will become clear later, if it isn't already.] Now we can check the program, first we must reserve space for the second screen, thus type: CLEAR 25800 Now we must draw an enclosed shape, for instance: CIRCLE 100,100,50 Next we give the computer one point inside our shape with the plot command, thus enter: PLOT 100,100 Then we instruct the computer to fill the area in with a USR call: LET a=USR 32000 The circle should now be filled and as an added bonus A now contains the number of points plotted which is proportional to the area of the shape. It should be noted that the program will fill any enclo- sed shape and not just circles. Great care must be taken that a gap is not left in the shape because a gap of just one pixel will allow the fill to spread to the whole screen. The normal ink, bright and flash commands are recognised only if there is no return to command mode between them and the USR call. The program you now have in memory will work on either a 16K or 48K Spectrum. If you have a 48K Spectrum you will want to move it to a higher address. To do this, enter and run the relocator program in figure 2 [on the TZX as, no surpise, "relocator"]. The clear address now becomes 58600 and the USR address 64800. The code can be saved with: SAVE "fill"CODE 64800,500 [And this is on the TZX under the name "fill 48".] The algorithm used by the program is fairly simple to understand. Imagine two pieces of paper, the first repre- sents the screen with the shape to be filled drawn on it. The second represents a corresponding blank screen stored in the computer's memory. The one point given to the com- puter is plotted onto the second sheet of paper. The computer then starts at the top left of the second sheet and scans from left to right and down looking for a point. If it finds one, it then in turn checks each of the four points surrounding that point and plots each of them on both sheets of paper only if the point is not already set on the first sheet. Once one scan is complete it is repeated but in the reverse direction and this continues until no more points can be plotted. Thus the overall effect is that the spread- ing of points is halted by a line on the first sheet. Figure 3 is a set of routines for drawing various geo- metrical shapes which can then be filled. The routine which draws an ellipse is particularly interesting, the ellipse is in fact made up of 30 straight lines. This makes the program much faster than the more usual method of calcu- lating each point individually from sines and cosines. [This article was illustrated with some samples of filled shapes: one ring, one each of the shapes from Figure 3, and one very complicated shape filled twice, once from a point inside the shape and once from a point outside. There are two demonstration programs on fill.tzx, one for the 16K Spectrum and one for the 48K. "Demo 16" draws the ring and the Figure 3 shapes, and fills in each of them. "Demo 48" also has memory enough for the complicated shape, filled and counter-filled. In both of these, lines 9000 and up are the listing from Figure 9.]