@@ -33,15 +33,47 @@ Bit 3 Tile VRAM Bank number (0=Bank 0, 1=Bank 1)
33
33
Bit 2-0 Background Palette number (BGP0-7)
34
34
```
35
35
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
-
41
36
Note that, if the map entry at ` 0:9800 ` is tile \$ 2A, the attribute at
42
37
` 1:9800 ` doesn't define properties for ALL tiles \$ 2A on-screen, but only
43
38
the one at ` 0:9800 ` !
44
39
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
+ - [ BG Map Attribute bit 7] ( < #BG Map Attributes (CGB Mode only) > )
44
+ - [ LCDC bit 0] ( < #LCDC.0 — BG and Window enable/priority > )
45
+ - [ OAM Attributes bit 7] ( < #Byte 3 — Attributes/Flags > )
46
+
47
+ We can infer the following rules from the table below:
48
+ * If the BG color index is 0, the OBJ will always have priority;
49
+ * Otherwise, if LCDC bit 0 is clear, the OBJ will always have priority;
50
+ * Otherwise, if both the BG Attributes and the OAM Attributes have bit 7 clear, the OBJ will have priority;
51
+ * Otherwise, BG will have priority.
52
+
53
+ The following table shows the relations between the 3 flags:
54
+
55
+ LCDC bit 0 | OAM attr bit 7 | BG attr bit 7 | Priority
56
+ :---------:|:--------------:|:-------------:|---------
57
+ 0 | 0 | 0 | OBJ
58
+ 0 | 0 | 1 | OBJ
59
+ 0 | 1 | 0 | OBJ
60
+ 0 | 1 | 1 | OBJ
61
+ 1 | 0 | 0 | OBJ
62
+ 1 | 0 | 1 | BG color 1–3, otherwise OBJ
63
+ 1 | 1 | 0 | BG color 1–3, otherwise OBJ
64
+ 1 | 1 | 1 | BG color 1–3, otherwise OBJ
65
+
66
+ [ This test ROM] ( https://github.com/alloncm/MagenTests ) can be used to observe the above.
67
+
68
+ ::: warning
69
+
70
+ Keep in mind that:
71
+ * OAM Attributes bit 7 will grant OBJ priority when ** clear** , not when ** set** .
72
+ * Priority between all OBJs is resolved ** before** priority with the BG layer is considered.
73
+ Please refer [ to this page] ( < #Drawing priority > ) for more details.
74
+
75
+ :::
76
+
45
77
## Background (BG)
46
78
47
79
The [ SCY and SCX] ( < #FF42–FF43 — SCY, SCX: Viewport Y position, X position > )
0 commit comments