Skip to content

Document more of the Window's behaviour - #626

Merged
avivace merged 5 commits into
gbdev:masterfrom
ISSOtm:window
Apr 15, 2026
Merged

Document more of the Window's behaviour#626
avivace merged 5 commits into
gbdev:masterfrom
ISSOtm:window

Conversation

@ISSOtm

@ISSOtm ISSOtm commented Sep 21, 2025

Copy link
Copy Markdown
Member

Fixes #376.

cc @LIJI32 for review

In particular, I have a TODO for linking to a test ROM, as I believe mealybug-tearoom has one for the “trigger Window multiple times in a single scanline” behaviour, but I couldn't figure out which one.

@ISSOtm
ISSOtm requested a review from avivace September 21, 2025 17:47
Comment thread src/Window.md
Comment thread src/Window.md Outdated
Comment thread src/Scrolling.md

If the WY condition has already been triggered and at the start of a row the window enable bit was set,
then resetting that bit before the WX condition gets triggered on that row yields a nice window glitch pixel where the window would have been activated.
The scroll registers are re-read on each [tile fetch](<#Get Tile>), except for the low 3 bits of `SCX`, which are only read at the beginning of the scanline (for the initial shifting of pixels).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd think the low bits of SCX would only be read once per line, because that's the logical way to do so, but unfortunately this isn't true. The fetched tile's X position is calculated (roughly) by adding SCX to LX and taking the 5 topmost bits, rather than adding the 5 topmost bits of SCX and LX.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Do you know of a test ROM that checks this?

Also, it seems like it'd be a better fit for a separate PR, so I'll open one when I have some info to pen down.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @LIJI32

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #659

Comment thread src/Window.md Outdated
Comment thread src/Window.md Outdated
Comment thread src/Window.md Outdated
Comment thread src/Window.md Outdated
Comment thread src/Window.md Outdated
Comment thread src/Window.md Outdated
Comment thread src/Window.md Outdated
Comment thread src/Window.md Outdated
ISSOtm and others added 2 commits October 4, 2025 06:18
Co-authored-by: Antonio Vivace <avivace4@gmail.com>
Co-authored-by: Antonio Vivace <avivace4@gmail.com>
Comment thread src/Scrolling.md

If the WY condition has already been triggered and at the start of a row the window enable bit was set,
then resetting that bit before the WX condition gets triggered on that row yields a nice window glitch pixel where the window would have been activated.
The scroll registers are re-read on each [tile fetch](<#Get Tile>), except for the low 3 bits of `SCX`, which are only read at the beginning of the scanline (for the initial shifting of pixels).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #659

@avivace
avivace merged commit 73b017f into gbdev:master Apr 15, 2026
2 checks passed
@ISSOtm
ISSOtm deleted the window branch April 15, 2026 21:59
@paulb-nl

Copy link
Copy Markdown

On GBC, clearing the [Window enable bit] in LCDC resets the Y condition; WY must be set to LY or greater for the Window to display again in the current frame.

This is not true. Where did this come from?

@calc84maniac

Copy link
Copy Markdown

The previous bullet seems a bit dodgy to me, too:

At the beginning of each scanline, if the value of WY is equal to [LY], the Y condition becomes true (and remains so for subsequent scanlines).

There's no mention of the prerequisite of the Window enable bit also being set in order to activate the Y condition. It could also maybe use clarification (since the bullet before that says the condition is cleared on each VBlank) that it only applies during active video scanlines, not VBlank scanlines.

Also, I'm fairly certain this condition is not checked only at the beginning of the scanline, based on my emudev experience and related discussions. Since the games I recall fixing using this knowledge were GBC games, I wonder if that's where the confusion is happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Window bug after disabling window mid-screen

5 participants