Colour change Elloit [sic] Gingold, Watford, Herfordshire. 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 instantaneously. 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 PRINT- ing 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 instantaneous 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 follows: 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 similar 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 presence 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 effects. The main points to note are that the colour to be re- placed is poked into location 65000 and the new colour is 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 65078. 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 machine code goes in at 32000. The details of use are the same except all relevant locations start with 32 rather than 65, e.g. 65031 becomes 32031. Do not forget to CLEAR 64999 - or 31999 - before loading the code in future appli- cations.