www.riscos.com Technical Support:
The display produced on a standard monitor can be in any of 24 different modes (modes 0-17, 22, 24, 33-36). Other modes are available for use with multiscan, high-resolution and VGA monitors. Each mode gives a different combination of values to the following four attributes:
For example, mode 0 allows 32 rows of text to be displayed, each containing up to 80 characters. It provides high resolution graphics, but allows just two colours to be displayed on the screen. In contrast, mode 1 can display just 40 characters on a row and provides medium resolution graphics; it supports, however, up to four colours. Different modes use different amounts of memory to hold the picture; the amount of memory is determined by the resolution and by the number of colours. Mode 0, for example, requires 20K.
Full details on screen modes are given in the Appendix on screen modes in the RISC OS User Guide.
Note: BASIC screen mode and graphics commands control the computer when BASIC is being run from the command line. When it is being run from a Task Window, these functions are controlled by the RISC OS Window Manager, hence these BASIC commands have no effect.
To change mode, use MODE followed by the mode number you want. For example,
changes the display to mode 12. This is one of the most useful modes since it provides high resolution graphics in 16 colours. It is the desktop's standard mode.
When you type a MODE command from the command line, the desktop is cleared automatically.
In addition to mode numbers 0 to 36, you can use 128 to 164 (i.e. the mode number with 128 added to it). These modes use the so-called 'shadow' memory. If you imagine that there are two separate areas of memory which may be used to hold the screen information, then selecting a normal mode will cause one area to be used, and selecting a shadow mode (in the range 128 to 164) will cause the alternative bank to be used.
You can force all subsequent mode changes to use the shadow bank with the command:
After this, you can imagine 128 to be added to any mode number in the range 0 to 36. To disable the automatic use of the shadow memory, issue the command:
In order to use the shadow bank, the ScreenSize configuration must reserve at least twice as much screen memory as the amount required for the non-shadow mode. For example, if you want to use both mode 0 and mode 128, 40K of screen memory must be available, as mode 0 takes 20K.
In fact, for a given mode, there may be several banks available. You can work out how many by dividing the amount of configured screen memory by the requirement of the current mode.
The normal, non-shadow bank is numbered bank 1, and the shadow bank, used by mode 128, is bank 2. There are two more, banks 3 and 4. Using operating system calls, you can choose which of the four banks is displayed, and which is used by the VDU drivers when displaying text and graphics.
The number of characters displayed on the screen is affected by the number which are allowed per row (i.e. the width of each character) and the number of rows which can be displayed on the screen (i.e. the spacing between the rows). Using 25 rows on the screen provides just the right amount of separation between the rows to make text easier to read.
You can change the size of text characters in the modes which support graphics. However, you can only do this when the display is in what is called VDU 5 mode. This mode is explained in the Simple graphics chapter.
To set the size of characters in VDU 5 mode, type:
where sx is the horizontal size of characters and sy is the vertical size. Characters are normally eight pixels square so to get double height you would use:
Single- and double-height character plotting is much faster than other sizes, but you can choose any numbers for sx and sy between 1 and 32767.
The graphics resolution is specified by the number of pixels (rectangular dots) which can be displayed horizontally and vertically. The greater the number of pixels which the screen can be divided into, the smaller each pixel is. Since all lines have to be at least one pixel thick, smaller pixels enable the lines to appear less chunky. To see the difference the pixel size makes try typing the following in BASIC:
10 MODE 9 20 MOVE 100,100 30 DRAW 100,924 40 MOVE 100,100 50 DRAW 1180,100 60 MOVE 100,100 70 DRAW 1180,924
10 MODE 0 20 MOVE 100,100 30 DRAW 100,924 40 MOVE 100,100 50 DRAW 1180,100 60 MOVE 100,100 70 DRAW 1180,924
The number of colours available on the screen at any given time is either 2, 4, 16 or 256. When you first enter a particular mode, the computer selects the default colours which it uses for that particular mode. These are assigned to colour numbers (see Appendix E: Colour modes).
The computer chooses one colour to display text and graphics and another for the background. These two colours are chosen so that under default conditions the text and graphics are in white and the background is black. For example, in four-colour modes the computer chooses to draw text and graphics in colour 3 (white) on a background which is colour 0 (black).
In the 256-colour modes, there are 64 different colours, and each colour may have four different brightnesses, resulting in a total of 256. The colours themselves are referred to as numbers 0-63. The brightness levels are called 'tints' and are in the range 0-255. However, because there are only four different tints, the numbers normally used are 0, 64, 128 and 192.
The 256-colour modes are described in more detail in 256-colour modes.
You may choose to display your text, graphics, or background in a different colour from the defaults. To do this, use the following commands:
Each command can affect both the foreground and background colours, depending on the value it is given:
If the colour number is greater than the number of colours available in a particular mode then it is reduced to lie within the range available. For example, in a four-colour mode COLOUR 5 and COLOUR 9 are both equivalent to COLOUR 1.
Try the following example:
10 MODE 1 : REM four-colour mode 20 COLOUR 129 : REM red background 30 COLOUR 2 : REM yellow foreground 40 PRINT "Hello There"
In addition to being able to select the colour in which numbers, text and so on are displayed, you can also change the physical colour associated with each colour number.
You can define the amount of red, green, and blue (as one of 16 levels) which go to make up the colour displayed for each of the logical colour numbers. Thus, any of the 16 colour numbers can be made to appear as a shade selected from the full range, or 'palette', of 16*16*16 = 4096 colours.
You can assign any of the shades available to a logical colour using the command:
This assigns r parts red, g parts green and b parts blue to logical colour n. Each of r, g and b must be values between 0 and 255. A value of zero specifies that none of that colour should be used and a value of 255 that the maximum intensity of that colour should be used. Thus setting all of them to zero gives black and setting all to 255 gives white.
To return to the default settings for each of the colours type
Note: you should not use VDU 20 if you are writing a BASIC program under the Wimp (described in the Window managed program section).
The following program allows you to mix and display various colours:
10 REPEAT 20 MODE 1 30: 40 REM Input values from the user 50: 60 INPUT"Amount of red (0 - 15) "red% 70 INPUT"Amount of green (0 - 15) "green% 80 INPUT"Amount of blue (0 - 15) "blue% 90: 100 REM Force the numbers into the range required 110: 120 red% = red% << 4 130 green% = green% << 4 140 blue% = blue% << 4 150: 160 COLOUR 0,red%,green%,blue% 170 GCOL 0 180 RECTANGLE FILL 540,412,200,200 190: 200 Now=TIME 250 REPEAT UNTIL TIME > Now + 500 260: 270 UNTIL FALSE : REM Repeat forever
This program asks you for three values, one for each of the amounts of red, green and blue you require. It then plots a rectangle in that colour. After it has displayed it for five seconds it clears the screen and starts again. To stop the program at any stage press Esc.
Note: the current display hardware only supports 16 levels for each colour component numbered 0, 16, 32 up to 240. Intermediate numbers will give the next lowest level.
Full control is not available over the colour palette setting in 256-colour modes.
As noted above, in these modes, a choice of 64 colours is available directly from the simple COLOUR and GCOL commands.
10 MODE 15 20 FOR Col% = 0 TO 63 30 COLOUR Col% 40 PRINT ":";Col%; 50 NEXT
As in the other modes the colour of the background can be changed by adding 128 to the parameter of the COLOUR command. Try modifying line 30 of the above program and running it again.
To understand the manner in which the colour number dictates the actual shade of colour which you see you need to consider the binary pattern which makes up the colour number. Only the right-most six bits are relevant. For an explanation of % and binary numbers, see the chapter entitled Bases.
In common with the other modes colour zero (%000000) is black.
|Colour||binary pattern||shade of colour|
Of the six bits which are used for the colour, the right-most two control the amount of red, the middle two the amount of green and the left-most two the amount of blue.
For example, COLOUR 35 is composed as follows: 35 = %100011, and so contains two parts of blue, no green and three parts of red, and appears as a purple shade. The remaining two bits of the eight bits of colour information are supplied via a special TINT keyword, already mentioned above.
The effect of TINT on the shade of the colour is to change the small amount of white tint used in conjunction with the base colour. This gives four subtle variations to each colour.
The range of the TINT value is 0 to 255; but there are only four distinct tint levels within this range, and so all the number values within the following ranges have the same effect:
|0-63||No extra brightness|
|64-127||Some extra brightness|
|128-191||More extra brightness|
|192-255||Maximum extra brightness|
COLOUR 35 TINT 128
GCOL 17 TINT 0
Here is a program which shows all possible tints and colours:
10 MODE 15
20 FOR col%=0 TO 63
30 FOR tint%=0 TO 192 STEP 64
40 GCOL col% TINT tint%
50 RECTANGLE FILL tint%*4,col%*16,256,16
60 NEXT tint%
70 NEXT col%
When writing programs which run under the window environment, you should not use the standard commands such as COLOUR and MODE as these will interfere with the running of other active programs. Instead you should use the facilities provided by the Wimp (see the section entitled Window managed programs for more details).