CODINGVIDEO / CRTC ★ WACCI CPC : AZ of CPC Chips - Part. 1 ★

Wacci CRTC (1/2)
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

This months thrilling instalment is all about the CRTC chip. There were several different versions of it implemented on the CPC, and guess what, they were all different. How's that for awkward?

The Carphone Bay Whatsit

As with most computer things this chip has an over complicated name, and come to think of it, a long one at that. CRTC actually stands for Cathode Ray Tube Controller. I think that it probably got that name because it controls that thing in the monitor which displays all those lovely graphics, which just happens to be called a Cathode Ray Tube! Exactly why they still call it a tube I don't know. An-swers on the back of a twenty pound note to .....

The CRTC chip scans the part of memory (usually &C000) where the screen data is stored, and translates this into separate bits, which are then sent to the monitor, via the VGA (explained in the next issue.) The monitor then displays a lit pixel if the bit is one, and displays an unlit pixel if the bit is zero.

This is a generalisation of the operation of the monitor because it doesn't take into account the different shades on a green screen monitor (or the different colours on a colour monitor.)
The monitor scans the screen from the top left down to the bottom right in horizontal lines across the screen. When it gets to the end of a row it moves back to the left and commences on the next row. The exact length of each row and the number of rows down the screen is determined by the CRTC settings (explained later.) What has to be kept in mind is that the monitor still scans the screen, even if no data is sent to it.

The CRTC chip that Amstrad put in the first CPCs was the HD6845SP (or something very similar.) This chip wasn't actually designed for the Z80 and so Amstrad had to employ a few tricks so that it would work with the Z80. This, of course, caused problems when Amstrad decided to use other manufacturers of this CRTC chip, owing to each chip being slightly different.

In the years that the CPC was in production Amstrad got through three different types of CRTC chip. The first one was the HD6845SP, then there was the UM6845SP, followed by the MC6845SP, these are usually identified using a type number, which refers to the characteristics of the chip. Type 0 is the HD6845, type 1, is the UM6845, and type 2 is the MC6845, it should be noted at this point, that these are just generalisations, some of the chips can act like the other chips in certain respects.

Chip Problems

The first chip was designed for use with the 680x range of processors, which had one line for enable and one line to indicate read/write. If you read the first article you will
know that the Z80 actually has two lines to indicate read/write, which caused Amstrad a problem when it came to using the HD6845. Their solution was to have different addresses so that bit 9 of the address could be used to select the direction. This was a neat solution, but like all solutions it didn't actually solve anything, it just put off the inevitable.
When Amstrad switched to the UM6845 chip their previous solution caused another problem. The designers of the UM6845 decided to use the Intel convention, which has a line for RD and a line for WR. Although this may seem better, because of the way the Z80 uses the RD and WR lines, it actually caused Amstrad another headache.

The CPC already had software, which made use of the different CRTC addresses for reading and writing, so they couldn't change to the new system, otherwise the old software wouldn't work with the new CPCs.

The only solution, without adding any extra hardware to the CPC board, was to make the chip write only, by making sure that the RD line was always high, and attaching A14 (A14 is low in all the CRTC addresses) of the address bus to the WR line. This meant that any access of the CRTC was treated as a write and when a byte was

supposed to be read an indeterminable number would be returned from the CRTC. This meant that all light pens, and light guns, were nigh on useless, because they relied on information from the CRTC to figure out where the light pen was supposed to be on the screen. It wasn't the best solution to the problem, but I suppose it got Amstrad out of a bit of a hole.
Some of the early UM6845 chips used the 680x convention, which meant that they could be read from, and hence were a type 0 CRTC, even though they weren't the HD6845. There are a few other differences between this and the HD6845 but they aren't really significant. I have one of these types of chip in my CPC, and it seems to have a problem when certain conditions are met.

This causes the data bus to be corrupted, which can cause problems when using certain types of program. I found that I couldn't load up Demoniak 6 because of this. If you have an inexplicable problem with some programs this could be the reason. If you do, write in to Fair Comment, as I am interested to learn of the extent of this problem.

The last type of chip was the MC6845. These chips have the same hardware conventions as the type 1 chips, but have slight internal differences concerning the horizontal sync position. The maximum distance that the screen can be offset to the left is three mode 1 characters, from start up. If the horizontal sync position (explained later) is set to greater than 49 characters this chip doesn't like it and does all sorts of weird and wonderful things.
It is possible, using the data above, to write an algorithm, that would find out the CRTC, for the CPC that it is operating on. This requires the program to set up certain conditions where the different types of CRTC won't work, and then, by analysing the results, deducing what kind of CRTC it is. This isn't fool proof, because some of the CRTC chips work like others, but it is accurate 99% of the time. Some demos have CRTC detection at the beginning. Two that I know of are The Demo, and Voyage '93.

Programming the CRTC

Thankfully, all the CRTCs have 17 registers, and they all do the same things, so there aren't any problems as far as programming is concerned (unless you want to read back from a register!) The CRTC has two ports for output and two ports for input, although the input ports only give sensible readings on type 0 CRTCs (otherwise they will always return &FF.) These ports are:

BCxx - Register Select (Output)
BDxx - Register Data (Output)
BExx - Status Register (Input)
BFxx - Register Data (Input)

where 'xx' can be any digits.

Writing to a register is fairly simple. The register that is to be written to is outputted to &BCxx and then the data to be written to that register is outputted to &BDxx, e.g. To output &28 to register I:

