示例#1
0
void psp_init(void)
{
	SceUID thid;
	char buff[128], *r;

	/* fw 1.5 sometimes returns 8002032c, although getcwd works */
	r = getcwd(buff, sizeof(buff));
	if (r) sceIoChdir(buff);

	main_thread_id = sceKernelGetThreadId();

	lprintf("running on %08x kernel\n", sceKernelDevkitVersion()),
	lprintf("entered psp_init, threadId %08x, priority %i\n", main_thread_id,
		sceKernelGetThreadCurrentPriority());

	thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, NULL);
	if (thid >= 0)
	{
		sceKernelStartThread(thid, 0, 0);
	}

	/* video */
	sceDisplaySetMode(0, 480, 272);
	sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
	current_screen = 1;
	psp_screen = VRAM_FB0;

	/* gu */
	sceGuInit();

	sceGuStart(GU_DIRECT, guCmdList);
	sceGuDrawBuffer(GU_PSM_5650, (void *)VRAMOFFS_FB0, 512);
	sceGuDispBuffer(480, 272, (void *)VRAMOFFS_FB1, 512); // don't care
	sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
	sceGuDepthBuffer((void *)VRAMOFFS_DEPTH, 512);
	sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
	sceGuViewport(2048, 2048, 480, 272);
	sceGuDepthRange(0xc350, 0x2710);
	sceGuScissor(0, 0, 480, 272);
	sceGuEnable(GU_SCISSOR_TEST);

	sceGuDepthMask(0xffff);
	sceGuDisable(GU_DEPTH_TEST);

	sceGuFrontFace(GU_CW);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
	sceGuAmbientColor(0xffffffff);
	sceGuColor(0xffffffff);
	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);


	/* input */
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
}
示例#2
0
void vidgu_init()
{

	g_pBlitBuff = (unsigned short *)(0x40000000 | (unsigned int)&g_BlitBuff);

	sceGuInit();

	// setup
	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_5650,(void*)0,512);
	sceGuDispBuffer(480,272,(void*)0x88000,512);
	sceGuDepthBuffer((void*)0x110000,512);
	sceGuOffset(2048 - (480/2),2048 - (272/2));
	sceGuViewport(2048,2048,480,272);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,480,272);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFrontFace(GU_CW);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(1);

}
示例#3
0
文件: main.c 项目: CDragu/pspsdk
void setupGu(void)
{
	sceGuInit();

	sceGuStart(GU_DIRECT, list);
	sceGuDrawBuffer(GU_PSM_8888, 0, BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000, BUF_WIDTH);

	sceGuOffset(0, 0);

	sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);

	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuEnable(GU_BLEND);

	//sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
	//sceGuTexFilter(GU_LINEAR_MIPMAP_LINEAR, GU_NEAREST);
	//sceGuTexWrap(GU_REPEAT, GU_REPEAT);

	sceGuClearColor(0);
	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(0, 0);
	
	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
}
示例#4
0
void psp_init() {
	SetupCallbacks();

	sceGuInit();

	//sceGuStart(GU_DIRECT,list);
	//sceGuDrawBuffer(GU_PSM_5650,(void*)0,512);
	//sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x44000,512);
	//sceGuViewport(0,0,SCR_WIDTH,SCR_HEIGHT);
	//sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	//sceGuEnable(GU_SCISSOR_TEST);
	//sceGuFrontFace(GU_CW);
	//sceGuShadeModel(GU_SMOOTH);
	//sceGuEnable(GU_CULL_FACE);
	//sceGuEnable(GU_TEXTURE_2D);
	//sceGuFinish();
	//sceGuSync(0,0);
	//sceGuDisplay(GU_TRUE);


	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_5650,(void*)0,512);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x44000,512);
	//sceGuViewport(0,0,SCR_WIDTH,SCR_HEIGHT);
	//sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	//sceGuEnable(GU_SCISSOR_TEST);
	//sceGuFrontFace(GU_CW);
	//sceGuShadeModel(GU_SMOOTH);
	//sceGuEnable(GU_CULL_FACE);
	//sceGuEnable(GU_TEXTURE_2D);
	sceGuFinish();
	sceGuSync(0,0);
	sceGuDisplay(GU_TRUE);

}
示例#5
0
void MasterGuRenderer::guInit() {
	DEBUG_ENTER_FUNC();

	sceGuInit();
	sceGuStart(0, _displayList);

	guProgramDisplayBufferSizes();

	sceGuOffset(2048 - (PSP_SCREEN_WIDTH / 2), 2048 - (PSP_SCREEN_HEIGHT / 2));
	sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
	sceGuDepthRange(0xC350, 0x2710);
	sceGuDisable(GU_DEPTH_TEST);	// We'll use depth buffer area
	sceGuDepthMask(GU_TRUE);		// Prevent writes to depth buffer
	sceGuScissor(0, 0, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFrontFace(GU_CW);
	sceGuEnable(GU_TEXTURE_2D);

	sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(1);
}
示例#6
0
文件: glib2d.c 项目: libcg/PSP_Bot
void _gInit()
{
  // Init & setup GU
  sceGuInit();
  sceGuStart(GU_DIRECT,list);

  sceGuDrawBuffer(GU_PSM_8888,(void*)FRAMEBUFFER_SIZE,PSP_LINE_SIZE);
  sceGuDispBuffer(G_SCR_W,G_SCR_H,(void*)0,PSP_LINE_SIZE);
  sceGuDepthBuffer((void*)(FRAMEBUFFER_SIZE*2),PSP_LINE_SIZE);
  sceGuOffset(2048-(G_SCR_W/2),2048-(G_SCR_H/2));
  sceGuViewport(2048,2048,G_SCR_W,G_SCR_H);

  gResetScissor();
  sceGuDepthRange(65535,0);
  sceGuClearDepth(65535);
  sceGuAlphaFunc(GU_GREATER,0,0xff);
  sceGuDepthFunc(GU_LEQUAL);
  sceGuBlendFunc(GU_ADD,GU_SRC_ALPHA,GU_ONE_MINUS_SRC_ALPHA,0,0);
  sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA);
  sceGuTexFilter(GU_LINEAR,GU_LINEAR);
  sceGuShadeModel(GU_FLAT);

  sceGuDisable(GU_CULL_FACE);
  sceGuDisable(GU_CLIP_PLANES);
  sceGuDisable(GU_DITHER);
  sceGuEnable(GU_ALPHA_TEST);
  sceGuEnable(GU_SCISSOR_TEST);

  sceGuFinish();
  sceGuSync(0,0);
  sceDisplayWaitVblankStart();
  sceGuDisplay(GU_TRUE);

  init = G_TRUE;
}
示例#7
0
void init()
{
	void *fbp0 = 0;
 
	sceGuInit();
	sceGuStart(GU_DIRECT, list);
	sceGuDrawBuffer(GU_PSM_8888, fbp0, BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, fbp0, BUF_WIDTH);
	sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFinish();
	sceGuSync(0, 0);
 
	sceDisplayWaitVblankStart();
	sceGuDisplay(1);
}
示例#8
0
bool8 S9xSceGUInit (void)
{
  sceGuInit ();

  sceDisplaySetMode (0, SCREEN_WIDTH, SCREEN_HEIGHT);

  S9xSceGUInit2 ();

  sceGuDrawBuffer (SceGU.pixel_format, (void *)0, SceGU.line_size);

#ifdef SCEGU_DOUBLE_BUFFERED
  sceGuDisplay    (1);
#endif

  return (TRUE);
}
示例#9
0
void Red3dInitScreen()
{
	
	intraFontInit();
    
	ltn = intraFontLoad("flash0:/font/ltn8.pgf", 0);
	if(!ltn) sceKernelExitGame();
	intraFontSetStyle(ltn, 1.0f, 0xFFFFFFFF, 0xBFBFBFBF, 0);
	
	void *fbp0 = vrelptr(valloc((FRAMEBUFFER_WIDTH * sizeof(unsigned int))   * SCREEN_HEIGHT));
	void *fbp1 = vrelptr(valloc((FRAMEBUFFER_WIDTH * sizeof(unsigned int))   * SCREEN_HEIGHT));
	void *zbp  = vrelptr(valloc((FRAMEBUFFER_WIDTH * sizeof(unsigned short)) * SCREEN_HEIGHT));
	
	pspDebugScreenInit();
	sceGuInit();
	sceGuStart(GU_DIRECT,list);

	sceGuDrawBuffer(GU_PSM_8888, fbp0, FRAMEBUFFER_WIDTH);
	sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, fbp1, FRAMEBUFFER_WIDTH);
	sceGuDepthBuffer(zbp, FRAMEBUFFER_WIDTH);
	sceGuOffset(2048 - (SCREEN_WIDTH/2),2048 - (SCREEN_HEIGHT/2));
	sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT);
	sceGuDepthRange(65535, 0);
    sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    sceGuDepthFunc(GU_GEQUAL);
    sceGuEnable(GU_DEPTH_TEST);
	sceGuEnable(GU_SCISSOR_TEST);
	
	sceGuFrontFace(GU_CCW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);
	
	sceGuEnable(GU_BLEND);
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGBA);
	sceGuTexFilter(GU_LINEAR,GU_LINEAR);
	
	sceGuFinish();
	sceGuSync(0,0);
	
	Red3dSetupScreen();
	
}
示例#10
0
文件: main.c 项目: joshdekock/jim-psp
int main_thread(SceSize args, void *argp)
{
    FILE *fp;
    int argc = 1;
    char *argv[] = {save_argv0};

#ifdef WITH_PSP2D
    sceGuInit();
#endif

    Py_Initialize();

    PySys_SetPath("ms0:/python");
    PySys_SetArgv(argc, argv);

    fp = fopen("script.py", "r");
    if (fp)
    {
       PyRun_SimpleFile(fp, "script.py");
       fclose(fp);
    }
    else
    {
#ifndef DEBUG
       pspDebugScreenInit();
#endif

       pspDebugScreenPrintf("Error - could not open script.py\n");
    }

#ifdef DEBUG
    sceKernelDelayThreadCB(1e7);
#endif

    Py_Finalize();

#ifdef WITH_PSP2D
    sceGuTerm();
#endif

    sceKernelExitGame();

    return 0;
}
示例#11
0
void InitGU( void )
{
	// Init GU
	sceGuInit();
	sceGuStart( GU_DIRECT, dList );

	// Set Buffers
	sceGuDrawBuffer( GU_PSM_8888, fbp0, BUF_WIDTH );
	sceGuDispBuffer( SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
	sceGuDepthBuffer( (void*)0x110000, BUF_WIDTH);

 	sceGuOffset( 2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2));
	sceGuDepthRange( 65535, 0);

	// Set Render States
	sceGuScissor( 0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable( GU_SCISSOR_TEST );
	sceGuDepthFunc( GU_GEQUAL );
	sceGuEnable( GU_DEPTH_TEST );
	sceGuFrontFace( GU_CW );
	sceGuEnable( GU_CULL_FACE );					
	sceGuShadeModel( GU_SMOOTH );
	sceGuEnable( GU_CLIP_PLANES );
	sceGuEnable( GU_TEXTURE_2D );
	sceGuEnable( GU_LIGHTING );
	sceGuEnable( GU_LIGHT0 );						// Enable Light 1 (NEW)

	// setup texture
	// 32-bit image, if we swizzled the texture will return true, otherwise false (NEW)
	sceGuTexMode( GU_PSM_8888, 0, 0, true );	
	sceGuTexFunc( GU_TFX_MODULATE, GU_TCC_RGB );	// Modulate the color of the image
	sceGuTexScale( 1.0f, 1.0f );					// No scaling
	sceGuTexOffset( 0.0f, 0.0f );

	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
	// finish
}
示例#12
0
int os_fb_init(int argc, char** argv) {
	int i;
	if (os_byte_fb != NULL)
		return 1;
	//os_byte_fb = //(os_byte_t*) malloc(640*480*4);
	os_byte_fb = pixels;

	for (i = 0; i < 256; ++i) {
		os_fb_palette[i].r = 0;
		os_fb_palette[i].g = 0;
		os_fb_palette[i].b = 0;
	}

	pspDebugScreenInit();
	SetupCallbacks();

	sceGuInit();

	// setup
	sceGuStart(0,list);
	sceGuDrawBuffer(GE_PSM_4444,(void*)0,512);
	sceGuDispBuffer(480,272,(void*)0x88000,512);
	sceGuDepthBuffer((void*)0x110000,512);
	sceGuOffset(2048 - (480/2),2048 - (272/2));
	sceGuViewport(2048,2048,480,272);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,480,272);
	sceGuEnable(GU_STATE_SCISSOR);
	sceGuFrontFace(GE_FACE_CW);
	sceGuEnable(GU_STATE_TEXTURE);
	sceGuClear(GE_CLEAR_COLOR|GE_CLEAR_DEPTH);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(1);

	return 0;
///	return x11_display_init(640, 480, "dacube2", argc, argv);
}
示例#13
0
void init() { 
	sceGuInit();
	sceGuStart(GU_DIRECT, list);
	sceGuDrawBuffer(GU_PSM_8888, fbp0, 512);
	sceGuDispBuffer(480, 272, fbp0, 512);
	sceGuDepthBuffer(dbp0, 512);
	sceGuOffset(2048 - (240 / 2), 2048 - (136 / 2));
	sceGuViewport(2048, 2048, 240, 136);
	sceGuDepthRange(65535, 0);
	sceGuDepthMask(0);
	sceGuScissor(0, 0, 480, 272);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuDisable(GU_TEXTURE_2D);

	ScePspFMatrix4 ones = {
		{1, 0, 0, 0},
		{0, 1, 0, 0},
		{0, 0, 1, 0},
		{0, 0, 0, 1},
	};

	sceGuSetMatrix(GU_MODEL, &ones);
	sceGuSetMatrix(GU_VIEW, &ones);
	sceGuSetMatrix(GU_PROJECTION, &ones);

	sceGuFinish();
	sceGuSync(0, 0);
 
	sceDisplayWaitVblankStart();
	sceGuDisplay(1);

	memset(copybuf, 0x44, sizeof(copybuf));
	sceKernelDcacheWritebackInvalidateAll();
	sceDmacMemcpy(sceGeEdramGetAddr(), copybuf, sizeof(copybuf));
	sceKernelDcacheWritebackInvalidateAll();

	displayBuffer("Initial");
}
示例#14
0
void init() {
	void *fbp0 = 0;

	drawbuf = (u32 *)sceGeEdramGetAddr();

	sceGuInit();
	sceGuStart(GU_DIRECT, list);
	sceGuDrawBuffer(GU_PSM_8888, fbp0, BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, fbp0, BUF_WIDTH);
	sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(1);

	memset(copybuf, 0, sizeof(copybuf));
	sceKernelDcacheWritebackInvalidateAll();
	sceDmacMemcpy(drawbuf, copybuf, sizeof(copybuf));
	sceKernelDcacheWritebackInvalidateAll();
}
示例#15
0
void initGraphics()
{
	dispBufferNumber = 0;

	sceGuInit();

	guStart();
	sceGuDrawBuffer(GU_PSM_8888, (void*)FRAMEBUFFER_SIZE, PSP_LINE_SIZE);
	sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void*)0, PSP_LINE_SIZE);
	sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
	sceGuDepthBuffer((void*) (FRAMEBUFFER_SIZE*2), PSP_LINE_SIZE);
	sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2));
	sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT);
	sceGuDepthRange(0xc350, 0x2710);
	sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuAlphaFunc(GU_GREATER, 0, 0xff);
	sceGuEnable(GU_ALPHA_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuTexMode(GU_PSM_8888, 0, 0, 0);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
	sceGuTexFilter(GU_NEAREST, GU_NEAREST);
	sceGuAmbient(0xffffffff);
	sceGuEnable(GU_BLEND);
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
	initialized = 1;
}
示例#16
0
int MFRenderer_CreateDisplay()
{
	gDisplay.width = SCR_WIDTH;
	gDisplay.height = SCR_HEIGHT;
	gDisplay.wide = true;

	gCurrentViewport.x = 0.0f;
	gCurrentViewport.y = 0.0f;
	gCurrentViewport.width = SCR_WIDTH;
	gCurrentViewport.height = SCR_HEIGHT;

	sceGuInit();

	sceGuStart(GU_DIRECT, displayList);
	sceGuDrawBuffer(GU_PSM_8888, (void*)0, BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)FRAME_SIZE, BUF_WIDTH);
	sceGuDepthBuffer((void*)(FRAME_SIZE*2), BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT);
	sceGuDepthRange(0x0, 0xFFFF);
	sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_LEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW); // NOTE: not CCW
	sceGuShadeModel(GU_SMOOTH);
	sceGuDisable(GU_CULL_FACE);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	return 0;
}
示例#17
0
static void *psp_init(const video_info_t *video,
      const input_driver_t **input, void **input_data)
{
   /* to-do : add ASSERT() checks or use main RAM if 
    * VRAM is too low for desired video->input_scale. */
   void *pspinput;
   int pixel_format, lut_pixel_format, lut_block_count;
   unsigned int red_shift, color_mask;
   void *displayBuffer, *LUT_r, *LUT_b;
   psp1_video_t *psp  = (psp1_video_t*)calloc(1, sizeof(psp1_video_t));

   if (!psp)
      return NULL;

   sceGuInit();

   psp->vp.x           = 0;
   psp->vp.y           = 0;
   psp->vp.width       = SCEGU_SCR_WIDTH;
   psp->vp.height      = SCEGU_SCR_HEIGHT;
   psp->vp.full_width  = SCEGU_SCR_WIDTH;
   psp->vp.full_height = SCEGU_SCR_HEIGHT;

   /* Make sure anything using uncached pointers reserves 
    * whole cachelines (memory address and size need to be a multiple of 64)
    * so it isn't overwritten by an unlucky cache writeback.
    *
    * This includes display lists since the Gu library uses 
    * uncached pointers to write to them. */

   /* Allocate more space if bigger display lists are needed. */
   psp->main_dList         = memalign(64, 256);

   psp->frame_dList        = memalign(64, 256);
   psp->menu.dList         = memalign(64, 256);
   psp->menu.frame         = memalign(16,  2 * 480 * 272);
   psp->frame_coords       = memalign(64,
         (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63));
   psp->menu.frame_coords  = memalign(64,
         (((PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t)) + 63) & ~63));

   memset(psp->frame_coords, 0,
         PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t));
   memset(psp->menu.frame_coords, 0,
         PSP_FRAME_SLICE_COUNT * sizeof(psp1_sprite_t));

   sceKernelDcacheWritebackInvalidateAll();
   psp->frame_coords       = TO_UNCACHED_PTR(psp->frame_coords);
   psp->menu.frame_coords  = TO_UNCACHED_PTR(psp->menu.frame_coords);

   psp->frame_coords->v0.x = 60;
   psp->frame_coords->v0.y = 0;
   psp->frame_coords->v0.u = 0;
   psp->frame_coords->v0.v = 0;

   psp->frame_coords->v1.x = 420;
   psp->frame_coords->v1.y = SCEGU_SCR_HEIGHT;
   psp->frame_coords->v1.u = 256;
   psp->frame_coords->v1.v = 240;

   psp->vsync = video->vsync;
   psp->rgb32 = video->rgb32;

   if(psp->rgb32)
   {
      uint32_t* LUT_r_local = (uint32_t*)(SCEGU_VRAM_BP32_2);
      uint32_t* LUT_b_local = (uint32_t*)(SCEGU_VRAM_BP32_2) + (1 << 8);

      red_shift = 8 + 8;
      color_mask = 0xFF;
      lut_block_count = (1 << 8) / 8;

      psp->texture = (void*)(LUT_b_local + (1 << 8));
      psp->draw_buffer = SCEGU_VRAM_BP32_0;
      psp->bpp_log2 = 2;

      pixel_format = GU_PSM_8888;
      lut_pixel_format = GU_PSM_T32;

      displayBuffer = SCEGU_VRAM_BP32_1;

      for (u32 i=0; i < (1 << 8); i++){
         LUT_r_local[i]= i;
         LUT_b_local[i]= i << (8 + 8);
      }

      LUT_r = (void*)LUT_r_local;
      LUT_b = (void*)LUT_b_local;

   }
   else
   {
      uint16_t* LUT_r_local = (uint16_t*)(SCEGU_VRAM_BP_2);
      uint16_t* LUT_b_local = (uint16_t*)(SCEGU_VRAM_BP_2) + (1 << 5);

      red_shift = 6 + 5;
      color_mask = 0x1F;
      lut_block_count = (1 << 5) / 8;

      psp->texture = (void*)(LUT_b_local + (1 << 5));
      psp->draw_buffer = SCEGU_VRAM_BP_0;
      psp->bpp_log2 = 1;

      pixel_format = 
         (g_extern.system.pix_fmt == RETRO_PIXEL_FORMAT_0RGB1555) 
         ? GU_PSM_5551 : GU_PSM_5650 ;

      lut_pixel_format = GU_PSM_T16;

      displayBuffer = SCEGU_VRAM_BP_1;

      for (u16 i = 0; i < (1 << 5); i++)
      {
         LUT_r_local[i]= i;
         LUT_b_local[i]= i << (5 + 6);
      }

      LUT_r = (void*)LUT_r_local;
      LUT_b = (void*)LUT_b_local;

   }

   psp->tex_filter = video->smooth? GU_LINEAR : GU_NEAREST;

   /* TODO: check if necessary. */
   sceDisplayWaitVblankStart();

   sceGuDisplay(GU_FALSE);

   sceGuStart(GU_DIRECT, psp->main_dList);

   sceGuDrawBuffer(pixel_format, TO_GU_POINTER(psp->draw_buffer),
         SCEGU_VRAM_WIDTH);
   sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT,
         TO_GU_POINTER(displayBuffer), SCEGU_VRAM_WIDTH);
   sceGuClearColor(0);
   sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
   sceGuEnable(GU_SCISSOR_TEST);
   sceGuTexFilter(psp->tex_filter, psp->tex_filter);
   sceGuTexWrap (GU_CLAMP, GU_CLAMP);
   sceGuEnable(GU_TEXTURE_2D);
   sceGuDisable(GU_DEPTH_TEST);
   sceGuCallMode(GU_FALSE);

   sceGuFinish();
   sceGuSync(0, 0);
 
   /* TODO : check if necessary */
   sceDisplayWaitVblankStart();
   sceGuDisplay(GU_TRUE);

   pspDebugScreenSetColorMode(pixel_format);
   pspDebugScreenSetBase(psp->draw_buffer);

   /* fill frame_dList : */
   sceGuStart(GU_CALL, psp->frame_dList);

   sceGuTexMode(pixel_format, 0, 0, GU_FALSE);
   sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
   sceGuEnable(GU_BLEND);

   /* green only */
   sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0x0000FF00, 0xFFFFFFFF);

   sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | 
         GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL,
         (void*)(psp->frame_coords));
   
   /* restore */
   sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF);

   sceGuTexMode(lut_pixel_format, 0, 0, GU_FALSE);

   sceGuClutMode(pixel_format, red_shift, color_mask, 0);
   sceGuClutLoad(lut_block_count, LUT_r);

   sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF |
         GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL,
         (void*)(psp->frame_coords));

   sceGuClutMode(pixel_format, 0, color_mask, 0);
   sceGuClutLoad(lut_block_count, LUT_b);
   sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | 
         GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL,
         (void*)(psp->frame_coords));

   sceGuFinish();

   if (input && input_data)
   {
      pspinput = input_psp.init();
      *input = pspinput ? &input_psp : NULL;
      *input_data = pspinput;
   }

   psp->vblank_not_reached = true;
   sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, psp_on_vblank, psp);
   sceKernelEnableSubIntr(PSP_VBLANK_INT, 0);

   psp->keep_aspect = true;
   psp->should_resize = true;
   psp->hw_render = false;

   return psp;
