The examples given above work correctly in Mednafen, Reality Boy, and on hardware.
> What should I do?
It's likely you will need to restructure or rewrite your main loop.
> If you don't want to use interrupts, you
> could sync to the actual screen refresh
> by using the DPSTTS [DPBSY flags]...
The reason for syncing to XPEND or using the XPEND interrupt is to avoid writing to VRAM, the world attributes, OAM, the parameter tables, etc, during the VIP drawing process. Syncing to GAMESTART is fine too, but means you need to use an interrupt:
#include "libgccvb.h"
void vip_isr()
{
VIP_REGS[INTENB]= 0;
if(VIP_REGS[INTPND] & XPEND)
{
VIP_REGS[INTCLR]= XPEND;
// drawing finished, write to VRAM, OAM, etc, here!
}
VIP_REGS[INTENB]= XPEND;
}
int main()
{
int count= 0;
VPU_VECTOR= (u32)vip_isr;
VIP_REGS[INTENB]= XPEND;
vbDisplayOn();
vbDisplayShow();
// main loop @ 50 Hz
while(1)
{
// sync with start of gameframe
while(!(VIP_REGS[INTPND] & GAMESTART));
// clear flag
VIP_REGS[INTCLR]= GAMESTART;
// read controller
// do stuff
if((count&15)==0)
VIP_REGS[BKCOL] ^= 3;
count++;
}
return 0;
}
Edited by dasi on 2011/2/16 1:38