1 #include "rockmacros.h"
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.
24 void stat_trigger(void)
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
);
44 * stat_change is called when a transition results in a change to the
45 * LCD STAT condition (the low 2 bits of R_STAT). It raises or lowers
46 * the VBLANK interrupt line appropriately and calls stat_trigger to
47 * update the STAT interrupt line.
50 static void stat_change(unsigned int stat
)
52 R_STAT
= (R_STAT
& 0x7C) | stat
;
54 if (stat
!= 1) hw_interrupt(0, IF_VBLANK
);
55 /* hw_interrupt((stat == 1) ? IF_VBLANK : 0, IF_VBLANK); */
60 void lcdc_change(byte b
)
64 if ((R_LCDC
^ old
) & 0x80) /* lcd on/off change */
80 switch ((byte
)(R_STAT
& 3))
104 switch ((byte
)(R_STAT
& 3))
107 if (!(hw
.ilines
& IF_VBLANK
))
110 hw_interrupt(IF_VBLANK
, IF_VBLANK
);
122 else if (R_LY
== 152)
142 /* FIXME -- how much of the hblank does hdma use?? */
151 hw_interrupt(IF_VBLANK
, IF_VBLANK
);