Timing of LYC==0

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
User avatar
dalton
Posts: 11
Joined: Mon Jun 09, 2014 1:18 pm
Location: Gothenburg, Sweden
Contact:

Timing of LYC==0

Post by dalton »

Hi,

does anyone know whether the horizontal timing of the LYC interrupt at Y==0 is different to other rows?

It seems the timing, (the number of cycles before the row graphics is shown) is consistent for all rows but the first. At Y==0 the interrupt seems to occur somewhat earlier.

Cheers
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Timing of LYC==0

Post by DarkMoe »

I guess nobody truly knows,

What I've seen implemented in some emulators is that ly = 0 when the LCD is just turned on has 456 cycles and when it hits VBLANK, ly = 0 has that double timing behaviour (456 * 2).

I have it like that on my emu, but my interrupt code is a mess. Not really sure if theres a demo or game that relies on that specific quirck
User avatar
dalton
Posts: 11
Joined: Mon Jun 09, 2014 1:18 pm
Location: Gothenburg, Sweden
Contact:

Re: Timing of LYC==0

Post by dalton »

Thanks!

It seems LYC==0 is early by a time corresponding to about one scanline, compared to the other LYC interrupts.
This loop in the beginning of the interrupt at row zero puts it into phase:

Code: Select all

        ld a,56
loop:
        dec a
        jr nz,loop
(cgb double speed)
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Timing of LYC==0

Post by tepples »

Having it be zero during the equivalent of a "pre-render" line would make sense in a way to me.
binji
Posts: 11
Joined: Thu Jun 16, 2016 11:53 am

Re: Timing of LYC==0

Post by binji »

Wilbert Pol's fork of mooneye-gb has some tests for LY=0. If these are correct, the behavior is that LY=153 lasts for just 4 cycles, then becomes LY=0, even though the mode is still VBLANK. So LY=0 actually lasts for 452 + 456 cycles. But it looks like the LY=LYC interrupt for LY=0 doesn't fire exactly when LY becomes 0, but after a 4-cycle delay. Another interesting case that is likely related: it seems that if you write 153 to LYC on the cycle when LY becomes 0, the STAT interrupt will fire.
Post Reply