Coordinating 32x screen flip and MD vblank?

Ask anything your want about the 32X Mushroom programming.

Moderator: BigEvilCorporation

Post Reply
djcouchycouch
Very interested
Posts: 698
Joined: Sat Feb 18, 2012 2:44 am

Coordinating 32x screen flip and MD vblank?

Post by djcouchycouch » Sun May 02, 2021 8:31 pm

Hi there,

I've got a basic 32x app loop running like

Code: Select all

while (1)
{
    // input
    // draw
    Hw32xScreenFlip(1); // 1 is for wait
}
where Hw32xScreenFlip

Code: Select all

void Hw32xScreenFlip(int wait)
{
    // Flip the framebuffer selection bit
    MARS_VDP_FBCTL = currentFB ^ 1;
    if (wait)
    {
        while ((MARS_VDP_FBCTL & MARS_VDP_FS) == currentFB) ;
        currentFB ^= 1;
    }
}
I believe is originally from Chilly Willy's SDK. I'm using marsdev, which is a descendant.

If I wanted to update some MD planes, which is typically done during vblank, when would that be done? It's not clear to me when vblank happens in the screen flip. I've seen one example doing a screen flip without waiting, modify a plane, then waiting.

Or is waiting for vblank something other than flipping and waiting?

Can anybody shed some light on this? Thanks!

djcouchycouch
Very interested
Posts: 698
Joined: Sat Feb 18, 2012 2:44 am

Re: Coordinating 32x screen flip and MD vblank?

Post by djcouchycouch » Mon May 03, 2021 12:18 am

pouring through the docs again:
"Frame buffer can be switched only in VBlank. During display, even when writing to the FS bit, the buffer does not switch until VBlank occurs; "

It says DRAM can be accessed after confirming the FS bit (from the Frame Buffer Control Register, which indicates which frame buffer it's pointing to) has changed.

So, I guess, if I flip and wait, then after that point I should be in vblank and should be ok to modify the MD VDP.

Post Reply