error:
   RARCH_ERR("PSP1 video could not be initialized.\n");
   return (void*)-1;
}
示例#18
0
文件: graphics.c 项目: yreeen/dxlibp
int dxpGraphicsInit()
{
	u32 i;
	//構造体初期化
	if(dxpGraphicsData.init)return 0;

	{//深度バッファの初期化
		dxpGraphicsData.depthbuffer.psm = GU_PSM_4444;
		dxpGraphicsData.depthbuffer.ppalette = NULL;
		dxpGraphicsData.depthbuffer.texdata = NULL;
		dxpGraphicsData.depthbuffer.width = 480;
		dxpGraphicsData.depthbuffer.height = 272;
		dxpGraphicsData.depthbuffer.pitch = 512;
		dxpGraphicsData.depthbuffer.umax = 480;
		dxpGraphicsData.depthbuffer.vmax = 272;
		dxpGraphicsData.depthbuffer.colorkey = 0;
		dxpGraphicsData.depthbuffer.size2_nflag = 0;
		dxpGraphicsData.depthbuffer.swizzledflag = 1;
		dxpGraphicsData.depthbuffer.reloadflag = 1;
		dxpGraphicsData.depthbuffer.alphabit = 0;
		dxpGraphicsData.depthbuffer.refcount = 0;
		dxpGraphicsData.depthbuffer.thisptrptr = NULL;
		if(dxpGraphicsData.usedepth || dxpGraphicsData.usedepth3d)
		{
			dxpGraphicsData.depthbuffer.texvram = valloc(vgetMemorySize(512,272,GU_PSM_4444));
			if(!dxpGraphicsData.depthbuffer.texvram)return -1;
		}else dxpGraphicsData.depthbuffer.texvram = NULL;
	}

	for(i = 0;i < 2;++i)
	{//フレームバッファの初期化
		dxpGraphicsData.displaybuffer[i].psm = dxpGraphicsData.display_psm;
		dxpGraphicsData.displaybuffer[i].ppalette = NULL;
		dxpGraphicsData.displaybuffer[i].texdata = NULL;
		dxpGraphicsData.displaybuffer[i].texvram = valloc(vgetMemorySize(512,272,dxpGraphicsData.display_psm));
		dxpGraphicsData.displaybuffer[i].width = 480;
		dxpGraphicsData.displaybuffer[i].height = 272;
		dxpGraphicsData.displaybuffer[i].pitch = 512;
//		dxpGraphicsData.displaybuffer[i].pitch = 480;//試したら見事に駄目だったw
		dxpGraphicsData.displaybuffer[i].umax = 480;
		dxpGraphicsData.displaybuffer[i].vmax = 272;
		dxpGraphicsData.displaybuffer[i].colorkey = 0;
		dxpGraphicsData.displaybuffer[i].size2_nflag = 0;
		dxpGraphicsData.displaybuffer[i].swizzledflag = 0;
		dxpGraphicsData.displaybuffer[i].reloadflag = 1;
		dxpGraphicsData.displaybuffer[i].alphabit = 0;
		dxpGraphicsData.displaybuffer[i].refcount = 0;
	}
	if(!dxpGraphicsData.displaybuffer[0].texvram || !dxpGraphicsData.displaybuffer[1].texvram)
	{
		vfree(dxpGraphicsData.displaybuffer[0].texvram);
		vfree(dxpGraphicsData.displaybuffer[1].texvram);
		vfree(dxpGraphicsData.depthbuffer.texvram);
		return -1;
	}
	dxpGraphicsData.displaybuffer_back = &dxpGraphicsData.displaybuffer[0];
	dxpGraphicsData.rendertarget = dxpGraphicsData.displaybuffer_back;
	dxpGraphicsData.texture = NULL;
	dxpGraphicsData.clear_color_value = 0;
	dxpGraphicsData.clear_depth_value = 0;
	dxpGraphicsData.clear_stencil_value = 0;
	dxpGraphicsData.gustarted = 0;
	dxpGraphicsData.clear_depth = 0;
	dxpGraphicsData.clear_stencil = 0;
	dxpGraphicsData.bilinear_enable = 0;
	dxpGraphicsData.create_vram_graph = 1;
	dxpGraphicsData.create_swizzled_graph = 1;
	dxpGraphicsData.colorkey = 0;

	dxpGraphicsData.blendmode = DX_BLENDMODE_NOBLEND;
	dxpGraphicsData.drawstate = DXP_DRAWSTATE_EITHER;
	dxpGraphicsData.flag = 0xffffffff;
	dxpGraphicsData.forceupdate = 1;
	dxpGraphicsData.z_2d = 0;
	dxpGraphicsData.color = 0xffffffff;
	//dxpGraphicsData.usedepth = 0;
	//dxpGraphicsData.usedepth3d = 0;
	dxpGraphicsData.writedepth = 0;
	dxpGraphicsData.writedepth3d = 0;

	dxpGraphicsData.fog_color = 0xffffffff;
	dxpGraphicsData.fog_near = 10.0f;
	dxpGraphicsData.fog_far = 100.0f;

	dxpGraphicsData.intrafont_scissor[0] = 0;
	dxpGraphicsData.intrafont_scissor[1] = 0;
	dxpGraphicsData.intrafont_scissor[2] = 480;
	dxpGraphicsData.intrafont_scissor[3] = 272;

	dxpGraphicsData.depthfunc = GU_GEQUAL;

	for(i = 0;i < DXP_BUILDOPTION_TEXTURE_MAXNUM;++i)dxpGraphicsData.texarray[i] = NULL;
	for(i = 0;i < DXP_BUILDOPTION_GHANDLE_MAXNUM;++i)dxpGraphicsData.grapharray[i] = NULL;
	//GEのセットアップ
	sceGuInit();
	GUSTART
		
	sceGuDrawBuffer(dxpGraphicsData.display_psm,vGuPointer(dxpGraphicsData.displaybuffer[0].texvram),dxpGraphicsData.displaybuffer[0].pitch);
	sceGuDispBuffer(480,272,vGuPointer(dxpGraphicsData.displaybuffer[1].texvram),dxpGraphicsData.displaybuffer[1].pitch);

	sceGuOffset(2048 - (480/2),2048 - (272/2));
	sceGuViewport(2048,2048,480,272);
	sceGuScissor(
		dxpGraphicsData.intrafont_scissor[0],
		dxpGraphicsData.intrafont_scissor[1],
		dxpGraphicsData.intrafont_scissor[2],
		dxpGraphicsData.intrafont_scissor[3]
	);
	sceGuClearDepth(0);
	sceGuDepthRange(65535,0);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_FLAT);
	sceGuTexScale(1.0f,1.0f);
	sceGuTexOffset(0.0f,0.0f);
	sceGuTexFilter(GU_NEAREST,GU_NEAREST);
	sceGuTexWrap(GU_CLAMP,GU_CLAMP);
	/*
		memo
		カメラ位置(画面横幅/2,画面縦幅/2,画面縦幅/(2 * tan(fovy)))
		注視点位置(画面横幅/2,画面縦幅/2,1)
		上    (0,1,0)
	*/
