/*---------------------------------------------------------------------------* Project: VI trap filter demo File: cross-color.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: cross-color.c,v $ Revision 1.1 07/22/2006 04:56:27 urata Initial checkin. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #define NTSC // if you change here, you can see PAL or M/PAL #if defined(NTSC) GXRenderModeObj* rmode = &GXNtsc480Int; #elif defined(PAL) GXRenderModeObj* rmode = &GXPal528Int; #elif defined(EURGB60) GXRenderModeObj* rmode = &GXEurgb60Hz480Int; #else GXRenderModeObj* rmode = &GXMpal480Int; #endif // for X frame buffer static u8* xfbA; static u8* xfbB; /*---------------------------------------------------------------------------* Name: allocateFB Description: Allocates memory for two frame buffers Arguments: fbSize each frame buffer size Returns: none *---------------------------------------------------------------------------*/ static void allocateFB(u32 fbSize) { void* arenaLo; arenaLo = OSGetArenaLo(); // allocate memory for frame buffer here. xfbA = (u8*)OSRoundUp32B(arenaLo); xfbB = (u8*)OSRoundUp32B(xfbA + fbSize); arenaLo = (void*)(xfbA + 2 * fbSize); OSSetArenaLo(arenaLo); } /*---------------------------------------------------------------------------* Name: YuvPset Description: Draw point Arguments: posX X coordinate posY Y coordinate width Stride of xfb xfb Frame buffer address luma Luma of point color u,v Chroma of point color Returns: None. *---------------------------------------------------------------------------*/ static void YuvPset(s32 posX, s32 posY, s32 width, u32 *xfb, u8 luma, u8 u, u8 v) { u32 *ptr; u32 y1, y2; ptr = xfb + (posX>>1) + (width/2) * posY; if (posX & 1) { y1 = (((*ptr) >> 24) & 0xFF ) ; y2 = luma; } else { y1 = luma; y2 = (((*ptr) >> 8) & 0xFF ) ; } *ptr = ((y1<<24) | (u<<16) | (y2<<8) | v); } /*---------------------------------------------------------------------------* Name: YuvCircle Description: Draw circle Arguments: posX Center of X coordinate posY Center of Y coordinate width Stride of xfb r Radius xfb Frame buffer address luma Luma of point color u,v Chroma of point color Returns: None. *---------------------------------------------------------------------------*/ static void YuvCircle(s32 posX, s32 posY, s32 width, s32 r, u32 *xfb, u8 luma, u8 u, u8 v) { int x, y, f; x = r; y = 0; f = -2 * r + 3; while (x >= y) { YuvPset(posX + x, posY + y, width, xfb, luma, u, v); YuvPset(posX - x, posY + y, width, xfb, luma, u, v); YuvPset(posX + x, posY - y, width, xfb, luma, u, v); YuvPset(posX - x, posY - y, width, xfb, luma, u, v); YuvPset(posX + y, posY + x, width, xfb, luma, u, v); YuvPset(posX - y, posY + x, width, xfb, luma, u, v); YuvPset(posX + y, posY - x, width, xfb, luma, u, v); YuvPset(posX - y, posY - x, width, xfb, luma, u, v); if (f >= 0) { x --; f -= x*4; } y++; f += 4*y + 2; } } /*---------------------------------------------------------------------------* Name: DrawCircles Description: Draw circles Arguments: width Screen width height Screen height fbSize Size of the frame buffer xfb Frame buffer address Returns: none *---------------------------------------------------------------------------*/ static void DrawCircles(s32 width, s32 height, u32 fbSize, u8* xfb) { s32 xoffset; s32 yoffset; s32 r; u8 luma,u,v; luma = 0xEB; u = 0x80; v = 0x80; xoffset = width / 2; yoffset = height / 2; for(r=2; rfbWidth) * rmode->xfbHeight * VI_DISPLAY_PIX_SZ); allocateFB(fbSize); VIConfigure(rmode); // Need to "flush" so that the VI changes so far takes effect // from the following field VIFlush(); VIWaitForRetrace(); first = 1; frame = 0; mode=0; // flip mode; 0 = disable trap filter, 1 = enable trap filter trap_filter=VI_DISABLE; OSReport("Disable Trap filter.\n"); DrawBlackScreen(fbSize, xfbA); DrawBlackScreen(fbSize, xfbB); while(1) { PADRead(pstat); if ((pstat[0].button & PAD_BUTTON_A) && !(plast & PAD_BUTTON_A)) { mode = 1 - mode; if (mode) { trap_filter = VI_ENABLE; OSReport("Enable Trap filter.\n"); } else { trap_filter = VI_DISABLE; OSReport("Disable Trap filter.\n"); } } xfb = (frame & 0x1)? xfbB : xfbA; DrawCircles( rmode->fbWidth, rmode->xfbHeight, fbSize, xfb); VISetNextFrameBuffer((void*)xfb ); if (first == 1) { VISetBlack(FALSE); first = 0; } VISetTrapFilter(trap_filter); // Need to "flush" so that the VI changes so far takes effect // from the following field VIFlush(); VIWaitForRetrace(); plast = pstat[0].button; frame++; } }