# Video: the picture processor Tags as in [README.md](README.md). Register bit layouts are GBATEK §GBA LCD Video Controller and its sub-sections (`DOC`); this page gives the behaviour and where the evidence is thin. ## Timing | Quantity | Value | Source | | --- | --- | --- | | dot | 4 cycles | GBATEK §LCD Dimensions and Timings; `DOC` | | line | 308 dots = 1,232 cycles: 240 visible, 68 H-blank | `DOC` | | frame | 228 lines = 280,896 cycles: 160 visible, 68 V-blank | `DOC` | | VCOUNT | 0-227 | GBATEK §LCD I/O Interrupts and Status; `DOC` | | V-blank flag | set in lines 160-226, **not 227** | `DOC` | | H-blank flag | 0 for 1,006 cycles of each line ("Although the drawing time is only 960 cycles (240*4), the H-Blank flag is "0" for a total of 1006 cycles"), in all 228 lines | `DOC`. CowBite says H-draw "approximately 1004 cycles" and H-blank "approximately 228" (`DOC`, approximate). destoer `line_timing.sav` holds `0x3EE` (1,006) as the measured value; the detectors print 1,012 (mGBA) and 1,004 (NBA) (`OBSERVED`). Rung 4: 1,007 by hw-test `ppu/status-irq-dma` (`TEST ROM`; "The dot model as built"). U-VID-1 | | V-count match flag | set while VCOUNT = DISPSTAT bits 8-15 | `DOC` | | V-blank IRQ | at the start of line 160 | gbadoc interrupts.md; `DOC` | | H-blank IRQ | at the H-blank flag's rise; GBATEK contradicts itself on V-blank lines: "The H-Blank conditions are generated once per scanline, including for the 'hidden' scanlines during V-Blank" (§LCD I/O Interrupts and Status) against "no H-Blank interrupts are generated within V-Blank period" (§LCD Dimensions and Timings). gbadoc: "H-blank interrupts DO occur during v-blank ... Thanks to gbcft for verifying this" | U-VID-2 | | H-blank DMA | lines 0-159 only | gbadoc registers.md; `DOC` | | video capture DMA | VCOUNT 2 to 162 | GBATEK §GBA DMA Transfers; `DOC` | The exact cycle within the line at which VCOUNT changes, the flags rise and fall, and the IRQs and DMAs are requested is what hw-test `ppu/status-irq-dma` measures (an interactive menu: its results are shown on screen per sub-test and read by eye) and what the mGBA suite's "H-blank bit start" edge-case tests check (both detectors fail 5-6 of them, [validation.md](validation.md)). The archived hw-test `basic-timing` README describes the quantities: "H-blank DMA start time (relative to when VCOUNT changes), H-blank flag set and unset time (relative to H-blank DMA), V-count coincidence flag set and unset time, H-blank IRQ assertion time" (`TEST ROM` prose; the ROM itself was "replaced or deemed unfit", archive/README.md). U-VID-1. ## Forced blank, display enables, latches - DISPCNT bit 7 (forced blank): white lines; all video memory freely accessible (GBATEK §LCD I/O Display Control; `DOC`). GBATEK quotes, unexplained: "When the internal HV synchronous counter cancels a forced blank during a display period, the display begins from the beginning, following the display of two vertical lines." (U-VID-3). - DISPCNT changes take effect per line: hw-test `ppu/dispcnt-latch` toggles BG, OBJ, WIN0/1 enables and forced blank per scanline against a hardware photograph (`TEST ROM`). Which DISPCNT fields latch at which point of a line is not written down; the photograph is the judge. - Affine reference points: BG2X/Y, BG3X/Y are copied to internal registers each V-blank; the internal registers advance by PB/PD (dmx, dmy) after each line; "Writing to a reference point register by software outside of the Vblank period does immediately copy the new value to the corresponding internal register" (GBATEK §LCD I/O BG Rotation/Scaling; `DOC`). hw-test `ppu/bgx` ("tests when BG2X/BG3X are latched after they have been written") and `ppu/bgpd` ("when BG2PD / BG3PD are latched") are judged by hardware photographs (`TEST ROM`). NBA's pictures match both photographs, mGBA's match neither (OBSERVED, read by eye). - Green swap (`04000002` bit 0): for each pair of dots the green intensities are exchanged, on the final picture (GBATEK; `DOC`); hw-test `ppu/greenswap` photograph (by eye the two detectors differ and the photograph does not decide: U-VID-4). ## Backgrounds Modes (GBATEK §LCD I/O Display Control; `DOC`): | Mode | BG0 | BG1 | BG2 | BG3 | | --- | --- | --- | --- | --- | | 0 | text | text | text | text | | 1 | text | text | affine | - | | 2 | - | - | affine | affine | | 3 | - | - | bitmap 240x160, 15-bit | - | | 4 | - | - | bitmap 240x160, 8-bit, two frames | - | | 5 | - | - | bitmap 160x128, 15-bit, two frames | - | Modes 6 and 7 are "prohibited"; what they show is not documented (U-VID-5). - **Text BGs** (GBATEK §LCD I/O BG Control, §LCD VRAM BG Screen Data Format; `DOC`): BGxCNT priority, character base (16 KB units), mosaic, 4/8 bpp, screen base (2 KB units), size (256x256 to 512x512 as one to four 32x32-entry maps at base, +2K, +4K, +6K); map entries: tile 0-1023, H/V flip, palette; 9-bit H/V scroll, always wrapping. - **Affine BGs**: 8-bit tiles only, one-byte map entries (tile 0-255), size 128 to 1024 dots square, bit 13 overflow: wrap or transparent; the point for screen x on a line is the internal reference point plus x times (PA, PC), 8.8 fixed point parameters and 20.8 reference points (§LCD I/O BG Rotation/Scaling; `DOC`). Bitmap modes are always transparent outside the bitmap. - **Bitmap modes**: mode 3 at `06000000` (480 bytes a line), mode 4 one byte a dot through BG palette (colour 0 transparent), frame select at `0600A000`; mode 5 160x128 (§LCD VRAM Bitmap BG Modes; `DOC`). Bitmaps are BG2 with affine support. - **Character data beyond 64 KB** in text modes: "On GBA and GBA SP, such invalid tiles are displayed as if the character data is filled by the 16bit BG Map entry value ... with two or more layers, things are getting much more complicated" (GBATEK §GBA Unpredictable Things; `DOC`; U-VID-6). - **Priority**: BG priority 0-3, equal priorities ordered BG0 first (§LCD I/O BG Control; `DOC`). ## OBJs (GBATEK §LCD OBJ - Overview, OAM Attributes, Rotation/Scaling Parameters, VRAM Character Mapping; `DOC`) - 128 entries of three attributes; the 32 affine parameter groups live in the fourth halfwords. - Attribute 0: Y (0-255), affine flag, double size (affine) or disable (not affine), mode (normal, semi-transparent, OBJ window, prohibited), mosaic, 4/8 bpp, shape. Attribute 1: X (9 bits), affine group (affine) or H/V flip, size. Attribute 2: tile, priority, palette. - Sizes 8x8 to 64x64 in three shapes; shape 3 is prohibited (U-VID-5). - "A very large OBJ (of 128 pixels vertically, ie. a 64 pixels OBJ in a Double Size area) located at Y>128 will be treated as at Y>-128": Y wraps at 256 (`DOC`). - Tile mapping: 2D (a 32x32-tile matrix; 16x32 in 8 bpp) or 1D (consecutive); in 8 bpp the tile number's low bit "should be zero (in 2-dimensional mapping mode, the bit is completely ignored)". In bitmap modes tiles 0-511 are not displayed. - OBJ priority: lower OAM index wins among OBJs; an OBJ is above BGs of equal priority. The OBJ layer resolves to one top-most OBJ dot before blending ("not for OBJ-to-OBJ"). - **Rendering budget**: 1,210 cycles a line (304 x 4 - 6), or 954 (240 x 4 - 6) with "H-Blank Interval Free"; a normal OBJ costs n cycles for n dots of width, an affine OBJ 10 + 2n, and off-screen OBJs with higher priority still cost. GBATEK asks: "Does the above also apply for VERTICALLY OFFSCREEN ... sprites?" (§LCD OBJ - Overview; `DOC`; U-VID-7). - OBJs are drawn for the next line during the current one: alyosha-tas `ppu/Sprite_Disable_Midline` says "enable sprites at scanline 0 / will render one scanline earlier" (source comment; `TEST ROM`, a picture test without a stored expectation). - The OBJ window: non-transparent dots of OBJs in mode 2 mark the window; they are not drawn (§LCD I/O Window Feature; `DOC`). - OBJ VRAM access at the end of the budget: alyosha-tas `ppu/Sprite_Last_VRAM_Access`, `_Free` (text verdicts) and `Sprite_Disable_on_VRAM_Access` (picture) judge which fetch is the last one that still shows. ## Windows WIN0H/WIN1H (X1 left, X2 right + 1), WIN0V/WIN1V; WININ, WINOUT; window 0 over window 1 over the OBJ window over outside; a layer shows only if both DISPCNT and the window's bit enable it; each region enables colour effects (GBATEK §LCD I/O Window Feature; `DOC`). "Garbage values of X2>240 or X1>X2 are interpreted as X2=240", likewise Y2>160 or Y1>Y2 as Y2=160 (`DOC`). Whether the window's vertical test is evaluated per line from a latched start/stop flag (so a mid-frame write changes what follows) is what destoer `window_midframe` shows (picture; no expectation in its repository; detectors differ: U-VID-8). ## Colour effects (GBATEK §LCD I/O Color Special Effects; `DOC`) - BLDCNT: first-target layers (BG0-3, OBJ, backdrop), effect (none, alpha, brighten, darken), second-target layers. BLDALPHA: EVA, EVB (0-16, values 17-31 act as 16). BLDY: EVY. - Alpha: `I = min(31, I1*EVA/16 + I2*EVB/16)` per channel, only when the top-most dot is a first target and the next-lower non-transparent dot is a second target; otherwise the top dot unchanged. - Brighten: `I = I1 + (31 - I1)*EVY/16`; darken: `I = I1 - I1*EVY/16`. - Semi-transparent OBJs are always first targets and always alpha-blend if a second target is below, overriding BLDCNT's effect; if there is no second target below, BLDCNT's brightness effect may apply to them. - The rounding of the /16 (truncation) is not stated by GBATEK (HYPOTHESIS: truncate; jsmolka `ppu/shades` and alyosha-tas `ppu/shades` are picture tests without stored expectations: U-VID-9). ## Mosaic MOSAIC: BG H/V size, OBJ H/V size (value + 1 dots). "When setting H-Size to 5, then pixels 0-5 of each display row are colorized as pixel 0, pixels 6-11 as pixel 6" (GBATEK §LCD I/O Mosaic Function; `DOC`). Vertical mosaic for BGs counts lines from line 0 (HYPOTHESIS). OBJ horizontal mosaic: hw-test `ppu/sprite-hmosaic`, whose expected.png is **a NanoBoyAdvance 1.8.2 screenshot**, not a photograph (its window title shows), so it is a detector's picture (U-VID-10). For affine BGs, how mosaic applies to the affine walk is not documented. ## Colour and the LCD Colours are 15-bit BGR (bits 0-4 red, 5-9 green, 10-14 blue); palette colour 0 is transparent; BG palette entry 0 is the backdrop (GBATEK §LCD Color Palettes; `DOC`). "The intensities 0-14 are practically all black" on the original GBA's LCD, and the LCD shows "some sort of interlace in which even scanlines are dimmed in each second frame" (§LCD Color Palettes, §LCD Dimensions and Timings; `DOC`). The board outputs the 15-bit values; any colour correction for the LCD is a host choice, not the board's (a statement of scope, not of behaviour). ## CPU access to video memory "The CPU appears to be able to access VRAM/OAM/Palette at any time, a waitstate (one clock cycle) being inserted automatically in case that the display controller was accessing memory simultaneously" (GBATEK §GBA Memory Map; `DOC`). OAM during H-blank needs "H-Blank Interval Free". Which cycles of a line the picture processor uses each memory for, per mode and layer, is not documented: hw-test `ppu/ram-access-timing` measures the stall pattern cycle by cycle for each layer setup (an interactive menu that draws the stall map; read by eye), the archived hw-test `mode2/3/4` README says they "test VRAM fetch timing" against photographs (replaced, but the photographs remain), and alyosha-tas `ppu/*` time CPU accesses against OBJ fetches. The schedule the board uses is therefore HYPOTHESIS and `FITTED` to those tests at rung 4 (U-VID-11). ## The dot-level model (rung 4) Rung 3 draws a line at a time from the registers at the line's start. Rung 4 must draw where a line changes mid-draw (hw-test `dispcnt-latch`, destoer `lyc_midline` and `window_midframe`, alyosha-tas `ppu/*`). No document gives the per-dot fetch order; the board's dot-level model is built from the tests and the test authors' prose, each choice tagged with the test that fixes it. destoer `lyc_midline`'s expected.jpg is a photograph of a dual-screen console (a DS-family unit, so a GBA-mode result, not an AGB-001's; `TEST ROM` with that caveat): start 7, end 0x3F, vcount 0x24, then "rapid toggle" start 0xDC0B, end 0xE0AA, lyc count 6. NBA prints the same numbers, mGBA does not (OBSERVED). ## The dot model as built (rung 4, 2026-11-21) `ppu/dots.py` draws each visible line by catching up: before a write that could change a dot not yet drawn (an LCD register, palette RAM, VRAM, OAM; by the CPU or DMA) the dots whose fetch time has passed are drawn with the state as it stood, then the write lands; the rest of a line is drawn at the next line's origin. `ppu/timing.py` counts every line from its **origin**, the cycle VCOUNT changes. Rung 3's `ppu/line.py` stays as the specification: on every line where nothing changes (from the previous line's origin, when the OBJ fetch for the line begins, to the line's end) the two agree dot for dot (`scripts/lockstep_pictures.py`, validation.md "Rung 4"). | Rule | Choice | Evidence | | --- | --- | --- | | line edges | from the origin: V-count flag +1, V-blank DMA request +1, IF V-blank +2, IF V-count +3, video capture DMA +4, H-blank flag +1,007, H-blank DMA +1,008, IF H-blank +1,009; VCOUNT, the V-blank flag and the H-blank flag's fall at the origin | `TEST ROM`: hw-test `ppu/status-irq-dma`'s expected values, 12/12. The H-blank flag is 0 for 1,007 cycles: over GBATEK's 1,006 (`DOC`) by one (U-VID-1) | | power-on | the board's cycle 0 is cycle `POWER_ON` = 3 of line 0, which keeps every IRQ at the cycle rung 1 fitted | `HYPOTHESIS`; alyosha-tas `ppu/start_up*` would judge it once the BIOS boot's length is right (they fail: U-VID-16) | | V-count flag on an LYC write | follows VCOUNT = LYC at once; its rise requests the IRQ two cycles later | `TEST ROM`: destoer `lyc_midline`'s photograph (vcount 0x24, 6 IRQs in one line of rewrites); the delay after a write `HYPOTHESIS` | | video capture DMA | starts at line 2 for a DMA3 enabled in special timing then, requests in lines 2-161 at origin +4 | `TEST ROM`: status-irq-dma "VIDEO DMA" (an enable in line 158 waits for line 2); every later line `HYPOTHESIS`; GBATEK's "VCOUNT 2 to 162" (`DOC`) | | video capture end | at VCOUNT 162 the capture ends and DMA3's enable clears, so a repeating capture runs one frame (rung 6) | `DOC`: GBATEK "it gets stopped when VCOUNT=162", "Capture Enable=AutoCleared ???"; `TEST ROM`: the AGS aging cartridges' DMA test 7 (validation.md "Rung 6"); the enable bit as the mechanism is provisional (U-DMA-3) | | dot fetch time | dot x at origin + `FETCH_START` + 4x, `FETCH_START` = 37 (36-38 fit) | `TEST ROM` prose: "PPU begins to fetch the BG2 bitmap 32 cycles into the scanline. It fetches a single pixel from the bitmap every four cycles" (hw-test archive `mode3`, `mode4`, source comments); `FITTED` to their photographs (DS-family console; edges at dots 120 and 180, alternating by one or two dots between lines as the board's do). Text and affine BGs, palette, windows and effects are sampled at the same time: `HYPOTHESIS` | | affine reference points | advanced (or reloaded at line 160) and taken for the line at origin + 2 (1-2 fit); writes later in the line do not change it | `TEST ROM`: hw-test `bgx` (column at dot 129; 0 gives 130, 3 gives 128), `bgpd` (first edge 75) | | green swap | applied to a dot pair 34 cycles after its fetch, with the register's value then | `FITTED` to hw-test `greenswap`'s photograph: the swap ends at dots 78-81 (the board: 80); the fetch time alone would end it at 89 | | DISPCNT inside a line | a BG shows at a dot only if enabled in the line's latched copy and at the dot; forced blank if set in either; OBJ display likewise; the OBJ fetch reads VRAM only while the OBJ bit is set now | `TEST ROM` prose (hw-test `ram-access-timing` source comments, the author's hardware findings): "BG VRAM fetch happens only if both the latched and current BG enable bit are set", the same for forced blank; "OBJ VRAM fetch happens only if the current OBJ enable bit is set (the latched one is disregarded)"; OBJ display `HYPOTHESIS` | | OBJs one line ahead | the OBJs of line y+1 are fetched in line y, from origin + `OBJ_START` = 16, OAM in order, n cycles per normal OBJ (dot i in cycle i), 10 + 2n per affine OBJ (dot i in 10 + 2i), within 1,210 or 954 cycles; lines 227 and 0-158 fetch for 0-159 | `TEST ROM`: alyosha-tas `Sprite_Disable_Midline` ("will render one scanline earlier"); budgets `DOC`; `OBJ_START` `FITTED` to `Sprite_Last_VRAM_Access_Free` (15-16 pass with the free BIOS; with Nintendo's the test's VCOUNT poll lands 9 cycles later and 24-25 would pass: provisional, U-VID-16) | | an OBJ only part of which fits | read until the budget runs out; its fetched dots show; no OBJ after it | `TEST ROM`: `Sprite_Last_VRAM_Access_Free` expects a wait on VRAM in the budget's last cycles, which only such reads fill (U-VID-14 closed); its dots showing `HYPOTHESIS` (NBA shows them). Rung 3's renderer follows the same rule | | windows' vertical test | a flag per window, set at an origin where VCOUNT = Y1, cleared where VCOUNT = Y2 (the clear after the set), in all 228 lines | destoer `window_midframe`: the author's model in its source and its expected screenshot (origin not stated, H?), which the board matches dot for dot; GBATEK's "Y1>Y2 ... Y2=160" (`DOC`) agrees on lines Y1-159, not on lines 0..Y2-1 of the next frame: `HYPOTHESIS`, provisional (U-VID-8) | | video-memory waits | one cycle per access cycle that meets a picture-processor read, then the access proceeds | GBATEK "a waitstate (one clock cycle)" (`DOC`); waiting until free fails `Sprite_Last_VRAM_Access_Free` | | palette reads | at each dot's fetch cycle, unless the top dot is a direct-colour bitmap dot; a second two cycles later when the dot is alpha-blended with a second colour from the palette | `TEST ROM` prose: the PRAM stall patterns beside ram-access-timing's options ("1000", "1010", "0000", "0010"), 11/11 | | OBJ VRAM and OAM reads | VRAM in each cycle an OBJ dot is read; OAM in an affine OBJ's 10 parameter cycles | `Sprite_Last_VRAM_Access_Free` for VRAM; OAM `HYPOTHESIS` (no judge: blind spot) | | BG VRAM reads | bitmap: one per dot at its fetch cycle; affine: two per dot (BG2 cycles 0-1, BG3 2-3); text: per 8 dots a map read and 2 (4 bpp) or 4 (8 bpp) tile reads at cycle 8n of the 32 | bitmap from the mode3/mode4 prose; the rest `HYPOTHESIS` (U-VID-11). destoer `lyc_midline` bounds the text rule: its printing must wait 37 cycles; this rule gives 60, no rule of whole contiguous reads fits (2 reads give 0-8 at any position) | ## The line renderer as built (rung 3, 2026-11-21) `ppu/line.py` draws each visible line whole at the line's start (cycle 0, when VCOUNT changes), from the registers, VRAM, palette and OAM as they stand then; `ppu/timing.py` keeps the per-line latches and hands the finished frame over at the start of V-blank (`GBA.picture()` returns the last finished frame). Changes made while a line is drawn take effect on the next line: that is rung 4's matter (mid-line writes are seen in hw-test `bgx`'s DMA, `greenswap`, alyosha-tas `stripes_x_offset`, `Sprite_Disable_*` and destoer `window_midframe`). Evidence per rule, beyond the GBATEK sections cited above (`DOC`): | Rule | Choice | Evidence | | --- | --- | --- | | affine reference points | copied to internal registers at the start of line 160; advanced by PB/PD at the start of each line 1-159, before drawing, with PB/PD as they stand then; a write copies at once | `DOC` (GBATEK); the advance's time `TEST ROM`: hw-test `bgpd`'s photograph shows two bands (PD read near the line's start; read at H-blank gives three, as mGBA shows); the copy at line 160 `HYPOTHESIS` | | DISPCNT display bits | sampled at every line's start; a BG or OBJ enable, or forced blank's end, shows on the third line that sees it; disabling and forced blank's start at once; window enables at once | `TEST ROM`: hw-test `dispcnt-latch`'s expected picture (lines 8-9, 24-25, 72-73 and 32-56), with GBATEK's "two vertical lines" quote (U-VID-3); NBA agrees (`OBSERVED`); mechanism `HYPOTHESIS` | | OBJs | drawn for the line at its start (not one line ahead) | `HYPOTHESIS` at line level; the one-line-ahead fetch is rung 4 | | OBJ against OBJ | colour from the lowest OAM number; priority the best among the OBJs on the dot | `DOC` (GBATEK, Tonc §24) for the effect, U-VID-12 | | OBJ budget | 1,210 or 954 cycles; normal n, affine 10+2n (box width); OBJs on the line only; an OBJ that does not fit ends the line's OBJs | `DOC`; U-VID-7 and U-VID-14 `HYPOTHESIS` | | OBJ details | X 9-bit (256-511 to the left), Y wraps at 256, disabled OBJs skipped, tiles wrap within OBJ VRAM, bitmap modes hide OBJ VRAM below 0x14000, 2D mapping linear | `DOC`; wraps and 2D past column 31 `HYPOTHESIS` (U-VID-15) | | mosaic | counted on the screen from dot 0 and line 0; affine BGs use the reference point of the mosaic block's first line; OBJ blocks starting outside the OBJ take its first dot or line | GBATEK's example `DOC`; the rest `HYPOTHESIS` (U-VID-10) | | windows | GBATEK's garbage rule (X2>240 or X1>X2 means X2=240, likewise Y) evaluated per line; OBJ window needs DISPCNT bits 12 and 15 | `DOC`; U-VID-8 | | colour effects | GBATEK's formulas truncated once; semi-transparent OBJs blend over a second target whatever BLDCNT's mode, else BLDCNT applies to them; the window's effect bit gates all of it; a backdrop dot is not blended with itself | `DOC`; rounding U-VID-9, gating of semi-transparent OBJs and U-VID-13 `HYPOTHESIS` | | text tiles beyond 64 KB | the map entry's value as tile data | `DOC` (single layer; U-VID-6); NBA agrees on scene `textoverflow` | | modes 6-7, OBJ shape 3 and mode 3 | no BGs; OBJ not drawn | `HYPOTHESIS` (U-VID-5); NBA agrees on mode 6, draws shape 3 | | green swap | per pair of dots on the final line | `DOC`; NBA agrees where swap is on for the whole line | The judges and every score are in [validation.md](validation.md) "Rung 3".