# The 6845 CRTC and its five CPC types Technical information in this document is sourced from the "Amstrad CPC CRTC Compendium" by Longshot (CC BY-NC-ND); see provenance.md. Source names as in start-here.md. ## The types (DOC: ACCC 4.2; KT `crtcnew`) | Type | Part | Maker | Found in | | --- | --- | --- | --- | | 0 | HD6845S(P) | Hitachi | 464, 664, 6128 (and the KC Compact, KT) | | 0 | UM6845 | UMC | same; behaves exactly like the HD6845S, no test tells them apart yet (ACCC 4.2 note 3) | | 1 (1-A, 1-B) | UM6845R | UMC | same; two sub-types seen, possibly not from the CRTC itself (ACCC 4.2 note 6, 11.6) | | 2 | MC6845(P) | Motorola | same | | 3 | inside ASIC 40489 | Amstrad | 464 Plus, 6128 Plus, GX4000 | | 4 | inside ASIC 40226 ("Pre-ASIC") | Amstrad | "cost-down" 464/6128 | Types 3 and 4 cannot be told apart from software while the Plus features are locked (ACCC 4.2 note 1); type 4 was numbered after 3 because it was found later (ACCC 4.2). The numbering is the demoscene's (Logon System's), not a manufacturer's. **C4. Which cost-down machines carry the 40226.** KT `crtcnew`: type 4 "as far as I know ... only in cost-down CPC6128 systems". KT `cpcptno`: 40226 is the "CPC464 cost-down ASIC" and "40235?" the 6128's. ACCC 4.2 and 29: 40226 in the "low-cost CPC", CRTC 4. Naming only; the board's parameter is the type, not the model. ## Wiring on the CPC (DOC: ap12 B, D; KT `crtcnew`; ACCC 4.1, 4.3) - Clock: 1 MHz character clock from the Gate Array, one character = 2 bytes (ap12 D). - Ports (A14 = 0, A9-A8): `BCxx` select, `BDxx` write, `BExx` status (type 1; types 3/4 mirror `BFxx`), `BFxx` read (ACCC 4.3, 28.1.8-28.1.9). The register number is taken modulo 32 (ACCC 5.1, 28.1.9). - The 6845's R/W pin is not driven by the Z80's RD/WR: a read of `BDxx` writes whatever is on the data bus to the selected register (ACCC 4.4.2). - Memory address = MA13-12 (16 KB page), RA2-0 (2 KB block), MA9-0, plus the byte-select phase from the Gate Array (KT `crtcnew` table, with its two "A15" rows read as A15/A14; ap12 B agrees). - DISPEN ("DISPTMG") selects border or pixels; HSYNC and VSYNC go to the Gate Array (and VSYNC also to PPI port B bit 0). CURSOR and LPSTB both go to the expansion port (KT `signals`: "CURSOR (Cursor; Output from CRTC)", "L.PEN (Light Pen trigger; Input to CRTC)"); the CPC's own video does not use the cursor (HYPOTHESIS: Gerald 40010's pin list has no CURSOR input; to confirm). - The firmware programs R15 down to R0, starting 64 µs after the first ROM instruction (ACCC 4.1 note 2; OBSERVED in MAME: the first CRTC write at 67 µs, R15 to R0, then R0 = 63, R1 = 40, R2 = 46, R3 = &8E, R4 = 38, R5 = 0, R6 = 25, R7 = 30, R9 = 7, R12/R13 = &3000, matching ap12 D's PAL column). ## Register differences that are documented (DOC: ACCC 4.3, 28) | | Type 0 | Types 1, 2 | Types 3, 4 | | --- | --- | --- | --- | | R3 | VSYNC width (bits 7-4) and HSYNC width | HSYNC width only; VSYNC fixed at 16 lines | both | | R8 | interlace and skew (DISPEN/cursor delay) | interlace only (no skew) | both | | R3 HSYNC width 0 | no HSYNC | type 1: no HSYNC; type 2: 16 µs | 16 µs | | R10/R11 | cursor (write) | cursor (write) | read back as ASIC status bytes | | R12/R13 | read/write | write only | read/write | | `BExx` status | none | type 1: status (bit 5 = vertical blanking phase, ACCC 21) | mirrors `BFxx` | | `BFxx` reads | R12-R17 | type 1: 0 except R14-R17 (and R31); type 2: R16-R17 only, 0 elsewhere | R10-R13, R16-R17 through a 3-bit table | **C5. Type 2's readable registers.** ACCC 4.3's table marks R14/R15 readable on types 1 and 2; ACCC 28.1.9 says type 2 returns R16/R17 and 0 for every other register. Motorola's register table (the bitsavers scan, PDF page 11, "Table 2") marks R14/R15 read/write, R16/R17 read-only and R12/R13 write-only for the MC6845. ACCC 28.1.9 is a measurement on CPC units and may reflect a die revision; a SHAKER read test on a type-2 unit decides for the board. ## Behaviour that is not in any data sheet (DOC: ACCC 10-21, measured with SHAKER) The famous differences demos depend on are counter rules, not register maps. ACCC gives each with per-type chronograms; the board's CRTC must follow them per type. The headline items, by ACCC chapter: - **Register update timing** (4.4.3): on types 0-2 an `OUT (C),r` reaches the CRTC in the instruction's 3rd µs, on types 3-4 in its 4th; `OUTI`/`OUTD` in the 5th on all types; `IN r,(C)` reads in the 4th. Code written for 3/4 places writes 1 µs earlier. - **R9 / C9 counting** (10): when the raster counter wraps and how a change mid-character is taken, per type (type 4 can cut C9 on any line, ACCC 4.2 note 2). - **R5 vertical adjust** (11): counting during the adjust, R5 updates during and before it, VSYNC during the adjust, "RFD" on type 1 (11.6), interlace adjust lines. - **R4 / C4 counting** (12): line-to-line rupture ("R.L.A.L."), type 2's "last line" concept, C4 overflow on type 3 (ACCC v1.9 change log). - **R0 / C0 counting** (13): R0 = 0 and R0 = 1 cases, freezes of VSYNC, of the adjust line and of C9 on type 0; vertical rupture; R0 updates per type. - **HSYNC/VSYNC** (7, 14-17, 28.1.2-28.1.4): ghost VSYNC on type 2 when VSYNC starts during HSYNC; VSYNC length programmable only on 0, 3, 4; VSYNC line counter start differs. - **Border and DISPEN** (28.1.6), **interlace** (28.1.7), **video pointer R12/R13** (20), **read and status registers** (21). - **Identification** (28): the tests software uses to tell the types apart, each of which is also a ready-made exit test for the board's CRTC. None of this is in MAME's `mc6845` device as a per-CPC-type model (OBSERVED: MAME 0.285 lists the cpc464's CRTC as "Hitachi HD6845S CRTC @ 1.00 MHz" and offers no type setting in `-listdevices`), so MAME cannot judge these rules. ## The oracles for the CRTC 1. **Real-machine SHAKER results** (tier 1 for what they show: photos of each test on each CRTC type, about 1,500, on the Shakerland portal) with SHAKER 2.7 itself (fetched, run only) as the stimulus. The board's exit test per type is "SHAKER module X, test Y produces the picture the real machine of that type produced". The photos are not fetched yet (U7: their terms and a pixel-comparable form). 2. **ACCC** (tier 3, measured): the rules and chronograms. 3. **The data sheets** (tier 2): HD6845S, UM6845R, MC6845 (KT transcriptions; the Motorola scan from bitsavers). They define the nominal counters; ACCC overrules them where it measured otherwise. 4. Emulators that claim SHAKER approval (Amspirit, closed source) and the rest (tier 5): detectors only. No die-level 6845 trace is known for the HD6845S, UM6845R or MC6845 (U6); the 40489 and 40226 ASICs have no public die work either. ## The chip rule: is a `crtc6845-python` warranted? Users of the 6845 family in the family today: **none besides this board**. Candidates that would use one: the BBC Micro (HD6845SP; no repository), the IBM PC's MDA/CGA cards (MC6845; `i8086-python` is a CPU core, no PC board exists), the Apple II's 80-column cards (Videx; `apple2-python` is a Phase 0 with no such card), many arcade boards (none in the family). The Amstrad PCW, Spectrum and other Amstrad machines have no 6845. So by the charter the 6845 **stays in this board**, behind a pin-shaped interface (`clock()` per character; outputs MA, RA, DISPEN, HSYNC, VSYNC, CURSOR; inputs LPSTB and the bus side: select, write, read, status), with the type as a variant table, so that extraction is a move when a second board arrives. Two cautions for that day: types 3 and 4 are Amstrad ASICs that exist only in CPCs (they would stay CPC variants inside the core or stay in the board), and the BBC's and CGA's uses exercise different corners (interlace, cursor, light pen) that the CPC barely touches. Open decision 2.