Example #1
0
void S9xSceGUSwapBuffers (void)
{
// This just makes things slower to be completely honest...
#ifdef SCEGU_DOUBLE_BUFFERED
  SceGU.vram_offset = sceGuSwapBuffers ();
#endif
}
Example #2
0
void vidgu_render_nostretch(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
{
	int start, end;

	sceGuStart(GU_DIRECT,list);
	sceGuTexMode(GU_PSM_5650,0,0,0); // 16-bit RGBA
	sceGuTexImage(0,512,512,512,g_pBlitBuff); // setup texture as a 256x256 texture
	//sceKernelDcacheWritebackAll();
	sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA); // don't get influenced by any vertex colors
	sceGuTexFilter(GU_NEAREST,GU_NEAREST); // point-filtered sampling
	for (start = sx, end = sx+sw; start < end; start += SLICE_SIZE, dx += SLICE_SIZE)
	{
		struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
		int width = (start + SLICE_SIZE) < end ? SLICE_SIZE : end-start;

		vertices[0].u = start; vertices[0].v = sy;
		vertices[0].color = 0;
		vertices[0].x = dx; vertices[0].y = dy; vertices[0].z = 0;

		vertices[1].u = start + width; vertices[1].v = sy + sh;
		vertices[1].color = 0;
		vertices[1].x = dx + width; vertices[1].y = dy + sh; vertices[1].z = 0;

		sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5650|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
	}
	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuSwapBuffers();
	//sceGuSwapBuffers();
}
Example #3
0
void App_Render(void)
{
	DrawScene();
	DebugScreen();
			
	sceDisplayWaitVblankStart();	
	fbp0 = sceGuSwapBuffers();
}
Example #4
0
void Red3dFlipGuBuffer()
{
	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	framebuffer = sceGuSwapBuffers();
	dispBufferNumber ^= 1;
	Red3dSetupScreen();
}
Example #5
0
void MFRenderer_EndFramePlatformSpecific()
{
	MFCALLSTACK;

	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuSwapBuffers();
}
Example #6
0
void gFlip(bool use_vsync)
{
  if (scissor) gResetScissor();

  sceGuFinish();
  sceGuSync(0,0);
  if (use_vsync) sceDisplayWaitVblankStart();
  sceGuSwapBuffers();

  start = G_FALSE;
}
Example #7
0
int ScreenFlip()
{
	GUINITCHECK;
	GUSYNC;
	if(dxpGraphicsData.debugScreenCallback)dxpGraphicsData.debugScreenCallback();
	dxpGraphicsWaitVSync();
	sceGuSwapBuffers();
	dxpGraphicsData.displaybuffer_back = &dxpGraphicsData.displaybuffer[0] == dxpGraphicsData.displaybuffer_back ? &dxpGraphicsData.displaybuffer[1] : &dxpGraphicsData.displaybuffer[0];
	if(dxpGraphicsData.rendertarget == &dxpGraphicsData.displaybuffer[0] || dxpGraphicsData.rendertarget == &dxpGraphicsData.displaybuffer[1])
		dxpGraphicsData.rendertarget = dxpGraphicsData.displaybuffer_back;
	return 0;
}
Example #8
0
// This callback is called when the render is finished. It swaps the buffers
int MasterGuRenderer::guCallback(int, int, void *__this) {

	MasterGuRenderer *_this = (MasterGuRenderer *)__this;

	sceGuSync(0, 0);				// make sure we wait for GU to finish
	sceDisplayWaitVblankStartCB();	// wait for v-blank without eating main thread cycles
	sceGuSwapBuffers();				// swap the back and front buffers

	_this->_renderFinished = true;	// Only this thread can set the variable to true

	_this->_renderSema.give(); 		// Release render semaphore
	return 0;
}
Example #9
0
void *psp_showPage(image *framebuffer, int tyres) {

	//perhaps:
	//sync at the top, instead of the bottom,
	//so that the framerendering can go on while the engine
	//proceeds instead of having to wait in showpage

	//sceGuSync(0,0);

	//swap the R and B bitfields, goddammit
	/*int w = framebuffer->width;
	int p = framebuffer->pitch;
	int h = framebuffer->height;
	unsigned short *buf = (unsigned short *)framebuffer->data;
	for(int y=0;y<h;y++) {
		for(int x=0;x<w;x++)
			buf[x] = (buf[x]<<11)|(buf[x]>>11)|(buf[x]&0x07E0);
		buf += p;
	}*/

	//make sure the software buffer is flushed
	sceKernelDcacheWritebackAll();

	//sceGuStart(GU_DIRECT,list);

	//// clear screen
	////sceGuClearColor(0xff000000);
	////sceGuClear(GU_COLOR_BUFFER_BIT);

	//sceGuTexMode(GU_PSM_5650,0,0,0);
	//sceGuTexImage(0,framebuffer->pitch,tyres,framebuffer->pitch,framebuffer->data);
	//sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
	//sceGuTexFilter(GU_NEAREST,GU_NEAREST);
	//sceGuTexScale(1.0f/(float)framebuffer->pitch,1.0f/(float)tyres);
	//sceGuTexOffset(0.0f,0.0f);

	//psp_renderSprite(0,
	//	(480-framebuffer->width)/2,
	//	(272-framebuffer->height)/2,
	//	framebuffer->width,framebuffer->height);

	//sceGuFinish();
	//sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	void *backBuffer = sceGuSwapBuffers();
	//sceGuSync(0,0);
	return backBuffer;

	//sceDisplayWaitVblankStart();

}
Example #10
0
void vidgu_render(int sx, int sy, int sw,int sh,int dx, int dy, int dw,int dh)
{
	unsigned int j,cx,cy;
	struct Vertex* vertices;

	cx=(480-dw)/2;
	cy=(272-dh)/2;

	sceGuStart(GU_DIRECT,list);
	sceGuTexMode(GU_PSM_5650,0,0,0); // 16-bit RGBA
	sceGuTexImage(0,512,512,512,g_pBlitBuff); // setup texture as a 256x256 texture
	//sceKernelDcacheWritebackAll();
	sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA); // don't get influenced by any vertex colors
	sceGuTexFilter(GU_LINEAR,GU_LINEAR); // point-filtered sampling

	int		start, end;
	float	ustart = (float)sx;
	float	ustep = (float)sw / (float)(dw / SLICE_SIZE);

	// blit maximizing the use of the texture-cache

	for (start = sx, end = sx+dw; start < end; start += SLICE_SIZE, dx += SLICE_SIZE)
	{
		struct Vertex* vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
		int width = (start + SLICE_SIZE) < end ? SLICE_SIZE : end-start;

		vertices[0].u = ustart; 
		vertices[0].v = (float)sy;
		vertices[0].color = 0;
		vertices[0].x = dx; 
		vertices[0].y = dy; 
		vertices[0].z = 0;

		vertices[1].u = ustart + ustep; 
		vertices[1].v = (float)(sy + sh);
		vertices[1].color = 0;
		vertices[1].x = dx + width; 
		vertices[1].y = dy + dh; 
		vertices[1].z = 0;

		sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_COLOR_5650|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);

		ustart += ustep;
	}


	sceGuFinish();
	sceGuSync(0,0);
	sceDisplayWaitVblankStart();
	sceGuSwapBuffers(); 
}
Example #11
0
int main(void) {
	init();
	
	while (pad_read()) {
		update();
		draw();
		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();
	}
	
	sceGuTerm();

	return 0;
}
Example #12
0
File: main.c Project: CDragu/pspsdk
int main(int argc, char *argv[])
{
	char url[] = "http://www.ps2dev.org/";

	setupGu();
	netInit();
	htmlViewerInit(url);	

	while(updateHtmlViewer())
	{
		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();
	}

	netTerm();
	sceKernelFreeVpl(vpl, params.memaddr);
	sceKernelDeleteVpl(vpl);
	sceKernelExitGame();

	return 0;
}
Example #13
0
void StartRendering()
{
	//printf("FrontEnd::StartRendering\n");
	
	/* Increment the frame */
	if (_frame >= 0xff)
	{
		_frame = 0;
	}
	else
	{
		++_frame;
	}
	
	BlockUntilFrameReady();	/*< Blocks the program until the frame is ready */
	
	/* Preps the display for rendering */
	sceGuSwapBuffers();
	sceGuStart(SCEGU_IMMEDIATE, (void*)disp_list, sizeof(disp_list));
	sceGuClearColor(_bgColour);
	sceGuClear(SCEGU_CLEAR_ALL);
}
Example #14
0
inline void MasterGuRenderer::guPostRender() {
	DEBUG_ENTER_FUNC();

	sceGuFinish();
#ifdef USE_DISPLAY_CALLBACK
	if (_callbackId < 0)
		PSP_ERROR("bad callbackId[%d]\n", _callbackId);
	else
		sceKernelNotifyCallback(_callbackId, 0);	// notify the callback. Nothing extra to pass
#else
	sceGuSync(0, 0);

#ifdef ENABLE_RENDER_MEASURE
	uint32 now = g_system->getMillis();
	PSP_INFO_PRINT("Render took %d milliseconds\n", now - _lastRenderTime);
#endif /* ENABLE_RENDER_MEASURE */

	sceDisplayWaitVblankStart();
	sceGuSwapBuffers();
	_renderFinished = true;
#endif /* !USE_DISPLAY_CALLBACK */
}
Example #15
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();
}
Example #16
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;
}
Example #17
0
File: main.c Project: 173210/ppsspp
int main(int argc, char *argv[])
{
	int i;
	pspDebugScreenInit();

	SceUID mod = pspSdkLoadStartModule ("flash0:/kd/chnnlsv.prx",PSP_MEMORY_PARTITION_KERNEL); 
	if (mod < 0) {
		printf("Error 0x%08X loading/starting chnnlsv.prx.\n", mod);
	}

	mod = pspSdkLoadStartModule ("kernelcall.prx",PSP_MEMORY_PARTITION_KERNEL); 
	if (mod < 0) {
		printf("Error 0x%08X loading/starting kernelcall.prx.\n", mod);
	}

	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
	for(;;)
	{
		printf("====================================================================");
		printf("PPSSPP Save Tool\n");
		printf("====================================================================\n\n\n");
	   
		switch(currentMenu)
		{
			
		case 0:
			{
				int maxOption = 0;
				for(i = 0; menuList0[i]; i++)
				{
					if(i == selectedOption)
						printf("   > %s\n",menuList0[i]);
					else
						printf("     %s\n",menuList0[i]);
					maxOption++;
				}
				
				int input = ProcessInput(maxOption, &selectedOption);
				if(input == 0)
				{
					currentMenu = 1;
					selectedOption = 0;
				}
				else if(input == 1)
				{
					currentMenu = 4;
					selectedOption = 0;
				}
				else if(input == 2)
				{
					sceKernelExitGame();
				}
			}
			break;
		case 4:
		case 1:
			{
				int maxOption = 0;
				printf("PPSSPP Decrypted Save Directory : \n");
				for(i = 0; menuList1[i]; i++)
				{
					if(i == selectedOption)
						printf("   > %s\n",menuList1[i]);
					else
						printf("     %s\n",menuList1[i]);
					maxOption++;
				}
				
				int input = ProcessInput(maxOption, &selectedOption);
				if(input == maxOption-1)
				{
					if(currentMenu == 1)
						selectedOption = 0;
					else
						selectedOption = 1;
					currentMenu = 0;
				}
				else if(input >= 0)
				{
					basePath = selectedOption;
					if(currentMenu == 1)
					{
						currentMenu = 2;
						UpdateValidDir(1);
					}
					else
					{
						currentMenu = 5;
						UpdateValidDir(0);
					}
					selectedOption = 0;
				}
			}
			break;
		case 5:
		case 2:
			{
				int maxOption = 0;
				if(currentMenu == 2)
					printf("Save to encrypt : \n");
				else
					printf("Save to decrypt : \n");
				
				if(numDirList == 0)
				{
					printf("No compatible data, see README for help on use\n");
				}
				for(i = 0; i < numDirList; i++)
				{
					if(i == selectedOption)
						printf("   > %s\n",dirList[i].name);
					else
						printf("     %s\n",dirList[i].name);
					maxOption++;
				}
				
				for(i = 0; menuList2[i]; i++)
				{
					if((i+numDirList) == selectedOption)
						printf("   > %s\n",menuList2[i]);
					else
						printf("     %s\n",menuList2[i]);
					maxOption++;
				}
				
				printf("\n Invalid path : \n");
				for(i = 0; i < numInvalidDirList && i < (22-numDirList); i++)
				{
					switch(invalidDirList[i].errorId)
					{
						case 1:
							printf("     %s : ENCRYPT_INFO.BIN not found\n",invalidDirList[i].name);
						break;
						case 2:
							printf("     %s : ENCRYPT_INFO.BIN read error\n",invalidDirList[i].name);
						break;
						case 3:
							printf("     %s : ENCRYPT_INFO.BIN wrong version\n",invalidDirList[i].name);
						break;
						case 4:
							printf("     %s : PARAM.SFO not found\n",invalidDirList[i].name);
						break;
						case 5:
							printf("     %s : PARAM.SFO read error\n",invalidDirList[i].name);
						break;
						case 6:
							printf("     %s : SAVEDATA_FILE_LIST not found in PARAM.SFO\n",invalidDirList[i].name);
						break;
						case 7:
							printf("     %s : no save name in SAVEDATA_FILE_LIST\n",invalidDirList[i].name);
						break;
						case 8:
							printf("     %s : no save found\n",invalidDirList[i].name);
						break;
						default:
						break;
					}
				}
				
				int input = ProcessInput(maxOption, &selectedOption);
				if(input == numDirList)
				{
					if(currentMenu == 2)
						currentMenu = 1;
					else
						currentMenu = 4;
					selectedOption = basePath;
				}
				else if(input >= 0)
				{
					if(currentMenu == 2)
						currentMenu = 3;
					else
						currentMenu = 6;
					workDir = input;
					selectedOption = 0;
				}
			}
			break;
		case 6:
		case 3:
		{
			
			EncryptFileInfo encryptInfo;
			if(FileRead(menuList1[basePath], dirList[workDir].name, "ENCRYPT_INFO.BIN",(u8*)&encryptInfo,sizeof(encryptInfo)) < 0)
			{
				printf("Can't read encrypt file\n");
			}
			else
			{
				printf("Key : ");
				for(i = 0; i < 16; i++)
					printf(" %02x",(u8)encryptInfo.key[i]);
				printf("\n");
				printf("SDK Version : 0x%x\n",encryptInfo.sdkVersion);
				
				char srcPath[128];
				char dstPath[128];
				if(currentMenu == 3)
				{
					sprintf(srcPath,"%s%s",menuList1[basePath], dirList[workDir].name);
					sprintf(dstPath,"ms0:/PSP/SAVEDATA/%s",dirList[workDir].name);
					sceIoMkdir(dstPath,0777);
				}
				else
				{
					sprintf(srcPath,"ms0:/PSP/SAVEDATA/%s",dirList[workDir].name);
					sprintf(dstPath,"%s%s",menuList1[basePath], dirList[workDir].name);
				}
					
				int dfd;
				dfd = sceIoDopen(srcPath);
				if(dfd >= 0)
				{
					SceIoDirent dirinfo;
					while(sceIoDread(dfd, &dirinfo) > 0)
					{
						
						if(!(dirinfo.d_stat.st_mode & 0x2000)) // is not a file
							continue;
							
						if(strcmp(dirinfo.d_name,"ENCRYPT_INFO.BIN") == 0) // don't copy encrypt info
							continue;
							
						FileCopy(srcPath, dstPath, dirinfo.d_name);
							
					}
					sceIoDclose(dfd);
				}
				
				if(currentMenu == 3)
				{
						
					char decryptedFile[258], encryptedFile[258], srcSFO[258], dstSFO[258];
					sprintf(decryptedFile,"%s/%s",srcPath ,dirList[workDir].saveFile);
					sprintf(srcSFO,"%s/PARAM.SFO",srcPath);

					sprintf(encryptedFile,"%s/%s",dstPath ,dirList[workDir].saveFile);
					sprintf(dstSFO,"%s/PARAM.SFO",dstPath);
						
					printf("Encoding %s into %s\n",decryptedFile, encryptedFile);
						
					int ret = encrypt_file(decryptedFile, 
											encryptedFile, 
											dirList[workDir].saveFile, 
											srcSFO, 
											dstSFO, 
											encryptInfo.key[0] != 0 ? encryptInfo.key : NULL, 
											GetSDKMainVersion(encryptInfo.sdkVersion)
											);
					
					if(ret < 0) {
						printf("Error: encrypt_file() returned %d\n\n", ret);
					} else {
						printf("Successfully wrote %d bytes to\n", ret);
						printf("  %s\n", encryptedFile);
						printf("and updated hashes in\n");
						printf("  %s\n\n", dstSFO);
					}
				}
				else
				{
					char decryptedFile[258], encryptedFile[258];
					sprintf(encryptedFile,"%s/%s",srcPath ,dirList[workDir].saveFile);
					sprintf(decryptedFile,"%s/%s",dstPath ,dirList[workDir].saveFile);
						
					printf("Decoding %s into %s\n",encryptedFile, decryptedFile);
						
					int ret = decrypt_file(decryptedFile, encryptedFile, encryptInfo.key[0] != 0 ? encryptInfo.key : NULL, GetSDKMainVersion(encryptInfo.sdkVersion));
					
					if(ret < 0) {
						printf("Error: decrypt_file() returned %d\n\n", ret);
					} else {
						printf("Successfully wrote %d bytes to\n", ret);
						printf("  %s\n", decryptedFile);
					}
				}
				printf("   > Back\n");
				
				int input = ProcessInput(1, &selectedOption);
				if(input >= 0)
				{
					if(currentMenu == 3)
						currentMenu = 2;
					else
						currentMenu = 5;
					selectedOption = 0;
				}
			}
		}
		break;
		default:
			sceKernelExitGame();
			break;
		}
	   
		pspDebugScreenClear();
		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();
	}
	return 0;
} 
/**
  * Created 24/02/2011
  * Prepares and clears the PSP display for rendering
  */
