The aim of the design of the screen system of the Master 512 is to make it resemble, as closely as possible, the screen of a PC-compatible with Colour Graphics Adapter (CGA).
This aim is only achievable up to a point. A true CGA screen can display 25 lines by 80 columns of characters in 16 colours (8 normal colours and 8 "intense" colours). The screen hardware in the BBC Micro host is very different from that of a true PC. There are 8 standard screen modes in the BBC Micro. None of these exactly matches any of the screen modes of a CGA-based PC system. It is possible to "adjust" the BBC Micro's screen modes by writing values to the control registers of the 6845 CRTC chip, and this way screen modes can be created which are the same size as CGA modes (ie they have the same number of rows and columns of characters and/or pixels). However, it is not possible to obtain the full range of colours.
<Note: Most of this article can be understood with little technical knowledge about the PC. There are a few references to such ideas as "Interrupt 10h", but these can safely be skipped over. A grasp of the processor's segment:offset addressing system will help with the Memory Map section>
A CGA system provides 7 screen modes, numbered 0 to 6. Each mode can display 25 lines of characters, or 200 rows of pixels in those modes which support graphics. (Characters on a CGA screen are defined on an 8-by-8 pixel matrix, just as on the BBC.)
Modes 0 to 3 of CGA are text-only modes. Modes 0 and 1 display 40 characters per row, and Modes 2 and 3 display 80. For each of these, every character on the screen has an associated "attribute byte" which defines the foreground and background colour in that character cell. This means that in Modes 1 and 3 a full range of 16 foreground and 8 background colours can be used. (The final bit of the attribute byte normally specifies whether a character should flash.) Modes 0 and 2 are like Modes 1 and 3 respectively, except that the colours are converted into shades of grey suitable for monochrome monitors. (This last only happens on the "composite video" output to which mono monitors may be connected. It does not make true colour monitors display in grey.)
The hardware of the BBC Computer cannot manage this colour range. The best it can do is two colours in 80-column modes and 4 colours in 40-column ones. Thus on the Master 512, CGA Modes 0 to 3 are converted into 4-colour or 2-colour BBC Micro screens. The details of how this is done are described below.
An attempt has been made to represent "intense" characters. This is done by thickening up the appearance of the characters. (The font is "ORed" with a copy of itself shifted one pixel to the right, to give a "bold" effect.) The result is characters which stand out to some extent, though legibility is not improved.
A couple of further features of these CGA modes have not been implemented on the Master 512. The text modes of CGA allow more than one "display page". Several screenfuls of data can be built up at once, and then they can be instantaneously swapped to the visible screen. The Master 512 only has one display page. In practice there are not many PC programs which use this feature.
The other thing that is not implemented is any method of changing the shape of the cursor. On the 512 you have to put up with the standard below-the-line cursor all the time. This very rarely affects actual program use.
On the Master 512, as indeed on many PCs, no attempt is made to convert the colours into grey scales for CGA Modes 0 and 2. These modes are treated exactly like Modes 1 and 3 respectively. So to all intents and purposes there are only two CGA text modes, and in all that follows we refer to these as Modes 0/1 and 2/3.
It may be worth noting that the start-up mode is Mode 3. Many programs running under DOS never change this and some, indeed, assume the screen is set up this way and will give a corrupted display if another mode has been selected.
Modes 4 to 6 of CGA are graphics modes. They are pixel-mapped modes, very similar to certain of the native BBC Computer modes, and the Master 512 can represent them much more closely than it can the text modes.
Modes 4 and 5 are 320 by 200 pixel modes (40 by 25 characters). Mode 4 can display four colours, and Mode 5 is just like it with the colours converted to shades of grey for mono monitors. No further distinction is made between these so, just as with the text modes, we will refer to this as Mode 4/5.
Mode 6 is a 640 by 200 pixel mode (80 by 25 characters), able to display just two colours.
CGA Mode 4/5 is thus very like BBC Mode 1, and CGA Mode 6 like BBC Mode 0, except that the BBC modes have more lines. By starting with a BBC mode (in fact it starts with Mode 3), and making minor adjustments to the hardware registers in the host, the Master 512 can simulate these CGA modes more-or-less exactly.
BBC Mode 3 is not very different from certain DOS screens, and you can use it from within DOS-Plus on the Master 512. Confusingly, when DOS-Plus is running this is known as Mode 7.
Note that, although this looks very like Mode 2/3 (apart from the separation between the lines), internally it is handled very differently. This is described in more detail in what follows.
Any of the CGA-emulation modes, and this last mentioned "Mode 7", can be selected manually with the PCSCREEN.EXE utility supplied on the DOS-Plus boot disk. They can also be selected by programs running under DOS by using Function 0 of Interrupt 10h.
There is also a certain amount of software support within DOS-Plus for another way of using the screen. The GEM system is supplied with the Master 512, and DOS-Plus was designed with this in mind. When GEM is running on a genuine PC with CGA, then the screen can only display 200 rows of pixels. The BBC screen can manage more than this, and if a greater than normal vertical range can be used then GEM will be improved. The 512's version of GEM does this, and when GEM is active on a Master 512 then the screen has 256 rows of pixels. GEM can be run in two ways on the 512, in a 2-colour form and in a 4-colour form. The 2-colour version of GEM uses BBC Screen Mode 0; the 4-colour version uses BBC Mode 1.
It is not possible to select either of these screens with any of the supplied utilities (other than GEM itself), and nor will any PC software use them. See below if you would like to use them in your own programs, though it is recommended that you read through the rest of the document before trying it out.
The following table sums up these screen modes:
|On a PC with CGA
|On the BBC Master 512
40 x 25 chars, 16 colours
8 display pages
40 x 25 chars, 4 colours (plus bold)
1 display page
80 x 25 chars, 16 colours
4 display pages
80 x 25 chars, 2 colours (plus bold)
1 display page
320 x 200 pixels, 4 colours
320 x 200 pixels, 4 colours
640 x 200 pixels, 2 colours
640 x 200 pixels, 2 colours
| BBC Mode 3 – Character mode:
80 x 25 chars, 2 colours (plus bold)
with spaces between lines
640 x 200 pixels, 2 colours
640 x 256 pixels, 2 colours
320 x 256 pixels, 4 colours
In addition to all of the above, it is possible to use the standard BBC screen system from the Master 512. Obviously this is the way the 80186 Monitor operates, but it is also possible to use them from within DOS-Plus. This is done, for instance, by Master 512 BBC Basic. A description of how to do it, if you want to, is included below.
In DOS text modes (Modes 0/1 and 2/3) each character is stored in the screen memory as two bytes. One of these is the ASCII value of the character, and the other is its "attribute byte". The attribute byte defines the foreground and background colour for the character. You can control the attributes of characters written to the screen in one of three ways:
|you can alter the "current attribute value" by writing
a control sequence to the screen driver,
|you can use Function 9 of Interrupt 10h to write attributes along with
|you can write the attribute bytes directly into the screen memory.
All programs or languages which allow you to change attributes must use one or other of these methods. Few are likely to use the first method, because on a true PC it relies on the presence of the file ANSI.SYS which must have been loaded on system boot (and few PCs are configured to do so). However this method could be quite useful on the Master 512 if you wanted to change attributes yourself without bothering to write a program.
On a true PC with CGA the meanings of the bits in the attribute byte are as follows:
|Intensity. The character is displayed as "intense" if this bit is set, "normal" if it is clear.
|Normally if this is set the character will flash on and off. The system can be set up so that this bit specifies whether intense colour is used for the background instead of having flashing characters.
The more limited facilities of the Master 512 mean that the attribute byte has to be interpreted in a more restricted way. This is done differently for Mode 2/3 (which can only manage two colours on the 512) from the way it is done for Mode 0/1 (which can cope with up to four). On the 512 the meanings of the bits in the attribute byte are as follows:
|"Intensity". If this is set characters are drawn using the thickened font.
|If all of these are clear (equivalent to background colour 0 on a PC), then characters appear normally. If any of them is set (background colour non-zero) then characters appear as "inverse video" (normally black on white instead of white on black).
|Ignored. (Only 4 colours are possible.)
|"Intensity". As for the 2-colour mode.
You will notice from this that it is changing the background colour that can have a visible effect in Mode 2/3 on the Master 512, whereas it is changing the foreground colour which may have an effect in Mode 0/1.
In graphics modes (Modes 4/5 and 6) things are done differently. In these modes each screen pixel is represented in the screen memory by one or two bits. Mode 4/5 uses two bits per pixel, so 4 colours are possible, known (naturally) as colours 0 to 3. Mode 6 uses only one bit per pixel, so it can only display two colours at once.
The colours can be set by programs (using Function Ch of Interrupt 10h, for single pixels; or one of Functions 9h or Eh of this interrupt, for characters – again there is the option of writing directly to the screen memory).
In these modes the 512 operates just like a standard PC when Function Ch of Interrupt 10h is used, and when items are written to the screen directly. However, the character functions work in a slightly unorthodox fashion. With this the colour value (specified in the BL register) is interpreted exactly as an attribute byte, acting on the setting of bit 3 (to give "intensity") for example. What this means in practice is that, on the 512, text written to the screen in Mode 4/5 will appear exactly the same as it would in Mode 0/1, and text in Mode 6 will appear as it would in Mode 2/3.
When text is written in Mode 7 then the current attribute is interpreted so that the text appears just as it would in the other 2-colour modes.
The displayed colours for a PC in CGA Mode 4/5 can be altered, but in a very limited way. Colour 0, normally used for the background, can be freely chosen, but possiblities for the other three (foreground) colours are much more restricted.
A CGA-based PC has 16 possible colours, any of which can be used for the background colour (colour 0). In theory the BBC Micro also has 16 possible colours, but these include 8 flashing ones which are not really very useful! In practice then, the BBC Micro (and so the 512) only has 8 possible colours. The way that the 16 IBM colours are converted into the 8 BBC colours for the background in this mode is as follows:
However for the other three colours, colours 1 to 3, the possibilites are far more limited. Only two choices are available. The colours used in the two sets are:
|Yellow. On the PC this is brown, but yellow is the closest the BBC Micro can do.
Note that the default palette on the Master 512 is like this:
and for some true PC systems this default exists. However any change to the palette, including a change to the background, will set the foreground colours to one of the two sets Palette 0 or Palette 1 described above. The initial colour values cannot easily be reset.
Palette changes are not used in other CGA screen modes on the PC. Text modes can display the full range of colours using character attributes (as described above). In the 2-colour graphics mode (Mode 6) you are stuck with black and white.
On the Master 512 colours in all screen modes can be set up to your own preference. You can do this either with the COLOUR.EXE utility, supplied on the boot disk, or else by using one of the screen control sequences.
The use of COLOUR.EXE is explained in the User Guide, but for completeness we also describe it here. To change a screen colour use the command:
COLOUR x y
where x and y are numbers. The first number x (0 <= x <= 7) specifies one of the "Master 512 logical colours" these are:
|Master 512 logical colour
|0 and 1
|Colours 0 and 1 (normally background and foreground resp.) in any of the DOS-Plus 2-colour modes, ie Modes 2/3, 6 and 7
|2 and 3
|Foreground and background (resp.) for Monochrome GEM
|4 to 7
|Colours 0 to 3 (resp.) in any of the 4-colour modes, ie DOS-Plus Modes 0/1 and 4/5 and also Colour GEM.
The number y (0 <= y <= 15) specifies the physical colour to be used to display this logical colour, according to the host BBC Micro scheme. So 0 means black, 1 means red, etc.
Note that the Master 512 logical colours for Mono GEM are different from the logical colours for 2-colour DOS-Plus modes. Colour GEM, on the other hand, uses the same four logical colours as 4-colour DOS modes. (By default Mono GEM appears black-on-white, the other way round from the DOS normal of white on black, and so reversing colours 0 and 1 as foreground and background.)
Note also that colour values of the eight Master 512 logical colours will be preserved until they are changed by another use of the COLOUR command (or its screen control sequence equivalent). They are only reset on boot.
The facilities provided in DOS for using the CGA screen are very limited. Because of this, quite a large number of PC programs use the technique of writing directly to the screen memory. The design of the Master 512 has had to take this into account. There has to be a copy of the screen (in "PC format") at the appropriate address of the 512's memory. On the other hand, the BBC Micro's hardware causes it to display what is stored in its own screen memory. This means that the copy of the screen in the 512 must regularly be updated across the Tube into the host. Since the memory maps of the two versions of the screen are quite different, a fairly complex translation procedure is necessary.
On a genuine CGA system the screen adapter memory is located in the memory map at segment B800h. A "standard memory" Master 512 (ie with 512kb of RAM) has memory running between locations 0 and 7FFFFh (20-bit absolute addresses). Some of this memory has to be used for the CGA copy of the screen, and if direct memory screen writes are to work, then accesses to memory in segment B800h must write the correct portion.
The main memory map of the Master 512 has been designed with this in mind. On a 512kb machine the memory between locations 40000h and 7FFFFh is duplicated in locations 80000h to BFFFFh. Programs which write to CGA memory will write to locations between B8000h and BFFFFh. Because of the way the 512 is put together, writing to any of these addresses writes data into the memory between locations 78000h and 7FFFFh.
It is possibly best to think of the memory of a standard Master 512 as being in two parts. The main memory extends between locations 0 and 6FFFFh. This totals 448kb and is used by DOS-Plus itself and programs. The other part of the memory is the screen memory and lies between locations B0000h and BFFFFh. There is 64kb of memory here. It will be explained below why it begins at B0000h rather than B8000h. (When a machine is extended to 1 Mb, the effect is that the gap between these two parts of the memory is filled. Such a machine has memory between 0 and AFFFFh available for programs – 704kb, which is more than any normal memory PC. In these the memory usable by DOS stops at 9FFFFh.)
The details of how the system works vary with which screen mode is in use. I will begin by describing things for the normal text modes, and then go on to show how things differ in other modes.
Screen memory for these modes begins at segment address B800h. For the reasons outlined above, the memory map has to be exactly the same as for CGA screens in these modes. Details can be found in books on the IBM PC, but a brief outline is given here.
For each character position on the screen there are two bytes. The first contains the ASCII value of the character at that position, and the second contains the attribute byte. The data is stored in the natural order – the first two bytes (offset 0 in this segment) relate to the character at the top-left of the screen, the next two to the second character in the first row. This continues right across the top of the screen, and then comes the second row, and so on.
On the Master 512 there is also a second copy of the screen, stored in segment BC00h. This is used to make sure the screen is kept up to date.
The way the system works is like this. Whenever a character is written to the screen by a program using one of the standard DOS or BIOS facilities, then the character is written to each of the three copies of the screen, namely the two copies in the 512's memory, in segments B800h and BC00h, and also the copy in the host's memory, which is the one actually being displayed.
This is fine when programs use the standard facilities. But the system must cope with programs which write directly to screen memory. At regular intervals (actually 10 times per second, on every fifth VSync event) the two copies of the screen in the 512's memory are compared. Any differences must have been caused by a program writing to the copy in segment B800h since this is the standard position. If a difference is detected, then the system finds the first and last characters which differ, and everything between them (including these characters themselves, of course) is copied from the segment B800h copy to the segment BC00h copy and also is translated into host BBC format and copied across the Tube. Thus all the copies of the screen are kept in step, with the CGA-emulation one being the controlling copy.
In the BBC Micro host the screen maps for Modes 4/5 and 6 are identical to those for Modes 0/1 and 2/3 respectively. (Both forms are actually derived from host Mode 3, with a few adjustments to the 6845 CRTC's registers and, for the 4-colour version, some alteration to the control register of the host video ULA.)
In the 512, though, the memory maps are quite different from the text modes. Once again, the map is exactly the same as for true CGA graphics modes. The screen memory is again found in segment B800h. The map is actually rather more simple than that of the host BBC Micro. The only oddity is that the screen is stored in two halves of alternate rows. The first 80 bytes of screen memory correspond to the top row of pixels, the next 80 to the third row, the next 80 to the fifth, and so on. The other rows are stored in exactly the same way, but beginning at offset 2000h in the same segment. Any decent reference on PC graphics will give these details in full.
As with the text modes, a second copy of the screen is stored in 512 memory. This time, though, it can be found at segment B000h. (This is why DOS cannot use more than the 448kb (or 704kb) already mentioned for itself and for programs. In fact the intervening portion of memory – 16kb starting at segment B400h – is used as a hard disk buffer.)
These modes work slightly differently from the text modes.
From one point of view they are the same: the two copies of the screen are compared ten times a second, though the way the updating is done is very slightly different. This time the two copies are compared character line by character line. If a character line (ie 8 rows of pixels) differs in any way between the two copies, then the whole line is transferred into the secondary copy and is also translated and sent across the Tube to the host. Nothing happens with the line if the two versions of it are identical. This difference in the two ways of doing things has no real effect. Perhaps it was felt to be more efficient for the kind of updates that were likely to be necessary when a graphics screen was in use, or maybe it is simply a difference in programming style between two different programmers.
The major difference from the way that the text modes work is this. When a character or pixel is written through the DOS or BIOS routines, then all that happens is that the main copy of the screen (the one at segment B800h) is altered. In Modes 4/5 and 6 the change is not made immediately to the second copy or to the host screen memory. Rather, in these modes the system relies on the regular, 10-times-a-second updating. The consequence of this is that in these modes the screen appears to respond more slowly than in Modes 0/1 and 2/3. There is often a noticeable delay before a character actually appears on the screen.
An oddity about the way the 512 does things is that in these graphics modes yet another copy of the screen exists. There is a "text copy", in the same format as a text screen, stored in segment BC00h. This is written when DOS or BIOS functions are used to display characters on the screen, but it is not updated in any way when the screen is written to directly. This copy of the screen is used in the processing of certain control code sequences which allow the attributes of characters already on the screen to be altered.
This is BBC Screen Mode 3.
Master 512 Mode 7 should not be confused with the "Mode 7" available on some PCs. The single screen mode available with the Monochrome Display Adapter (MDA), which can also be emulated on EGA and VGA systems, is defined as Mode 7. DOS Mode 7 on the Master 512 is not the same as this PC mode.
Mode 7 is not memory mapped in the 512's memory. When a character is written to the screen in this mode, then it is written directly to the screen memory in the host. It is written as a bit pattern rather than as a character, so that characters outside the normal printing range (ASCII 32 to 126) appear in their "PC shapes" rather than being treated as control characters or being given their (variable) "BBC shapes".
Having said this, however, a copy is kept of the screen in 512 memory at segment location BC00h. This is done in exactly the same way, and for the same purpose, as the "text copy" in Modes 4/5 and 6. Writing characters to this copy will not cause them to appear on the screen. The copy is used in the processing of certain control sequences.
Since the host screen is not reflecting anything in the 512's memory, the regular screen updating across the Tube is switched off when Mode 7 is selected.
When GEM is active in its normal 2-colour mode, then the host screen is set up as normal BBC Mode 0.
Under GEM, there is only one copy of the screen in the 512's memory. This is normally in segment B800h, though it could in theory be elsewhere in memory. Its position is defined by a call to XIOS function 83h. The monochrome GEM screen is a simple pixel-mapped screen taking up 20kb of memory and beginning at offset location 0 in the given segment. It is stored in what is perhaps the most natural way for a pixel-mapped screen: the first 80 bytes represent the top row of pixels, the next 80 the second row and so on. Within each byte, the most significant bit represents the left-most pixel of the set of 8. Note that the rows are not interleaved in the way that they are in the CGA-emulating graphics modes.
Unlike the CGA modes, GEM screens are not automatically updated across the Tube. If a section of the screen is altered then the controlling program (usually GEM itself, of course) must cause it to be written to the host, and it does this with a call to XIOS function 84h.
No software support exists in DOS-Plus for writing to the GEM screen. If another program wanted to use this kind of screen it would have to handle all writing to the screen itself.
In its basic principles the 4-colour GEM screen works like the monochrome screen does. It is a pixel-mapped screen, one copy of which exists in the 512's memory. It is not automatically updated across the Tube, so updating after each change has to be prompted by the controlling program.
The 4-colour screen does differ from the monochrome screen, though, in a number of significant ways.
When this mode is active, the BBC Micro host is set up in its normal Screen Mode 1. This is a 4-colour mode of 320 by 256 pixels, taking up 20kb of the host memory.
On the other hand, within the 512 the screen is set up as though it were a 640 by 256 pixel screen in 4 colours. It takes up 40kb of memory in the 512. In order for it to be displayed when it is copied across the Tube it has to be compressed so that it will fit in the BBC's screen memory. Every two internal GEM pixels have to be combined into a single BBC pixel.
In order to understand the memory map it is best to think of a notional screen made up of 640 by 256 pixels, each capable of 4 colour values. The screen is stored in the 512's memory in two halves, a "Colour 1 section" and a "Colour 2 section". (For those familiar with genuine PCs, these are of rather the same kind as the bit-planes used by VGA and similar systems, except that in the 512 they are at different locations.) The Colour 1 section begins at offset 0 in the screen segment. It contains one bit for each pixel, with exactly the same memory map as the monochrome GEM screen. This is the "low-bit component" of the pixel colour value. It takes up 20kb of memory. The Colour 2 section is in exactly the same form, but starts at offset location 5000h in the same segment. This contains the "high-bit component" of the pixel colour values. The way it works is that the two sections are to be understood as "ORed" together for each pixel. Thus a pixel of colour 0 will have its corresponding bits clear in both the screen copies; one of colour 1 will have the bit set in the first copy, clear in the second; one of colour 2 will have the bit clear in the first copy and set in the second; and naturally bits will be set in both copies for a pixel of colour 3.
The way that the notional GEM pixels are combined into half the number of BBC pixels is really rather odd. The algorithm that is followed is this:
If within a block of 8 GEM pixels (corresponding to a single byte in each half of the memory map) there exists at least one GEM pixel of colour zero, then each pair of GEM pixels within this byte is combined into a single visible pixel by the two colour values being ORed together. If, however, there is no GEM pixel of colour zero within the block of 8, then the pixel colour values in each pair are ANDed together.
This extremely strange algorithm can occasionally have curious effects on the visible screen. It can sometimes mean that changing one GEM pixel affects the appearance of 4 visible pixels on the screen.
In addition to the above, there are two further ways in which the 4-colour GEM screen differs from the monochrome version. Since it takes up 40kb of 512 memory it will not fit at the usual screen memory location at segment B800h. It therefore has to be stored elsewhere. When it is being used in the normal way by GEM, the screen is stored in a portion of memory actually within the GEM screen driver program. (The exact position is not fixed, and will depend on DOS version, resident TSRs, etc.)
The final difference from the monochrome screen is that updates have to be done using XIOS function 8Ch rather than 84h.
It is possible to write programs for the Master 512 which will use either the GEM method of controlling the screen, or else will use the native BBC screens and screen functions, all from within DOS-Plus.
To do either of these, you should begin by selecting DOS Mode 7. This will switch off the regular (ten times per second) updating of the screen across the Tube.
To use a GEM screen, decide what area of 512 memory you are going to use for the screen, clear (or otherwise initialize) it, and then use XIOS function 83h to set things up. Remember that none of the standard DOS screen writing facilities will work. Your program must itself implement all screen writing, including displaying of characters. It will have to contain a copy of all the necessary character fonts, and do all manipulations on them itself. When an area of the screen has been written to in the 512, you have to use XIOS function 84h or 8Ch, as appropriate, to copy the changes to the host screen so that they can be seen.
Using a BBC screen is a matter of correct handling of host OSWRCH calls from the 512. You can make the calls either by using Interrupt 49h or by directly writing to Tube Register 1. It makes little difference which of these you adopt. In either case you need to be careful about claiming and releasing the Tube. Some details can be found here.
The one other problem you need to get round when using either BBC or GEM screens from 512 DOS-Plus, is how to control the cursor position. In all normal DOS screen modes the cursor position and on/off state are updated across the Tube on every third VSync event. (For some reason it does not keep in step with the updating of the screen contents in Modes 0 to 6.) DOS-Plus will set the cursor to where it "thinks" it is, but if you are not using DOS routines to write to the screen, then DOS is likely to be confused about the true cursor position. There would appear to be three options:
|You could switch the hardware cursor off and use a software cursor generated
by your own program. This is what GEM does.
|The second option is to try to inform DOS-Plus about where the cursor
really is, but this may not be wholly successful if you are using a mode
very different from any that DOS recognizes.
|The third option is somehow to switch off the regular cursor updating. There is no obvious "legal" way of doing this, and it is probably a matter of patching either DOS-Plus itself or the 6502.SYS code in the host.
I must confess that I have not myself tried to use any of these techniques to program a non-standard screen on a Master 512. All I can really say is that it should be possible in the way I have just described! Remember that these techniques will only work on a Master 512, and programs using them will not work on a true PC-compatible.