observing the code included from vu1_triangle (main.c), there is a while(1) which in each iteration, a variable called final_matrix is uploaded to VU1mem, a triangle prim (packed into a GIF_TAG) is uploaded to VU1mem and finally VIF_NOP-VIF_MSCAL are sent to VIF1.
Now, the question is: why the demo doesn't work fine (the triangle isnt drawn) when i upload the triangle prim just before the while(1) and not in each iteration?
Considering the triangle prim is the same at all iterations, i upload it before the while(1) and not uploading it into the while(1) with the intention to save cycles.
It seems that after each iteration (more in particular, after the execution of the vu-program), the VU1mem is cleared and all the data lost.
Thats my code:
Code: Select all
///////////////////////////////////////////////////////////////////////////
// Add giftag and color of the triangle
*((u64*)p_data)++ = DMA_CNT_TAG( 5 );
*((u32*)p_data)++ = VIF_CODE( VIF_STCYL,0,0x0404 );
*((u32*)p_data)++ = VIF_CODE( VIF_UNPACK_V4_32,5,4 );
*((u64*)p_data)++ = GIF_TAG( 1, 1, 1, GS_SETREG_PRIM( GS_PRIM_PRIM_TRIANGLE,
0, 0, 0, 0, 0, 0, 0, 0 ), 0, 4 );
*((u64*)p_data)++ = 0x5551;
*((u32*)p_data)++ = 127;
*((u32*)p_data)++ = 127;
*((u32*)p_data)++ = 127;
*((u32*)p_data)++ = 0;
///////////////////////////////////////////////////////////////////////////
// add vertex coords of the triangle
*((float*)p_data)++ = -100.0f;
*((float*)p_data)++ = 100.0f;
*((float*)p_data)++ = 0.0f;
*((float*)p_data)++ = 1.0f;
*((float*)p_data)++ = -100.0f;
*((float*)p_data)++ = -100.0f;
*((float*)p_data)++ = 0.0f;
*((float*)p_data)++ = 1.0f;
*((float*)p_data)++ = 50.0f;
*((float*)p_data)++ = 50.0f;
*((float*)p_data)++ = 100.0f;
*((float*)p_data)++ = 1.0f;
/////////////////////////////////////////////////////////////////////////////
// Loop of the demo
while( 1 )
{
angle += 0.03f;
PbScreenClear( 30<<16|20<<8|40 );
///////////////////////////////////////////////////////////////////////////
// Rotate & build final matrix to be used in the vu1 program.
PbMatrixRotateZ( &rotate_matrix, angle );
PbMatrixMultiply( &temprot_matrix, &rotate_matrix, &camera_matrix );
PbMatrixMultiply( &final_matrix, &temprot_matrix, &viewscreen_matrix );
FlushCache(0);
p_data = p_store = PbSprAlloc( 10*16 );
///////////////////////////////////////////////////////////////////////////
// Build the data we need to send to the vu1
*((u64*)p_data)++ = DMA_REF_TAG( (u32)&final_matrix, 4 );
*((u32*)p_data)++ = VIF_CODE( VIF_STCYL,0,0x0404 );
*((u32*)p_data)++ = VIF_CODE( VIF_UNPACK_V4_32,4,0 );
///////////////////////////////////////////////////////////////////////////
// End the list and start the program
*((u64*)p_data)++ = DMA_END_TAG( 0 );
*((u32*)p_data)++ = VIF_CODE( VIF_NOP,0,0 );
*((u32*)p_data)++ = VIF_CODE( VIF_MSCAL,0,0 );
PbDmaSend01ChainSpr( p_store );
///////////////////////////////////////////////////////////////////////////
// Sync and flipscreen
PbScreenSyncFlip();
}