** Maggie article / 770 words ** Want to know just how demos are written? Tat of Avena shares some of the tricks of the trade with us... The idea of doing an ST intro was sparked by seeing the stuff Cream had managed to squeeze out of an ST in their "Things that make you go hmmm" demo. A wave of nostalgia for the old warhorse sitting in my cupboard made me start bashing some Falcon and PC conversions out of it, and the ST intro was the result. There are only two effects: the "tunnel" and the "washing machine" effect and here's how they were done. The Tunnel This is a very simple effect - the problem making it run at a decent speed on the ST. All we have is a simple table, calculated in GFA Basic, we calculate an offset into the background pattern then copy the relevant pixels in a stream onto the screen. To get the impression of movement, we move along the background pattern and the tunnel appears to zoom forward. On a Falcon the code would look something like this: ** np font here ** .loop: move.w (a0)+,d0 ;fetch offset from table move.l (a1,d0.l*4),(a2)+ ;copy onto screen (2 words) dbf d1,.loop ;next pixel ** np font off ** Doing this on an ST is a LOT harder. First of all we have to use bitplanes and secondly we cannot use the cache (built-in on the Falcon) to speed up the loop. To get the desired speed, a huge long routine is self-written before the effect starts. This gets all the table offsets, makes four copies of the graphics, each shifted by two pixels and occupies about 100Kb memory. All the necessary offsets can then be "hard-coded" into this huge routine. This saves extra data fetches on the ST - squeezing the last ounce of speed from it. Look at the source code for a fuller explanation which also includes the cycle timings for a standard ST machine. As a result the demo doesn't run at anywhere near full speed on a Falcon, because the instruction and data caches are useless because the routines are so big. A forthcoming article on sprites in ST demos in a future issue of Maggie will cover the idea of hard-coding and self-modifying code more fully. The "Washing Machine" effect This second effect works in a similar manner to the tunnel. Each point on the screen is given two values, a "ring" number, depending on how far away from the centre of the screen it is, and a "ring angle" which increases as we move around this ring. Then for each pixel we calculate the ring and angle, increase the angle and ring with some distortion effects, then look up the graphics. These graphics are also split into concentric rings, so finding the relevant graphic is a simple lookup case. Again the effect pre-writes a huge routine to do this and maximise its speed on an ST machine. There are also a couple of cunning tricks involving registers hardened coders may like to look at... To get more effective wrapping and memory management, each ring is made up of 256 bytes. Looping round the ring is merely as case of add.b rather than adding an extra instruction to limit the data. The routine draws the screen using the MOVEP instruction which is extremely handy for bitplane routines! The way this works is to place individual bytes at (a0), 2(a0) 4(a0) and 6(a0) i.e. on different bitplanes. Also when combining the four pixel chunks together to create an eight pixel block the entire graphic can be held in one longword data register - very neat. The Design This took much longer than the coding to get right. The wobbly patterns are made by overlaying two patterns distorting at different speeds, the font is "borrowed" from a well-known PC computer firm and the fade routine is a total killer to write without losing your marbles. That's generally it. Play around with the source code, amazingly it's fairly easy to read, although there are a couple of data declarations which overlap - otherwise the intro won't work on a standard 520ST machine. Feel free to use any of the code for any purpose but if you do use it please credit me. ** boxout ** Source sources The source code and associated files are in Maggie Issue 21 which is available from most PD/Shareware libraries and on-line services. For more details contact: ** bc font on ** Steve Tattersall, 6 Derwent Drive, Littleborough, Lancs, OL15 0BT, England Email: s.j.tattersall@cms.salford.ac.uk FTP: ftp://ftp.uni-kl.de/pub/atari/magazines/maggie/ ** bc font off ** ** end boxout **