LD BC, &BC01
OUT (C) ,C
LD BC, &BD28
OUT (C) ,C

Reading from a register is equally simple. The register is selected as before and then the data is read from &BFxx, e.g. To read the value of register 16 into A:

LD BC, &BC10
OUT (C) ,C
LD BC, &BF00
IN A, (C)

The status register wasn't implemented on all CRTCs, so you may not be able to read it back. To read the status register the following code can be used.

LD BC, &BE00
IN A, (C)

The status register is bit significant as follows:

Bit 7 - 1 if the CRTC is accessible.

Bit 6 - 0 when register 16 and 17 have been read. 1 if the light pen has been detected.

Bit 5 - 1 if it is in frame flyback The other bits are unused.

They're fairly self explanatory, really. The status register is only available on the S version of the CRTC chip, though.

Register Summaries

There are many different demo effects that can be accomplished by changing the CRTC registers at specific times, but in order to explain all of them I would need about 15 pages, so I am just going to summarise the operation of each register (the numbers in brackets are the start up values of the register.)

I should add a warning at this point. If some of the registers are altered too much they can cause damage to the monitor. If you do change the values of these registers make sure you turn off the computer immediately if something goes wrong, i.e. if the screen scrolls uncontrollably, goes totally black, if the computer crashes, or if anything else un-expected happens.

0.         ;Horizontal Total (63)

This register tells the CRTC how many mode 1 characters there are across the screen in total, including the ones that aren't displayed i.e. the border.

1.         ;Horizontal Displayed (40)

This register tells the CRTC how many mode 1 characters to display across the screen, before the border is to be displayed.
This register is changed for overscan, so that the whole screen contains data ie. there isn't a border.

2.          Horizontal Sync Pos. (46)

This register is used to synchronise the output of data to the screen, with the start of a new row. If this register is increased the screen will move to the right, and if it is decreased it will move to the left. Be warned, though, that the screen can become unstable if it is moved too far in either direction.

3.          Sync Width (142)

This register determines how long the synchronisation pulses will be for each horizontal and vertical sync. The minimum length of pulse that is needed varies from monitor to monitor. This register should not be altered, because if the value is set too low it can damage the monitor.

4.          Vertical Total (38)

This register is the vertical counterpart of register 0. It dictates how many mode 1 characters the are down the screen, including the borders.

5.          Vertical Total Adjust (0)

This register is used to make sure that each frame takes 1/50th or 1/60th of a second by adding a small delay between each frame. It can also be used to scroll the screen smoothly.

6.          Vertical Displayed (25)

This register is the vertical counterpart for register 1 and controls how many characters are displayed vertically. This register is also changed when doing overscan, so that the bottom and top parts of the border are covered.

7.          Vertical Sync Pos. (30)

This is the vertical counterpart of register 2. It controls the positioning of the data, vertically, on the screen. If it is incremented the screen will move up and it will move the screen down if it is decremented.

8.          Interlace and Skew (0)

This is a two bit register that isn't used on the Amstrad. It is used for some demo techniques on type 0 CRTCs, due to an error in the operation of the chip.

9.          Maximum Raster Addr. (7)

This describes how many rows there are per character and should be left as 7, otherwise the lines will start repeating, due to the way the CRTC is wired in the CPC.

10.        Cursor Start Raster (0)

This register can't be used on the CPC due to the way the CRTC is wired in the CPC.

11.        Cursor End Raster (0)

Ditto.

12.        Start Address (High) (48)

This is a 6 bit register which controls the screen length (16k or 32k (used for overscan)), the start address of the screen, and bit 9 and 10 of the offset. It is laid out as follows:

Bit 5 - Start of screen. Bit 4 - Start of screen. Bit 3 - Length of screen. Bit 2 - Length of screen. Bit 1 - Bit 9 of screen offset. Bit 0 - Bit 8 of screen offset.

Bits 5 and 4 dictate the start address of the screen memory, as follows: Bits 3 and 2 control the length of the screen. If the screen length is set to 32k there will be enough screen data to fill the whole of the screen, so by altering the position of the screen, with respect to the border, and by increasing the vertical and horizontal characters displayed, the whole screen area can be filled. The screen length is changed as follows: Bits 1 and 0 are bits 9 and 8 of the screen offset.

13.        Start Address (Low) (0)

This register controls bits 0-7 of the screen offset i.e. the second byte of the screen address. This register can be used in conjunction with register 12 to make the screen start almost anywhere in memory, except bits 10-13 of the screen position aren't accessible (they are presumed to be 0.) If this register is incremented it will appear as if the screen is scrolling to the left.

14.        Cursor Register (H) (192)

Isn't used on the CPC, although it is still set to &C0!

15.        Cursor Register (Low) (0)

Ditto.

16.        Light Pen (High)

This provides bits 15-8 of where the light pen is on the screen. This requires the lightpen to be attached to the CRTC, via the expansion port. It is only readable with CRTC type 0, though.

17.        Light Pen (Low)

This provides bit 7-0 of where the light pen is on the screen. It is only readable with CRTC type 0.

The End

There are many other effects that can be accomplished by clever timing and changing of the registers, like horizontal/vertical splitting, superposition, pseudo 640x400 pixel screen, overscan, smooth scrolling, and loads more.

In the next issue we will be looking at how the VGA fits into the picture.

James Hoskisson, WACCI MAG

★ AUTHOR: James Hoskisson

CPCrulez[Content Management System] v8.7-desktop/cache
Page créée en 075 millisecondes et consultée 1598 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.