The Beeb Bodybuilding Course Exercise 77 THE CHAMELEON part 1 By Mike Cook Well I thought we would have a colourful start to new decade and look at a project that will give the humble Model B or Master some of the extra colours enjoyed by owners of the Archimedes. With the Archimedes you can choose the displayed colours from a palette of 4096 different colours and shades. By using The Chameleon colour palette you can have that choice on any computer. This is a great improvement on the garish primary and secondary colours which are normally displayed. The number of different colours displayed at any one time is still the same however as that depends on the graphics mode being used. The maximum number of colours can be displayed in MODE 2. There, you can display up to eight different colours on the screen at any one time, and those colours can be defined exactly as you want. This even works with MODE 7 graphics. Because you have total control over the colours displayed, graphic displays become more realistic, charts and graphs can be more meaningful and the whole layout of the screen may be made to harmonise instead of clashing. This will considerably reduce operator fatigue as the colours can be chosen to be restful for the eyes. Well how can we do this trick? The first thing we need is an analogue RGB monitor of the type used on the Archimedes which will allow the three guns (Red, Green and Blue) to be turned on progressively instead of the simple ON/OFF control with the normal TTL monitor. Then we need a way of turning the logical TTL RGB signals into analogue quantities. What we do is to forget that the three logic signals of the RGB output mean anything to do with the colour and just look at them as logic signals. This means that at any instant they will be in one of eight possible states. Now we use this signal to address a fast memory which can have as many bits per address as we want. If we have 12 bits per address for example we can have 4 bits devoted to each of the three guns. If we feed these bits to a digital to analogue converter we can get the proportional signal to drive an analogue monitor. This means that the colour displayed depends upon the contents of the memory. The address is known as the logical colour and the contents is known as the display colour. In addition to this we have to program this fast memory in the first place so we need to switch the memory address from the RGB output to a computer output. Figure I shows the basic block diagram of a palette of this type. Unfortunately such a simple arrangement will not work with the BBC computer as we don't have so many outputs. We have to resort to a little bit of trickery to squeeze the control information onto the User Port. This is done with the aid of a latch and decoder as shown in figure II. We can use bits 0 to 3 to supply the address of the memory and hold that in a latch. Then we can use these same four bits to enter data into one of three memories. As all these memories are being addressed by the same lines we can consider each one as containing one third of the number. This is very convenient as they can be thought of as Red, Green and Blue memories. These numbers are clocked into the latch or memories by the strobe signal or pulse that can be generated on control line 2 of the VIA. Bits 6 and 7 of the User Port control where this pulse goes, this is done by using a decoder. The User Port bit allocation is summerised in Table 1. The practical circuit is shown in figure III, the memory is made from three 74LS189 16x4-bit memory chips. The latch is a 74LS175 and the decoder uses half of a 74LS155, unfortunately the other half goes to waste in this circuit. Finally the 74LS158 is the switch to the address lines, the 74LS157 (inverting switch) would do equally as well as it does not matter which way round the address lines are. The digital to analogue converter simply consists of a weighted resistor network. If we use 1% resistors then there is enough accuracy for 4 bits. In order to get the exact values we want, the two least significant bits are weighted using two resistors. The summing junction is fed into the base of a PNP transistor acting as an emitter follower. This gives an analogue signal relative to the 5 volt line, the final NPN transistor turns it the right way round again. All the parts are avalilable as Body Build Pack No. 56 including a double sided, plated through-hole printed circuit board. This does not have a component reference printed on but there is an accompanying sheet showing the component locations. For those of you not using the kit you need to add three 0.1uF capacitors to the power lines to the ICs, these are omitted from the diagram for the sake of clarity. You also need a standard 20 way Body Build ribbon cable with IDC sockets and a monitor connection cable. This is simply made with two 6 pin DIN plugs wired up "one for one". The PCB has mounted sockets to plug it into the RGB socket of the BBC Micro and into the user port. The RGB of an analogue colour monitor then plugs into the board. Power can be taken from the monitor output so that once the Chameleon has been programmed with the required colours, the user port may then be disconnected and used for any other purpose. The BBC Micro normally demands a colour monitor with a digital input. But in order to use the Chameleon, you must have an analogue RGB colour monitor. Many monitors like my Electrohome are suitable for analogue or digital input. In addition some digital monitors can be changed to an analogue input. For example, one model of the MicroVitec colour monitor has several links inside that allow you or your dealer to change it to an analogue input. If you remove the panel at the back of the monitor you should see them, the settings are shown in figure IV. If you do not see these links then ask your dealer about the availability of a modification. As there are high voltages inside a monitor case, even after the plug has been removed for some time, if you are at all unsure about this then get some expert advice. As the memories used are 16x4 bits and for MODE 2 we only require 8x4 bits we can use the other half of the memories to define a so-called alternate palette. We can switch between this and the main palette instantly simply by changing bit 3 in the address latch. Now in order to use the Chameleon we have to access the memory locations of the look-up RAM and, due to the complications of the latches and decoder, this requires some work on behalf of the software. This can be done in either machine code or BASIC and the algorithm is shown in figure V. As the monitor is effectively blank for part of this cycle you are best to start with a *FX19 command. This waits until the raster is flying back so any slight flicker that occurs will always be at the top of the screen and not noticed. Listing 1 shows a simple BASIC program to initialise the main palette to produce the normal BBC colours and the alternate palette to give a grey scale. By changing the numbers in the Data statements you can change the colour mapping. Let's talk you through the program so you can understand it, first the VIA lines must be made into outputs. This is done by storing &FF in I/O location &FE62. CB2 must be made to pulse whenever anything is output to the user port, this is done by storing &AE in I/O location &FE6C. For normal operation DB6 and DB7 should be at logic one. To alter a colour first write the colour number you want to change on the four least significant bits with bits DB6 and DB7 set. This latches the colour value for subsequent operation, the state of DB3 at this stage will determine whether the colour number is in the main or alternate palette. Then write the three colour values on the four least significant bits with DB6 set for the green component or DB7 set for the blue component of the colour, or neither set for the red component of the colour. Note that these values should be inverted, that is write 0 for maximum amount of colour and 15 for none of that colour. Finally return the Chameleon to its normal state by storing &E0 at the user port for the main palette or &C0 for the alternate palette. During this sequence the input of the look up RAM will be being fed from the computer and not the video lines and so the Chameleon will not produce any video output. If for any reason the sequence is not completed the monitor will be blank. On switch-on the memory will have random values in it, this will produce a strange mapping of colours and might not even be readable until you run listing 1. As an alternative to this there is an optional initialisation ROM to program the Chameleon to the default automatically on power up. The alternative palette may be used at any time by using the BASIC command: ?&FE62=&FF:?&FE60=&C0. To revert to the main palette use: ?&FE60=&E0. You can change the background colour, this is colour 0. Note that this affects the appearance of the other colours. This is a trick played by the eye and not by the Chameleon. Occasionally however, a particular type of monitor might "object to this" and produce some distortion, when this happens it is because the monitor is performing black level clamping on the video signal. The effect will be that, instead of the background altering, it will stay black and all the other colours will change. The technical solution is to apply frame and line blanking signals to the video signals between the Chameleon and the monitor. This can be done with most mixing consoles or signal processing units. However if you do not have access to these units then, if you do experience this difficulty, keep the change in background colour (colour 0) small, or use the VDU 19 command to change the background colour and keep colour 0 defined as black. Remember that the Chameleon changes the display colours on the BBC Micro, and so the display colours as defined by the VDU 19 statement act in the same way as the logical colours did. Note also that you can use flashing colours with the Chameleon. As each colour can be precisely defined you are not restricted to flashing a colour and its complement, they can be any two colours that you have defined. There is a lot more to handling colours than shown in listing 1 and so next month we will explore how to get the most out of the Chameleon. Have a happy and colourful New Year. Table 1 Programming the Chameleon The Chameleon plugs into the user port of the BBC computer and uses the following pins: CB1 - Unused CB2 - Latch strobe DB0 - Bit 0 of Colour amount or colour address. DB1 - Bit 1 of Colour amount or colour address. DB2 - Bit 2 of Colour amount or colour address. DB3 - Bit 3 of Colour amount or main/alternate palette access. DB4 - Unused DB5 - Video access/program access to memory. DB7 ---+ DB6 ------+ Program access | | 1 1 Specify colour to program: logical colour number in b0-b2, palette number in b3 1 0 Write Blue colour component to lookup RAM. 0 1 Write Green colour component to lookup RAM. 0 0 Write Red colour component to lookup RAM.