#ifndef DXP_BUILDOPTION_NO3D
	VECTOR v[3] = {{240,136,-235.5589f},{240,136,0},{0,1,0}};
	SetCameraPositionAndTargetAndUpVec(v[0],v[1],v[2]);

	sceGumMatrixMode(GU_MODEL);
	sceGumLoadIdentity();

	dxpGraphicsData.camera.aspect = 480.0f / 272.0f;
	dxpGraphicsData.camera.near = 0.5f;
	dxpGraphicsData.camera.far = 1000.0f;
	dxpGraphicsData.camera.fov = 60;
	dxpGraphics3dUpdateProjectionMatrix();
#endif

	GUFINISH;
	sceDisplayWaitVblankStart();
	GUSTART;
	sceGuDisplay(GU_TRUE);
	dxpGraphicsData.init = 1;


	return 0;
}
示例#19
0
int main(int argc, char* argv[]) {
	/* Setup Homebutton Callbacks */
	setupCallbacks();

	sceKernelDcacheWritebackAll();

	// setup GU

	SceCtrlData pad;
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);

	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW);
	sceGuColor(0xffffffff);
	sceGuShadeModel(GU_SMOOTH);
//	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexMode(GU_PSM_8888, 0, 0, 0);
	sceGuTexImage(0, 16, 16, 16, texture);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
	sceGuTexEnvColor(0xffffff);
	sceGuTexFilter(GU_LINEAR, GU_LINEAR);
	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
	sceGuTexScale(1.0f, 1.0f);
	sceGuTexOffset(0.0f, 0.0f);
	sceGuAmbientColor(0xffffffff);

	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
	
	void* buffer = 0;

	pspDebugScreenInit();

	unsigned int old = 0;
	unsigned int flags = PSP_CTRL_CIRCLE | PSP_CTRL_CROSS;

	int tex = 1;

	while(running()) {
		sceGuStart(GU_DIRECT,list);

		sceGuClearColor(0);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(90.0f, 480.0/272.0f, 0.1f, 10.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();
		ScePspFVector3 trans = { 0.0f, 0.0f, -1.8f };
		sceGumTranslate(&trans);
		
		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();

		sceGumDrawArray(objects[o].prim, objects[o].flags, objects[o].count, 0, objects[o].data);

		sceCtrlReadBufferPositive(&pad, 1);
		if(old != pad.Buttons) {
			if(pad.Buttons & PSP_CTRL_CROSS) {
				o++;
				if(o >= sizeof(objects) / sizeof(Object)) {
					o = 0;
				}
			}
			if(pad.Buttons & PSP_CTRL_CIRCLE) {
				tex = !tex;
				if(tex) {
					sceGuEnable(GU_TEXTURE_2D);
				} else {
					sceGuDisable(GU_TEXTURE_2D);
				}
			}
		}
		old = pad.Buttons;

		sceGuFinish();
		sceGuSync(0,0);

		pspDebugScreenSetOffset((int)buffer);
		pspDebugScreenSetXY(0, 0);
		pspDebugScreenPrintf("Mode: %s (X to change)    Texture: %s (O to change)", objects[o].text, tex ? "on " : "off");

		sceDisplayWaitVblankStart();
		buffer = sceGuSwapBuffers();
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
示例#20
0
void app() {
    setupCallbacks();

    #ifdef DEBUG
    pspDebugScreenInit();
    #endif

    sceGuInit();

    void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
    void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
    void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);

    sceGuStart(GU_DIRECT, list);

    sceGuDrawBuffer(GU_PSM_8888, fbp0, BUF_WIDTH);
    sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, fbp1, BUF_WIDTH);
    sceGuDepthBuffer(zbp, BUF_WIDTH);

    sceGuOffset(2048 - (SCR_WIDTH / 2), 2048 - (SCR_HEIGHT / 2));
    sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT);

    sceGuDepthRange(65535, 0);
    sceGuClearDepth(65535);
    sceGuDepthFunc(GU_LEQUAL);

    sceGuAlphaFunc(GU_GREATER, 0, 255);
    sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
    sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
    sceGuTexFilter(GU_LINEAR, GU_LINEAR);
    sceGuShadeModel(GU_SMOOTH);

    sceGuEnable(GU_DEPTH_TEST);
    sceGuEnable(GU_ALPHA_TEST);
    sceGuEnable(GU_SCISSOR_TEST);
    sceGuEnable(GU_BLEND);

    sceGuDisable(GU_CULL_FACE);
    sceGuDisable(GU_CLIP_PLANES);
    sceGuDisable(GU_DITHER);

    sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);

    sceGuFinish();
    sceGuSync(0, 0);

    sceDisplayWaitVblankStart();
    sceGuDisplay(GU_TRUE);


    //g2dInit();

    /*tileset_tex = g2dTexLoad((char *) "resources/tilemap.png", G2D_SWIZZLE);
    outline_tex = g2dTexLoad((char *) "resources/tilemap2.png", G2D_SWIZZLE);
    text_tex = g2dTexLoad((char *) "resources/ui-font.png", G2D_SWIZZLE);
    frame_tex = g2dTexLoad((char *) "resources/frame.png", G2D_SWIZZLE);*/

    while (running()) {
        sceGuStart(GU_DIRECT,list);

        // Clear screen
        sceGuClearColor(0xff554433); // TODO change to black when everything works
        sceGuClearDepth(0);
        sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);

        // Process and draw a frame
        //menu.update();
        //background.draw();
        //menu.draw();
        
        sceGuFinish();
        sceGuSync(0,0);

        // Swap buffers and wait for VSYNC
        sceDisplayWaitVblankStart();
        sceGuSwapBuffers();
    }

    sceGuDisplay(GU_FALSE);
    sceGuTerm();

    sceKernelExitGame();
}
示例#21
0
文件: signals.c 项目: CDragu/pspsdk
int main(int argc, char* argv[])
{
	unsigned int i,j;

	pspDebugScreenInit();
	SetupCallbacks();

#ifdef ENABLE_PROFILER
	// Enable profiling 
	pspDebugProfilerClear();
	pspDebugProfilerEnable();
#endif

	// initialize global context
	g_context.iterationCount = NUM_VERTEX_BUFFERS * NUM_ITERATIONS;
	g_context.t = 0;
	g_context.sint = 0;

	// initialize torus
	for (i = 0; i < NUM_SLICES; ++i)
	{
		for (j = 0; j < NUM_ROWS; ++j)
		{
			float s = i + 0.5f, t = j;
			float x,y,z;

			x = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * cosf(t * ((GU_PI*2)/NUM_ROWS));
			y = (RING_SIZE + RING_RADIUS * cosf(s * ((GU_PI*2)/NUM_SLICES))) * sinf(t * ((GU_PI*2)/NUM_ROWS));
			z = RING_RADIUS * sinf(s * ((GU_PI*2)/NUM_SLICES));

			torus_vertices[j + i * NUM_ROWS].x = x;
			torus_vertices[j + i * NUM_ROWS].y = y;
			torus_vertices[j + i * NUM_ROWS].z = z;
		}
	}

	// initialize torus modifiers

	for (j = 0; j < NUM_ROWS; ++j)
	{
		float t = j;
		torus_modifiers[j].x = 0;
		torus_modifiers[j].y = 0;
		torus_modifiers[j].z = 0.3*cosf( t * 8.0f *((GU_PI*2)/NUM_ROWS) );
	}

	// init GU and set callbacks
	sceGuInit();

	// 0x01 - user callback
	// 0x04 - 'rendering finished' callback
	sceGuSetCallback(1, &mySignalHandler);
	sceGuSetCallback(4, &myFinishHandler);

	// setup GU
	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,(void*)0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)0x88000,BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(0xc350,0x2710);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuAlphaFunc(GU_GREATER,0,0xff);
	sceGuEnable(GU_ALPHA_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	// run sample

#ifdef USING_SIGNALS
	sceGuCallMode(1);
#endif

	// generate callable command-list with texture setup
	{
		sceGuStart(GU_CALL, smallList1);

		// setup texture
		sceGuTexMode(GU_PSM_5551,0,0,0);
		sceGuTexImage(0,32,32,32,ball_start); // width, height, buffer width, tbp
		sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGBA); // NOTE: this enables reads of the alpha-component from the texture, otherwise blend/test won't work
		sceGuTexFilter(GU_NEAREST,GU_NEAREST);
		sceGuTexWrap(GU_CLAMP,GU_CLAMP);
		sceGuTexScale(1,1);
		sceGuTexOffset(0,0);
		sceGuAmbientColor(0xffffffff);

		sceGuFinish();
		sceGuSync(0,0);
	}

	// generate callable command-list for cube rendering
	{
		sceGuStart(GU_CALL, smallList2);

		// draw cube
		sceGuDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,cubeVertices);

		sceGuFinish();
		sceGuSync(0,0);
	}

	for(;;)
	{
		sceGuStart(GU_DIRECT,list);

		unsigned int i = 0;
		for( ; i < NUM_VERTEX_BUFFERS; i++ )
			g_context.vbuffer[i] = sceGuGetMemory((NUM_SLICES/g_context.iterationCount) * 2 * NUM_ROWS * sizeof(Vertex));
		g_context.vertsRendered = 0;

		// clear screen
		sceGuClearColor(0x00334455);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		// setup matrices
		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();

		sceGumMatrixMode(GU_MODEL);
		{
			ScePspFVector3 pos = {0.0f,0.0f,-3.5f};
			ScePspFVector3 rot = {g_context.t * 0.3f * (GU_PI/180.0f), g_context.t * 0.7f * (GU_PI/180.0f), g_context.t * 1.3f * (GU_PI/180.0f)};

			sceGumLoadIdentity();
			sceGumTranslate(&pos);
			sceGumRotateXYZ(&rot);
		}

		sceGumStoreMatrix(&g_context.world);

		// call pregenerated command-list to setup texture		
		sceGuCallList(smallList1);

		// start billboard rendering
		render_billboards(0);

		// call pregenerated command-list to render cube
		{
			ScePspFVector3 scale = {0.3f, 0.3f, 0.3f};
			sceGumScale(&scale);
		}

		sceGumUpdateMatrix();
		sceGuCallList(smallList2);	

#ifndef USING_SIGNALS
		// HACK: sceGuFinish() is called inside the signal interupt handler when all rendering job is done
		// this is done in order to stall GPU if it is ahead of CPU
		sceGuFinish();
#endif
		sceGuSync(0,0);

#ifndef ENABLE_FRAMERATE
		// wait for next frame
		sceDisplayWaitVblankStart();
#endif
		sceGuSwapBuffers();

		pspDebugScreenSetXY(0,0);

#ifdef ENABLE_PROFILER
		// Print profile information to the screen
		pspDebugProfilerPrint();
#endif

#ifdef ENABLE_FRAMERATE
		// simple frame rate counter
		static float curr_ms = 1.0f;
		static struct timeval time_slices[16];
		static int t = 0;

		float curr_fps = 1.0f / curr_ms;

		t++;
		
		float vertsPerSec = g_context.vertsRendered*curr_fps;
		float kbPerSec = vertsPerSec * sizeof(Vertex) / 1024.0f;
		gettimeofday(&time_slices[t & 15],0);
		pspDebugScreenPrintf("fps: %d.%03d  ms: %d  vert/s: %dK  MB/s: %d.%03d",(int)curr_fps, ((int)(curr_fps*1000.0f)%1000), (int)(curr_ms*1000.0f),
			(int)(vertsPerSec/1000.0f),
			(int)(kbPerSec/1024.0f), (int)((1000.0f/1024.0f)*((int)kbPerSec%1024)) );

		if (!(t & 15))
		{
			struct timeval last_time = time_slices[0];
			unsigned int i;

			curr_ms = 0;
			for (i = 1; i < 16; ++i)
			{
				struct timeval curr_time = time_slices[i];

				int curr_time_usec = curr_time.tv_usec + curr_time.tv_sec * 1000000;
				int last_time_usec = last_time.tv_usec + last_time.tv_sec * 1000000;

				if( last_time_usec < curr_time_usec )
					curr_ms += (( curr_time_usec - last_time_usec ) * (1.0f/1000000.0f));

				last_time = time_slices[i];
			}
			curr_ms /= 15.0f;
		}
#endif
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
示例#22
0
void StartUpDisplay()
{
	//ScePspFVector3	vec;

	_rotationSpeed = 1.0f;
	_rotation.x = 0.0f;
	_rotation.y = 0.0f;
	_rotation.z = 0.0f;
	_bgColour = 0;
	_frame = 0;
	_viewMode = 0;
	sceGuInit();
	sceGuStart(SCEGU_IMMEDIATE, (void *)disp_list, sizeof(disp_list));

	sceGuDrawBuffer(SCEGU_PF5551, SCEGU_VRAM_BP_0, SCEGU_VRAM_WIDTH);
	sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, SCEGU_VRAM_BP_1,
		SCEGU_VRAM_WIDTH);
	sceGuDepthBuffer(SCEGU_VRAM_BP_2, SCEGU_VRAM_WIDTH);

	sceGuOffset(SCEGU_SCR_OFFSETX, SCEGU_SCR_OFFSETY);
	sceGuViewport(2048, 2048, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuDepthRange(50000, 10000);

	sceGuDisable(SCEGU_BLEND);

	sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuEnable(SCEGU_SCISSOR_TEST);

	sceGuDepthFunc(SCEGU_GEQUAL);
	sceGuEnable(SCEGU_DEPTH_TEST);

	sceGuFrontFace(SCEGU_CW);

	sceGuDisable(SCEGU_TEXTURE);
	sceGuShadeModel(SCEGU_SMOOTH);

	sceGuEnable(SCEGU_DITHER);

	//vec.x = 0.0f;
	//vec.y = 0.0f;
	//vec.z = 1.0f;
	//sceGuLightColor(0, SCEGU_DIFFUSE, 0xffffffff);
	//sceGuLight(0, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//vec.x = 1.0f;
	//vec.y = 0.0f;
	//vec.z = 0.0f;
	//sceGuLightColor(1, SCEGU_DIFFUSE, 0xff00ffff);
	//sceGuLight(1, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//vec.x = -1.0f;
	//vec.y = 0.0f;
	//vec.z = 0.0f;
	//sceGuLightColor(2, SCEGU_DIFFUSE, 0xffff00ff);
	//sceGuLight(2, SCEGU_LIGHT_DIRECTION, SCEGU_DIFFUSE, &vec);
	//sceGuEnable(SCEGU_LIGHT0);
	//sceGuEnable(SCEGU_LIGHT1);
	//sceGuEnable(SCEGU_LIGHT2);
	//sceGuEnable(SCEGU_LIGHTING);

	//sceGuFog(14.50, 25.0, 0x007f00ff);

	//sceGuAmbient(0xcc004cb2);
	sceGuAmbient(0xffffffff);
	sceGuColor(0xff0000ff);

	//sceGuTexMode(SCEGU_PF5551, 1, SCEGU_SINGLE_CLUT, SCEGU_TEXBUF_NORMAL);
	//sceGuTexFilter(SCEGU_LINEAR_MIPMAP_NEAREST, SCEGU_LINEAR);
	//sceGuTexFunc(SCEGU_TEX_MODULATE, SCEGU_RGB);
	//sceGuTexWrap(SCEGU_REPEAT, SCEGU_REPEAT);

	sceGumSetMatrixStack(matrix_stack, 1, 1, 2, 0);
	sceGumMatrixMode(SCEGU_MATRIX_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(SCEGU_RAD(45.0f), SCEGU_SCR_ASPECT,
		1.000000f, 100.000000f);

	sceGumMatrixMode(SCEGU_MATRIX_WORLD);

	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);

	sceGuDisplay(SCEGU_DISPLAY_ON);
}
示例#23
0
int main(int argc, char* argv[])
{
    SetupCallbacks();

    // generate geometry

    genGrid( GRID_ROWS, GRID_COLUMNS, GRID_SIZE, grid_vertices, grid_indices );
    genTorus( TORUS_ROWS, TORUS_SLICES, TORUS_RADIUS, TORUS_THICKNESS, torus_vertices, torus_indices );

    // flush cache so that no stray data remains

    sceKernelDcacheWritebackAll();

    // setup VRAM buffers

    void* frameBuffer = (void*)0;
    const void* doubleBuffer = (void*)0x44000;
    const void* renderTarget = (void*)0x88000;
    const void* depthBuffer = (void*)0x110000;

    // setup GU

    sceGuInit();

    sceGuStart(GU_DIRECT,list);
    sceGuDrawBuffer(GU_PSM_4444,frameBuffer,BUF_WIDTH);
    sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)doubleBuffer,BUF_WIDTH);
    sceGuDepthBuffer((void*)depthBuffer,BUF_WIDTH);
    sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
    sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
    sceGuDepthRange(0xc350,0x2710);
    sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
    sceGuEnable(GU_SCISSOR_TEST);
    sceGuDepthFunc(GU_GEQUAL);
    sceGuEnable(GU_DEPTH_TEST);
    sceGuFrontFace(GU_CW);
    sceGuShadeModel(GU_SMOOTH);
    sceGuEnable(GU_CULL_FACE);
    sceGuEnable(GU_TEXTURE_2D);
    sceGuEnable(GU_DITHER);
    sceGuFinish();
    sceGuSync(0,0);

    sceDisplayWaitVblankStart();
    sceGuDisplay(GU_TRUE);


    // setup matrices

    ScePspFMatrix4 identity;
    ScePspFMatrix4 projection;
    ScePspFMatrix4 view;

    gumLoadIdentity(&identity);

    gumLoadIdentity(&projection);
    gumPerspective(&projection,75.0f,16.0f/9.0f,0.5f,1000.0f);

    {
        ScePspFVector3 pos = {0,0,-5.0f};

        gumLoadIdentity(&view);
        gumTranslate(&view,&pos);
    }

    ScePspFMatrix4 textureProjScaleTrans;
    gumLoadIdentity(&textureProjScaleTrans);
    textureProjScaleTrans.x.x = 0.5;
    textureProjScaleTrans.y.y = -0.5;
    textureProjScaleTrans.w.x = 0.5;
    textureProjScaleTrans.w.y = 0.5;

    ScePspFMatrix4 lightProjection;
    ScePspFMatrix4 lightProjectionInf;
    ScePspFMatrix4 lightView;
    ScePspFMatrix4 lightMatrix;

    gumLoadIdentity(&lightProjection);
    gumPerspective(&lightProjection,75.0f,1.0f,0.1f,1000.0f);
    gumLoadIdentity(&lightProjectionInf);
    gumPerspective(&lightProjectionInf,75.0f,1.0f,0.0f,1000.0f);

    gumLoadIdentity(&lightView);
    gumLoadIdentity(&lightMatrix);

    // define shadowmap

    Texture shadowmap = {
        GU_PSM_4444,
        0, 128, 128, 128,
        sceGeEdramGetAddr() + (int)renderTarget
    };

    // define geometry

    Geometry torus = {
        identity,
        sizeof(torus_indices)/sizeof(unsigned short),
        torus_indices,
        torus_vertices,
        0xffffff
    };
    Geometry grid = {
        identity,
        sizeof(grid_indices)/sizeof(unsigned short),
        grid_indices,
        grid_vertices,
        0xff7777
    };

    // run sample

    int val = 0;

    for(;;)
    {
        // update matrices

        // grid
        {
            ScePspFVector3 pos = {0,-1.5f,0};

            gumLoadIdentity(&grid.world);
            gumTranslate(&grid.world,&pos);
        }

        // torus
        {
            ScePspFVector3 pos = {0,0.5f,0.0f};
            ScePspFVector3 rot = {val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f)};

            gumLoadIdentity(&torus.world);
            gumTranslate(&torus.world,&pos);
            gumRotateXYZ(&torus.world,&rot);
        }

        // orbiting light
        {
            ScePspFVector3 lightLookAt = { torus.world.w.x, torus.world.w.y, torus.world.w.z };
            ScePspFVector3 rot1 = {0,val * 0.79f * (GU_PI/180.0f),0};
            ScePspFVector3 rot2 = {-(GU_PI/180.0f)*60.0f,0,0};
            ScePspFVector3 pos = {0,0,LIGHT_DISTANCE};

            gumLoadIdentity(&lightMatrix);
            gumTranslate(&lightMatrix,&lightLookAt);
            gumRotateXYZ(&lightMatrix,&rot1);
            gumRotateXYZ(&lightMatrix,&rot2);
            gumTranslate(&lightMatrix,&pos);
        }

        gumFastInverse(&lightView,&lightMatrix);

        // render to shadow map

        {
            sceGuStart(GU_DIRECT,list);

            // set offscreen texture as a render target

            sceGuDrawBufferList(GU_PSM_4444,(void*)renderTarget,shadowmap.stride);

            // setup viewport

            sceGuOffset(2048 - (shadowmap.width/2),2048 - (shadowmap.height/2));
            sceGuViewport(2048,2048,shadowmap.width,shadowmap.height);

            // clear screen

            sceGuClearColor(0xffffffff);
            sceGuClearDepth(0);
            sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

            // setup view/projection from light

            sceGuSetMatrix(GU_PROJECTION,&lightProjection);
            sceGuSetMatrix(GU_VIEW,&lightView);

            // shadow casters are drawn in black
            // disable lighting and texturing

            sceGuDisable(GU_LIGHTING);
            sceGuDisable(GU_TEXTURE_2D);

            // draw torus to shadow map

            drawShadowCaster( &torus );

            sceGuFinish();
            sceGuSync(0,0);
        }

        // render to frame buffer

        {
            sceGuStart(GU_DIRECT,list);

            // set frame buffer

            sceGuDrawBufferList(GU_PSM_4444,(void*)frameBuffer,BUF_WIDTH);

            // setup viewport

            sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
            sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);

            // clear screen

            sceGuClearColor(0xff554433);
            sceGuClearDepth(0);
            sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

            // setup view/projection from camera

            sceGuSetMatrix(GU_PROJECTION,&projection);
            sceGuSetMatrix(GU_VIEW,&view);
            sceGuSetMatrix(GU_MODEL,&identity);

            // setup a light
            ScePspFVector3 lightPos = { lightMatrix.w.x, lightMatrix.w.y, lightMatrix.w.z };
            ScePspFVector3 lightDir = { lightMatrix.z.x, lightMatrix.z.y, lightMatrix.z.z };

            sceGuLight(0,GU_SPOTLIGHT,GU_DIFFUSE,&lightPos);
            sceGuLightSpot(0,&lightDir, 5.0, 0.6);
            sceGuLightColor(0,GU_DIFFUSE,0x00ff4040);
            sceGuLightAtt(0,1.0f,0.0f,0.0f);
            sceGuAmbient(0x00202020);
            sceGuEnable(GU_LIGHTING);
            sceGuEnable(GU_LIGHT0);

            // draw torus

            drawGeometry( &torus );

            // setup texture projection

            sceGuTexMapMode( GU_TEXTURE_MATRIX, 0, 0 );
            sceGuTexProjMapMode( GU_POSITION );

            // set shadowmap as a texture

            sceGuTexMode(shadowmap.format,0,0,0);
            sceGuTexImage(shadowmap.mipmap,shadowmap.width,shadowmap.height,shadowmap.stride,shadowmap.data);
            sceGuTexFunc(GU_TFX_MODULATE,GU_TCC_RGB);
            sceGuTexFilter(GU_LINEAR,GU_LINEAR);
            sceGuTexWrap(GU_CLAMP,GU_CLAMP);
            sceGuEnable(GU_TEXTURE_2D);

            // calculate texture projection matrix for shadowmap

            ScePspFMatrix4 shadowProj;
            gumMultMatrix(&shadowProj, &lightProjectionInf, &lightView);
            gumMultMatrix(&shadowProj, &textureProjScaleTrans, &shadowProj);

            // draw grid receiving shadow

            drawShadowReceiver( &grid, shadowProj );

            sceGuFinish();
            sceGuSync(0,0);
        }

        sceDisplayWaitVblankStart();
        frameBuffer = sceGuSwapBuffers();

        val++;
    }

    sceGuTerm();

    sceKernelExitGame();
    return 0;
}
示例#24
0
文件: main.c 项目: bensaraceno/PSP
int main() {
	SceCtrlData pad;
	int cancel = 0, uninstall = 0, reinstall = 0, lftv = 0, ok = 0, installed = 0, uninstalled = 0, autoExit = 0;
	SetupCallbacks();

	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
	sceCtrlReadBufferPositive(&pad, 1);
	if (pad.Buttons & PSP_CTRL_LTRIGGER) { quickinstall = 1; lftv = 1; } else if (pad.Buttons & PSP_CTRL_RTRIGGER) { quickinstall = 1; }
	if (fileExist(PRX_LFTVBACKUP) | fileExist(PRX_RPLYBACKUP)) uninstall = 1;

	sceGuInit();
	sceGuStart(GU_DIRECT, list);
	sceGuClearColor(0xFFFFFFFF);
	sceGuDrawBuffer(GU_PSM_8888, (void*)0, BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000, BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH / 2), 2048 - (SCR_HEIGHT / 2));
	sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT);
	sceGuDepthRange(0xc350, 0x2710);
	sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDisable(GU_DEPTH_TEST);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_BLEND);
	sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexMode(GU_PSM_8888, 0, 0, 0);
	sceGuTexImage(0, 256, 128, 256, font);
	sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
	sceGuTexEnvColor(0x0);
	sceGuTexOffset(0.0f, 0.0f);
	sceGuTexScale(1.0f / 256.0f, 1.0f / 128.0f);
	sceGuTexWrap(GU_REPEAT, GU_REPEAT);
	sceGuTexFilter(GU_NEAREST, GU_NEAREST);
	sceGuFinish();
	sceGuSync(0,0);
	sceGuDisplay(GU_TRUE);

	// Check for low battery.
	if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) {
		sceGuStart(GU_DIRECT, list);
		sceGuClear(GU_COLOR_BUFFER_BIT);
		drawStringCenter("Battery charge should be at least 25% when modifying flash!", 40 + (10 * i), 0xFF0000FF, 8); i += 2;
		drawStringCenter("Connect the AC adapter to ignore this warning and continue!", 40 + (10 * i), 0xFF0000FF, 8); i += 2;
		drawStringCenter(uninstall ? "Press any button to cancel uninstallation of warPSP." : "Press any button to cancel installation of warPSP.", 50 + (10 * i), 0xFF0000FF, 8); i += 2;
		drawObjects();
		while (!scePowerIsPowerOnline()) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) { cancel = 1; break; } }
	}

	if (!cancel) {
		float c = 0.0;
		for (c = 10.0; c <= 100.0; c++) {
			unsigned int col = 0xFF000000 |
				(unsigned int)((c / 100.0) * 255.0f) << 16 |
				(unsigned int)((c / 100.0) * 255.0f) <<  8 |
				(unsigned int)((c / 100.0) * 255.0f) <<  0;
			sceGuClearColor(col);
			clearScreenPrintHeader(90);
			if (quickinstall & (c > 50)) drawStringCenter("Quick Install Activated!", 250, 0xFF006600, 8);
			drawObjects();
		}
		sceKernelDelayThread(3000000);
		for (c = 100.0; c >= 10.0; c--) {
			unsigned int col = 0xFF000000 |
				(unsigned int)((c / 100.0) * 255.0f) << 16 |
				(unsigned int)((c / 100.0) * 255.0f) <<  8 |
				(unsigned int)((c / 100.0) * 255.0f) <<  0;
			sceGuClearColor(col);
			clearScreenPrintHeader(90);
			drawObjects();
		}
	}

	sceGuClearColor(0xFFFFFFFF);

	// Show disclaimer and options.
	if (!cancel & !quickinstall) {
		sceGuStart(GU_DIRECT, list);
		sceGuClear(GU_COLOR_BUFFER_BIT);
		drawStringCenter("!!! DISCLAIMER !!!", 40 + (10 * i), 0xFF0000FF, 10); i += 2;
		drawStringCenter("This program modifies the flash drive of your Sony PSP.", 60 + (10 * i), 0xFF0000FF, 8); i++;
		drawStringCenter("You accept the risk when running this installation app.", 60 + (10 * i), 0xFF0000FF, 8); i += 2;
		drawStringCenter("DO NOT REMOVE THE MEMORY STICK WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i++;
		drawStringCenter("DO NOT TURN OFF THE PSP SYSTEM WHEN ORANGE LED FLASHES.", 60 + (10 * i), 0xFF0000FF, 8); i += 2;
		drawStringCenter("Press START to acknowledge and to continue to briefing.", 60 + (10 * i), 0xFF0000FF, 8); i++;
		drawStringCenter("Press SELECT to decline and to abort installing warPSP.", 60 + (10 * i), 0xFF0000FF, 8); i += 2;
		drawStringCenter("THE AUTHOR DOES NOT HOLD RESPONSIBILITY FOR ANY DAMAGE.", 60 + (10 * i), 0xFF0000FF, 8); i++;
		drawStringCenter("THIS SOFTWARE IS PRESENTED WITHOUT WARRANTY/GUARANTEES.", 60 + (10 * i), 0xFF0000FF, 8); i += 4;
		drawObjects();
		while (1) {
			sceCtrlReadBufferPositive(&pad, 1);
			if (pad.Buttons & PSP_CTRL_START) { break; }
			if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; }
		}
	}

	// Check if backup file exists.
	if (!cancel & !quickinstall) {
		swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0);
		drawStringCenter("Briefing", 50 + (10 * i), 0xFF000000, 0); i+= 2;
		drawStringCenter("Thanks for your interest in the warPSP Software Suite!", 50 + (10 * i), 0xFF006600, 0); i += 2;
		drawStringCenter("warPSP is an advanced warXing utility for the Sony PSP.", 50 + (10 * i), 0xFF000000, 8); i += 2;
		drawStringCenter("Please see the README.TXT file for more information.", 50 + (10 * i), 0xFF660000, 8); i += 3;
		drawStringCenter("Options", 50 + (10 * i), 0xFF000000, 0); i += 2;
		if (uninstall) {
			drawStringCenter("Press SQUARE to uninstall warPSP and restore backup files.", 50 + (10 * i), 0xFF000000, 8); i++;
			drawStringCenter("Press CIRCLE to reinstall warPSP to the last slot selected.", 50 + (10 * i), 0xFF000000, 8); i++;
		} else {
			drawStringCenter("Press SQUARE to install warPSP to the LFTV Player slot.", 50 + (10 * i), 0xFF000000, 8); i++;
			drawStringCenter("Press CIRCLE to install warPSP to the Remote Play slot.", 50 + (10 * i), 0xFF000000, 8); i++;
		}
		drawStringCenter(uninstall ? "Press SELECT to cancel uninstallation of warPSP and exit." : "Press SELECT to cancel installation of warPSP and exit.", 50 + (10 * i), 0xFF000099, 8); i += 2;
		drawObjects();
		while (1) {
			sceCtrlReadBufferPositive(&pad, 1);
			if (uninstall) {
				if (pad.Buttons & PSP_CTRL_SQUARE) { break; }
				if (pad.Buttons & PSP_CTRL_CIRCLE) {
					uninstall = 0; reinstall = 1;
					if (fileExist(PRX_LFTVBACKUP)) lftv = 1; else lftv = 0;
					break;
				}
			} else {
				if (pad.Buttons & PSP_CTRL_SQUARE) { lftv = 1; break; }
				if (pad.Buttons & PSP_CTRL_CIRCLE) { lftv = 0; break; }
			}
			if (pad.Buttons & PSP_CTRL_SELECT) { cancel = 1; break; }
		}
	}

	if (!cancel) {
		if ((scePowerGetBatteryLifePercent() < 25) & !scePowerIsPowerOnline()) {
			swapBuffers(); sceGuStart(GU_DIRECT, list);
			drawStringCenter(" Battery is below 25%% and AC adapter is not connected!", 50 + (10 * i), 0xFF000099, 0); i += 2;
			cancel = 1; drawObjects();
		}
	}

	if (cancel) {
		swapBuffers(); sceGuStart(GU_DIRECT, list);
		sprintf(buffer, "%sstallation cancelled!", uninstall ? "Unin" : "In");
		drawStringCenter(buffer, 50 + (10 * i), 0xFF0000FF, 0); i += 2;
		drawObjects();
		sceKernelDelayThread(1000000);
	}

	// Perform installation, uninstallation or reinstallation.
	if (!cancel) {
		scePowerLock(0);
		swapBuffers(); clearScreenPrintHeader(0); drawObjects(); clearScreenPrintHeader(0); drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list);
		drawStringCenter(uninstall ? "Uninstallation" : "Installation", 50 + (10 * i), 0xFF990000, 0); i += 2;
		if (quickinstall) { drawStringCenter("Quick installing warPSP to the location free player slot.", 50 + (10 * i), 0xFF990000, 0); i += 2; }
		drawObjects(); swapBuffers(); sceGuStart(GU_DIRECT, list);
		if (uninstall) {
			if (fileExist(PRX_LFTVBACKUP)) { lftv = 1; ok = 1; } else if (fileExist(PRX_RPLYBACKUP)) { lftv = 0; ok = 1; }
			if (ok) {
				drawStringCenter("Backup prx found. Ok to uninstall!", 50 + (10 * i), 0xFF990000, 8); i++;
				drawStringCenter("The backup prx will be copied to the flash drive of your PSP!", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects();
				if (fileCopy(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstalled successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP); uninstalled = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Backup file reinstallation failed!", 50 + (10 * i), 0xFF000099, 8); }
				i += 2; drawObjects();
				if (uninstalled) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("To reinstall warPSP, rerun the Easy Installation Program.", 50 + (10 * i), 0xFF990000, 8); i += 2; drawObjects(); }
			}
		} else {
			if (fileExist(PRX_WARPSP_XMB)) { sceIoRemove(PRX_WARPSP_XMB); sceKernelDelayThread(1000000); }
			drawStringCenter("Extracting warPSP.prx to the root of the memory stick.", 50 + (10 * i), 0xFF000000, 8); i += 2; drawObjects();
			sceKernelDelayThread(2000000);
			// Open PBP file and read contents into the buffer.
			int pbpFile, prxFile, pkgSize = 0, prxSize = 0; char buf[1024*1024];
			pbpFile = sceIoOpen(PBP_WARPSP_EIP, PSP_O_RDONLY, 0);
			sceKernelDelayThread(1000000);
			if (pbpFile) {
				// Get size of entire package.
				pkgSize = sceIoRead(pbpFile, buf, sizeof(buf));
				sceKernelDelayThread(1000000);
				if (pkgSize > 0) {
					swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP loaded into memory successfully!", 50 + (10 * i), 0xFF006600, 8); i += 2; drawObjects();
					// Calculate size of prx to extract (size of entire package - size of eboot.pbp).
					prxSize = pkgSize - pbpSize;
					// Open PRX file and write buffer into the contents.
					prxFile = sceIoOpen(PRX_WARPSP_XMB, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
					sceKernelDelayThread(100000);
					if (prxFile) {
						// Write prx file from end of eboot.pbp.
						sceIoWrite(prxFile, buf + pbpSize, prxSize);
						sceKernelDelayThread(1000000);
						sceIoClose(prxFile);
						sceKernelDelayThread(1000000);
						swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extracted from memory successfully!", 50 + (10 * i), 0xFF006600, 8); drawObjects();
					} else {
						swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP.prx extraction from memory failed!", 50 + (10 * i), 0xFF000099, 8); drawObjects();
					}
					i += 2;
				}
				sceIoClose(pbpFile);
				sceKernelDelayThread(1000000);
			} else {
				swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("EBOOT.PBP load into memory failed!", 50 + (10 * i), 0xFF000099, 8); i += 2; drawObjects();
			}
			buf[0] = (char)"\0";
			swapBuffers(); sceGuStart(GU_DIRECT, list);
			if (!fileExist(PRX_WARPSP_XMB)) { drawStringCenter("warPSP.prx not found! Install cancelled!", 50 + (10 * i), 0xFF000099, 8); } else { drawStringCenter("warPSP.prx found. Ok to install!", 50 + (10 * i), 0xFF006600, 8); ok = 1; }
			i += 2; drawObjects();
			// Create backup of original file and install warPSP.
			if (ok) {
				if (!reinstall) {
					swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("The backup file will be copied to the memory stick!", 50 + (10 * i), 0xFF990000, 8); i++; drawObjects();
					if (fileCopy(lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY, lftv ? PRX_LFTVBACKUP : PRX_RPLYBACKUP)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file backed up successfully!", 50 + (10 * i), 0xFF006600, 8); } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Original prx file back up failed!", 50 + (10 * i), 0xFF000099, 8); }
					i += 2; drawObjects();
				}
				if (fileCopy(PRX_WARPSP_XMB, lftv ? PRX_LFTVPLAYER : PRX_REMOTEPLAY)) { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installed successfully!", 50 + (10 * i), 0xFF006600, 8); sceIoRemove(PRX_WARPSP_XMB); installed = 1; } else { swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("warPSP^xmb installation failed!", 50 + (10 * i), 0xFF000099, 8); installed = 0; }
				i += 2; drawObjects();
			}
		}
		scePowerUnlock(0);
	}

	if (installed | uninstalled) { sceKernelDelayThread(1000000); }
	if (!quickinstall) {
		swapBuffers(); sceGuStart(GU_DIRECT, list);
		sprintf(buffer, "Press any button to %s! (Auto-Exit in 10s).", (installed | uninstalled) ? "restart the PSP" : "return to the xmb"); drawStringCenter(buffer, 50 + (10 * i), 0xFF000000, 8); i++;
		if (installed) { drawStringCenter("Happy warXing!", 50 + (10 * i), 0xFF006600, 8); i++; } else if (uninstalled) { drawStringCenter("Thank you for using warPSP", 50 + (10 * i), 0xFF990000, 8); i++; }
		drawObjects();
		// Wait for exit.
		while (1) {
			if (autoExit >= 1000) break;
	    	sceCtrlReadBufferPositive(&pad, 1);
			if (pad.Buttons) break;
			sceKernelDelayThread(10000);
			autoExit++;
		}
	}

	if (quickinstall) { sceKernelDelayThread(1000000); }
	swapBuffers(); sceGuStart(GU_DIRECT, list); drawStringCenter("Exiting!", 50 + (10 * i), (installed | uninstalled) ? 0xFF990000 : 0xFF0000FF, 8); drawObjects();
	if (installed | uninstalled) { sceKernelExitGame(); scePower_0442D852(50000); } else { sceKernelExitGame(); }
	return 0;
}
void FrontEnd::StartUpDisplay(void)
#endif
{
#ifdef PC
	UNREFERENCED_PARAMETER( hInst );

	// register window class
	WNDCLASSEX wc = 
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MainWndProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		L"Cross-Platform Development", NULL
	};
	wc.hInstance = hInst;
	_wc = wc;
	if( !RegisterClassEx( &wc ) )
	{
		MessageBox( 0, L"Failed to Register Class", 0, 0 );
		PostQuitMessage( 0 );
	}

	// create the window
	_d3dParameters.BackBufferHeight = 272;
	_d3dParameters.BackBufferWidth = 480;
	HWND hWnd = CreateWindow( L"Cross-Platform Development", L"Cross-Platform Development", WS_OVERLAPPEDWINDOW, 100, 100, 
		_d3dParameters.BackBufferWidth, _d3dParameters.BackBufferHeight, NULL, NULL, wc.hInstance, NULL );

	// check if the hWnd has been created
	if( !hWnd )
	{
		MessageBox( 0, L"Failed to Create Window", 0, 0 );
		PostQuitMessage( 0 );
	}

	/* Create the device */
	if ( NULL == ( _pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		MessageBox( 0, L"DirectX SDK Version Wrong", 0, 0 );
		PostQuitMessage( 0 );
	}

	// set up the structure used to create the D3DDevice
	int height = _d3dParameters.BackBufferHeight;
	int width = _d3dParameters.BackBufferWidth;
	ZeroMemory( &_d3dParameters, sizeof( _d3dParameters ) );
	_d3dParameters.Windowed = TRUE;
	_d3dParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
	_d3dParameters.BackBufferFormat = D3DFMT_UNKNOWN;
	_d3dParameters.BackBufferHeight = height;
	_d3dParameters.BackBufferWidth = width;
	_d3dParameters.EnableAutoDepthStencil = TRUE;		/* Allow directX to create and manage a z buffer for me */
	_d3dParameters.AutoDepthStencilFormat = D3DFMT_D16;	/* Use the 16bit format */

	// create D3DDevice
	if ( FAILED( _pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING, &_d3dParameters, &_pd3dDevice ) ) )
	{
		if ( FAILED( _pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING, &_d3dParameters, &_pd3dDevice ) ) )
		{
			MessageBox( 0, L"This machine cannot process vertices", 0, 0 );
			PostQuitMessage( 0 );
		}
	}

	// set up some default render modes
	_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );		/*< Solid fill rendering */
	_pd3dDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT );		/*< Default shading */
	_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );		/*< Culling off */ 
	_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );				/*< Lighting on */ 
	_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255) );
	_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );			/*< Turn on z buffering */
	_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );			/*< Allow writing to the z buffer */
	_pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL );		/*< Render each pixel if it's less than or equal to an existing pixel */

	ShowWindow( hWnd, UpdateWindow( hWnd ) );

	/* Set up the vertex buffer for rendering */
	Vertex* vertexBuffer = false;
	if( SUCCEEDED( _pd3dDevice->CreateVertexBuffer( 36 * sizeof( D3DFVF_Vertex ), 0, 
		D3DFVF_XYZ, D3DPOOL_DEFAULT, &_vertexBuffer, NULL ) ) )
	{
		if( SUCCEEDED( _vertexBuffer->Lock( 0, 36 * sizeof( D3DFVF_Vertex ), (void**)&vertexBuffer, 0 ) ) )
		{	
			for( DWORD i = 0; i < 36; ++i )
			{
				vertexBuffer[i].x = Cube[i].x;
				vertexBuffer[i].y = Cube[i].y;
				vertexBuffer[i].z = Cube[i].z;
			}

			_vertexBuffer->Unlock();

			/* Apply a material for lighting to work */
			D3DMATERIAL9 material;
			ZeroMemory( &material, sizeof( material ) );
			material.Diffuse.r = material.Ambient.r = 1.0f;
			material.Diffuse.g = material.Ambient.g = 1.0f;
			material.Diffuse.b = material.Ambient.b = 1.0f;
			material.Diffuse.a = material.Ambient.a = 1.0f;

			_pd3dDevice->SetMaterial( &material );
			_pd3dDevice->SetStreamSource( 0, _vertexBuffer, 0, sizeof(D3DFVF_Vertex) );
			_pd3dDevice->SetFVF( D3DFVF_XYZ );
		}
	}
