YOUR COMPUTER JAN. 84 - Page 196 COLOUR CHANGE Elliot Gingold, Watford, Herefordshire One feature of computers such as the BBC that is often admired by Spectrum owners is the ability to change colours of objects already on the screen. Thus using the BBC command VDU19 one is able to, say, change all the blue objects to red instanteously. Such a command also allows one to draw a complicated diagram in an "invisible" colour and then, by redefinition of the colours, make it suddenly appear in its full completion. The Spectrum, of course, has no such feature. It is possible to do a colour change from Basic by Over 1 Printing an empty string 704 spaces long but this is rather slow and produces a display with a single colour Ink or Paper. But the organisation of the Spectrum attribute file makes almost instanieous Ink or Paper changes of specific types easy to achieve with simple machine-code routines. The attribute file consists of 768 bytes corresponding to the positions on the screen. Each byte controls the colour of the 8 by 8 pixel square as shown: BIT 7 6 5 4 3 2 1 0 ----- ----- PAPER INK Thus Bits 0 to 2 hold a number from 0 to 7 corresponding to the set Ink colour with a similiar situation for bits 3 to 5 and Paper colour. To change all blue Ink to red all that is needed is to move through the 768 bytes, check bits 0-2 for the prescence of the code 1, and if this is found change it to 2. A similar look at bits 3-5 will effect selective Paper changes. The program actually consists of three short routines that act in this way. In addition to Ink and Paper changing I have included a routine that will swap any two nominated Ink colours. This final routine is useful in producing a variety of flashing affects. Note that in the listing any pound signs should be replaced with #. Once you have typed the program in as far as line 110, I would suggest running it to see if the checksum works ̶ this is the variable 'cs'. If there is no error reported, you have probably made no mistakes in the Data lines. You could then Save the machine code for later use. Use SAVE "colour" CODE 65000,122 You had better Save the Basic listing as well just in case. The rest of the program just demonstrates the use of these new functions, I hope that readers will come up with better applications. The main points to note are that the colour to be replaced is Poked into location 65000 and the new colour Poked into 65001. If you wish to change Ink colour call USR 65002, or if it is the paper you want to alter call USR 65031. The Ink Swap routine is obtained from USR 6507S. To achieve a flashing effect, it is called from within a loop, the length of any Pause command determining the flash rate. Try having one of the two colours the same as the Paper: this produces a rather more sedate effect than that in the demonstration program. The program was written on a 48K Spectrum but, with a few changes, the routines can be relocated anywhere. I have included a loader program for a 16K machine, in this case the mahine code goes in at 32000. The details of use are the same except all relevant locations start with 32 rather than 65 i.e., 65031 becomes 32031. Do not forget to Clear 64090 ̶ or 31090- before loading the code in future applications. cc 2020, Ignacio Prini Garcia (Spain) Program typed and saved to .tap with Spectaculator 8.0 Only modified line 90 in 16K version (Clear 32999 to 31999, because it causes M Ramtop no good error)