Ejemplo n.º 1
0
int main(int argc, char *argv[]) {
	checkpointNext("Establishing base values:");
	SceSize baseMaxFree = sceKernelMaxFreeMemSize();
	if (baseMaxFree < 0) {
		checkpoint("sceKernelMaxFreeMemSize: %08x", baseMaxFree);
	} else {
		checkpoint("sceKernelMaxFreeMemSize: OK");
	}

	SceSize baseTotal = sceKernelTotalFreeMemSize();
	if (baseTotal < 0) {
		checkpoint("sceKernelTotalFreeMemSize: %08x", baseTotal);
	} else {
		checkpoint("sceKernelTotalFreeMemSize: OK");
	}

	checkpointNext("After allocating:");
	SceUID blocks[8];
	int i;
	for (i = 0; i < 8; ++i) {
		blocks[i] = sceKernelAllocPartitionMemory(PSP_MEMORY_PARTITION_USER, "test", PSP_SMEM_Low, 0x8000, NULL);
	}

	checkpoint("sceKernelMaxFreeMemSize: at base - %d", baseMaxFree - sceKernelMaxFreeMemSize());
	checkpoint("sceKernelTotalFreeMemSize: at base - %d", baseTotal - sceKernelTotalFreeMemSize());
	
	checkpointNext("After fragmenting:");
	sceKernelFreePartitionMemory(blocks[5]);
	blocks[5] = -1;

	checkpoint("sceKernelMaxFreeMemSize: at base - %d", baseMaxFree - sceKernelMaxFreeMemSize());
	checkpoint("sceKernelTotalFreeMemSize: at base - %d", baseTotal - sceKernelTotalFreeMemSize());

	checkpointNext("After free again:");
	for (i = 0; i < 8; ++i) {
		if (blocks[i] >= 0) {
			sceKernelFreePartitionMemory(blocks[i]);
		}
	}

	checkpoint("sceKernelMaxFreeMemSize: at base - %d", baseMaxFree - sceKernelMaxFreeMemSize());
	checkpoint("sceKernelTotalFreeMemSize: at base - %d", baseTotal - sceKernelTotalFreeMemSize());

	checkpointNext("Allocate near limits:");
	tryAllocate("Allocate sceKernelMaxFreeMemSize", sceKernelMaxFreeMemSize());
	tryAllocate("Allocate sceKernelMaxFreeMemSize + 0x100", sceKernelMaxFreeMemSize() + 0x100);
	tryAllocate("Allocate sceKernelTotalFreeMemSize", sceKernelTotalFreeMemSize());

	return 0;
}
Ejemplo n.º 2
0
int main_thread(SceSize args, void *argp)
{
	#ifdef DEBUG
	pspDebugScreenInit();
	printf("Free Memory: %u KB\n",sceKernelTotalFreeMemSize()/1024);
	#else
	initGraphics();
	loadTheme();
	background = loadImageFromMemory(images[BACKGROUND].data, images[BACKGROUND].hdr.size);
	sceKernelFreePartitionMemory(images[BACKGROUND].blockid);
	images[BACKGROUND].blockid = -1;
	mask = loadImageFromMemory(images[MASK].data, images[MASK].hdr.size);
	sceKernelFreePartitionMemory(images[MASK].blockid);
	images[MASK].blockid = -1;
	#endif

	int firstUse = 0;
	int recovery = 0;
	int bytesRead = 0;
	Config cfg;
	char input[11];

	if ((args == 9) && (strcmp(argp, "recovery") == 0))
	{
		recovery = 1;
	}

	SceUID fp;
	fp = sceIoOpen("flash0:/buttons.ini", PSP_O_RDONLY, 0777);

	if (fp < 0)
	{
		#ifdef DEBUG
		printf("\nflash0:/buttons.ini could not be opned. Assuming first usage.");
		#endif
		firstUse = 1;
	}
	else
	{
		bytesRead = sceIoRead(fp, &cfg, sizeof(cfg));
		sceIoClose(fp);

		if(bytesRead != sizeof(cfg))
		{
			firstUse = 1;
		}
	}

	if (firstUse)
	{
		setPassword();
	}
	else if (((args == 0) || (recovery != 0)) || !(cfg.onlyBoot))
	{
		int len;
main_password:
		#ifndef DEBUG
		footer_pressselect = loadImageFromMemory(images[FOOTER_PRESSSELECT].data, images[FOOTER_PRESSSELECT].hdr.size);
		title_password = loadImageFromMemory(images[TITLE_PASSWORD].data, images[TITLE_PASSWORD].hdr.size);
		#endif
		while(1)
		{
			selectEnabled = 1;

			#ifdef DEBUG
			printf("\nPress START to accept.\nPress SELECT to change password.\nEnter password: "******"\nPassword OK.");
				#else
				int temp;
				blitImageToScreen(0, 0, images[BACKGROUND].hdr.w, images[BACKGROUND].hdr.h, background, images[BACKGROUND].hdr.x, images[BACKGROUND].hdr.y);
				blitAlphaImageToScreen(0, 0, images[FOOTER_PRESSSELECT].hdr.w, images[FOOTER_PRESSSELECT].hdr.h, footer_pressselect, images[FOOTER_PRESSSELECT].hdr.x, images[FOOTER_PRESSSELECT].hdr.y);
				blitAlphaImageToScreen(0, 0, images[TITLE_PASSWORD].hdr.w, images[TITLE_PASSWORD].hdr.h, title_password, images[TITLE_PASSWORD].hdr.x, images[TITLE_PASSWORD].hdr.y);
				msg_passwordok = loadImageFromMemory(images[MSG_PASSWORDOK].data, images[MSG_PASSWORDOK].hdr.size);
				blitAlphaImageToScreen(0, 0, images[MSG_PASSWORDOK].hdr.w, images[MSG_PASSWORDOK].hdr.h, msg_passwordok, images[MSG_PASSWORDOK].hdr.x, images[MSG_PASSWORDOK].hdr.y);
				freeImage(msg_passwordok);
				for(temp = 0; temp < len; temp++)
				{
					blitAlphaImageToScreen(0, 0, images[MASK].hdr.w, images[MASK].hdr.h, mask, images[MASK].hdr.x+(temp*images[MASK].hdr.w), images[MASK].hdr.y);
				}
				sceDisplayWaitVblankStart();
				flipScreen();
				#endif
				sceKernelDelayThread(1000*1000);
				break;
			}
			else
			{
				#ifdef DEBUG
				printf("\nIncorrect password.");
				#else
				int temp;
				blitImageToScreen(0, 0, images[BACKGROUND].hdr.w, images[BACKGROUND].hdr.h, background, images[BACKGROUND].hdr.x, images[BACKGROUND].hdr.y);
				blitAlphaImageToScreen(0, 0, images[FOOTER_PRESSSELECT].hdr.w, images[FOOTER_PRESSSELECT].hdr.h, footer_pressselect, images[FOOTER_PRESSSELECT].hdr.x, images[FOOTER_PRESSSELECT].hdr.y);
				blitAlphaImageToScreen(0, 0, images[TITLE_PASSWORD].hdr.w, images[TITLE_PASSWORD].hdr.h, title_password, images[TITLE_PASSWORD].hdr.x, images[TITLE_PASSWORD].hdr.y);
				msg_passwordincorrect = loadImageFromMemory(images[MSG_PASSWORDINCORRECT].data, images[MSG_PASSWORDINCORRECT].hdr.size);
				blitAlphaImageToScreen(0, 0, images[MSG_PASSWORDINCORRECT].hdr.w, images[MSG_PASSWORDINCORRECT].hdr.h, msg_passwordincorrect, images[MSG_PASSWORDINCORRECT].hdr.x, images[MSG_PASSWORDINCORRECT].hdr.y);
				freeImage(msg_passwordincorrect);
				for(temp = 0; temp < len; temp++)
				{
					blitAlphaImageToScreen(0, 0, images[MASK].hdr.w, images[MASK].hdr.h, mask, images[MASK].hdr.x+(temp*images[MASK].hdr.w), images[MASK].hdr.y);
				}
				sceDisplayWaitVblankStart();
				flipScreen();
				#endif
				sceKernelDelayThread(3000*1000);
			}
		}
		#ifndef DEBUG
		freeImage(footer_pressselect);
		freeImage(title_password);
		#endif

		if(len == -1)
		{
			#ifndef DEBUG
			footer_changemode = loadImageFromMemory(images[FOOTER_CHANGEMODE].data, images[FOOTER_CHANGEMODE].hdr.size);
			title_oldpassword = loadImageFromMemory(images[TITLE_OLDPASSWORD].data, images[TITLE_OLDPASSWORD].hdr.size);
			#endif
			while(1)
			{
				#ifdef DEBUG
				printf("\nChange password mode.\nEnter old password: "******"\nPassword OK.");
					#else
					int temp;
					blitImageToScreen(0, 0, images[BACKGROUND].hdr.w, images[BACKGROUND].hdr.h, background, images[BACKGROUND].hdr.x, images[BACKGROUND].hdr.y);
					blitAlphaImageToScreen(0, 0, images[FOOTER_CHANGEMODE].hdr.w, images[FOOTER_CHANGEMODE].hdr.h, footer_changemode, images[FOOTER_CHANGEMODE].hdr.x, images[FOOTER_CHANGEMODE].hdr.y);
					blitAlphaImageToScreen(0, 0, images[TITLE_OLDPASSWORD].hdr.w, images[TITLE_OLDPASSWORD].hdr.h, title_oldpassword, images[TITLE_OLDPASSWORD].hdr.x, images[TITLE_OLDPASSWORD].hdr.y);
					msg_passwordok = loadImageFromMemory(images[MSG_PASSWORDOK].data, images[MSG_PASSWORDOK].hdr.size);
					blitAlphaImageToScreen(0, 0, images[MSG_PASSWORDOK].hdr.w, images[MSG_PASSWORDOK].hdr.h, msg_passwordok, images[MSG_PASSWORDOK].hdr.x, images[MSG_PASSWORDOK].hdr.y);
					freeImage(msg_passwordok);
					for(temp = 0; temp < len; temp++)
					{
						blitAlphaImageToScreen(0, 0, images[MASK].hdr.w, images[MASK].hdr.h, mask, images[MASK].hdr.x+(temp*images[MASK].hdr.w), images[MASK].hdr.y);
					}
					sceDisplayWaitVblankStart();
					flipScreen();
					#endif
					sceKernelDelayThread(3000*1000);
					break;
				}
				else
				{
					#ifdef DEBUG
					printf("\nIncorrect password.");
					#else
					int temp;
					blitImageToScreen(0, 0, images[BACKGROUND].hdr.w, images[BACKGROUND].hdr.h, background, images[BACKGROUND].hdr.x, images[BACKGROUND].hdr.y);
					blitAlphaImageToScreen(0, 0, images[FOOTER_CHANGEMODE].hdr.w, images[FOOTER_CHANGEMODE].hdr.h, footer_changemode, images[FOOTER_CHANGEMODE].hdr.x, images[FOOTER_CHANGEMODE].hdr.y);
					blitAlphaImageToScreen(0, 0, images[TITLE_OLDPASSWORD].hdr.w, images[TITLE_OLDPASSWORD].hdr.h, title_oldpassword, images[TITLE_OLDPASSWORD].hdr.x, images[TITLE_OLDPASSWORD].hdr.y);
					msg_passwordincorrect = loadImageFromMemory(images[MSG_PASSWORDINCORRECT].data, images[MSG_PASSWORDINCORRECT].hdr.size);
					blitAlphaImageToScreen(0, 0, images[MSG_PASSWORDINCORRECT].hdr.w, images[MSG_PASSWORDINCORRECT].hdr.h, msg_passwordincorrect, images[MSG_PASSWORDINCORRECT].hdr.x, images[MSG_PASSWORDINCORRECT].hdr.y);
					freeImage(msg_passwordincorrect);
					for(temp = 0; temp < len; temp++)
					{
						blitAlphaImageToScreen(0, 0, images[MASK].hdr.w, images[MASK].hdr.h, mask, images[MASK].hdr.x+(temp*images[MASK].hdr.w), images[MASK].hdr.y);
					}
					sceDisplayWaitVblankStart();
					flipScreen();
					#endif
					sceKernelDelayThread(3000*1000);
				}
			}
			#ifndef DEBUG
			freeImage(footer_changemode);
			freeImage(title_oldpassword);
			#endif
			if(len == -1)
			{
				goto main_password;
			}
			selectEnabled = 0;
			setPassword();
		}
	}

	#ifndef DEBUG
	freeImage(background);
	freeImage(mask);
	sceGuTerm();
	int i;
	for (i = 0; i < NUMFILES; i++)
	{
		if (images[i].blockid != -1)
		{
			sceKernelFreePartitionMemory(images[i].blockid);
		}
	}
	#endif

	__psp_free_heap();
	#ifdef DEBUG
	printf("\n__psp_free_heap(): %u KB\n",sceKernelTotalFreeMemSize()/1024);
	sceKernelDelayThread(3000*1000);
	#endif

	#ifdef DEBUG
	printf("\nLoading loader.prx");
	#endif

	SceUID mod = sceKernelLoadModule("flash0:/loader.prx", 0, NULL);

	if (mod & 0x80000000)
	{
		#ifdef DEBUG
		printf("\nLoadModule failed 0x%x", mod);
		#endif
	}
	else
	{
		SceUID startmod;
		startmod = sceKernelStartModule(mod, args, argp, NULL, NULL);

		if (mod != startmod)
		{
			#ifdef DEBUG
			printf("\nStartModule failed 0x%x", startmod);
			#endif
		}
	}

	return sceKernelExitDeleteThread(0);
}
Ejemplo n.º 3
0
/*
====================
Host_Init
====================
*/
void Host_Init (quakeparms_t *parms)
{
	#if defined(_WIN32) && defined(GLQUAKE)
	FILE *fp = fopen("opengl32.dll","r");
	if (fp) {
		// exists
		fclose(fp);
		Sys_Error ("OpenGL32.dll found in Quake folder.  You must delete this file from your Quake folder to run this engine.");
	}
	#endif // Windows only

	if (standard_quake)
		minimum_memory = MINIMUM_MEMORY;
	else
		minimum_memory = MINIMUM_MEMORY_LEVELPAK;

	if (COM_CheckParm ("-minmemory"))
		parms->memsize = minimum_memory;

	host_parms = *parms;

	if (parms->memsize < minimum_memory)
		Sys_Error ("Only %4.1f megs of memory available, can't execute game and memsize = %i and minimum memory is %i", parms->memsize / (float)0x100000, parms->memsize, minimum_memory);

	com_argc = parms->argc;
	com_argv = parms->argv;
#ifdef SUPPORTS_CHEATFREE
	// JPG 3.00 - moved this here
#if defined(_WIN32)
	srand(time(NULL) ^ _getpid());
#else
	srand(time(NULL) ^ getpid());
#endif
#endif

	Memory_Init (parms->membase, parms->memsize);
	Cbuf_Init ();
	Cmd_Init ();
	Cvar_Init ();
	V_Init ();
	Chase_Init ();
	Host_InitVCR (parms);
	COM_Init (parms->basedir);
	Host_InitLocal ();

	W_LoadWadFile ("gfx.wad");
	Key_Init ();

	Con_Init ();
	M_Init ();
	PR_Init ();
	Mod_Init ();
#ifdef PROQUAKE_EXTENSION
	Security_Init ();	// JPG 3.20 - cheat free
#endif
	NET_Init ();
	SV_Init ();
#ifdef PROQUAKE_EXTENSION
	IPLog_Init ();	// JPG 1.05 - ip address logging

	Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
#endif
#ifdef PSP_SYSTEM_STATS
	Con_Printf ("Insomnia ProQuake Engine v 4.71 Rev4\n"); //(EBOOT: "__TIME__" "__DATE__")\n");

	int currentCPU = scePowerGetCpuClockFrequency();
	int currentVRAM = sceGeEdramGetSize();
    int currentVRAMADD = sceGeEdramGetAddr();
	int currentRAMAVAIL = sceKernelTotalFreeMemSize();

#ifdef NORMAL_MODEL
	Con_Printf ("PSP Normal 32MB RAM Mode \n");
#endif
#ifdef SLIM_MODEL
	Con_Printf ("PSP Slim 64MB RAM Mode \n");
#endif

	Con_Printf ("%4.1f megabyte heap \n",parms->memsize/ (1024*1024.0));
	Con_Printf ("%4.1f PSP application heap \n",1.0f*PSP_HEAP_SIZE_MB);
	Con_Printf ("%d VRAM \n",currentVRAM);
    Con_Printf ("%d VRAM Address \n",currentVRAMADD);
    Con_Printf ("%d Current Total RAM \n",currentRAMAVAIL);

	Con_Printf ("CPU Speed %d MHz\n", currentCPU);
	Con_Printf ("%s \n", com_gamedir);

	
	
	R_InitTextures ();		// needed even for dedicated servers
#else
	Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0));
