You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add CPU mode select register - KEY0
Add the register decription to the CGB Registers page
and updated the CGB flag cartrigde and the Power Up Sequence with refs to the new register
PGB mode remains a mystery
* Remove the leaked info reference and try to make PGB mode references less confusing
* Review fixes
Move the pgb mode brief to the research needed box and add a link to a new issue regarding this topic
* Update src/CGB_Registers.md
* Apply suggestions from code review
Co-authored-by: Antonio Vivace <[email protected]>
---------
Co-authored-by: Antonio Vivace <[email protected]>
Copy file name to clipboardexpand all lines: src/CGB_Registers.md
+27-1
Original file line number
Diff line number
Diff line change
@@ -219,13 +219,39 @@ ON/OFF pulses (length 10us ON, 17.5us OFF each) instead of a permanent
219
219
880us LED ON signal. Even though being generally CGB compatible, the GBA
220
220
does not include an infra-red port.
221
221
222
+
### FF4C — KEY0 (CGB Mode only): CPU mode select
223
+
224
+
This GBC-only register (which is not officially documented) is written only by the CGB boot ROM,
225
+
as it gets locked after the bootrom finish execution (by a write to the [BANK register](<#Monochrome models (DMG0, DMG, MGB)>)).
226
+
227
+
Once it is locked, the behavior of the system can't be changed without a reset (this behavior can be observed using [this test ROM](https://github.com/alloncm/MagenTests?tab=readme-ov-file#key0-cpu-mode-register-lock-after-boot)).
228
+
229
+
As a result of the above most of the behavior is not directly testable without hardware manipulation.
230
+
Even though we can't test its behavior directly we can inspect the disassembly of the CGB bootrom and infer the following:
231
+
232
+
{{#bits 8 >
233
+
"KEY0" 2:"DMG compatibility mode"
234
+
}}
235
+
236
+
-**DMG compatibility mode**: `0` = Disabled (full CGB mode, for regular CGB cartridges), `1` = Enabled (for DMG only cartridges)
237
+
238
+
#### PGB mode
239
+
240
+
:::tip Research needed
241
+
242
+
It has been speculated that setting bit 3 is related to a special mode called "PGB" for controlling the LCD externally.
243
+
244
+
This mode is not well researched nor documented yet, you are welcome to help [here!](https://github.com/gbdev/pandocs/issues/581)
This register serves as a flag for which object priority mode to use. While
225
251
the DMG prioritizes objects by x-coordinate, the CGB prioritizes them by
226
252
location in OAM. This flag is set by the CGB bios after checking the game's CGB compatibility.
227
253
228
-
OPRI has an effect if a PGBvalue (`0xX8`, `0xXC`) is written to KEY0 but STOP hasn't been executed yet, and the write takes effect instantly.
254
+
OPRI has an effect if a [PGB](<#PGB mode>)value (`0xX8`, `0xXC`) is written to [KEY0](<#FF4C — KEY0 (CGB Mode only): CPU mode select>) but STOP hasn't been executed yet, and the write takes effect instantly.
Copy file name to clipboardexpand all lines: src/Power_Up_Sequence.md
+3-1
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,9 @@ Then, like the monochrome boot ROMs, the header logo is checked *from the buffer
86
86
For unknown reasons, however, only the first half of the logo is checked, despite the full logo being present in the HRAM buffer.
87
87
88
88
Finally, the boot ROM fades all BG palettes to white, and sets the hardware to compatibility mode.
89
-
If [the CGB compatibility byte](<#0143 — CGB flag>) indicates CGB compatibility, the byte is written directly to `KEY0` ($FF4C), potentially enabling PGB mode; otherwise, $04 is written to `KEY0` (enabling DMG compatibility mode in the CPU), $01 is written to [`OPRI`](<#FF6C — OPRI (CGB Mode only): Object priority mode>) (enabling [DMG OBJ priority](<#Object Priority and Conflicts>)), and the [compatibility palettes](<#Compatibility palettes>) are written.
89
+
If [the CGB compatibility byte](<#0143 — CGB flag>) indicates CGB compatibility, the byte is written directly to [`KEY0`](<#FF4C — KEY0 (CGB Mode only): CPU mode select>), potentially [enabling "PGB mode"](<#PGB mode>);
90
+
otherwise, $04 is written to [`KEY0`](<#FF4C — KEY0 (CGB Mode only): CPU mode select>) (enabling DMG compatibility mode in the CPU),
91
+
$01 is written to [`OPRI`](<#FF6C — OPRI (CGB Mode only): Object priority mode>) (enabling [DMG OBJ priority](<#Object Priority and Conflicts>)), and the [compatibility palettes](<#Compatibility palettes>) are written.
90
92
Additionally, the DMG logo tilemap is written [if the compatibility requests it](<#Compatibility palettes>).
91
93
92
94
Like all other boot ROMs, the last thing the color boot ROMs do is hand off execution at the same time as they unmap themselves, though they write $11 instead of $01 or $FF.
0 commit comments