Changes
CRTC
,== Overview ==
The 6845 Cathode Ray Tube Controller (CRTC) is a programmable IC used to generate video displays. This IC is used in a variety of computers including the Amstrad CPC, Amstrad CPC+ and KC Compact.
The CRTC is a simple chip really . It is just a bunch made up of counters and equality operators, tied by simple logic. But All the devil is in the details, and that's what we will discuss in this articlecomplexity stems from its multiple independent implementations with their subtle differences.
The CRTC was a common part available from many different manufacturers. During the life of the CPC, Amstrad sourced the CRTC from various manufacturers.
This table lists the known ICs used, with their part number, manufacturer and type number.
{| class="wikitable"{{Prettytable|width: 700px; font-size: 2em;}}!|''Part number!''||''Manufacturer!''||''Type number (note 3)''
|-
|HD6845S||Hitachi||0
3. In the Amstrad community each 6845 implementation has been assigned a type number. This type identifies a group of implementations which operate in exactly the same way.
It is possible to detect the 6845 present using software methods, and this is done to:
* In most cases, the type of the detected 6845 is reported.
4. As far as I (Kevin Thacker) know, the KC compact used HD6845R only.
==Programming==
The 6845 is selected when bit 14 of the I/O port address is set to "0". Bit 9 and 8 of the I/O port address define the function to access. The remaining bits can be any value, but it is adviseable to set these to "1" to avoid conflict with other devices in the system.
The recommended I/O port addresses are:
{| class="wikitable"
|-
!I/O port address
!/CS (A14)
!R/W (A9)
!RS (A8)
!Function
!Read/Write
|-
|&BCxx||0||0||0||Select 6845 register||Write only
|-
|&BDxx||0||0||1||Write to selected internal 6845 register data||Write only
|-
|&BExx||(note 0||1)||0||* CRTCs 0/2: —* CRTC 1: Read Status Register* CRTCs 3/4: Read from selected internal 6845 register||Read only
|-
|&BFxx||(note 0||1)||1||Read from selected internal 6845 register||Read only
|-
|}
==Video Memory Address (VMA)Addressing==
The VMA of the [[Gate Array]] is constructed from the CRTC MA and RA signals:
=== Overscan bits ===
It's is possible to use 32KB screen size (used for [[Programming:Overscan|overscan]]) by setting bits 11 and 10 of Register 12 both to 1. Bits MA11 and MA10 of the address generated by the CRTC are not written on the address bus to access video memory; settings both bits to 1 is the only way to cause a carry to bit MA12 when address pass over the end of current video page to change the memory address to the next video page.
<br>
== Split screen (aka Rupture) ==
While there is usually 1 CRTC frame per screen frame, the screen frame can be divided into multiple CRTC frames of varying proportions.
This is useful for defining different scrolling zones in your screen frame. For example, it was used for hardware parallax scrolling in the game [https://www.cpc-power.com/index.php?page=detail&num=1307 The Living Daylights], released in 1987. [https://www.cpcwiki.eu/forum/programming/the-living-daylights-extra-colours-in-mode-1-rasters-screen-splits/ Source]
And this is basically the bread and butter of innumerable CPC demos.
Some rules of thumb [https://www.cpcwiki.eu/forum/programming/advice-on-split-screen-code/msg242186/ Source]:
Total height of all splits must be 39.
<br>
CRTC pin CUDISP is not connected to the Gate Array, so it has no effect on a barebone CPC or Plus machine.
However, this signal is provided to the expansion [[Connector:Expansion port]]. And it is used by the [[PlayCity]] and [[Play2CPC]] expansions.
<br>
==== Interline border ====
On CRTCs 0/2, R1>R0 generates one byte (0.5µs) of border at the end of the raster line. On CRTCs 1/3/4, it does not.
To see the border bytes with your own eyes, type this BASIC line after reset:
</pre>
=== Signal delay === On all CRTCs, there is a 1µs delay in display between when the CRTC provides a video pointer, and when the Gate Array displays the corresponding 16-bit character. But on CRTCs 0/1/2, there is no delay for HSYNC. On CRTCs 3/4, the Amstrad engineers fixed the issue by adding a 1µs delay for the HSYNC signal. So now we have a bigger issue: on CRTCs 3/4, HSYNC occurs 1µs later than on CRTCs 0/1/2. Interrupts being dependent on HSYNC, this is a serious compatibility issue for time-sensitive code. It also explains why the CTM monitor has to be calibrated differently on CRTCs 3/4. === Discolouration effect === On CRT monitors from other brands, a colour calibration can happen just after the C-HSYNC pulse. So even when a fully valid C-HSYNC pulse of 4µs is emitted, an HSYNC shorter than usual combined with a coloured border can induce a discolouration effect on those monitors. <br> == VSYNC == The VSYNC signal from the CRTC is not directly connected to the display. It is passed to the [[Gate Array]] for further modification. See its wiki page. While VSYNC is active, all the CRTC counters continue to increment normally and addresses continue to be generated. On all CRTCs, while a VSYNC is ongoing, the condition VCC=R7 is ignored. So we cannot trigger a new VSYNC during a VSYNC. On CRTCs 0/1/2, the sole condition to trigger a VSYNC is that VCC=R7. While on CRTCs 3/4, it is necessary to have VCC=R7 and HCC=0 and VLC=0 to trigger a VSYNC. === Ghost VSYNC === On CRTC 2, if a VSYNC is triggered during an HSYNC, the CRTC produces a ghost VSYNC. The CRTC then counts the lines as if a VSYNC were taking place by preventing a new VSYNC from occurring, but without the VSYNC pin being enabled. === Mid-VSYNC === On all CRTCs, in both interlace modes, a mid-VSYNC is generated when VCC=R7 on the even field. The VSYNC pulse starts in the middle of the raster line, at HCC=R0/2. As an exception, on CRTCs 3/4, if R7=0 then mid-VSYNC will instead occur on the odd field. === PPI VSYNC === The VSYNC pin of the CRTC is directly connected to bit0 of port B of the PPI. There is no delay involved. In the CRTC Compendium, chapter 7.3 "Fake VSYNC", [[Longshot]] has also experimented with reversing the direction of PPI port B to output a VSYNC signal from the PPI to the Gate Array. This technique is not for the faint of heart! <br> == CRTC registers 6845 Registers ==
The Internal registers of the 6845 are:
{| class="wikitable"{{Prettytable|width: 700px; font-size: 2em;}}|''Register Index''||''Register Name''||''Range''||''CPC Setting''||''Notes''
|-
|-
|1||Horizontal Displayed||00000000||40||Number of characters displayed. Once horizontal character count (HCC) matches this value, DISPTMG is set to 1.
|-
|2||Horizontal Sync Position ||00000000||46||When to start the HSync signal.
|-
|3||Horizontal and Vertical Sync Widths||VVVVHHHH||128+14||HSync pulse width in characters (0 means 16 on some CRTC), should always be more than 8; VSync width in scan-lines . (0 means 16 on some CRTC. Not present on all CRTCs, fixed to 16 lines on these) ; HSync pulse width in characters.
|-
|4||Vertical Total (-1)||x0000000||38||Height of the screen, in characters.
|-
|5||Vertical Total Adjust||xxx00000||0||Measured in scanlines, can be used for smooth vertical scrolling on CPC.
|6||Vertical Displayed||x0000000||25||Height of displayed screen in characters. Once vertical character count (VCC) matches this value, DISPTMG is set to 1.
|-
|7||Vertical Sync Positionposition||x0000000||30||When to start the VSync signal, in characters.
|-
|8||Interlace and Skew||CCDDxxIIxxxxxx00||0||CC00: Cursor Skew (Only in CRTCs 0, 3 and 4). DDNo interlace; 01: Display Skew (Only in CRTCs 0, 3 and 4). IIInterlace Sync Raster Scan Mode; 10: No Interlace ; 11: Interlace Sync and Video Raster Scan Mode.
|-
|9||Maximum Raster Address (aka Number of Scan Lines) (-1)||xxx00000||7||Maximum scan line address on CPC can hold between 0 and 7, higher values' upper bits are ignored
|-
|10||Cursor Start Raster||xBP00000||0||Cursor signal is not connected to the Gate Array but is provided to the expansion portused on CPC. B = Blink On/Off; P = Blink Period Control (Slow/Fast). Sets first raster row of character that cursor is on to invert.
|-
|11||Cursor End Raster||xxx00000||0||Sets last raster row of character that cursor is on to invert
|-
|12||Display Start Address (High)||xx000000||48||On Amstrad Plus, bit7 of the printer port is controlled by bit3 of CRTC R12 (ie. bit11 of Display Start Address)
|-
|13||Display Start Address (Low)||00000000||0||Allows you to offset the start of screen memory for hardware scrolling, and if using memory from address &0000 with the firmware.
|15||Cursor Address (Low)||00000000||0
|-
|16||Light Pen Address (High)||xx000000||||Read Only. On CRTC1, bit6 of Status register goes to 0 when R16 is read
|-
|17||Light Pen Address (Low)||00000000||||Read Only. On CRTC1, bit6 of Status register goes to 0 when R17 is read
|-
|}
The following tables list the functions that can be accessed for each type:
Type 0
{| class="wikitable"{{Prettytable|width: 700px; font-size: 2em;}}!|''b1!''||''b0!''||''Function!''||''Read/Write ''
|-
|0||0||Select internal 6845 register||Write Only
|1||0||-||-
|-
|1||1||Read from selected internal 6845 register||Read Only only
|-
|}
Type 1
{| class="wikitable"{{Prettytable|width: 700px; font-size: 2em;}}!|''b1!''||''b0!''||''Function!''||''Read/Write''
|-
|0||0||Select internal 6845 register||Write Only
|1||0||Read Status Register||Read Only
|-
|1||1||Read from selected internal 6845 register||Read Only only
|}
Type 2
{| class="wikitable"{{Prettytable|width: 700px; font-size: 2em;}}!|''b1!''||''b0!''||''Function!''||''Read/Write''
|-
|0||0||Select internal 6845 register||Write Only
|1||0||-||-
|-
|1||1||Read from selected internal 6845 register||Read Only only
|-
|}
Type 3 and 4
{| class="wikitable"{{Prettytable|width: 700px; font-size: 2em;}}!|''b1!''||''b0!''||''Function!''||''Read/Write''
|-
|0||0||Select internal 6845 register||Write Only
|1||0||Read from selected internal 6845 register||Read Only
|-
|1||1||Read from selected internal 6845 register||Read Only only
|-
|}
It is not possible to read from all the internal registers, this table shows the read/write status of each register for each type:
{| class="wikitable"{{Prettytable|width: 700px; font-size: 2em;}}!|rowspan=2|''Register Index!''||rowspan=2|''Register Name!''||colspan=34|''Type''
|-
|-
|0||Horizontal Total (-1)||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|1||Horizontal Displayed||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|2||Horizontal Sync Position||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|3||Horizontal and Vertical Sync Widths||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|4||Vertical Total (-1)||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|5||Vertical Total Adjust||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|6||Vertical Displayed||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|7||Vertical Sync Positionposition||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|8||Interlace and Skew||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|9||Maximum Raster Address (aka Number of Scan Lines) (-1)||colspan=3 style="text-align: center;"Write Only||Write Only||Write Only||(note 2)||(note 3)
|-
|10||Cursor Start Raster||Write Only||Write Only||Read/WriteOnly||(note 2)||(note 3)
|-
|11||Cursor End Raster||Write Only||Write Only||Read/WriteOnly||(note 2)||(note 3)
|-
|12||Display Start Address (High)||Read/Write||Write Only||Write Only||Read/Write (note 2)||(note 3)
|-
|13||Display Start Address (Low)||Read/Write||Write Only||Write Only||Read/Write(note 2)||(note 3)
|-
|14||Cursor Address (High)||colspan=3 style="text-align: center;"Read/Write||Read/Write||Read/Write||Read/Write (note 2)||(note 3)
|-
|15||Cursor Address (Low)||colspan=3 style="text-align: center;"Read/Write||Read/Write||Read/Write||Read/Write (note 2)||(note 3)
|-
|16||Light Pen Address (High)||colspan=3 style="text-align: center;"Read Only||Read Only||Read Only||Read Only (note 2)||(note 3)
|-
|17||Light Pen Address (Low)||colspan=3 style="text-align: center;"Read Only||Read Only||Read Only||Read Only (note 2)||(note 3)
|-
|}
'''Notes'''
=== Horizontal and Vertical Sync (R3) ===
Type 0:
*Bits 7..4 define Vertical Sync Width. If 0 is programmed , this gives 16 lines of VSYNC.*Bits 3..0 define Horizontal Sync Width. If 0 is programmed , no HSYNC is generated (and therefore, no interrupts).
Type 1:
*Bits 7..4 are ignored. Vertical Sync is fixed at 16 lines.
*Bits 3..0 define Horizontal Sync Width. If 0 is programmed , no HSYNC is generated (and therefore, no interrupts).
Type 2:
*Bits 7..4 are ignored. Vertical Sync is fixed at 16 lines.
*Bits 3..0 define Horizontal Sync Width. If 0 is programmed , this gives a HSYNC width of 16.
Types 3/4:
*Bits 7..4 define Vertical Sync Width. If 0 is programmed , this gives 16 lines of VSYNC.*Bits 3..0 define Horizontal Sync Width. If 0 is programmed , this gives a HSYNC width of 16.
<br>
*Bits 5..4 define the skew (delay) of the DISPTMG signal (00 = Non-skew ; 01 = One-character skew ; 10 = Two-character skew ; 11 = Non-output).
*Bits 3..2 are ignored.
*Bits 1..0 define the interlace mode (00 = No Interlace; 01 = Interlace Sync; 10 = No Interlace; 11 = Interlace Sync and Video).
Types 1/2:
*Bits 7..2 are ignored.
*Bits 1..0 define the interlace mode.
<br>
<br>
==UM6845R and R12/R13 = Status register on Type = The UM6845R differs to other CRTC in respect of R12/R13. When VCC=0, R12/R13 is re-read at the start of each line. R12/R13 can therefore be changed for each scanline when VCC=0. Just like other CRTCs when RC==(R9-1 ), the current MA is captured for the next char-line. In demos to make a display compatible with all CRTCs program R12/R13 when VCC!=0. This will then take effect at the next frame start. == UM6845R status register ==
The UM6845R has a status register that can be read using port &BExx.
All the other bits read as 0 and don't have any function.
<pre>
10 MODE 1:' Reinitialize screen
</pre>
Distinguishing between CRTCs 3 and 4 can be done by trying to [[Programming:Unlocking ASIC|unlock the ASIC]] or by testing the [[8255|PPI chip]]. On ASIC, if PPI Port B is set as output it will behave the same as input.
<br>
<br>
== Internal Counters Block Diagrams ==
{| class="wikitable"
|-
|-
|Horizontal Sync Counter|HSC|C3l||-|Vertical Character Counter|VCC|C4||-|Vertical Sync Counter|VSC|C3h|-|Vertical Line Counter|VLC|C9|If not in IVM mode, this counter is exposed on [[File:CRTC pins RA0Block Diagram..RA4png|-Hitachi]]|Vertical Total Adjust Counter|VTAC|C5|This counter does not exist on CRTCs 0/3/4[[File:UMC CRTC Block Diagram. C9 is reused insteadpng|-UMC]]|Frame Counter|FC||Used to alternate frames in interlace and for [[File:Motorola CRTC cursor blinkingBlock Diagram.png|-|Memory Address|MA||This counter is exposed on CRTC pins MA0..MA13Motorola]]
|}
<br>
This chip was never used by Amstrad. However, some CPC enthusiasts have replaced the original CRTC chip in their CPC with this one.
With this chip, split-screen becomes easy: [https://thecheshirec.at/2024/05/20/des-splitscreens-en-basic-sur-crtc5/ Split-screen in BASIC]. And 3 new graphics modes (160x100x16160x100x16c, 320x100x4320x100x4c, 640x100x2640x100x2c) are available: [https://thecheshirec.at/2024/11/10/trois-nouveaux-modes-video-grace-au-crtc-5/ New graphics modes in BASIC].
This is the cheapest way to upgrade the CPC's graphics capabilities, costing only 1.29€. [https://thecheshirec.at/2024/05/19/des-crtc5-a-129e/ Source]
== Datasheets ==
==== Used by Amstrad ====
* [[Media:hd6845.hitachi.pdf|HD6845S (Hitachi)]] aka Type 0
* [[Media:UM6845-UMC.pdf|UM6845 (UMC)]] aka Type 0
* [[Media:Um6845r.umc.pdf|UM6845R (UMC)]] aka Type 1
* [[Media:Mc6845.motorola.pdf|MC6845 (Motorola)]] aka Type 2 [[Media:Mc6845.pdf|Other datasheet version]]
* [[Media:CPC_Plus_Asic_Schematic.GIF|AMS40489 (Amstrad)]] aka Type 3 ([[ASIC]])
* [[AMS40226 (Amstrad)]] aka Type 4 (Pre-ASIC)
<br>
==== Unused clones ====
* [[CM607P]] a Bulgarian clone made in Pravetz factory (maybe . It is used on [[KC Compact]] and in the [[Aleste 520EX]])* [[Media:EF6845P.pdf|EF6845]] by Thomson Semiconductors* [[Media:hd6845.hitachi.pdf|HD6845R]] by Hitachi. According to Kevin Thacker, the [[KC Compact]] used HD6845R only.
* [[Media:UM6845E-UMC.pdf|UM6845E]] by UMC
* [[Media:Mc6845.pdf|MC6845-1]] by Motorola
* [[Media:F6845.pdf|F6845]] by Fairchild
* [[Media:EF6845P.pdf|EF6845]] by Thomson Semiconductors* [[Media:VL6845 VTi.pdf|VL6845]] by VTi* [[Media:C6845 CRTC (CAST).pdf|C6845]] by Cast* [[Media:MB89321B FUJ.pdf|MB89321B]] by Fujitsu. It is pin-compatible with the 6845* [[Media:MB89321A datasheet CRTC.pdf|MB89321A]] by Fujitsu. Enhanced version that adds smooth scroll, screen partitioning, independent scrolling of screen partitions, and other convenient features* [[Media:Mos 6545-1 crtc.pdf|CRTC MOS 6545]] (MOS, Rockwell, Synertek) is pin-compatible with the 6845 and only has minor . Its differencesare found in the R8 register.* [https://www.cpcwiki.eu/forum/other-retro/interesting-discussion-about-the-c128-s-cpm-poor-performance/msg223058/#msg223058 MOS 8563] It is an evolution of the 6545/6845 CRTC chip, with blitter abilities to autonomously perform block memory copies within its dedicated video RAM.
* [https://github.com/hoglet67/BeebFpga/blob/dev/src/common/mc6845.vhd BeebFpga] [https://github.com/MiSTer-devel/Amstrad_MiSTer/blob/master/rtl/UM6845R.v MiSTer] [https://opencores.org/websvn/filedetails?repname=System09&path=%2FSystem09%2Ftrunk%2Frtl%2FVHDL%2Fcrtc6845.vhd OpenCores] Verilog/VHDL implementations of the 6845
* [http://en.wikipedia.org/wiki/6845 Wikipedia on the CRTC]
* [[Media:ACCC1.8-EN.pdf]] CPC CRTC Compendium - Latest (04/2024!) document containing in-depth info about CRTC programming on CPC.
* [[Media:CRTC Compendium Podcast.mp3]] The CRTC Compendium digested in podcast format
* [http://www.grimware.org/doku.php/documentations/devices/crtc CRTC documentation from Grimware]
* [http://quasar.cpcscene.net/doku.php?id=assem:crtc Quasar CRTC documentation (in french)]
* [https://pulkomandy.github.io/shinra.github.io/crtc.html PulkoMandy's table] [https://www.theoddys.com/acorn/the_6845_crtc/6845%20Variants.xlsx Oddy's table] Differences between CRTC types]
* [[Media:Dossier Rupture(Gozeur Paradox).pdf]]
* [[Media:Dossier CRTC(Ramlaid Mortel).pdf]] Les entrailles du CRTC
* [https://thecheshirec.at/tag/crtc6845/ Leçons CRTC (CheshireCat)]
* [[Mediahttps:ACCC1//martin.8-ENhinner.pdf]] [[Media:ACCC1.8-FR.pdf]] CPC CRTC Compendium - Latest (04info/2024!) document containing in-depth info about CRTC programming on CPCvga/pal.* [[Media:CRTC Compendium Podcast.mp3]html PAL video timing specification] The CRTC Compendium digested in podcast format <br>
==Related pages==
*[[Synchronising with the CRTC and display]] : technic and details on the relationship between Gate Array and CRTC.
*[[VIDI digitizer]] This extension contains its own CRTC chip
[[Category:Hardware]] [[Category:CPC Internal Components]] [[Category:Electronic Component]] [[Category:Programming]] [[Category:Datasheet]] [[Category:Graphic]]