Expand description
The window: a second tilemap laid over the background.
It has no scroll of its own. Wherever it is placed, it draws from its grid’s top left corner, so moving what it shows means rewriting the grid. Staying put is what suits it to a status bar or a text box while the background scrolls underneath.
§Position
The hardware register is the screen column plus seven, so WX of 7 is the
left edge. set_position takes the screen column and adds it, which also
puts the off-screen values out of reach: WX below 7 starts the window left
of the screen and is where the hardware behaves least predictably. Reach for
mmio::WX directly if that is wanted.
§Writing mid-frame
WX, WY and the enable bit are least glitchy written during VBlank, or
during HBlank where they must change mid-frame, which is what the Access
here is for. set_map is not among them: it takes effect from the next
tile fetched and has nothing to go wrong.
Use hide where the window has to come and go within a frame, not the
enable bit. The PPU turns the window on for a frame when WY
first matches LY, and on the Game Boy Color clearing the enable bit undoes
that: the window then stays away until WY matches again, which for the rest
of the frame it cannot. See https://gbdev.io/pandocs/Window.html.
Constants§
- X_
OFFSET - What
WXis offset by:WXof 7 is screen column 0.
Functions§
- enabled
- Whether the PPU draws the window at all, from
LCDCbit 5. - hide
- Take the window off screen without disturbing the enable bit.
- map
- Which grid the window reads, from
LCDCbit 6. - position
- Where the window’s top left corner sits on screen, as
(x, y). - set_
enabled - Set
LCDCbit 5. - set_map
- Point the window at a grid.
- set_
position - Put the window’s top left corner at
(x, y)on screen.