# The LCD controller and its DMA DS p. 33-40 (tier 2), and what the firmware does under MAME (OBSERVED, tier 5). ## VRAM and pixels (DS p. 34) - Two pages, A (A000-BFFF) and B (C000-DFFF), each 160 x 200 dots (or 200 x 160) at 2 bits per dot: 8,000 bytes used of 8 KB. **Four dots per byte, dot 0 in bits 7-6**, dot 3 in bits 1-0 (Fig. 16). - LCC bit 6 chooses the page shown; the firmware alternates B0h / F0h (page A / page B: double buffering, OBSERVED, 16 writes of each in 300 frames). ## LCD timing (DS p. 37-38) - LCC (0030): bit 7 display on; bit 6 page; bits 5-4 gradation (which of five grey levels each of the four colours shows: `00` black, gray 1, gray 2, white; `01` black, gray 1, gray 3, white; `11` black, gray 2, gray 3, white; `10` reserved); bits 3-1 LCDC/DMA clock fCK/2, /4, /6 ... /16; bit 0 "normal white / normal black". - LCH (0031): bit 5 H-dot size 160 or 200; bits 4-0 H-timing. - LCV (0032): bit 7 V-blank (read only); bits 5-4 V-lines 100, 160, 200; bits 3-0 V-blank width (must not be 0, or the LCDC interrupt never comes). DS's text says "bits 4 to 0" for the width while its bit diagram shows VBWD3-0 in bits 3-0 (**C1**). - Formulas (DS p. 37): horizontal display cycle = (shift clock x LCDC/DMA clock) x (H-timing + 1), shift clock 40 (160 dots) or 50 (200 dots); frame cycle = horizontal display cycle x (V-lines + V-blank width). **The firmware's settings** (OBSERVED): LCC = B0h (on, page A, gradation 11, fCK/2), LCH = 07h (160 dots, H-timing 7), LCV = 27h (200 lines, V-blank width 7). By DS's formulas, with the LCDC/DMA clock period = 2 fCK periods: 40 x 2 x 8 = 640 fCK periods a line, 640 x 207 = 132,480 a frame, **83.48 Hz**. MAME's screen says **59.732155 Hz** (11,059,200 / 59.732155 = 185,146 fCK periods). **C2**: the two disagree by 40%. Either the formula's units are read wrongly here (shift clock in LCDC clocks per dot group? H-timing counted otherwise?) or MAME's figure is not derived from the registers. No measurement exists. The build implements DS's formula as written, records C2, and keeps MAME's frame rate as a detector only. The LCDC interrupt (vector 100E, priority 5) and the V-blank bit: when the interrupt fires in the frame (start of V-blank, HYPOTHESIS from the note tying it to the V-blank width) is **U6**. ## The DMA (DS p. 33-40) A rectangle blitter in dot units: - DMC (0034): bit 7 start; bit 4 source y decrement; bit 3 source x decrement (with each 4-dot group mirrored left-right, so x-decrement draws a horizontally flipped image: DS p. 39); bits 2-1 mode: `00` VRAM to VRAM, `01` ROM to VRAM, `10` extend RAM to VRAM, `11` VRAM to extend RAM; bit 0 compound (0: source colour 0 is transparent) or overwrite. - DMX1/DMY1 source x, y; DMDX/DMDY width - 1, height - 1 (up to 256 x 256); DMX2/DMY2 destination x, y. - DMPL (003B): a palette: each source colour 0-3 is replaced by a 2-bit value before it is stored (bits 7-6 for colour 0 ... 1-0 for colour 3). - DMBR (003C): the ROM bank, in units of a 256 x 256-dot (16 KB) image, "irrespective of MMU": 7 bits, 128 x 16 KB = 2 MB. - DMVP (003D): bit 1 destination page, bit 0 source page. - **Start sequence (DS p. 37):** set the registers, set DMC bit 7, **execute HALT**; the DMA then runs and its end raises the DMA interrupt (vector 1000, priority 1), which wakes the CPU. The firmware does exactly this (OBSERVED: 3,652 DMC writes and HALT executed 148 times in the first 2 s; IE0 toggled between 00h and 80h around each). Unknown: the DMA's speed (bytes or dots per LCDC clock) **U7**; what happens if the CPU does not HALT **U8**; whether the LCD keeps refreshing during a DMA (it fetches the same VRAM) **U9**; the exact dot order of a transfer when source and destination overlap in VRAM-to-VRAM mode **U10**. ## Modelling level Video timing and the LCDC interrupt at cycle level (they are what software can see); the DMA as a transaction (each rectangle's dots in its defined order, with a busy time once U7 is known, FITTED from MAME until then); pictures from the shown page through the gradation table. This is the transaction-level pattern the charter allows, and the DMA log is a pure producer for later tiers.