bool FrontEnd::StartRendering(void)
{
	//printf("FrontEnd::StartRendering\n");
	
	/* Increment the frame */
	++_frame;

	/* Check controls */
	if( _playerInput->IsLShoulderDown() )
	{
		++_viewMode;
		if( _viewMode >= 3 )
		{
			_viewMode = 0;
		}
	}
	else if( _playerInput->IsRShoulderDown() )
	{
		--_viewMode;
		if( _viewMode < 0 )
		{
			_viewMode = 2;
		}
	}
	if( _playerInput->IsDPadLeft() )
	{
		if( _rotationSpeed > 1 )
		{
			--_rotationSpeed;
		}
	}
	else if( _playerInput->IsDPadRight() )
	{
		if( _rotationSpeed < 180 )
		{
			++_rotationSpeed;
		}
	}

	/* Increment the rotation */
	switch( _viewMode )
	{
	case -1:
			break;
		case 0:
			_rotation.x += DEGSTORADS( _rotationSpeed );
			if( _rotation.x > DEGSTORADS( 360.0f ) )
			{
				_rotation.x = 0.0f;
			}
			break;
		case 1:
			_rotation.y += DEGSTORADS( _rotationSpeed );
			if( _rotation.y > DEGSTORADS( 360.0f ) )
			{
				_rotation.y = 0.0f;
			}
			break;
		case 2:
			_rotation.z += DEGSTORADS( _rotationSpeed );
			if( _rotation.z > DEGSTORADS( 360.0f ) )
			{
				_rotation.z = 0.0f;
			}
			break;
	}
	
#ifdef PC
	/* Start the device */
	_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, IntToD3DColor( _bgColour ), 1.0f, 0 );
	_pd3dDevice->BeginScene();

	/* Set up the view matrix */
	D3DXMATRIXA16 view;
	D3DXMatrixTranslation( &view, _view.x, _view.y, 25.0f );
	_pd3dDevice->SetTransform( D3DTS_VIEW, &view );

	/* Set up the projection matrix */
	D3DXMATRIXA16 projection;
	D3DXMatrixPerspectiveFovLH( &projection, DEGSTORADS(45.0f), 1.7647f, 1.0f, 100.0f ); 
	_pd3dDevice->SetTransform( D3DTS_PROJECTION, &projection );

