Skip to content

Commit 86d3af0

Browse files
committed
Add BG-to-OBJ priority in CGB mode section
Add this section at the Tile_Maps.md file cause this place describe the BG Map attributes and they are the new addition in CGB mode that cause this confusion
1 parent ae8f65b commit 86d3af0

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/Tile_Maps.md

+33-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,43 @@ Bit 3 Tile VRAM Bank number (0=Bank 0, 1=Bank 1)
3333
Bit 2-0 Background Palette number (BGP0-7)
3434
```
3535

36-
When Bit 7 is set, the corresponding BG tile will have priority above
37-
all OBJs (regardless of the priority bits in OAM memory). There's also
38-
a Master Priority flag in LCDC register Bit 0 which overrides all other
39-
priority bits when cleared.
40-
4136
Note that, if the map entry at `0:9800` is tile \$2A, the attribute at
4237
`1:9800` doesn't define properties for ALL tiles \$2A on-screen, but only
4338
the one at `0:9800`!
4439

40+
### BG-to-OBJ Priority in CGB Mode
41+
42+
In CGB Mode, the priority between the BG (and window) layer and the OBJ layer is declared in three different places:
43+
1. [BG Map Attribute bit 7](#bg-map-attributes-cgb-mode-only) - BG-to-OAM Priority (CGB Mode)
44+
2. [LCDC bit 0](LCDC.md#lcdc0--bg-and-window-enablepriority) - BG and Window Priority (CGB Mode)
45+
3. [OAM Attributes bit 7](OAM.md#byte-3--attributesflags) - BG and Window over OBJ
46+
47+
We can infer the following rules from the table below:
48+
* When the BG color is 0 the OBJ will always have priority (ignoring the flags)
49+
* When LCDC bit 0 is clear OBJ will always have priority (ignoring the rest of the flags)
50+
* In order to grant the BG priority (color 1-3) LCDC bit 0 must be set and if OAM attributes bit 7 is clear BG Map attributes bit 7 must be set to override it
51+
52+
::: tip NOTE
53+
54+
OAM Attributes bit 7 will grant OBJ priority when clear and not when set
55+
56+
:::
57+
58+
The following table visualize the relations between the 3 flags
59+
60+
LCDC bit 0 | OAM attr bit 7 | BG attr bit 7 | Priority
61+
:---------:|:--------------:|:-------------:|---------
62+
0 | 0 | 0 | OBJ
63+
0 | 0 | 1 | OBJ
64+
0 | 1 | 0 | OBJ
65+
0 | 1 | 1 | OBJ
66+
1 | 0 | 0 | OBJ
67+
1 | 0 | 1 | BG color 1–3, otherwise OBJ
68+
1 | 1 | 0 | BG color 1–3, otherwise OBJ
69+
1 | 1 | 1 | BG color 1–3, otherwise OBJ
70+
71+
[This test ROM](https://github.com/alloncm/MagenTests) can be used to observe the above.
72+
4573
## Background (BG)
4674

4775
The [SCY and SCX](<#FF42–FF43 — SCY, SCX: Viewport Y position, X position>)

0 commit comments

Comments
 (0)