示例#1
0
文件: font.c 项目: AKuHAK2/ps2sdk
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);

}
示例#2
0
文件: font.c 项目: AKuHAK2/ps2sdk
void init_texture()
{
	packet_t *packet = packet_init(50,PACKET_NORMAL);

	qword_t *q = packet->data;

	myaddress = graph_vram_allocate(512,256,GS_PSM_4, GRAPH_ALIGN_BLOCK);
	clutaddress = graph_vram_allocate(8,2,GS_PSM_32, GRAPH_ALIGN_BLOCK);

	q = packet->data;

	q = draw_texture_transfer(q,image_pixel,512,256,GS_PSM_4,myaddress,512);
	q = draw_texture_transfer(q,image_clut32,8,2,GS_PSM_32,clutaddress,64);
	q = draw_texture_flush(q);

	dma_channel_send_chain(DMA_CHANNEL_GIF,packet->data, q - packet->data, 0,0);
	dma_wait_fast();

	packet_free(packet);

}
示例#3
0
文件: font.c 项目: AKuHAK2/ps2sdk
void run_demo(packet_t *packet)
{

	int context = 0;

	vertex_t v0;

	color_t c0;
	color_t c1;

	texbuffer_t texbuf;
	clutbuffer_t clut;
	lod_t lod;

	packet_t *packets[2];
	packet_t *current;

	packets[0] = packet_init(10000,PACKET_NORMAL);
	packets[1] = packet_init(10000,PACKET_NORMAL);

	// Use linear filtering for good scaling results
	lod.calculation = LOD_USE_K;
	lod.max_level = 0;
	lod.mag_filter = LOD_MAG_LINEAR;
	lod.min_filter = LOD_MIN_LINEAR;
	lod.l = 0;
	lod.k = 0;

	texbuf.width = 512;
	texbuf.psm = GS_PSM_4;
	texbuf.address = myaddress;

	texbuf.info.width = draw_log2(512);
	texbuf.info.height = draw_log2(256);
	texbuf.info.components = TEXTURE_COMPONENTS_RGBA;
	texbuf.info.function = TEXTURE_FUNCTION_MODULATE;

	clut.storage_mode = CLUT_STORAGE_MODE1;
	clut.start = 0;

	clut.psm = GS_PSM_32;
	clut.load_method = CLUT_LOAD;
	clut.address = clutaddress;

	v0.x = 320.0f;
	v0.y = 240.0f;
	v0.z = 4;

	c0.r = 0xFF;
	c0.g = 0xFF;
	c0.b = 0xFF;
	c0.a = 0x80;
	c0.q = 1.0f;

	c1.r = 0xFF;
	c1.g = 0x00;
	c1.b = 0x00;
	c1.a = 0x40;
	c1.q = 1.0f;

	// UTF-8
	unsigned char str0[] = { 0x61, 0x62, 0xC2, 0xA9, 0x78, 0xC2, 0xA5, 0xC2, 0xB2, '\0'};

	// Shift-JIS
	unsigned char str1[] = {0x81, 0xBC, 0x93, 0xF1, 0x93, 0xF1, 0x93, 0xF1, 0x81, 0x69, 0x81, 0x40, 0x81,
							0x4F, 0x83, 0xD6, 0x81, 0x4F, 0x81, 0x6A, 0x93, 0xF1, 0x81, 0xBD, 0x0D, '\0' };

	qword_t *q = packet->data;

	while(1)
	{

		current = packets[context];
		q = current->data;

		q = draw_clear(q,0,0,0,640.0f,448.0f,0x40,0x40,0x40);

		q = draw_texture_sampling(q,0,&lod);
		q = draw_texturebuffer(q,0,&texbuf,&clut);

		impress.scale = 3.0f;

		q = fontx_print_sjis(q,0,str1,CENTER_ALIGN,&v0,&c0,&krom_u,&krom_k);
		q = fontstudio_print_string(q,0,str0,CENTER_ALIGN,&v0,&c1,&impress);

		q = draw_finish(q);

		dma_wait_fast();
		dma_channel_send_normal(DMA_CHANNEL_GIF,current->data, q - current->data, 0,0);

		draw_wait_finish();

		context ^= 1;

		graph_wait_vsync();

	}

	free(packets[0]);
	free(packets[1]);
}
示例#4
0
文件: mpeg.c 项目: AzagraMac/PS2_SDK
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 */