#else
	/* Set up the starting matrices */
	//sceGumPushMatrix();
	ScePspFVector3 view;
	view.x = _view.x;
	view.y = _view.y;
	view.z = _view.z;
	sceGumLoadIdentity();
	sceGumTranslate( &view );
	//BlockUntilFrameReady();	/*< Blocks the program until the frame is ready */
	
	/* Preps the display for rendering */
	sceGuSwapBuffers();
	sceGuStart(SCEGU_IMMEDIATE, (void*)_displist, sizeof(_displist));
	sceGuClearColor(_bgColour);
	sceGuClear(SCEGU_CLEAR_ALL);
#endif

	return true;
}
Example #19
0
int main(int argc, char **argv)
{
    SceCtrlData pad;
    int oldButtons = 0;
    int useVblank = 1;

    pspDebugScreenInit();
    if (argc > 0) {
        printf("Bootpath: %s\n", argv[0]);
    }

    printf("Triangle - Exit\n");
    printf("Square - Toggle vblank (60 fps limit)\n");
    printf("\n");

    SetupCallbacks();

    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

    sceRtcGetCurrentTick( &fpsTickLast );
    tickResolution = sceRtcGetTickResolution();

    printGetDayOfWeek();
    printf("\n");

    printGetDaysInMonth();
    printf("\n");

    printSetTick();
    printf("\n");

    printGetTick();
    printf("\n");

    printf("sceRtcGetTickResolution: %d", (int)tickResolution);

    while(!done)
    {
        sceCtrlPeekBufferPositive(&pad, 1);
        int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons;

        if (buttonDown & PSP_CTRL_SQUARE)
        {
            useVblank ^= 1;
        }

        if (buttonDown & PSP_CTRL_TRIANGLE)
            done = 1;

        oldButtons = pad.Buttons;

        updateDrawFPS();

        if (useVblank)
            sceDisplayWaitVblankStart();
        fbp0 = sceGuSwapBuffers();
    }

    sceKernelExitGame();    // Quits Application
    return 0;
}
Example #20
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;
}
Example #21
0
void flipScreen()
{
	if (!initialized) return;
	sceGuSwapBuffers();
	dispBufferNumber ^= 1;
}
Example #22
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;
}
Example #23
0
File: ui.c Project: kradhub/pspdc
void
ui_msg_dialog (UI * ui, const char * msg)
{
	pspUtilityMsgDialogParams params;
	unsigned int swap_count = 0;
	SceCtrlLatch latch;

	memset (&params, 0, sizeof (params));

	params.base.size = sizeof (params);
	params.base.language = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH;
	params.base.buttonSwap = PSP_UTILITY_ACCEPT_CROSS;

	/* Thread priorities */
	params.base.graphicsThread = 17;
	params.base.accessThread = 19;
	params.base.fontThread = 18;
	params.base.soundThread = 16;

	params.mode = PSP_UTILITY_MSGDIALOG_MODE_TEXT;
	params.options = PSP_UTILITY_MSGDIALOG_OPTION_TEXT;
	snprintf (params.message, 512, msg);

	sceUtilityMsgDialogInitStart (&params);

	while (running) {
		int done = 0;

		/* directly use GU to avoid flickering with SDL */
		sceGuStart (GU_DIRECT, list);
		sceGuClearColor (0xff554433);
		sceGuClearDepth (0);
		sceGuClear (GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
		sceGuFinish ();
		sceGuSync (0,0);

		switch (sceUtilityMsgDialogGetStatus ()) {
			case PSP_UTILITY_DIALOG_NONE:
				break;
			case PSP_UTILITY_DIALOG_VISIBLE:
				sceUtilityMsgDialogUpdate (1);
				break;
			case PSP_UTILITY_DIALOG_QUIT:
				sceUtilityMsgDialogShutdownStart ();
				break;
			case PSP_UTILITY_DIALOG_FINISHED:
				done = 1;
				break;
			default:
				break;
		}

		sceDisplayWaitVblankStart ();
		sceGuSwapBuffers ();
		swap_count++;

		if (done)
			break;
	}

	/* hack for SDL compatibility.
	 * if it end up on an odd buffer, SDL won't be displayed.
	 * ie SDL will display in an hidden buffer
	 */
	if (swap_count & 1)
		sceGuSwapBuffers ();

	/* message dialog seems to causes strange latch behavior, next read
	 * of latch will contains all button pressed during dialog.
	 * read one to reset it */
	sceCtrlReadLatch (&latch);
}
Example #24
0
static bool psp_frame(void *data, const void *frame,
                      unsigned width, unsigned height, unsigned pitch, const char *msg)
{
    static char fps_txt[128], fps_text_buf[128];
    psp1_video_t *psp = (psp1_video_t*)data;

#ifdef DISPLAY_FPS
    static uint64_t currentTick,lastTick;
    static float fps=0.0;
    static int frames;
#endif

    if (!width || !height)
        return false;

    sceGuSync(0, 0);

    pspDebugScreenSetBase(psp->draw_buffer);

    pspDebugScreenSetXY(0,0);

    if(g_settings.fps_show)
    {
        gfx_get_fps(fps_txt, sizeof(fps_txt), fps_text_buf, sizeof(fps_text_buf));
        pspDebugScreenSetXY(68 - strlen(fps_text_buf) - 1,0);
        pspDebugScreenPuts(fps_text_buf);
        pspDebugScreenSetXY(0,1);
    }
    else
        gfx_get_fps(fps_txt, sizeof(fps_txt), NULL, 0);

    if (msg)
        pspDebugScreenPuts(msg);

    if (psp->vsync)
        sceDisplayWaitVblankStart();



#ifdef DISPLAY_FPS
    frames++;
    sceRtcGetCurrentTick(&currentTick);
    uint32_t diff = currentTick - lastTick;
    if(diff > 1000000)
    {
        fps = (float)frames * 1000000.0 / diff;
        lastTick = currentTick;
        frames = 0;
    }

    pspDebugScreenSetXY(0,0);
    pspDebugScreenPrintf("%f", fps);
#endif

    psp->draw_buffer = FROM_GU_POINTER(sceGuSwapBuffers());
    g_extern.frame_count++;

    psp->frame_coords->v0.x = (SCEGU_SCR_WIDTH - width * SCEGU_SCR_HEIGHT / height) / 2;
//   psp->frame_coords->v0.y = 0;
//   psp->frame_coords->v0.u = 0;
//   psp->frame_coords->v0.v = 0;

    psp->frame_coords->v1.x = (SCEGU_SCR_WIDTH + width * SCEGU_SCR_HEIGHT / height) / 2;
//   psp->frame_coords->v1.y = SCEGU_SCR_HEIGHT;
    psp->frame_coords->v1.u = width;
    psp->frame_coords->v1.v = height;

    sceGuStart(GU_DIRECT, psp->main_dList);

    if ((uint32_t)frame&0x04000000) // frame in VRAM ? texture/palette was set in core so draw directly
    {
        sceGuClear(GU_COLOR_BUFFER_BIT);
        sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_4444 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, (void*)(psp->frame_coords));
    }
    else
    {
        if (frame!=NULL)
        {
            sceKernelDcacheWritebackRange(frame,pitch * height);
            sceGuCopyImage(GU_PSM_5650, ((u32)frame & 0xF) >> psp->bpp_log2, 0, width, height, pitch >> psp->bpp_log2, (void*)((u32)frame & ~0xF), 0, 0, width, psp->texture);
        }

        sceGuClear(GU_COLOR_BUFFER_BIT);
        sceGuTexImage(0, next_pow2(width), next_pow2(height), width, psp->texture);
        sceGuCallList(psp->frame_dList);
    }
Example #25
0
int main(int argc, char** argv) {

	SceCtrlData pad;
	
	getcwd(currentPath, MAX_PATH - 1);
	strcat(currentPath, "/");
	
	strcpy(szAppRomPath, currentPath);
	strcat(szAppRomPath, "ROMS/");
	
	int thid = sceKernelCreateThread(PBPNAME, CallbackThread, 0x11, 0xFA0, 0, 0);
	if(thid >= 0) sceKernelStartThread(thid, 0, 0);
	
	nGameStage = 1;
	init_gui();
	
	
	BurnLibInit();
	
	for (nBurnDrvSelect=0; nBurnDrvSelect<nBurnDrvCount; nBurnDrvSelect++) 
		if ( strcmp("aerofgt", BurnDrvGetText(DRV_NAME)) == 0 )
			break;
	if (nBurnDrvSelect >= nBurnDrvCount) nBurnDrvSelect = ~0U;
	
	bBurnUseASMCPUEmulation = false;
	
	nInterpolation = 3;
	pBurnSoundOut = 0;	//&mixbuf[0];
	nBurnSoundRate = SND_RATE;
	nBurnSoundLen = 0;	//SND_FRAME_SIZE;
	
	//BurnDrvGetFullSize(&VideoBufferWidth, &VideoBufferHeight);
	//printf("%d x %d \n", VideoBufferWidth, VideoBufferHeight);
	nBurnBpp = 2;
	nBurnPitch  = 512 * 2;
	BurnHighCol = HighCol16;
	
	int ret = 0;
	
	//DrvInit(nBurnDrvSelect, false);
	//if (nRet != 0) return 0;

	//BurnRecalcPal();
	//InpInit();
	//InpDIP();
	
	pBurnDraw = (unsigned char *) video_frame_addr(tex_frame, 0, 0);
	
	//szAppRomPath
	//strcat(ui_current_path, "roms");
	
	draw_ui_main();
	bGameRunning = 1;
	
	while( bGameRunning ) {
		sceCtrlReadBufferPositive(&pad, 1); 
		
		if ( nGameStage ) {

			do_ui_key( pad.Buttons );
			
			update_gui();
			sceDisplayWaitVblankStart();
			
		} else {
			
			if ( pad.Buttons & PSP_CTRL_LTRIGGER ) {
				
				scePowerSetClockFrequency(222, 222, 111);
				nGameStage = 1;
				draw_ui_main();
				
				continue;
			}
			
			InpMake(pad.Buttons);
			
			nFramesEmulated++;
			nCurrentFrame++;
			nFramesRendered++;
		
			pBurnDraw = (unsigned char *) video_frame_addr(tex_frame, 0, 0);
			BurnDrvFrame();
			pBurnDraw = NULL;
	
			update_gui();
			
		//sceDisplayWaitVblankStart();

		}

		
		show_frame = draw_frame;
		draw_frame = sceGuSwapBuffers();
	}

	scePowerSetClockFrequency(222, 222, 111);

	exit_gui();
	
	DrvExit();
	BurnLibExit();
	InpExit();
	
	sceKernelExitGame();
}
Example #26
0
int main(int argc, char* argv[])
{
	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(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_CLIP_PLANES);
	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);

	setupSH();
	indicesSH();

	// run sample

	int val = 0;

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

		// clear screen

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

		// light settings

		sceGuEnable(GU_LIGHTING);
		sceGuEnable(GU_LIGHT0);
		sceGuEnable(GU_LIGHT1);
		sceGuEnable(GU_LIGHT2);
		sceGuLightMode(1);
		{
			unsigned int i;

			for (i = 0; i < 3; ++i)
			{
				sceGuLight(i,GU_DIRECTIONAL,GU_DIFFUSE_AND_SPECULAR,&lsettings[i].position);
				sceGuLightColor(i,GU_DIFFUSE,lsettings[i].diffuse);
				sceGuLightColor(i,GU_SPECULAR,lsettings[i].specular);
				sceGuLightAtt(i,0.0f,1.0f,0.0f);
			}
			sceGuSpecular(12.0f);
			sceGuAmbient(0x000000);
		}

		// setup matrices

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

		sceGumMatrixMode(GU_VIEW);
		{
			ScePspFVector3 pos = { 0, 0, -5.0f };

			sceGumLoadIdentity();
			sceGumTranslate(&pos);
		}

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

		// setup texture

		sceGuAmbientColor(0xffffffff);

		// draw

		renderSH(parametersSH);

		sceGuFinish();
		sceGuSync(0,0);

		sceDisplayWaitVblankStart();
		sceGuSwapBuffers();

		val++;

		if ((val%600) == 0)
		{
			unsigned int i;
			for (i = 0; i < 8; ++i)
				parametersSH[i] = (int)((rand() / ((float)RAND_MAX)) * 6.0f);
		}
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Example #27
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;
}
Example #28
0
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;
}
Example #29
0
static bool psp_frame(void *data, const void *frame,
      unsigned width, unsigned height, unsigned pitch, const char *msg)
{
   static char fps_txt[128], fps_text_buf[128];
   psp1_video_t *psp = (psp1_video_t*)data;

#ifdef DISPLAY_FPS
   static uint64_t currentTick,lastTick;
   static float fps=0.0;
   static int frames;
#endif

   if (!width || !height)
      return false;

   if (((uint32_t)frame&0x04000000) || (frame == RETRO_HW_FRAME_BUFFER_VALID))
      psp->hw_render = true;
   else if (frame)
      psp->hw_render = false;

   if (!psp->hw_render)
      sceGuSync(0, 0); /* let the core decide when to sync when HW_RENDER */

   pspDebugScreenSetBase(psp->draw_buffer);

   pspDebugScreenSetXY(0,0);

   video_monitor_get_fps(fps_txt, sizeof(fps_txt),
         g_settings.fps_show ? fps_text_buf : NULL,
         g_settings.fps_show ? sizeof(fps_text_buf) : 0);

   if(g_settings.fps_show)
   {
      pspDebugScreenSetXY(68 - strlen(fps_text_buf) - 1,0);
      pspDebugScreenPuts(fps_text_buf);
      pspDebugScreenSetXY(0,1);
   }

   if (msg)
      pspDebugScreenPuts(msg);

   if ((psp->vsync)&&(psp->vblank_not_reached))
      sceDisplayWaitVblankStart();

   psp->vblank_not_reached = true;

#ifdef DISPLAY_FPS
   frames++;
   sceRtcGetCurrentTick(&currentTick);
   uint32_t diff = currentTick - lastTick;
   if(diff > 1000000)
   {
      fps = (float)frames * 1000000.0 / diff;
      lastTick = currentTick;
      frames = 0;
   }

   pspDebugScreenSetXY(0,0);
   pspDebugScreenPrintf("%f", fps);
#endif

   psp->draw_buffer = FROM_GU_POINTER(sceGuSwapBuffers());
   g_extern.frame_count++;


   RARCH_PERFORMANCE_INIT(psp_frame_run);
   RARCH_PERFORMANCE_START(psp_frame_run);

   if (psp->should_resize)
      psp_update_viewport(psp);

   psp_set_tex_coords(psp->frame_coords, width, height);

   sceGuStart(GU_DIRECT, psp->main_dList);

   sceGuTexFilter(psp->tex_filter, psp->tex_filter);
   sceGuClear(GU_COLOR_BUFFER_BIT);

   /* frame in VRAM ? texture/palette was 
    * set in core so draw directly */
   if (psp->hw_render) 
      sceGuDrawArray(GU_SPRITES, GU_TEXTURE_32BITF | GU_VERTEX_32BITF | 
            GU_TRANSFORM_2D, PSP_FRAME_VERTEX_COUNT, NULL,
            (void*)(psp->frame_coords));
   else
   {
      if (frame)
      {
         sceKernelDcacheWritebackRange(frame,pitch * height);
         sceGuCopyImage(GU_PSM_5650, ((u32)frame & 0xF) >> psp->bpp_log2,
               0, width, height, pitch >> psp->bpp_log2,
               (void*)((u32)frame & ~0xF), 0, 0, width, psp->texture);
      }
      sceGuTexImage(0, next_pow2(width), next_pow2(height), width, psp->texture);
      sceGuCallList(psp->frame_dList);
   }

   sceGuFinish();

   RARCH_PERFORMANCE_STOP(psp_frame_run);

   if(psp->menu.active)
   {
      sceGuSendList(GU_TAIL, psp->menu.dList, &(psp->menu.context_storage));
      sceGuSync(0, 0);
   }

   return true;
}
Example #30
0
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;
}