void draw_init_env() { framebuffer_t frame; zbuffer_t z; packet_t *packet = packet_init(16,PACKET_NORMAL); qword_t *q = packet->data; frame.width = 640; frame.height = 448; frame.psm = GS_PSM_32; frame.mask = 0; frame.address = graph_vram_allocate(frame.width,frame.height,frame.psm,GRAPH_ALIGN_PAGE); z.enable = 0; z.method = ZTEST_METHOD_GREATER; z.address = 0; z.mask = 1; z.zsm = 0; graph_initialize(frame.address,640,448,GS_PSM_32,0,0); q = draw_setup_environment(q,0,&frame,&z); q = draw_finish(q); dma_channel_send_normal(DMA_CHANNEL_GIF,packet->data, q - packet->data, 0,0); dma_wait_fast(); packet_free(packet); }
int main ( void ) { /* read file (or part of it ) into memory */ PACKET *lPck = malloc(sizeof(PACKET)); QWORD *q; FRAMEBUFFER frame; ZBUFFER z; InitCBParam lInfo; int lFD = fioOpen ( MPEG_BITSTREAM_FILE, O_RDONLY ); long lSize; long lPTS, lCurPTS; frame.width = 640; frame.height = 512; frame.mask = 0; frame.psm = GS_PSM_32; frame.address = graph_vram_allocate(frame.width,frame.height, frame.psm, GRAPH_ALIGN_PAGE); z.enable = 0; z.mask = 0; z.method = 0; z.zsm = 0; z.address = 0; packet_allocate(lPck, 100, 0, 0); if ( lFD < 0 ) { printf ( "test_mpeg: could not open '%s'\n", MPEG_BITSTREAM_FILE ); goto end; } /* end if */ lSize = fioLseek ( lFD, 0, SEEK_END ); fioLseek ( lFD, 0, SEEK_SET ); if ( lSize <= 0 ) { printf ( "test_mpeg: could not obtain file size (%ld)\n", lSize ); goto end; } /* end if */ s_pMPEGData = ( unsigned char* )malloc ( lSize = lSize > MAX_SIZE ? MAX_SIZE : lSize ); if ( !s_pMPEGData ) { printf ( "test_mpeg: could not allocate enough memory (%ld)\n", lSize ); goto end; } /* end if */ if ( fioRead ( lFD, s_pTransferPtr = s_pMPEGData, s_MPEGDataSize = lSize ) != lSize ) { printf ( "test_mpeg: could not read file\n" ); goto end; } /* end if */ fioClose ( lFD ); /* initialize DMAC (I have no idea what this code does as */ /* I'm not quite familiar with ps2sdk) */ dma_channel_initialize ( DMA_CHANNEL_toIPU, NULL, 0 ); dma_channel_initialize ( DMA_CHANNEL_GIF, NULL, 0 ); dma_channel_fast_waits( DMA_CHANNEL_GIF ); /* initialize graphics synthesizer */ graph_initialize(0,640,512,GS_PSM_32,0,0); /* setup texture buffer address just after the framebuffer */ lInfo.m_TexAddr = graph_vram_allocate(0,0,GS_PSM_32,GRAPH_ALIGN_BLOCK); q = lPck->data; q = draw_setup_environment(q,0,&frame,&z); /* clear screen */ q = draw_clear(q,0,0,0,640.0f,512.0f,0,0,0); dma_channel_send_normal(DMA_CHANNEL_GIF, lPck->data, q - lPck->data, 0, 0); /* now it's time to initialize MPEG decoder (though it can be */ /* initialized any time). Just make sure that DMA transfers */ /* to and from IPU (and DRAM -> SPR) are not active, otherwise */ /* unpredicted things will happen. Initialization code is also */ /* allocating some memory using 'memalign' function and no */ /* check is performed whether the allocation was successful or */ /* not, so, before calling this make sure that at least WxHx4x3 */ /* bytes are avaliable for dynamic allocation (possibly using */ /* ps2_sbrk ( 0 ) call) where W and H are picture dimensions in */ /* units of pixels. */ MPEG_Initialize ( SetDMA, NULL, InitCB, &lInfo, &lCurPTS ); /* during decoding scratchpad RAM from address 0x0000 to 0x3C00 */ /* is used by the decoder. */ /* let's go */ while ( 1 ) { /* try decode picture into "lInfo.m_pData" area. It's allowed */ /* to supply different area each time, just make sure that */ /* there're no conflicts with data cache, as decoder doesn't do */ /* anything to synchronize/flush/invalidate data cache. */ /* RGB -> YUV colorspace conversion is pefromed automatically */ /* using interrupt hahdler/semaphore, so, multithreaded */ /* application can benefit from it. Usage of IPU and DMA channels */ /* to/from IPU and DRAM -> SPR is strictly forbidden during */ /* decoding :). */ if ( !MPEG_Picture ( lInfo.m_pData, &lPTS ) ) { /* MPEG_Picture returns nonzero if the picture was successfully */ /* decoded. Zero return means one of the following: */ /* - end of stream was detected (SetDMA function returned zero) */ /* - MPEG sequence end code (0x000001B7) was detected */ /* this test just finishes in both cases */ if ( lInfo.m_pInfo -> m_fEOF ) break; /* ...instead of 'break' we can continue to the next sequence...*/ /* ...but I'm too lazy to handle second call of 'InitCB' :D */ else break; } /* end if */ /* now transfer decoded picture data into texture area of GS RAM */ dma_wait_fast(); dma_channel_send_chain( DMA_CHANNEL_GIF, lInfo.m_XFerPck.data, lInfo.m_XFerPck.qwc, 0, 0); /* wait for vsync 2 times (we have interlaced frame mode) */ graph_wait_vsync (); graph_wait_vsync (); /* no need to wait for DMA transfer completion since vsyncs above */ /* have enough lattency... */ /* ...and finally draw decoded picture... */ dma_channel_send_normal( DMA_CHANNEL_GIF, lInfo.m_DrawPck.data, lInfo.m_DrawPck.qwc, 0, 0); /* ...and go back for the next one */ } /* end while */ /* free memory and other resources */ MPEG_Destroy (); end: printf ( "test_mpeg: test finished\n" ); return SleepThread (), 0; } /* end main */