#endif

	if (cls.state != ca_dedicated)
	{
		host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp");
		if (!host_basepal)
			Sys_Error ("Couldn't load gfx/palette.lmp");
		host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp");
		if (!host_colormap)
			Sys_Error ("Couldn't load gfx/colormap.lmp");

#ifndef _WIN32 // on non win32, mouse comes before video for security reasons
		IN_Init ();
#endif
		VID_Init (host_basepal);

        Draw_Init ();
		SCR_Init ();
		R_Init ();
#ifndef	_WIN32
	// on Win32, sound initialization has to come before video initialization, so we
	// can put up a popup if the sound hardware is in use
		S_Init ();
#else

#ifdef	GLQUAKE
	// FIXME: doesn't use the new one-window approach yet
		S_Init ();
#endif

#endif	// _WIN32
		CDAudio_Init ();
		Sbar_Init ();
		CL_Init ();
#ifdef _WIN32 // on non win32, mouse comes before video for security reasons
		IN_Init ();
#endif

#ifdef _WIN32
		// Baker: 3.99m to get sys info
		// must be AFTER video init stuff
		Sys_InfoInit();  // We don't care about dedicated servers for this

		// Baker 3.76 - Autoplay demo

		if (com_argc >= 2)
		{
			char *infile = com_argv[1];

			if (infile[0] && infile[0] != '-' && infile[0] != '+') {
				char tmp[1024] = {0}, *ext = COM_FileExtension(infile);

				if (!strncasecmp(ext, "dem", sizeof("dem")))
					snprintf(tmp, sizeof(tmp), "playdemo \"%s\"\n", infile);

				if (tmp[0])
				{
					nostartdemos = true;
					Cbuf_AddText(tmp);
				}
			}
		}
#endif


	}

	Cbuf_InsertText ("exec quake.rc\n");

#ifdef PROQUAKE_EXTENSION
	// Baker 3.80x: this is a hack

	if (!isDedicated) {

		Cbuf_AddText ("\nsavefov\n");
		Cbuf_AddText ("savesensitivity\n");
	}
#endif
	Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
	host_hunklevel = Hunk_LowMark ();

	host_initialized = true;

	Con_Printf ("Host Initialized\n");
	Sys_Printf ("========Quake Initialized=========\n");
}