GernotFrisch
Member
- Joined
- Jan 2, 2007
- Messages
- 445
Hi,
when I perform a flipscreen, sometimes it flickers. I think it's showing a memory page somewhere deeper in memory.
Here's my swap-code:
CODE
template<class T> inline void SwapMe(T& a, T& b)
{
register T c;
c=a; a=b; b=c;
}
const unsigned long SCREEN0_HW = 0x3101000; // this is the one to restore afterwards
const unsigned long SCREEN1_HW = 0x3381000; // this is the back buffer when ending
// swap these toghether with pRawFrameBuffer and cBuffer
unsigned long FRONTBUFFER_HW = SCREEN0_HW;
unsigned long BACKBUFFER_HW = SCREEN1_HW;
// dummy blit to force MMSP2's blitter to flush it's cache
void gp2x_dummy_blit(void)
{
// SDL method
do {} while (blitter32[MESGSTATUS] & MESG_BUSY);
blitter32[MESGDSTCTRL] = MESG_DSTENB | MESG_DSTBPP_16;
blitter32[MESGDSTADDR] = 0x3101000;
blitter32[MESGDSTSTRIDE] = 4;
blitter32[MESGSRCCTRL] = MESG_SRCBPP_16 | MESG_INVIDEO;
blitter32[MESGPATCTRL] = MESG_PATENB | MESG_PATBPP_1;
blitter32[MESGFORCOLOR] = ~0;
blitter32[MESGBACKCOLOR] = ~0;
blitter32[MESGSIZE] = (1 << MESG_HEIGHT) | 32;
blitter32[MESGCTRL] = MESG_FFCLR | MESG_XDIR_POS | MESG_YDIR_POS | 0xAA;
asm volatile ("":::"memory");
blitter32[MESGSTATUS] = MESG_BUSY;
do {
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
} while (blitter32[MESGSTATUS] & MESG_BUSY);
}
inline void gp2x_vblank()
{
if (vsync_polarity)
do {} while ( (gp2x_memreg16[GPIOB_PINLVL] & GPIOB_VSYNC));
else
do {} while (!(gp2x_memreg16[GPIOB_PINLVL] & GPIOB_VSYNC));
}
// Flip the framebuffer pointer
void gp2x_video_flip()
{
// swap pointers
SwapMe(BACKBUFFER_HW, FRONTBUFFER_HW);
SwapMe(Screen.cBuffer, Screen.pRawFrameBuffer);
// VBlank
gp2x_dummy_blit();
gp2x_vblank();
// set still RGB image pointer
// odd part
gp2x_memreg16[MLC_STL_EADRL]=(unsigned short)(FRONTBUFFER_HW & 0xFFFF);
// even part
gp2x_memreg16[MLC_STL_EADRH]=(unsigned short)(FRONTBUFFER_HW >> 16);
// Wait for vblank to end (to prevent 2 close page flips in one frame)
// while (!(data->io[GPIOB_PINLVL] & GPIOB_VSYNC));
}
when I perform a flipscreen, sometimes it flickers. I think it's showing a memory page somewhere deeper in memory.
Here's my swap-code:
CODE
template<class T> inline void SwapMe(T& a, T& b)
{
register T c;
c=a; a=b; b=c;
}
const unsigned long SCREEN0_HW = 0x3101000; // this is the one to restore afterwards
const unsigned long SCREEN1_HW = 0x3381000; // this is the back buffer when ending
// swap these toghether with pRawFrameBuffer and cBuffer
unsigned long FRONTBUFFER_HW = SCREEN0_HW;
unsigned long BACKBUFFER_HW = SCREEN1_HW;
// dummy blit to force MMSP2's blitter to flush it's cache
void gp2x_dummy_blit(void)
{
// SDL method
do {} while (blitter32[MESGSTATUS] & MESG_BUSY);
blitter32[MESGDSTCTRL] = MESG_DSTENB | MESG_DSTBPP_16;
blitter32[MESGDSTADDR] = 0x3101000;
blitter32[MESGDSTSTRIDE] = 4;
blitter32[MESGSRCCTRL] = MESG_SRCBPP_16 | MESG_INVIDEO;
blitter32[MESGPATCTRL] = MESG_PATENB | MESG_PATBPP_1;
blitter32[MESGFORCOLOR] = ~0;
blitter32[MESGBACKCOLOR] = ~0;
blitter32[MESGSIZE] = (1 << MESG_HEIGHT) | 32;
blitter32[MESGCTRL] = MESG_FFCLR | MESG_XDIR_POS | MESG_YDIR_POS | 0xAA;
asm volatile ("":::"memory");
blitter32[MESGSTATUS] = MESG_BUSY;
do {
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
asm volatile ("nop");
} while (blitter32[MESGSTATUS] & MESG_BUSY);
}
inline void gp2x_vblank()
{
if (vsync_polarity)
do {} while ( (gp2x_memreg16[GPIOB_PINLVL] & GPIOB_VSYNC));
else
do {} while (!(gp2x_memreg16[GPIOB_PINLVL] & GPIOB_VSYNC));
}
// Flip the framebuffer pointer
void gp2x_video_flip()
{
// swap pointers
SwapMe(BACKBUFFER_HW, FRONTBUFFER_HW);
SwapMe(Screen.cBuffer, Screen.pRawFrameBuffer);
// VBlank
gp2x_dummy_blit();
gp2x_vblank();
// set still RGB image pointer
// odd part
gp2x_memreg16[MLC_STL_EADRL]=(unsigned short)(FRONTBUFFER_HW & 0xFFFF);
// even part
gp2x_memreg16[MLC_STL_EADRH]=(unsigned short)(FRONTBUFFER_HW >> 16);
// Wait for vblank to end (to prevent 2 close page flips in one frame)
// while (!(data->io[GPIOB_PINLVL] & GPIOB_VSYNC));
}