#else
	_rotationSpeed = 1.0f;
	_rotation.x = 0.0f;
	_rotation.y = 0.0f;
	_rotation.z = 0.0f;
	_frame = 0;
	_viewMode = -1;
	sceGuInit();
	sceGuStart(SCEGU_IMMEDIATE, (void*)_displist, sizeof(_displist));

	sceGuDrawBuffer(SCEGU_PF5551, SCEGU_VRAM_BP_0, SCEGU_VRAM_WIDTH);
	sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, SCEGU_VRAM_BP_1,
		SCEGU_VRAM_WIDTH);
	sceGuDepthBuffer(SCEGU_VRAM_BP_2, SCEGU_VRAM_WIDTH);

	sceGuOffset(SCEGU_SCR_OFFSETX, SCEGU_SCR_OFFSETY);
	sceGuViewport(2048, 2048, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuDepthRange(50000, 10000);

	sceGuDisable(SCEGU_BLEND);

	sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
	sceGuEnable(SCEGU_SCISSOR_TEST);

	sceGuDepthFunc(SCEGU_GEQUAL);
	sceGuEnable(SCEGU_DEPTH_TEST);

	sceGuFrontFace(SCEGU_CW);

	sceGuDisable(SCEGU_TEXTURE);
	sceGuShadeModel(SCEGU_SMOOTH);

	sceGuEnable(SCEGU_DITHER);

	sceGumSetMatrixStack(_matrixStack, 1, 1, 2, 0);
	sceGumMatrixMode(SCEGU_MATRIX_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(DEGSTORADS(45.0f), SCEGU_SCR_ASPECT,
		1.000000f, 100.000000f);

	sceGumMatrixMode(SCEGU_MATRIX_WORLD);

	sceGuClearDepth(0);
	sceGuClearStencil(0);

	sceGuFinish();
	sceGuSync(SCEGU_SYNC_FINISH, SCEGU_SYNC_WAIT);

	sceGuDisplay(SCEGU_DISPLAY_ON);
#endif
}
示例#26
0
int main(int argc, char* argv[])
{
	setupCallbacks();

	int i, j;

	// Load emd mesh from file
	EMD_MESH* mesh = EMD_LoadMeshFromFile("scene.emd");
	int vert_count = EMD_GetVertexCount(mesh);
	int idx_count = 0;

	int elem_count = EMD_GetElementCount(mesh);
	for (i=0; i<elem_count; i++)
	{
		idx_count += EMD_GetIndexCount(mesh, i);
	}

	VERTEX* vert_buf = (VERTEX*)memalign(16, sizeof(VERTEX) * vert_count);
	GW_UINT16* idx_buf = (GW_UINT16*)memalign(16, sizeof(GW_UINT16) * idx_count);

	for (i=0; i<vert_count; i++)
	{
		EMD_GetVertexByIndex(mesh, i, &vert_buf[i].x, &vert_buf[i].y, &vert_buf[i].z);
		EMD_GetTexcoordByIndex(mesh, i, &vert_buf[i].u, &vert_buf[i].v);
		EMD_GetNormalByIndex(mesh, i, &vert_buf[i].nx, &vert_buf[i].ny, &vert_buf[i].nz);
		//vert_buf[i].color = 0xffffffff;
	}

	GW_UINT32 idx_head = 0;
	GW_UINT32* data;
	GW_UINT32 count;

	// Pack 32-bit index into 16-bit buffer
	for (i=0; i<elem_count; i++)
	{
		count = EMD_GetIndexCount(mesh, i);
		data = EMD_GetIndexArray(mesh, i);
		for (j=0; j<count; j++)
		{
			idx_buf[j + idx_head] = (GW_UINT16)data[j];
		}

		idx_head += count;
	}

	EMD_FreeMesh(mesh);


	// flush cache so that no stray data remains

	sceKernelDcacheWritebackAll();

	// setup GU

	void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);

	pspDebugScreenInit();
	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
	sceGuDepthBuffer(zbp,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(65535,0);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuFrontFace(GU_CCW);
	sceGuShadeModel(GU_SMOOTH);
	sceGuEnable(GU_CULL_FACE);
	//sceGuDisable(GU_TEXTURE_2D);
	sceGuEnable(GU_CLIP_PLANES);
	sceGuEnable(GU_LIGHTING);
	sceGuEnable(GU_LIGHT0);
	sceGuEnable(GU_LIGHT1);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	// run sample

	int val = 0;

	while(running())
	{
		sceGuStart(GU_DIRECT,list);

		// clear screen

		sceGuClearColor(0xff554433);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		
		// setup lights

		ScePspFVector3 light_dir = { 1.0f, 1.0f, 1.0f };

		// GU_DIRECTIONAL
		// GU_POINTLIGHT
		sceGuLight(0, GU_POINTLIGHT, GU_DIFFUSE, &light_dir);
		sceGuLightColor(0, GU_DIFFUSE, 0xffffffff);
		sceGuAmbient(0x00202020);

		light_dir.x = -light_dir.x;
		light_dir.y = -light_dir.y;
		light_dir.z = -light_dir.z;

		sceGuLight(1, GU_DIRECTIONAL, GU_DIFFUSE_AND_SPECULAR, &light_dir);
		sceGuLightColor(1, GU_DIFFUSE, 0xff7f7f7f);
		

		// setup matrices for cube

		sceGumMatrixMode(GU_PROJECTION);
		sceGumLoadIdentity();
		sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);

		sceGumMatrixMode(GU_VIEW);
		sceGumLoadIdentity();

		sceGumMatrixMode(GU_MODEL);
		sceGumLoadIdentity();
		{
			ScePspFVector3 pos = { 0, 0, -5.0f };
			ScePspFVector3 rot = { val * 0.79f * (GU_PI/180.0f), val * 0.98f * (GU_PI/180.0f), val * 1.32f * (GU_PI/180.0f) };
			sceGumTranslate(&pos);
			sceGumRotateXYZ(&rot);
		}

		// setup texture

		//sceGuTexMode(GU_PSM_4444,0,0,0);
		// sceGuTexImage(0,64,64,64,logo_start);
		//sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
		//sceGuTexEnvColor(0xffff00);
		//sceGuTexFilter(GU_LINEAR,GU_LINEAR);
		//sceGuTexScale(1.0f,1.0f);
		//sceGuTexOffset(0.0f,0.0f);
		//sceGuAmbientColor(0xff7f7f7f);

		// draw cube

		sceGuColor(0xffffff);
		sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_INDEX_16BIT|GU_TRANSFORM_3D,
				idx_count, idx_buf, vert_buf);
		

		pspDebugScreenSetXY(0, 0);
		pspDebugScreenPrintf("v: %d", vert_count);
		pspDebugScreenSetXY(0, 1);
		pspDebugScreenPrintf("i: %d", idx_count);

		sceGuFinish();
		sceGuSync(0,0);

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();

		val++;
	}

	sceGuTerm();

	// Release buffers
	free(vert_buf);
	free(idx_buf);

	sceKernelExitGame();
	return 0;
}
示例#27
0
文件: DOD_Gx.cpp 项目: manlon/dod-rge
	static void dod_init_gu()
	{
		void* pDrawBuffer	= dod_get_static_vram_buffer(DOD_BUFFER_WIDTH, DOD_SCREEN_HEIGHT, GU_PSM_8888);
		void* pDispBuffer	= dod_get_static_vram_buffer(DOD_BUFFER_WIDTH, DOD_SCREEN_HEIGHT, GU_PSM_8888);
		void* pZBuffer		= dod_get_static_vram_buffer(DOD_BUFFER_WIDTH, DOD_SCREEN_HEIGHT, GU_PSM_4444);
		
		sceGuInit();
		sceGuStart(GU_DIRECT, s_list);
		
		sceGuDrawBuffer(GU_PSM_8888, pDrawBuffer, DOD_BUFFER_WIDTH);
		sceGuDispBuffer(DOD_SCREEN_WIDTH, DOD_SCREEN_HEIGHT, pDispBuffer, DOD_BUFFER_WIDTH);
		sceGuDepthBuffer(pZBuffer, DOD_BUFFER_WIDTH);
		
		sceGuOffset(2048 - (DOD_SCREEN_WIDTH / 2), 2048 - (DOD_SCREEN_HEIGHT / 2));
		sceGuViewport(2048, 2048, DOD_SCREEN_WIDTH, DOD_SCREEN_HEIGHT);
		sceGuDepthRange(65535, 0);
		
		sceGuScissor(0, 0, DOD_SCREEN_WIDTH, DOD_SCREEN_HEIGHT);
		sceGuEnable(GU_SCISSOR_TEST);
		
		sceGuEnable(GU_CULL_FACE);
	 	sceGuFrontFace(GU_CCW);
		
		sceGuShadeModel(GU_SMOOTH);

		//sceGuDepthFunc(GU_GEQUAL);
		//sceGuDepthMask(GU_TRUE);		// disable z-writes
		//sceGuEnable(GU_DEPTH_TEST);
		
		sceGuEnable(GU_TEXTURE_2D);
		//sceGuEnable(GU_CLIP_PLANES);
				
		sceGuDisable(GU_COLOR_TEST);
		sceGuDisable(GU_ALPHA_TEST);
		sceGuDisable(GU_CLIP_PLANES);
		

		// Lighting
		sceGuDisable(GU_LIGHTING);
		sceGuDisable(GU_LIGHT0);
		sceGuDisable(GU_LIGHT1);
		sceGuDisable(GU_LIGHT2);
		sceGuDisable(GU_LIGHT3);
		
		// Texturing
		sceGuTexWrap(GU_CLAMP, GU_CLAMP);
		sceGuTexFilter(GU_LINEAR, GU_LINEAR);
		sceGuTexOffset(0.f, 0.f);
		sceGuTexScale(1.f, 1.f);
		//sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
		//sceGuTexEnvColor(0xffffffff);
		
		//sceGuColor(0xffffffff);
		//sceGuAmbientColor(0xffffffff);

		// Blending
		//sceGuEnable(GU_BLEND);
		//sceGuBlendFunc(GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
		//sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
		//sceGuTexFilter(GU_LINEAR, GU_LINEAR);
		sceGuDisable(GU_DITHER);

		sceGuFinish();
		sceGuSync(0,0);
		
		sceDisplayWaitVblankStart();
		sceGuDisplay(GU_TRUE);
	}
