# The two 2D engines, the capture unit and the display Source: GBATEK "DS Video" (Stuff, BG Modes/Control, OBJs, Extended Palettes, Capture and Main Memory Display Mode, Display System Block Diagram); DOC unless marked. The DS has two 2D engines, **A** (main: registers at 4000000h) and **B** (sub: 4001000h), each "an extended variant of the GBA's video controller" (GBATEK "DS Technical Data"), feeding two 256 x 192 LCDs with 18-bit colour; POWCNT1 bit 15 chooses which engine drives which screen. ## Display timing Dot clock 5.585664 MHz = bus clock / 6; 355 dots per line (256 visible, 99 blank), 263 lines (192 visible, 71 blank), 59.8261 Hz. VCOUNT 0-262 (9 bits; LYC in DISPSTAT bits 8-15 and 7); VBlank flag in lines 192-261, not 262 (as on the GBA). H-blank flag "0" for 1,606 cycles on the ARM9 (1,613 on the ARM7) although drawing takes 1,536. VCOUNT is writable (lines 202-212) to synchronise linked consoles. The 3D engine's own V-blank is lines 191-213 (video-3d.md). ## What carries over from gba-python gba-python (`../gba-python`, rungs 0-6 built and judged; its docs/video.md and `src/gba_python/ppu/`) specifies the GBA's picture processor at line level (rung 3) and at dot level with VRAM/palette/OAM contention (rung 4). For each part, what the DS changes: | Part | GBA (gba-python) | DS engine A / B | Carries over | | --- | --- | --- | --- | | Text BGs (4) | 4/8 bpp tiles, 32x32-64x64 maps, scroll, flip | same, plus **extended palettes** (BG 256-colour with 16 palettes of 256 per BG, in VRAM slots) and 64 KB-step char/screen bases in DISPCNT | the tile/map fetch and composition rules, as specification text and judged behaviours | | Affine BGs | 8-bit maps, 2 BGs | same, plus **extended affine**: 16-bit map entries (flip, palette), 256-colour bitmap, direct-colour bitmap; engine A mode 6 "large" 512 KB bitmap | the affine stepping (reference points latched per frame, incremented per line) | | Bitmap modes 3-5 | fixed-size bitmaps | replaced by the extended affine bitmaps | | | BG0 | 2D | engine A: 2D or **3D** (DISPCNT bit 3), with a horizontal scroll | composition with a 3D layer is new | | OBJs | 128 OBJs, 1D/2D mapping (32 KB) | 128 per engine; tile mapping 1D with 32-256 KB boundaries; **bitmap OBJs** (direct colour, 2D 128x512/256x256 or 1D); extended OBJ palettes; OBJ processing in H-blank bit moved to DISPCNT 23 | the OBJ evaluation and the per-line cycle budget idea; the budget numbers differ (U2) | | Windows | 2 + OBJ window | same; but Y compares use only 8 bits of the 9-bit line count, so Y1 = 0-6 also trigger in lines 256-262 ("DS Window Glitches"); X2 = 0 means 256 | the window logic, with the glitch added | | Colour effects, mosaic | BLDCNT, BLDALPHA, BLDY, MOSAIC | same, plus 3D alpha blending of BG0 with the layers beneath (U3) | | | Output | 15-bit to the LCD | 15/18-bit; **master brightness** per engine (6-bit intensity up/down); engine A display modes: off (white), normal, **VRAM display**, **main memory display** (a bitmap streamed by DMA mode 4) | | | Capture | none | engine A's **capture unit**: writes a line of the 3D or 2D output, optionally blended with VRAM or main-memory source, into a VRAM bank (A-D) | new | | VRAM | fixed 96 KB | nine banks mapped by VRAMCNT (memory-map.md); the engines see whatever is mapped | the access rules must be re-derived | | CPU/VRAM contention | the CPU waits on VRAM, palette and OAM while the PPU reads them (gba-python rung 4) | ARM9 waits 1 cycle when the display controller reads VRAM in the same 6-cycle slot (removable with forced blank); capture adds VRAM writes; ARM7-mapped VRAM is wait-free | the method (a dot-level model that knows which slot the PPU uses) | So what carries over is **the specification knowledge and the test-judged behaviours**, not code: the DS engine is a larger chip with different memory, timing and features. The chip rule keeps the DS engines in nds-python; an extraction of a shared "AGB/NTR 2D engine" core is an Open decision to revisit once both exist (handoff-brief.md). The GBA picture in **GBA mode** is the GBA's own picture processor (the DS runs as a GBA, GBATEK "DS Backwards-compatible GBA-Mode"), framed by a border that engine A captures from VRAM A/B each frame: that mode is gba-python's board with a DS model row, not this engine. ## Modelling level (proposal) Line level first (as gba-python's rung 3), then a dot-level model of VRAM reads and register latching where test ROMs show mid-line effects (as gba-python's rung 4). The 6 bus cycles per dot make a dot model cheaper per CPU cycle than the GBA's (4 per dot), but two engines and capture double the work. ## Unknowns (U) and contradictions (C) - U1 Which mid-line register writes take effect at the dot, and which are latched per line on the DS (gba-python's dispcnt-latch and bgx tests have no DS equivalents found). - U2 The DS OBJ cycle budget per line (GBA: 1,210 / 954 cycles; DS: not documented). - U3 How 3D BG0's alpha blends with the 2D layers (GBATEK "DS Video Display System Block Diagram" describes the path; per-pixel details belong to video-3d.md's judges). - U4 Master brightness rounding at 6 bits; the 18-bit output's low bit (how 15-bit colours are expanded) per model (DS vs DS Lite LCDs differ in colour, GBATEK). - U5 Capture's exact timing (which line of which frame lands where, and VRAM wait slots). - U6 What engine B does with the bits it lacks (mode 6, display modes 2-3, BG0 3D): reserved behaviour.