This page goes deeper than the picture unit summary. It is our own wording of the raw Pan Docs Markdown (CC0, read 2026-11-19, kept in the site’s sample sources with SHA-256 in the sample README); each section names its file. The sources are Pan Docs, the Mooneye acceptance tests for the picture unit, the SameBoy source (display.c and memory.c), the gbdev wiki and the blargg test ROMs; each section names the ones it uses. We ran no ROM and no emulator, and we had no hardware. What the Mooneye tests, SameBoy and blargg report about real consoles is stated on this page as their statement, not as something we measured. Where Pan Docs says a point is unconfirmed, this page says so. The register bits are on the register bit layouts page.
PPU modes and timing
Source: Rendering.md.
A frame is 154 lines. The first 144 are drawn from top to bottom and left to right, straight to the screen. The picture is not built first and shown after. Changing a rendering parameter in the middle of the frame is therefore visible. This is called a raster effect. The best known is changing the scroll registers between lines to make a wavy picture.
A dot is one tick of the 4.194 MHz clock (222 Hz). There are 4 dots in a normal-speed M-cycle and 2 in a double-speed one, so dots do not change with CPU speed. One frame takes about 16.74 ms, not 16.67 ms: the console is 0.45 % slower than 60 Hz.
Pan Docs’ STAT page puts the same unit this way: a dot is the shortest time in which the PPU can output one pixel. It equals 1 T-cycle on the DMG and on the Color in normal speed, and 2 T-cycles on the Color in double speed. In mode 3 every dot either sends a pixel or is a stall of the FIFOs. VBlank is ten lines of 456 dots, 4560 dots. At 4194304 dots a second that is 1.087 ms; Pan Docs gives about 1.1 ms for the time the video memory is free in VBlank (Interrupt_Sources.md).
| Mode | What happens | Length | Memory the CPU can reach |
|---|---|---|---|
| 2 | Searching for objects that overlap this line (OAM scan) | 80 dots | VRAM, Color palettes |
| 3 | Sending pixels to the screen | 172 to 289 dots | none |
| 0 | Waiting for the end of the line (HBlank) | 376 minus the length of mode 3 | VRAM, OAM, Color palettes |
| 1 | Waiting for the next frame (VBlank) | 4560 dots, 10 lines | VRAM, OAM, Color palettes |
A line is therefore 80 + 376 = 456 dots whatever mode 3 does. While the PPU uses a memory, the CPU cannot: writes are ignored and reads return rubbish, usually $FF.
Mode 3 length and its penalties
In mode 3 the PPU normally sends one pixel per dot, left to right. The screen is 160 pixels wide, so the shortest mode 3 is 160 + 12 = 172 dots. The 12 extra dots are two tile fetches at the start. One of them gives the first tile of the line, shifted by SCX mod 8 pixels. The other is simply thrown away.
Unlike a home console, the Game Boy can pause, because it drives its own screen. Any pause makes mode 3 longer and, because the line has a fixed length, mode 0 shorter by the same amount. Pan Docs names three causes:
- Background scrolling. At the very start, drawing waits for SCX mod 8 dots while that many pixels are discarded from the leftmost tile.
- The window. After the last background pixel, a 6-dot pause sets the background fetcher up for the window.
- Objects. Each object drawn on the line, even partly, costs 6 to 11 dots (the algorithm is below).
On the DMG and on a Color running a monochrome game, a write to BGP in the middle of a line shows the length of these pauses exactly, because each pause moves the effect of the write that many dots to the left.
The object penalty algorithm
Only the leftmost pixel of the object matters, transparent or not. Pan Docs calls it “the pixel”. For each object on the line, in order from the leftmost, ties going to the lowest OAM address:
- Find the background or window tile that the pixel lies in. Scrolling and the window change which tile that is.
- If an earlier object has not already used that tile: count the tile’s pixels that are strictly to the right of the pixel, subtract 2, and add that many dots, or none if the result is negative. This is the wait for the background fetch to finish.
- Add a flat 6 dots for fetching the object’s tile.
An object with OAM X = 0 (completely off the left edge) always costs 11 dots, whatever SCX is. That is the 6 to 11 range above. The number 11 is the general rule at work: the pixel is at −8, seven pixels of its tile lie to its right, 7 − 2 = 5, and 5 + 6 = 11. A second object on that same tile pays only the flat 6, see the check against the Mooneye tests.
Drawing: one line and one frame
Our own drawing of the facts in the table above (Pan Docs has a picture of its own). The upper bar is the shortest line, with mode 3 at 172 dots. The lower bar is the longest, with mode 3 at 289 dots. The line stays 456 dots, so mode 0 gives up the dots that mode 3 takes. One dot is two units across.
OAM scan
Source: OAM.md and Rendering.md (summarised on the summary page), and OAM_Corruption_Bug.md.
Mode 2 takes 80 dots. In it the PPU checks every object’s Y against LY, using the object height from LCDC bit 2, and keeps the first 10 that fit, in OAM order. Objects that are off the screen sideways still use up one of the 10 places. The OAM bug section below says the PPU reads OAM one 8-byte row per M-cycle during this mode, which is 20 rows in 20 M-cycles, or 80 dots.
OAM DMA interferes with the scan (OAM_DMA_Transfer.md, see DMA, joypad and serial): if a DMA is running during mode 2, most PPU revisions see every object as off-screen and hide it on that line. If one is running during mode 3, the PPU reads whatever 16-bit word the DMA is writing at that moment, so an object that was already found to be in range can get a wrong tile number and wrong attributes.
Reaching VRAM and OAM
Source: Accessing_VRAM_and_OAM.md.
While the screen is being drawn, the CPU cannot use VRAM or OAM. A write is ignored. A read gives undefined data, typically $FF. A program should therefore check the mode bits of STAT before it touches them. It must also make sure no interrupt happens between the wait loop and the access, because the memory is only guaranteed to be free for a few cycles, fewer than the length of mode 2, after a wait loop ends.
| Memory | Free in modes | How to wait for it |
|---|---|---|
VRAM ($8000–$9FFF) | 0, 1 and 2 | Loop reading STAT until bit 1 is 0 (mode 0 or 1). When the loop ends at the very end of mode 0 or 1, mode 2 follows, which also allows VRAM, so a few more cycles are safe. |
OAM ($FE00–$FE9F) | 0 and 1 | First loop until bit 1 is 1 (not mode 0 or 1), then loop until it is 0 again. That catches the start of a mode 0 or 1 period. |
- With the screen switched off (LCDC bit 7 = 0), both memories are free, but the screen is blank (white), so Pan Docs advises switching it off only during start-up.
- On the Color, VRAM can also be filled by HDMA (DMA, joypad and serial).
- If no STAT interrupt is needed, another way to reach the start of mode 0 is: enable only the mode 0 source (STAT bit 3), enable the STAT interrupt in IE (bit 1), clear IME with
diand usehalt. That gives all of mode 0 on one line plus mode 2 on the next, 165 to 288 dots. Pan Docs notes that a stack copy of 8 bytes takes 144 dots (9 cycles per 2 bytes at 4 dots), which fits the worst case. - Outside modes 0 and 1, an OAM DMA has priority over the PPU for OAM, and the PPU reads
$FFfrom OAM meanwhile.
The pixel FIFO and the fetcher
Source: pixel_fifo.md (Pan Docs’ file name is in lower case). This is Pan Docs’ model of how the PPU makes pixels in mode 3. It is a model; Pan Docs itself says one timing is not confirmed.
There are two FIFOs (first in, first out queues): one for background and window pixels, one for object pixels. They are separate and meet only when a pixel is popped for the screen. Object pixels take priority over background pixels unless they are transparent (colour 0). Each holds up to 16 pixels. The fetcher keeps the background FIFO at 8 pixels or more, because 8 are needed to draw. Both FIFOs are used only in mode 3, and both are emptied when it starts. Each pixel carries four properties:
- colour: a value 0 to 3;
- palette: 0 to 7 on the Color; on the DMG it applies to objects only;
- sprite priority: the OAM index of the object on the Color; it does not exist on the DMG;
- background priority: the object’s “behind background” attribute bit.
The fetcher
The fetcher has five steps. The first four take 2 dots each. The fifth is tried on every dot until it works.
- Get tile. Picks the tile ID. The map is
$9800by default. LCDC bit 3 chooses$9C00when the current X is outside the window. LCDC bit 6 chooses$9C00when it is inside the window. For a background tile, X is ((SCX ÷ 8) + fetcher X) AND$1F, so 0 to 31, and Y is (line + SCY) AND 255. For a window tile the window’s own X and Y are used. If the PPU’s read of VRAM is blocked (below), the tile ID reads as$FF. The Color gets the tile ID and its attributes in the same dot. - Get tile data low. LCDC bit 4 chooses how the tile ID is turned into an address (the tile data addressing mode, as LCDC.md says). Pan Docs’ pixel_fifo.md says “which tilemap” here, which is a slip: the map was already chosen in step 1 by bits 3 and 6. On the Color the VRAM bank and the vertical flip are applied here. A blocked read gives
$FF. - Get tile data high. The same, one address higher. This step also makes a first attempt to push a row of 8 pixels to the background FIFO. That attempt is not one of the five steps, so a background row gets three chances to be pushed per fetcher cycle. Pan Docs writes “not part of the 8 steps”, but its own list has five steps. It probably means the 8 dots of the four timed steps. That is a second slip, and we say five.
- Sleep. Nothing happens.
- Push. Pushes the row of 8 pixels, but only if the background FIFO is empty. A tile flipped horizontally is pushed least significant bit first, otherwise most significant bit first.
Drawing: the fetcher and the two FIFOs
Our own drawing of the text above. The upper part shows the five steps in time: four steps of 2 dots, then the push, which is tried every dot. The lower part shows where the pixels go.
When the PPU’s own reads are blocked
Reads of VRAM by the PPU return $FF when the LCD is turning off, at line 0 on the Color in normal speed, when mode 3 changes to mode 0, and on the Color when the OAM scan reaches object index 37. Reads are restored at line 0 on the DMG and on the Color in double speed, on the DMG when the scan reaches index 37, and after mode 2 changes to mode 3. Pan Docs adds that these conditions are checked only when the console enters STOP mode, and that access is always restored when it leaves STOP.
The window in the FIFO
When the window starts, the background FIFO is cleared and the fetcher goes back to step 1. If WX is 0 and SCX AND 7 is more than 0, mode 3 is 1 dot shorter. Sources disagree here. SameBoy’s Core/display.c does the opposite for the DMG family: when the window starts with WX = 0 and SCX AND 7 not 0 on a model that is not a Color, it adds 1 dot to the line (cycles_for_line += 1) and stalls one dot, so mode 3 is one dot longer. It has a comment that the fetcher timing in this case is not verified. We found no test (Mooneye has none for this) that decides between “one dot shorter” (Pan Docs, no model named) and “one dot longer” (SameBoy, non-Color only); the two may measure from different starting points. Both are stated, neither is settled. There is a bug when WX is changed after the window has started: when the new WX value is reached, a pixel of colour 0 with the lowest priority is pushed to the background FIFO.
Fetching objects
The steps below run for each object on the line, if LCDC bit 1 is on (the Color ignores this condition) and an object sits at the current X. Otherwise the object fetch is cancelled.
- The fetcher is advanced one step at a time until it is at step 5 or the background FIFO is not empty. Each step advanced adds 1 dot to mode 3. The fetch can be cancelled after that.
- If SCX AND 7 is more than 0 and an object is at X = 0, mode 3 grows by the low three bits of SCX. A cancel is possible after this. Pan Docs says it is not confirmed whether this penalty comes before or after the wait for the fetcher, and that more research is needed.
- The fetcher is advanced two more steps, adding 1 dot and then 3 dots, each followed by a chance to cancel.
- The low address of the object’s tile row is read, adding 1 dot. This is the last chance to cancel. Leaving the object fetch adds 1 dot. Then the high address is read, which adds nothing.
- The VRAM access check is made for the low and high addresses. If the object FIFO has fewer than 8 pixels, transparent pixels of lowest priority are pushed to bring it to 8. Each pixel of the object row is then compared (the Color applies horizontal flip here): it replaces the pixel in the FIFO if it is not colour 0 and the FIFO pixel is colour 0, or if the FIFO pixel has higher priority.
- A pixel is rendered, and the fetcher is advanced one step. That adds 1 dot unless the current X is 160. At X = 160 the PPU stops handling objects, since they would not show.
Pan Docs’ FIFO description and its object penalty algorithm (above) are two accounts of the same stalls. Pan Docs does not reconcile them. We did the part the sources allow, with SCX AND 7 = 0 and no window. The fetch steps above add 1 + 3 + 1 + 1 = 6 dots for every object, which is the flat 6 of the algorithm. SameBoy’s Core/display.c has the same 1, 2, 2, 1 dots (also 6). The wait before step 1, “advance the fetcher until it is at step 5 or the FIFO is not empty”, is the algorithm’s “pixels to the right of the pixel, minus 2”. Computed for every case of Mooneye’s intr_2_mode0_timing_sprites (see the check) the algorithm gives the measured totals, so the two accounts agree where they can be tested. They are not tested against each other with SCX AND 7 above 0 and an object on the line: no Mooneye test has both, and the rule “SCX AND 7 added when an object is at X = 0, before or after the wait” is still unconfirmed. For SCX alone Mooneye measures what the FIFO account says (see measured behaviour).
Making a pixel
- If both FIFOs hold pixels, one is popped from each. Nothing goes to the screen if the background FIFO is empty or the pixel number is 160 or more.
- If the object pixel is not transparent and LCDC bit 1 is on, its background priority bit is used when it is the same as or higher than the background pixel’s priority.
- If LCDC bit 0 is off, the background is off on the DMG (colour 0), and on the Color the background pixel loses its priority. If the background pixel has a colour other than 0 and has priority, the object pixel is thrown away.
- On the DMG the colour comes from BGP for a background pixel, or from OBP0 or OBP1 for an object pixel (1 selects OBP1). On the Color, a pixel is black when palette access is blocked.
Colour palette access is blocked, giving black pixels, when the LCD is turning off, in the first HBlank of the frame, when the scan reaches object 37, after mode 2 changes to mode 3, and 2 dots after entering HBlank in normal speed. It is restored at the end of mode 2 and, in double speed only, for 2 dots when HBlank starts. As above, these are checked only when entering STOP and always restored on leaving it.
Cancelling an object fetch
An object fetch is cancelled if LCDC bit 1 is cleared while the PPU is fetching an object. This lengthens mode 3 by the dots of the previous instruction plus the dots the PPU still had to process. A pixel is then rendered and the fetcher advanced one step, adding 1 dot unless the pixel is 160.
The OAM corruption bug
Source: OAM_Corruption_Bug.md.
A flaw in the original hardware writes rubbish into OAM. It happens when one of the instructions below is used while the 16-bit register it works on, before the operation, is in $FE00–$FEFF and the PPU is in mode 2:
inc rr and dec rr (rr = BC, DE or HL), ld a,[hli], ld a,[hld], ld [hli],a, ld [hld],a.
Objects 0 and 1 ($FE00 and $FE04) are not affected. The Game Boy Color and Advance are not affected, even when they run monochrome software.
Two bugs in one
- Reading or writing OAM (including
$FEA0–$FEFF) while the PPU is in mode 2 corrupts it. - Increasing or decreasing a 16-bit register (BC, DE, HL, SP or PC) while it is in
$FE00–$FEFFcauses an access to OAM. Pan Docs explains that the CPU’s increment and decrement unit is wired straight to the address bus, so the value is put out as an address even when no read or write is asked for.
Which operations trigger it
| Operation | Corruptions |
|---|---|
| Any instruction that accesses OAM | one |
inc rr, dec rr with rr in OAM | one write |
ld [hli],a, ld [hld],a, ld a,[hli], ld a,[hld] with HL in OAM | two: the access and the extra write of the increment or decrement |
pop rr and the ret family | three, not four: one read, one glitched write, and a second read without a glitched write. Pan Docs says “for some reason”. |
push rr, the call family, rst and interrupt entry | four (two writes and two glitched writes from the hidden dec sp), but one glitched write falls in the same M-cycle as a real write, so it behaves like three |
| Running code from OAM | two when PC is in OAM (one for the PC increment, one for the read of $FF, which is rst $38); a multi-byte instruction run from $FDFE or $FDFF likewise triggers it twice for every read from OAM |
The corruption patterns
OAM is 20 rows of 8 bytes. In mode 2 the PPU reads one row per M-cycle. The pattern depends on the kind of access (read, write or both) and on the row the PPU is reading at that moment. The address or value the CPU used has no effect. OAM has a 16-bit data bus, so everything is done on 16-bit words. In the formulas, a is the first word of the row being read by the PPU, and b and c are the first and third words of the row before it.
- Write corruption (not on the first row): the first word of the row becomes
((a ^ c) & (b ^ c)) ^ c, and its last three words are copied from the last three words of the previous row. - Read corruption: as a write corruption, but the first word becomes
b | (a & c). - Write during an increase or decrease: two writes in one M-cycle, which behaves like a single write.
- Read during an increase or decrease: a read and a write in one M-cycle, with a more complex pattern. (Pan Docs’ text for this case says “write” where its heading says read; we follow the heading and the “read and write” result it states.) It does not happen if the row is one of the first four or the last. Otherwise the first word of the previous row becomes
(b & (a | c | d)) | (a & c & d), where here a is the first word two rows before the current row, b the first word of the previous row, c the first word of the current row and d the third word of the previous row. The previous row, after that change, is then copied to the current row and to the row two before it. A normal read corruption follows in every case.
Drawing: which words the patterns use
Our own drawing of the formulas above (Pan Docs has pictures of its own). Each row of OAM is four 16-bit words, w0 to w3. The PPU is reading the bottom row. In the simple read and write patterns, a is w0 of the row being read, b is w0 of the row before it and c is w2 of that row. The result goes into w0 of the row being read, and its words w1 to w3 are copied from the row before. In the complex read pattern the names are different (see the list): a is w0 two rows back, b w0 one row back, c w0 of the row being read and d w2 one row back.
Rows and models in SameBoy
Pan Docs gives one pattern for the rows 4 to 18 and does not mention models. SameBoy’s GB_trigger_oam_bug_read (samples/gb/sources/sameboy-src/memory.c) is more detailed. It does nothing on the Color. Otherwise it looks at the row number (the OAM byte offset divided by 8), from row 1 on:
- Row mod 4 = 2: the complex pattern of this page, and only when the row is below the last one (offset under
$98). On every non-Color model. - Row mod 4 = 0: a different formula for each model and row. The comment in the source calls this “extremely revision and instance specific”. The MGB, the SGB2 and the other DMG units each get their own formulas, and the cases on rows
$20,$40and$60(offsets) differ again. Some DMG results are non-deterministic in the author’s units, while other units give constant zeros; SameBoy emulates the zero ones. A formula for the MGB in the source is commented out. - Row mod 4 = 1 or 3: the simple read pattern
b | (a & c). SameBoy puts that value into w0 of the row before as well, then copies the whole row before into the row being read. The row being read therefore ends as in Pan Docs. Pan Docs does not say that the row before changes too.
So the one-pattern account of Pan Docs is right for the simple cases and for rows mod 4 = 2, and it is the model-independent summary. We have not checked the row mod 4 = 0 formulas against hardware.
Copies into the first row
One more step of the read bug is in the same file and is not in Pan Docs. Offsets are bytes from $FE00. At the end of GB_trigger_oam_bug_read (lines 239 to 247), after the formulas, the code copies the 8 bytes of the row before the accessed row into the accessed row. Then two cases copy the accessed row into the first row, memcpy(gb->oam, gb->oam + gb->accessed_oam_row, 8):
- the accessed row is
0x80, on every non-Color model (line 242); - the model is the MGB and the accessed row is
0x40(line 245).
So an access in row $80 (and, on the MGB, row $40) also overwrites the first object, bytes $FE00 to $FE07. The cause is in the comment in oam_bug_tertiary_read_corruption (lines 179 to 182), which we quote in our words: on some units the corrupted row is copied to the first row for some accessed rows; on the author’s DMG this happens for row $80, and on the author’s MGB for row $60 (the code uses $40 for the MGB: the comment and the code differ, and we do not know which is right). Some units copy only the odd or only the even bytes. Also, on some units, for accessed rows that do not reach the first row, the last two bytes of the row before are corrupted with a random chance. SameBoy does not code the odd/even copies or the random corruption: only the plain copy above exists in the source. The whole behaviour is therefore one author’s observation of his own units, and no more than that is known here.
STAT, LY and LYC
Source: STAT.md and Interrupt_Sources.md. The bits are on registers/#ff41.
- LY (
$FF44, read-only) is the line that is about to be drawn, being drawn or just drawn. It runs 0 to 153; 144 to 153 is VBlank. - LYC (
$FF45) is compared with LY all the time. When they are equal, the “LYC = LY” flag in STAT (bit 2) is set and, if enabled, a STAT interrupt is requested. - STAT bits 6 to 3 select the sources (LYC = LY, mode 2, mode 1, mode 0). Bits 1 to 0 are the PPU mode. The mode reads 0 while the PPU is switched off.
The STAT interrupt line
Each source that is enabled puts its state on one shared line, as a logical OR. A STAT interrupt is requested only when the line goes from low to high.
STAT blocking. If a source turns the line high while another source already holds it high, or just after, there is no rising edge and no interrupt. For example, if modes 0 and 1 are both enabled, no interrupt is requested for mode 1, because the line never has a chance to go low between them. Pan Docs points to a Mooneye test (stat_irq_blocking) as an example.
The spurious STAT interrupt (monochrome only)
On the monochrome Game Boy, writing to STAT (even writing $00) during the OAM scan, HBlank, VBlank or LY = LYC can make the LCD interrupt happen. It acts as if $FF were written for one M-cycle and the real value on the next. The Color running a monochrome game does not have this quirk. Two games that depend on it, Road Rash (Ocean) and Xerd no Densetsu (Vic Tokai), do not run on a Color.
Use
The popular use is a STAT interrupt at a chosen line to change SCX or SCY for a raster effect. Pan Docs’ example: set LYC to WY, enable the LY = LYC interrupt, and have the handler turn objects off, so objects are hidden behind a window text box at the bottom of the screen. The VBlank interrupt comes at the start of VBlank (LY = 144) about 59.7 times a second on a handheld and about 61.1 on a Super Game Boy.
Measured behaviour (Mooneye test ROMs)
Source: the assembly sources of Mooneye’s acceptance/ppu tests (MIT licence), saved in samples/gb/sources/mooneye-ppu. Each source says which consoles pass it on real hardware (“Verified results”). Pan Docs does not give any of the facts in this section. We did not run the ROMs; we read the expected values and the timings in the sources. A M-cycle is 4 dots in normal speed.
The mode 2 source at line 144
vblank_stat_intr-GS: if STAT bit 5 (the mode 2 source) is set, a STAT interrupt is also requested at line 144, when VBlank starts, at the same moment as the VBlank interrupt. The test compares the time from VBlank to VBlank with the time from VBlank to that STAT interrupt and expects the same. The DMG, MGB, SGB and SGB2 pass. The Color and the Advance (CGB, AGB, AGS) do not: this behaviour belongs to the monochrome family.
The LYC flag while the screen is off
stat_lyc_onoff (all of DMG, MGB, SGB, SGB2, CGB, AGB and AGS pass). With the LCD off (LCDC bit 7 = 0) the LYC = LY flag, STAT bit 2, is kept as it was and does not go back to 0. The test turns the screen off at line $90 with LYC = $90, and STAT reads $C4 afterwards: bit 7 always reads 1, bit 6 is the LYC source the test switched on, bit 2 is the kept flag and the mode is 0. Changing LYC while the screen is off does not change the flag, because the comparison is not running. When the screen is turned on, the comparison runs again against LY = 0:
- flag was set and LYC is now not 0: the flag goes to 0 (STAT reads
$C0); - flag was set and LYC is 0: the flag stays set and no interrupt happens, because the signal never fell;
- flag was clear and LYC is not 0: it stays clear;
- flag was clear and LYC is 0: the flag becomes set and a STAT interrupt (with the LYC source on) happens.
The first lines after the screen is turned on
lcdon_timing-GS and lcdon_write_timing-GS (DMG, MGB, SGB and SGB2 pass; CGB, AGB and AGS do not, and the CGB before revision D fails differently from D, E and the Advance). Expectations written in the sources: line 0 starts in mode 0 and goes straight to mode 3, without mode 2; line 0 has different timing because the PPU is late by 2 T-cycles; lines 1 and 2 are normal. The sources read LY, STAT, OAM and VRAM at chosen M-cycles after the write to LCDC that turns the screen on (three passes, each one cycle later, so cycle numbers 0, 1 and 2 plus the offsets 17, 60, 110, 130, 174, 224 and 244). The values the sources expect, with STAT read for LYC = 0, are below. “OAM ok” means a read of OAM returned its real value, “blocked” means $FF.
0: LY 0, mode 0, OAM ok, VRAM ok 1: LY 0, mode 0, OAM ok, VRAM ok 2: LY 0, mode 0, OAM ok, VRAM ok 17: LY 0, mode 0, OAM ok, VRAM ok 18: LY 0, mode 3, OAM blocked, VRAM blocked 19: LY 0, mode 3, OAM blocked, VRAM blocked 60: LY 0, mode 3, OAM blocked, VRAM blocked 61: LY 0, mode 0, OAM ok, VRAM ok 62: LY 0, mode 0, OAM ok, VRAM ok 110: LY 0, mode 0, OAM ok, VRAM ok 111: LY 1, mode 0, OAM blocked, VRAM ok 112: LY 1, mode 2, OAM blocked, VRAM ok 130: LY 1, mode 2, OAM blocked, VRAM ok 131: LY 1, mode 2, OAM blocked, VRAM blocked 132: LY 1, mode 3, OAM blocked, VRAM blocked 174: LY 1, mode 3, OAM blocked, VRAM blocked 175: LY 1, mode 0, OAM ok, VRAM ok 176: LY 1, mode 0, OAM ok, VRAM ok 224: LY 1, mode 0, OAM ok, VRAM ok 225: LY 2, mode 0, OAM blocked, VRAM ok 226: LY 2, mode 2, OAM blocked, VRAM ok 244: LY 2, mode 2, OAM blocked, VRAM ok 245: LY 2, mode 2, OAM blocked, VRAM blocked 246: LY 2, mode 3, OAM blocked, VRAM blocked
What the rows show, read directly: line 0 has no mode 2 and mode 3 lasts from cycle 18 to cycle 60, 43 M-cycles, which is 172 dots, the shortest mode 3. LY becomes 1 at cycle 111 and 2 at cycle 225, 114 M-cycles or 456 dots apart. Line 1 has mode 2 from cycle 112 to 131 (20 M-cycles, 80 dots) and mode 3 from 132 to 174 (43 M-cycles, 172 dots). The STAT bit 2 flag follows LY for LYC = 0 and LYC = 1 in every row but one: for LYC = 1 the flag still reads clear at cycle 111, when LY already reads 1, and is set from cycle 112. Two details are not in Pan Docs: OAM reads are blocked in the M-cycle when LY changes, while the mode still reads 0 (cycles 111 and 225), and VRAM reads are blocked one M-cycle before mode 3 starts (cycles 131 and 245), though the mode still reads 2. We state only what the rows say, not a cause.
lcdon_write_timing-GS does the same with writes (a value is written to OAM or VRAM at the cycle and then checked; the cycles are 0, 17, 18, 60, 61, 110, 111, 112, 130, 131, 132, 174, 175, 224, 225, 226, 244, 245 and 246):
0: OAM write passes, VRAM write passes 17: OAM write passes, VRAM write passes 18: OAM write ignored, VRAM write ignored 60: OAM write ignored, VRAM write ignored 61: OAM write passes, VRAM write passes 110: OAM write passes, VRAM write passes 111: OAM write passes, VRAM write passes 112: OAM write ignored, VRAM write passes 130: OAM write ignored, VRAM write passes 131: OAM write passes, VRAM write passes 132: OAM write ignored, VRAM write ignored 174: OAM write ignored, VRAM write ignored 175: OAM write passes, VRAM write passes 224: OAM write passes, VRAM write passes 225: OAM write passes, VRAM write passes 226: OAM write ignored, VRAM write passes 244: OAM write ignored, VRAM write passes 245: OAM write passes, VRAM write passes 246: OAM write ignored, VRAM write ignored
The write at cycle 111 passes while the read at 111 is blocked, and the write at 131 passes while the read at 131 is blocked. The sources do not explain this, and neither do we.
SCX and the end of the line
hblank_ly_scx_timing-GS (DMG, MGB, SGB and SGB2 pass; CGB, AGB and AGS fail) has no objects and no window. It measures from the mode 0 STAT interrupt to the increment of LY: 51 M-cycles for SCX AND 7 = 0, 50 M-cycles for 1 to 4, 49 M-cycles for 5 to 7. In dots, the shortest mode 0 is 376 − 172 = 204 dots, which is exactly 51 M-cycles. Every dot of SCX AND 7 takes a dot from mode 0 (mode 3 is longer by that much, see the penalties above), and the whole M-cycles are counted, so (204 − SCX AND 7) ÷ 4 rounded down is 51 for 0, 50 for 1 to 4 (203 to 200 dots) and 49 for 5 to 7 (199 to 197 dots). Our calculation reproduces all eight values, so the Mooneye result is the SCX AND 7 penalty of the FIFO account (mode 3 grows by SCX AND 7 dots).
The object penalty against the Mooneye tests
intr_2_mode0_timing_sprites (all models pass) measures, from the mode 2 interrupt to mode 0, how many extra M-cycles objects add. It has more than a hundred cases with SCX = 0 and no window, in which up to ten objects sit at chosen OAM X positions. We computed the page’s algorithm for every case (the object’s pixel is at X − 8, the tile is that pixel’s tile, objects from the leftmost, ties by OAM index) and divided the dots by 4, rounding down. Every case equals the Mooneye number. Examples, the dots computed and the M-cycles the test expects:
X = 8: 11 dots, M-cycles 2 X = 9: 10 dots, M-cycles 2 X = 10: 9 dots, M-cycles 2 X = 11: 8 dots, M-cycles 2 X = 12: 7 dots, M-cycles 1 X = 13: 6 dots, M-cycles 1 X = 14: 6 dots, M-cycles 1 X = 15: 6 dots, M-cycles 1 1 object at X = 0: 11 dots, M-cycles 2 2 objects at X = 0: 17 dots, M-cycles 4 3 objects at X = 0: 23 dots, M-cycles 5 4 objects at X = 0: 29 dots, M-cycles 7 5 objects at X = 0: 35 dots, M-cycles 8 6 objects at X = 0: 41 dots, M-cycles 10 7 objects at X = 0: 47 dots, M-cycles 11 8 objects at X = 0: 53 dots, M-cycles 13 9 objects at X = 0: 59 dots, M-cycles 14 10 objects at X = 0: 65 dots, M-cycles 16
The first object at X = 0 costs 11 dots and each further one 6, because they share one tile, so only the flat 6 is added. That is why ten objects cost 11 + 9 × 6 = 65 dots. Objects with X of 168 or more are never on the line, and the test confirms it (0 extra cycles). The sprites test has no SCX at all, so it says nothing about SCX together with objects. This is the limit of what the sources settle.
Other Mooneye timing tests read
stat_irq_blocking confirms the blocking rule of the STAT section above (DMG ABC, MGB, CGB, AGB and AGS pass; the early DMG 0 fails). intr_1_2_timing-GS, intr_2_0_timing, intr_2_mode3_timing, intr_2_oam_ok_timing and intr_2_mode0_timing measure the time between STAT interrupts in counted CPU cycles. They give no dot figure without a model of the interrupt latency, so we use none of their numbers.
Sources
- Raw Pan Docs Markdown (CC0), read 2026-11-19, in
samples/gb/sources/pandocswith SHA-256 in the sample README:Rendering.md,pixel_fifo.md,Accessing_VRAM_and_OAM.md,OAM_Corruption_Bug.md,STAT.md,Interrupt_Sources.md,OAM_DMA_Transfer.md,OAM.md. - Mooneye test suite (MIT), assembly sources of
acceptance/ppuinsamples/gb/sources/mooneye-ppu:vblank_stat_intr-GS,stat_lyc_onoff,lcdon_timing-GS,lcdon_write_timing-GS,hblank_ly_scx_timing-GS,intr_2_mode0_timing_sprites,stat_irq_blockingand five interrupt-timing tests. SameBoy (MIT)Core/display.cinsamples/gb/sources/sameboy-coreandCore/memory.cinsamples/gb/sources/sameboy-src. SHA-256 of each file is in the sample README. - Rendering, Pixel FIFO, OAM Corruption Bug, LCD Status Registers – Pan Docs
Not described
Known, not yet covered
- Nothing known is left. The drawings of this chapter are redrawn from the text (one line and one frame, the fetcher and FIFOs, the OAM bug words), the Mooneye behaviours are in the measured-behaviour section, and the model dependence of the OAM bug rows is in its own section.
Unknown
- Whether the object penalty for SCX AND 7 (an object at X = 0) comes before or after the wait for the fetcher. Pan Docs marks it unconfirmed, and no test in the sources has SCX AND 7 above 0 together with an object. The FIFO account and the penalty algorithm agree on every Mooneye case with SCX = 0 (all tested), but their agreement with SCX above 0 and objects is untested.
- Whether the window with WX = 0 and SCX AND 7 above 0 makes mode 3 one dot shorter (Pan Docs) or one dot longer (SameBoy, non-Color models). Neither source gives a measurement.
- The OAM bug formulas for rows with row mod 4 = 0 on each model: SameBoy’s source says they are revision and instance specific and partly non-deterministic. Only the SameBoy formulas exist as a source, and they were not compared with hardware.
- Why OAM reads are blocked when LY changes and VRAM reads one M-cycle before mode 3 (the Mooneye lcdon rows). The sources give the numbers, no cause.
- Whether any of this is right on real consoles, as far as the sources do not already say so. We ran no ROM and no emulator and had no hardware. What the Mooneye tests, SameBoy and blargg say about real consoles is stated as their statement, and we cannot confirm it ourselves.