示例#28
0
int main(int argc, char* argv[])
{
    SetupCallbacks();

    // generate geometry

    genTorus( TORUS_ROWS, TORUS_SLICES, TORUS_RADIUS, TORUS_THICKNESS, torus_vertices, torus_indices );

    // flush cache so that no stray data remains

    sceKernelDcacheWritebackAll();

    // setup Edram buffers

    void* frameBuffer = (void*)0;
    const void* doubleBuffer = (void*)0x44000;
    const void* renderTarget = (void*)0x88000;
    const void* depthBuffer = (void*)0x110000;

    // setup GU

    sceGuInit();

    sceGuStart(GU_DIRECT,list);
    sceGuDrawBuffer(GU_PSM_4444,frameBuffer,BUF_WIDTH);
    sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)doubleBuffer,BUF_WIDTH);
    sceGuDepthBuffer((void*)depthBuffer,BUF_WIDTH);
    sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
    sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
    sceGuDepthRange(0xc350,0x2710);
    sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
    sceGuEnable(GU_SCISSOR_TEST);
    sceGuDepthFunc(GU_GEQUAL);
    sceGuEnable(GU_DEPTH_TEST);
    sceGuFrontFace(GU_CW);
    sceGuShadeModel(GU_SMOOTH);
    sceGuEnable(GU_CULL_FACE);
    sceGuEnable(GU_TEXTURE_2D);
    sceGuFinish();
    sceGuSync(0,0);

    sceDisplayWaitVblankStart();
    sceGuDisplay(GU_TRUE);

    // run sample
    int val = 0;
    Texture offscreenTexture = {
        GU_PSM_4444,
        0, 128, 128, 128,
        sceGeEdramGetAddr() + (int)renderTarget
    };

    for(;;)
    {
        sceGuStart(GU_DIRECT,list);

        {
            sceGuDrawBufferList(GU_PSM_4444,(void*)renderTarget,offscreenTexture.stride);

            // setup viewport

            sceGuOffset(2048 - (offscreenTexture.width/2),2048 - (offscreenTexture.height/2));
            sceGuViewport(2048,2048,offscreenTexture.width,offscreenTexture.height);

            // clear screen

            sceGuClearColor(0xffffffff);
            sceGuClearDepth(0);
            sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

            // draw torus to offscreen texture

            drawTorus( val );
        }

        {
            // set frame buffer

            sceGuDrawBufferList(GU_PSM_4444,(void*)frameBuffer,BUF_WIDTH);

            // setup viewport

            sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
            sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);

            // clear screen

            sceGuClearColor(0xff554433);
            sceGuClearDepth(0);
            sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

            // draw cube using offscreen texture

            drawCube( &offscreenTexture, val );

        }

        sceGuFinish();
        sceGuSync(0,0);

        sceDisplayWaitVblankStart();
        frameBuffer = sceGuSwapBuffers();

        val++;
    }

    sceGuTerm();

    sceKernelExitGame();
    return 0;
}
示例#29
0
static void *psp_init(const video_info_t *video,
                      const input_driver_t **input, void **input_data)
{
    // to-do : add ASSERT() checks or use main RAM if VRAM is too low for desired video->input_scale
    void *pspinput;
    int pixel_format, lut_pixel_format, lut_block_count;
    unsigned int red_shift, color_mask;
    void *displayBuffer, *LUT_r, *LUT_b;
    psp1_video_t *psp  = (psp1_video_t*)calloc(1, sizeof(psp1_video_t));

    if (!psp)
        return NULL;

    sceGuInit();

    psp->main_dList         = memalign(16, 256); // make sure to allocate more space if bigger display lists are needed.
    psp->frame_dList        = memalign(16, 256);
    psp->rgui.dList         = memalign(16, 256);
    psp->rgui.frame         = memalign(16,  2 * 480 * 272);
    psp->frame_coords       = memalign(64,  1 * sizeof(psp1_sprite_t));
    psp->rgui.frame_coords  = memalign(64, 16 * sizeof(psp1_sprite_t));

    memset(psp->frame_coords      , 0,  1 * sizeof(psp1_sprite_t));
    memset(psp->rgui.frame_coords , 0, 16 * sizeof(psp1_sprite_t));
    sceKernelDcacheWritebackInvalidateAll();
    psp->frame_coords       = TO_UNCACHED_PTR(psp->frame_coords);
    psp->rgui.frame_coords  = TO_UNCACHED_PTR(psp->rgui.frame_coords);;

    psp->frame_coords->v0.x = 60;
    psp->frame_coords->v0.y = 0;
    psp->frame_coords->v0.u = 0;
    psp->frame_coords->v0.v = 0;

    psp->frame_coords->v1.x = 420;
    psp->frame_coords->v1.y = SCEGU_SCR_HEIGHT;
    psp->frame_coords->v1.u = 256;
    psp->frame_coords->v1.v = 240;

    psp->vsync = video->vsync;
    psp->rgb32 = video->rgb32;

    if(psp->rgb32)
    {
        uint32_t* LUT_r_local = (uint32_t*)(SCEGU_VRAM_BP32_2);
        uint32_t* LUT_b_local = (uint32_t*)(SCEGU_VRAM_BP32_2) + (1 << 8);

        red_shift = 8 + 8;
        color_mask = 0xFF;
        lut_block_count = (1 << 8) / 8;

        psp->texture = (void*)(LUT_b_local + (1 << 8));
        psp->draw_buffer = SCEGU_VRAM_BP32_0;
        psp->bpp_log2 = 2;

        pixel_format = GU_PSM_8888;
        lut_pixel_format = GU_PSM_T32;

        displayBuffer = SCEGU_VRAM_BP32_1;

        for (u32 i=0; i < (1 << 8); i++) {
            LUT_r_local[i]= i;
            LUT_b_local[i]= i << (8 + 8);
        }

        LUT_r = (void*)LUT_r_local;
        LUT_b = (void*)LUT_b_local;

    }
    else
    {
        uint16_t* LUT_r_local = (uint16_t*)(SCEGU_VRAM_BP_2);
        uint16_t* LUT_b_local = (uint16_t*)(SCEGU_VRAM_BP_2) + (1 << 5);

        red_shift = 6 + 5;
        color_mask = 0x1F;
        lut_block_count = (1 << 5) / 8;

        psp->texture = (void*)(LUT_b_local + (1 << 5));
        psp->draw_buffer = SCEGU_VRAM_BP_0;
        psp->bpp_log2 = 1;

        pixel_format = GU_PSM_5650;
        lut_pixel_format = GU_PSM_T16;

        displayBuffer = SCEGU_VRAM_BP_1;

        for (u16 i = 0; i < (1 << 5); i++) {
            LUT_r_local[i]= i;
            LUT_b_local[i]= i << (5 + 6);
        }

        LUT_r = (void*)LUT_r_local;
        LUT_b = (void*)LUT_b_local;

    }

    sceDisplayWaitVblankStart();   // TODO : check if necessary
    sceGuDisplay(GU_FALSE);

    sceGuStart(GU_DIRECT, psp->main_dList);

    sceGuDrawBuffer(pixel_format, TO_GU_POINTER(psp->draw_buffer), SCEGU_VRAM_WIDTH);
    sceGuDispBuffer(SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT, TO_GU_POINTER(displayBuffer), SCEGU_VRAM_WIDTH);
    sceGuClearColor(0);
    sceGuScissor(0, 0, SCEGU_SCR_WIDTH, SCEGU_SCR_HEIGHT);
    sceGuEnable(GU_SCISSOR_TEST);
    sceGuTexFilter(GU_LINEAR, GU_LINEAR);  // TODO , move this to display list
    sceGuTexWrap (GU_CLAMP, GU_CLAMP);
    sceGuEnable(GU_TEXTURE_2D);
    sceGuDisable(GU_DEPTH_TEST);
    sceGuCallMode(GU_FALSE);

    sceGuFinish();
    sceGuSync(0, 0);

    sceDisplayWaitVblankStart();   // TODO : check if necessary
    sceGuDisplay(GU_TRUE);

    pspDebugScreenSetColorMode(pixel_format);
    pspDebugScreenSetBase(psp->draw_buffer);

    // fill frame_dList :

    sceGuStart(GU_CALL, psp->frame_dList);

    sceGuTexMode(pixel_format, 0, 0, GU_FALSE);
    sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
    sceGuEnable(GU_BLEND);

    sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0x0000FF00, 0xFFFFFFFF); // green only
    sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_4444 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, (void*)(psp->frame_coords));
    sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, 0xFFFFFFFF, 0xFFFFFFFF); // restore

    sceGuTexMode(lut_pixel_format, 0, 0, GU_FALSE);

    sceGuClutMode(pixel_format, red_shift, color_mask, 0);
    sceGuClutLoad(lut_block_count, LUT_r);

    sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_4444 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, (void*)(psp->frame_coords));

    sceGuClutMode(pixel_format, 0, color_mask, 0);
    sceGuClutLoad(lut_block_count, LUT_b);
    sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_4444 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, (void*)(psp->frame_coords));

    sceGuFinish();

    if (input && input_data)
    {
        pspinput = input_psp.init();
        *input = pspinput ? &input_psp : NULL;
        *input_data = pspinput;
    }

    return psp;
