15 * stat_trigger updates the STAT interrupt line to reflect whether any
16 * of the conditions set to be tested (by bits 3-6 of R_STAT) are met.
17 * This function should be called whenever any of the following occur:
18 * 1) LY or LYC changes.
19 * 2) A state transition affects the low 2 bits of R_STAT (see below).
20 * 3) The program writes to the upper bits of R_STAT.
21 * stat_trigger also updates bit 2 of R_STAT to reflect whether LY=LYC.
26 static const int condbits
[4] = { 0x08, 0x10, 0x20, 0x00 };
32 if (R_STAT
& 0x40) flag
= IF_STAT
;
36 if (R_STAT
& condbits
[R_STAT
&3]) flag
= IF_STAT
;
38 if (!(R_LCDC
& 0x80)) flag
= 0;
40 hw_interrupt(flag
, IF_STAT
);
43 void stat_write(byte b
)
45 R_STAT
= (R_STAT
& 0x07) | (b
& 0x78);
46 if (!hw
.cgb
&& !(R_STAT
& 2)) /* DMG STAT write bug => interrupt */
47 hw_interrupt(IF_STAT
, IF_STAT
);
53 * stat_change is called when a transition results in a change to the
54 * LCD STAT condition (the low 2 bits of R_STAT). It raises or lowers
55 * the VBLANK interrupt line appropriately and calls stat_trigger to
56 * update the STAT interrupt line.
59 static void stat_change(int stat
)
62 R_STAT
= (R_STAT
& 0x7C) | stat
;
64 if (stat
!= 1) hw_interrupt(0, IF_VBLANK
);
65 /* hw_interrupt((stat == 1) ? IF_VBLANK : 0, IF_VBLANK); */
70 void lcdc_change(byte b
)
74 if ((R_LCDC
^ old
) & 0x80) /* lcd on/off change */
90 switch ((byte
)(R_STAT
& 3))
114 switch ((byte
)(R_STAT
& 3))
117 if (!(hw
.ilines
& IF_VBLANK
))
120 hw_interrupt(IF_VBLANK
, IF_VBLANK
);
132 else if (R_LY
== 152)
151 /* FIXME -- how much of the hblank does hdma use?? */
160 hw_interrupt(IF_VBLANK
, IF_VBLANK
);