# The 6845 CRTC and the video address path Citations as in [start-here.md](start-here.md); HD = Hitachi's 1981 data book (HD6845S data sheet, pinned), CRTC = Motorola's MC6845 data sheet (pinned, scanned TIFFs; OCR text in `reference/text/ocr/MC6845_*.txt`). ## Which 6845 Acorn's parts lists name only "6845" (SM85-1 parts list item 153, IC2; SMBP item 164, IC78; MSM "6845 CRTC NMOS 1MHZ", IC22). MAME 0.285 fits a "Hitachi HD6845S CRTC" to every BBC driver (OBSERVED: `mame -listdevices bbcb`). HD lists the HD6845SP at 1.0 MHz bus timing with a 3.7 MHz display clock limit, "upward compatible with MC6845" (DOC: HD, HD6845S features and ordering table). The bus side of the BBC's 6845 is always accessed in a stretched 1 MHz cycle ([timing.md](timing.md)), which fits a 1 MHz bus-grade part; its display clock is 1 or 2 MHz (below 3.7). **Unknown U1**: which makers' 6845s were fitted over the production run (Hitachi, Motorola, Rockwell, UMC ...). The 6845 variants differ in the corners a raster-effect demo uses: whether R3's vertical sync width is programmable, how R8's interlace and skew bits behave, whether R12/R13 are readable, what a mid-frame write to R4/R6/R9 does. The specification follows the HD6845S (HD's data sheet: tier 2) and keeps every variant difference as a field of one variant record, so an MC6845 row can be added when evidence says some BBCs carried one. **This is the chip the Amstrad CPC needs too** (the CPC's "CRTC types" are exactly these maker differences). Open decision 2 proposes a shared `crtc6845-python` core with variant rows, built once for both boards. ## Registers as the BBC uses them R0-R17 as in the data sheets (DOC: HD; AUG 18.2-18.10). The MOS's values for each mode are listed in AUG appendix F (DOC); in summary: | Mode | 6845 clock | R0 | R1 | R4 | R5 | R8 | R9 | Notes | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | 0, 1, 2 | 2 MHz | 127 | 80 | 38 | 0 | &01 | 7 | 20 KB screen at &3000 | | 3 | 2 MHz | 127 | 80 | 30 | 2 | &01 | 9 | 10-line rows, 16 KB at &4000 | | 4, 5 | 1 MHz | 63 | 40 | 38 | 0 | &01 | 7 | 10 KB at &5800 | | 6 | 1 MHz | 63 | 40 | 30 | 2 | &01 | 9 | 8 KB at &6000 | | 7 | 1 MHz | 63 | 40 | 30 | 2 | &93 (MOS) | 18 | teletext, 1 KB at &7C00 | R0, R1, R4, R5 and R9 checked against AUG appendix F for all eight modes. R8 for mode 7 is what OS 1.20 writes (below), not appendix F's. **What the MOS actually writes** (OBSERVED: OS 1.20, `os12.rom` by SHA-1 in [census.md](census.md), booting to mode 7 under MAME, whose trace only carries the firmware's own writes to &FE00/&FE01): R0=&3F R1=&28 R2=&33 R3=&24 R4=&1E R5=&02 R6=&19 **R7=&1C** **R8=&93** R9=&12 R10=&72 R11=&13 R12=&28 R13=&00. Two differ from appendix F: - **C3**: appendix F gives mode 7's R8 interlace field as 1 ("interlace sync"), with display delay 1 and cursor delay 2, i.e. &91; AUG 18.6.1 says mode 7 is "interlaced sync and video" (field 3), and the MOS writes &93. The firmware and 18.6.1 agree: follow them. - **C4**: appendix F gives mode 7's R7 (vertical sync position) as &1B (27); OS 1.20 writes &1C (28). The firmware is the judge of what the machine does at boot; the table is a book's. - **R8**: every mode is "interlaced sync only" except mode 7, "interlaced sync and video" (DOC: AUG 18.6.1). Mode 7 also sets a one-character display delay (bits 4-5) and a two-character cursor delay (bits 6-7), "because the SAA5050 character generator is used" (DOC: AUG 18.6.2-18.6.3). - **R12/R13** hold the screen start address divided by 8 in modes 0-6 (DOC: AUG 18.10); in mode 7 "take the high byte and subtract &74, then EOR the result with &20" (DOC: AUG 18.11.3), which is the teletext address map below seen from the MOS's side. - **Light pen**: LPSTB comes from the analogue port to both the 6845 and the system VIA's CB2 (DOC: AUG 23.1; MRM "Light Pen"). ## The address path (board, not chip) The 6845's MA0-MA13 and RA0-RA4 are not a RAM address. The board makes one: **Modes 0-6** (DOC: SM section 3.3 and its figure 7; AUG 18.13, 23.2): - RAM address = MA × 8 + RA0-2 (the 8 scan lines of a character are 8 consecutive bytes; "MA4 to MA7 are buffered to A0 to A3", SM 3.3, so the bit wiring is to be transcribed from the schematic, not assumed). - **Hardware wrap-around**: when MA12 = 1 (an address above &7FFF), a 74LS283 adder (IC39) adds a number chosen by the addressable latch's C0/C1 (bits 4 and 5) to the high address lines: 12 KB (modes 0-2), 16 KB (mode 3), 22 KB (modes 4-5), 24 KB (mode 6), so the address comes back into the screen area (DOC: SM 3.3; AUG 23.2 table). Arithmetic is modulo 32 KB. - **Lines 8 and 9 of a 10-line row** (modes 3 and 6) are blank on screen. The mechanism (RA3 set suppressing the display) is **HYPOTHESIS**: to be read from the schematic (SCH) before it is written. **Mode 7** (DOC: SM 3.3): "the top four address lines on the 81LS95 (IC11) are tied to logic 1"; the teletext map is selected when R12/R13 are so high that "an extra carry is generated on MA13", which enables ICs 10 and 11, disables ICs 8 and 9 and enables the data latch IC15 in front of the SAA5050. The RAM address is then &7C00 + MA0-MA9 on a 32 KB machine (&3C00 on a 16 KB Model A: a row field). RA is not used for the address (the SAA5050 gets the scan line itself: [saa5050.md](saa5050.md)). **B+ and Master**: the shadow bit (B+ &FE34 bit 7; Master ACCCON D) decides whether the 6845's fetch reads main or shadow RAM (DOC: SMBP 5.4.3; MRM): one more input to the same function. ## What the specification owes - The chip (registers, counters, sync, interlace, cursor, light pen, display enable with skew) as its own class with no BBC knowledge, stepped one character clock at a time. - The address function above as a pure function of (MA, RA, latch C0/C1, shadow, row) in the board. - The 6845's clock switches between 1 and 2 MHz when Video ULA control bit 4 changes (DOC: AUG 19.1.4): **what happens to a character in progress when the clock changes mid-line** is unknown (U2), and is exactly what split-mode demos exercise. ## Judges | Behaviour | Best judge | Tier | | --- | --- | --- | | register meanings, counters, interlace modes | HD (HD6845S), CRTC (MC6845) | 2 | | the BBC's use, address path, wrap-around | SM 3.3, AUG 18, 23.2, the schematics | 2 | | mid-frame register writes, clock switching mid-line | none in hand at tier 1; b2's `teletest_v1` pictures and the Video ULA test drive (drive 5) are candidates once their pictures' provenance is known | - | | pictures overall | MAME (5), detector only | 5 |