Skip to content

Commit d244a38

Browse files
authored
Add STAT phrasing to clarify and emphasize the interrupt they are associated with (#280)
1 parent 1559a69 commit d244a38

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

content/Video_Display.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ A *dot* is the shortest period over which the PPU can output one pixel: is it eq
77
### FF41 - STAT (LCD Status) (R/W)
88

99
```
10-
Bit 6 - LYC=LY Interrupt (1=Enable) (Read/Write)
11-
Bit 5 - Mode 2 OAM Interrupt (1=Enable) (Read/Write)
12-
Bit 4 - Mode 1 VBlank Interrupt (1=Enable) (Read/Write)
13-
Bit 3 - Mode 0 HBlank Interrupt (1=Enable) (Read/Write)
14-
Bit 2 - LYC=LY Flag (0=Different, 1=Equal) (Read Only)
15-
Bit 1-0 - Mode Flag (Mode 0-3, see below) (Read Only)
10+
Bit 6 - LYC=LY STAT Interrupt source (1=Enable) (Read/Write)
11+
Bit 5 - Mode 2 OAM STAT Interrupt source (1=Enable) (Read/Write)
12+
Bit 4 - Mode 1 VBlank STAT Interrupt source (1=Enable) (Read/Write)
13+
Bit 3 - Mode 0 HBlank STAT Interrupt source (1=Enable) (Read/Write)
14+
Bit 2 - LYC=LY Flag (0=Different, 1=Equal) (Read Only)
15+
Bit 1-0 - Mode Flag (Mode 0-3, see below) (Read Only)
1616
0: In HBlank
1717
1: In VBlank
1818
2: Searching OAM
@@ -92,24 +92,36 @@ milliseconds.
9292

9393
### INT 48 - STAT Interrupt
9494

95-
There are various reasons for this interrupt to occur as described by
96-
the STAT register (\$FF41). One very popular reason is to indicate to
97-
the user when the video hardware is about to redraw a given LCD line.
98-
This can be useful for dynamically controlling the SCX/SCY registers
99-
($FF43/$FF42) to perform special video effects.
95+
There are various sources which can trigger this interrupt to occur as
96+
described by the [STAT register (\$FF41)](#ff41-stat-lcd-status-r-w).
97+
One very popular use is to indicate to the user when the video
98+
hardware is about to redraw a given LCD line. This can be useful for
99+
dynamically controlling the SCX/SCY registers ($FF43/$FF42) to [perform
100+
special video effects](https://github.com/BlitterObjectBob/DeadCScroll).
100101

101102
Example application: set LYC to WY, enable LY=LYC interrupt, and have
102103
the handler disable sprites. This can be used if you use the window for
103104
a text box (at the bottom of the screen), and you want sprites to be
104105
hidden by the text box.
105106

107+
The various STAT interrupt sources (modes 0-2 and LYC=LY) have their
108+
state (inactive/low and active/high) logically ORed into a shared
109+
STAT interrupt line if their respective enable bit is turned on.
110+
111+
A STAT interrupt will be triggered by a rising edge (transition from
112+
low-to-high) on the STAT interrupt line.
113+
106114
::: warning
107-
As mentioned in the description of the STAT register, the PPU cycles
108-
through the different modes in a fixed order. If we set the STAT bits
109-
in a way that they would interrupt the CPU at two
110-
consecutive modes, then the second interrupt will not trigger. So for example,
111-
if we enable the interrupts for Mode 0 and Mode 1,
112-
the Mode 1 interrupt will not trigger.
115+
If a STAT interrupt source logically ORs the interrupt line high while
116+
(or immediately after) it's already set high by another source, then
117+
there will be no low-to-high transition and so no interrupt will occur.
118+
This phenomenon is known as "STAT blocking" ([test ROM example](https://github.com/Gekkio/mooneye-gb/blob/2d52008228557f9e713545e702d5b7aa233d09bb/tests/acceptance/ppu/stat_irq_blocking.s#L21-L22)).
119+
120+
As mentioned in the description of the [STAT register](#ff41-stat-lcd-status-r-w),
121+
the PPU cycles through the different modes in a fixed order. So for
122+
example, if interrupts are enabled for two consecutive modes such as
123+
Mode 0 and Mode 1, then no interrupt will trigger for Mode 1 (since
124+
the STAT interrupt line won't have a chance to go low between them).
113125
:::
114126

115127
# LCD Position and Scrolling

0 commit comments

Comments
 (0)