# The video cards: MDA, CGA (the 6845), EGA as a later row Source names: **A81** IBM PC Technical Reference, Aug 1981; **V2** *Options and Adapters* volume 2, Apr 1984 (page n of its MDA section = PDF - 9, CGA section = PDF - 41, EGA section = PDF - 83); **MC** Motorola MC6845 data sheet (PDF pages). reenigne's CGA netlists: `8088/cga/circuit.txt` and `circuit_1501981.txt` (two board revisions, transcribed from IBM's logic diagrams; Unlicense), his notes `8088/cga/notes.txt`. ## The MC6845 CRTC (shared by both cards) - One write-only address register and R0-R17 (MC PDF 9, 11-12, 15): R0-R3 horizontal total, displayed, sync position, sync width (8-bit, write-only); R4 vertical total (7-bit); R5 total adjust (5-bit); R6 displayed and R7 sync position (7-bit); R8 interlace (2 bits); R9 max scan line (5-bit); R10/R11 cursor start (blink mode in bits 5-6) and end; R12/R13 start address (14-bit, write-only); R14/R15 cursor (read/write); R16/R17 light pen (read-only). "Vertical sync pulse width is fixed at 16 scan-line times" on the MC6845 (MC PDF 12). Maximum clock 3.0 MHz (MC PDF 5). - The data sheet gives no rule for *when* a register write takes effect within a frame (MC: not found). The CPC Phase 0 (`../cpc-python/docs/crtc-6845.md`) documents that the counter rules demos depend on (R0/R4/R9 changes mid-frame, R5 adjust) are not in any data sheet and differ between makers' parts. On the CGA they matter just as much: 8088 MPH and Area 5150 reprogram the CRTC mid-frame for their raster effects (MartyPC CREDITS lists both demos; the techniques themselves are recorded in the demos' write-ups, not fetched). - On the CGA the CRTC is clocked by `-CCLK` and its R/W pin is `-IOW` (circuit.txt sheet 1). The CPC Phase 0 found the same R/W wiring makes a read of the data port write the register on the CPC; whether the CGA's decode lets a read reach the 6845 at all is U8. - Which makers' 6845s IBM fitted: MAME's `cga` device uses `mc6845`; IBM's text says only "6845" (U9; the CPC found Motorola, Hitachi and UMC parts behave differently). ## The MDA (Monochrome Display and Printer Adapter) - 80x25, 9x14 character box, 7x9 characters, 720x350, 50 Hz, horizontal 18.432 kHz (A81 p.53, p.59 / 2-37, 2-43; V2 Mono 2). The dot clock is not stated; 16.257 MHz appears only as the display's bandwidth (U10; from 18.432 kHz x 882 dots = 16.257 MHz if the line is 98 characters of 9 dots: R0 = 61h = 97, so 98 characters: arithmetic, consistent). - Ports 3B4/3B5 (CRTC), 3B8 control (bit 0 high resolution, bit 3 video enable, bit 5 blink), 3BA status (bit 0 horizontal drive, bit 3 video), 3BC-3BE printer (A81 p.58-59 / 2-42-2-43). - "If the high resolution mode is not set, an infinite CPU wait-state will occur!" (A81 p.57 / 2-41): the card's wait logic runs off the character clock, so the board's bus model must route MDA accesses through the card's READY (cpu-8088.md). - At least one wait state on every CPU access; "two bytes are fetched ... in 553 ns" (A81 p.55 / 2-39). 4 KB static RAM at B0000 (A81 p.53 / 2-37). - 6845 values for 80x25: 61, 50, 52, 0F, 19, 06, 19, 19, 02, 0D, 0B, 0C (A81 p.57 / 2-41; BIOS table A81 p.236 / A-46). - The ninth-column rule for C0h-DFh (line graphics repeat the eighth dot) is stated only in the EGA section (V2 EGA 58); for the MDA it is HYPOTHESIS until the MDA logic diagram or a test decides (U11). - Character ROM 5788005 (8 KB), shared with the CGA (census.md). ## The CGA (Color/Graphics Monitor Adapter) - Timing source: the system's 14.31818 MHz (A81 p.19 / 2-3); the card speaks of "7 or 14 megahertz video bandwidth depending on the mode" (A81 p.62 / 2-46). Character clocks are not stated (in 80 columns 8 dots at 14.318 MHz; in 40 columns 8 dots at 7.16 MHz: HYPOTHESIS from the 6845 tables, R0 = 71h in 80 columns vs 38h in 40, both giving a 15.7 kHz line). - Ports: 3D4/3D5 CRTC, 3D8 mode (bit 0 80x25, bit 1 graphics, bit 2 B&W, bit 3 video enable, bit 4 640x200, bit 5 blink), 3D9 colour select (bits 0-3 border/background/foreground, bit 4 intensity set, bit 5 palette), 3DA status (bit 0 "can be made without interfering with the display", bit 1 light-pen trigger, bit 2 light-pen switch, bit 3 vertical retrace), 3DB/3DC light-pen latch clear/preset (A81 p.73-76 / 2-57-2-60; V2 CGA 15-21). - **C3:** status bit 3 is "Alpha Dots" in A81 and "vertical retrace" in V2; the BIOS waits on it as vertical retrace (A81 p.241 / A-51). Follow V2 and the BIOS. - 16 KB dynamic RAM at B8000 (the card refreshes it from the CRTC addresses: reenigne notes, "Each of the 128 rows must be refreshed every 2ms"), dual-ported with the CPU. - 6845 tables (A81 p.72 / 2-56): 40x25 `38 28 2D 0A 1F 06 19 1C 02 07 06 07`; 80x25 `71 50 5A 0A 1F 06 19 1C 02 07 06 07`; graphics `38 28 2D 0A 7F 06 64 70 02 01 06 07`. OBSERVED: the 5150 BIOS writes the 80x25 row at boot (mame-oracle.md). - **Snow.** IBM: in high-resolution text "the CPU should access this buffer during the horizontal retrace intervals ... a small amount of display interference will result" otherwise (A81 p.64 / 2-48; V2 CGA 5); the BIOS scroll turns the video off during vertical retrace (A81 p.241 / A-51) and the character read/write routines wait for status bit 0 (A81 p.243-244). The mechanism, from the netlist: "When we have +HRES, we always latch the character ... even on cycles when the CGA's memory address comes from the CPU" (reenigne `cga/notes.txt` l.327-329, DOC-derived from the logic diagram). So in 80-column text a CPU access replaces the character and attribute the card latches in that character slot with the CPU's byte(s). Exactly which slots and bytes are hit is a function of the CPU access's phase against the character clock, which only a bus-cycle-exact board can reproduce (cpu-8088.md). Tier-1 evidence would be a capture of real snow; reenigne's `cga/` holds the test programs (`stability_test`, `lockstep_test2`, `crtc_test`), not captured pictures (U12). - **Composite output and artifact colour.** The composite jack carries "approximately 1.5 Volts peak to peak" (A81 p.78 / 2-62); colour burst is the 14.318 MHz / 4 = 3.58 MHz derivation (A81 p.19 / 2-3); in B&W modes "COLOR BURST IS NOT ENABLED" (BIOS, A81 p.233 / A-43). 640x200 dots at 14.318 MHz are four dots per colour-burst cycle, so on an NTSC monitor patterns of dots become colours (artifact colour); in 80-column text with suitable CRTC settings the same trick gives the 1,024-colour mode of 8088 MPH. The board's job is the composite *signal* per 14.318 MHz dot (the logic diagram's "Composite Color Generator", A81 p.64); decoding it to RGB is a host concern. reenigne's composite colour algorithm is public domain (`8088/cga/`, and credited as MartyPC's composite code in its CREDITS.md); IBM changed the composite generator between board revisions ("old" and "new" CGA, matching the two netlists: U13 to confirm which revision the 1501981 file is). ## The EGA (a later card row) Its own LSI chips, not a 6845: "five large scale integration (LSI) modules custom designed for this controller" (V2 EGA 1); four 16 KB planes (64 KB, to 256 KB with expansion); 14 MHz (from the bus) and 16 MHz clocks selected in 3C2 bits 3-2 (V2 EGA 5, 13); sequencer, CRTC (at 3B4 or 3D4), graphics controller, attribute controller; BIOS 6277356 (16 KB, census.md). Modes 0-6 emulate the CGA, mode 7 the MDA (V2 EGA 5-6). A Phase 0 of its own when the 5160 rows are done.