error:
    RARCH_ERR("PSP1 video could not be initialized.\n");
    return (void*)-1;
}
示例#30
0
文件: logic.c 项目: CDragu/pspsdk
int main(int argc, char* argv[])
{
	pspDebugScreenInit();

	setupCallbacks();

	// setup GU

	void* fbp0 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* fbp1 = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_8888);
	void* zbp = getStaticVramBuffer(BUF_WIDTH,SCR_HEIGHT,GU_PSM_4444);

	sceGuInit();

	sceGuStart(GU_DIRECT,list);
	sceGuDrawBuffer(GU_PSM_8888,fbp0,BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,fbp1,BUF_WIDTH);
	sceGuDepthBuffer(zbp,BUF_WIDTH);
	sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
	sceGuDepthRange(65535,0);
	sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	int val = 0;

	gettimeofday(&base_time,0);

	while(running())
	{
		struct Vertex* vertices;
		struct timeval tv;

		sceGuStart(GU_DIRECT,list);

		// clear screen

		sceGuClearColor(0);
		sceGuClearDepth(0);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

		// draw triangle 1 (normal)

		sceGuColor(0xffffffff);

		vertices = (struct Vertex*)sceGuGetMemory(3*sizeof(struct Vertex));
		vertices[0].x = (SCR_WIDTH/2) + cosf(val * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[0].y = (SCR_HEIGHT/2) + sinf(val * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[0].z = 0;
		vertices[1].x = (SCR_WIDTH/2) + cosf((val+120) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[1].y = (SCR_HEIGHT/2) + sinf((val+120) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[1].z = 0;
		vertices[2].x = (SCR_WIDTH/2) + cosf((val+240) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[2].y = (SCR_HEIGHT/2) + sinf((val+240) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[2].z = 0;
		sceGuDrawArray(GU_TRIANGLES,GU_VERTEX_32BITF|GU_TRANSFORM_2D,3,0,vertices);

		// draw triangle 2 (affected by logic op)

		sceGuEnable(GU_COLOR_LOGIC_OP);
		sceGuLogicalOp(curr_state);

		sceGuColor(0xffff00ff);

		vertices = (struct Vertex*)sceGuGetMemory(3*sizeof(struct Vertex));
		vertices[0].x = (SCR_WIDTH/2) + cosf((val*1.1f) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[0].y = (SCR_HEIGHT/2) + sinf((val*1.1f) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[0].z = 0;
		vertices[1].x = (SCR_WIDTH/2) + cosf((val*1.1f+120) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[1].y = (SCR_HEIGHT/2) + sinf((val*1.1f+120) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[1].z = 0;
		vertices[2].x = (SCR_WIDTH/2) + cosf((val*1.1f+240) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[2].y = (SCR_HEIGHT/2) + sinf((val*1.1f+240) * (GU_PI/180)) * (SCR_HEIGHT/2);
		vertices[2].z = 0;
		sceGuDrawArray(GU_TRIANGLES,GU_VERTEX_32BITF|GU_TRANSFORM_2D,3,0,vertices);

		sceGuDisable(GU_COLOR_LOGIC_OP);

		sceGuFinish();
		sceGuSync(0,0);

		gettimeofday(&tv,0);
		if ((tv.tv_sec-base_time.tv_sec) > TIME_SLICE)
		{
			curr_state = (curr_state + 1) & 15;
			base_time = tv;
		}

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();
		pspDebugScreenSetXY(0,0);
		pspDebugScreenPrintf("%s",names[curr_state]);

		val++;
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}