Exemplo n.º 1
0
int main(int argc, char *argv[])
{
	#ifdef PSPSDK
		pspDebugScreenInit();
		SetupCallbacks();
	#else
		// Shut down the server if we get a kill signal.
		signal( SIGINT, (sighandler_t) shutdownServer );
		signal( SIGTERM, (sighandler_t) shutdownServer );
	#endif

	/* Setup Data-Directory */
	dataDir = CBuffer(argv[0]).replaceAll("\\", "/");
	dataDir = dataDir.copy(0, dataDir.findl('/') + 1);
	programDir = dataDir;
	dataDir << "world/";

	/* Main Initiating */
	adminNames.load( __admin, sizeof(__admin) / sizeof(const char*) );
	colourNames.load( __colours, sizeof(__colours) / sizeof(const char*) );
	clothCommands.load( __cloths, sizeof(__cloths) / sizeof(const char*) );
	defaultGaniNames.load( __defaultgani, sizeof(__defaultgani) / sizeof(const char*) );
	defaultSwordNames.load( __defaultsword, sizeof(__defaultsword) / sizeof(const char*) );
	defaultShieldNames.load( __defaultshield, sizeof(__defaultshield) / sizeof(const char*) );
	playerIds.add(0);
	playerIds.add(0);
	npcIds.add(0);
	srand((int)time(NULL));

	/* Load Important Files */
	updateFile("rchelp.txt");
	updateFile("rcmessage.txt");
	updateFile("rules.txt");
	updateFile("serverflags.txt");
	updateFile("servermessage.html");
	updateFile("foldersconfig.txt");

	/* Load Settings */
	if (!loadSettings("serveroptions.txt"))
	{
		errorOut("errorlog.txt", "Unable to load server settings..");
		return 1;
	}

	/* Load Weapons */
	if (!loadWeapons("weapons.txt"))
	{
		errorOut("errorlog.txt", "Unable to load weapons from weapons.txt..");
		return 1;
	}

	/* Initialize Sockets */
	if (CSocket::sockStart() != 0)
		return 1;

	if(!serverSock.listenSock(serverPort, 20))
	{
		errorOut("errorlog.txt", CString() << "SOCK ERROR: Unable to listen on port: " << toString(serverPort));
		return 1;
	}
	serverSock.setSync(false);

	/* Server Finished Loading */
	printf("GServer 2 by 39ster\nSpecial thanks to Marlon, Agret, Pac300, 39ster and others for porting the \noriginal 1.39 gserver to 2.1\nServer listening on port: %i\nServer version: Build %s\n\n", serverPort, listServerFields[3].text());
	errorOut("serverlog.txt", "Server started");

	if ( listServerFields[5] == "localhost" )
        errorOut("serverlog.txt", "[DEBUG_LOCALHOSTMODE] Localhost mode is activated.\nListserver communication & account authentication are disabled.", true);

	serverRunning = true;

	if ( !(listServerFields[5] == "localhost") )
		if (!lsConnected)
			ListServer_Connect();

	while (serverRunning)
	{
		long long second = time(NULL);

		while (second == time(NULL))
		{
			acceptNewPlayers(serverSock);
			for (int i = 0; i < newPlayers.count(); i ++)
			{
				CPlayer* player = (CPlayer*)newPlayers[i];
				player->main();
				if (player->deleteMe)
				{
					delete player;
					i--;
				}
			}

			for(int i = 0; i < playerList.count(); i++)
			{
				CPlayer* player = (CPlayer*)playerList[i];
				player->main();
				if(player->deleteMe)
				{
					delete player;
					i--;
				}
			}

			// Was moved so it can process faster. - Joey
			ListServer_Main();
			wait(100);
		}

		doTimer();
		gameTime ++;
		NOLEVEL->reset();

		// Every 30 seconds
		if (gameTime % 30 == 0)
		{
			ListServer_Send(CPacket() << (char)SLSPING);
		}

		// Every 10 seconds
		if (gameTime % 10 == 0)
		{
			CPacket pPacket;
			CString file;

			for (int i = 0; i < playerList.count(); i++)
			{
				CPlayer *player = (CPlayer *)playerList[i];
				file << player->accountName << "," << player->nickName << "," << player->levelName << "," << toString(player->x) << "," << toString(player->y) << "," << toString(player->ap) << "\n";
			}

			file.save("logs/playerlist.txt");
			serverFlags.save("serverflags.txt");
		}

		//Every 5 seconds?
		int current = getNWTime();
		if (nwTime != current)
		{
			nwTime = current;
			for (int i = 0; i < playerList.count(); i++)
			{
				CPacket out;
				out << (char)NEWWORLDTIME;
				out.writeByte4(current);
				((CPlayer*)playerList[i])->sendPacket(out);
			}
		}
	}
}
Exemplo n.º 2
0
/* main routine */
int main(int argc, char *argv[])
{
    SceCtrlData pad;

    //init screen and callbacks
    pspDebugScreenInit();
    pspDebugScreenClear();
    SetupCallbacks();

    // Setup Pad
    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(0);

    // Load modules
    int status = sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC);
    if (status<0)
    {
        ERRORMSG("ERROR: sceUtilityLoadModule(PSP_MODULE_AV_AVCODEC) returned 0x%08X\n", status);
    }

    status = sceUtilityLoadModule(PSP_MODULE_AV_MP3);
    if (status<0)
    {
        ERRORMSG("ERROR: sceUtilityLoadModule(PSP_MODULE_AV_MP3) returned 0x%08X\n", status);
    }

    // Open the input file
    int fd = sceIoOpen( MP3FILE, PSP_O_RDONLY, 0777 );
    if (fd<0)
    {
        ERRORMSG("ERROR: Could not open file '%s' - 0x%08X\n", MP3FILE, fd);
    }

    // Init mp3 resources
    status = sceMp3InitResource();
    if (status<0)
    {
        ERRORMSG("ERROR: sceMp3InitResource returned 0x%08X\n", status);
    }

    // Reserve a mp3 handle for our playback
    SceMp3InitArg mp3Init;
    mp3Init.mp3StreamStart = 0;
    mp3Init.mp3StreamEnd = sceIoLseek32( fd, 0, SEEK_END );
    mp3Init.unk1 = 0;
    mp3Init.unk2 = 0;
    mp3Init.mp3Buf = mp3Buf;
    mp3Init.mp3BufSize = sizeof(mp3Buf);
    mp3Init.pcmBuf = pcmBuf;
    mp3Init.pcmBufSize = sizeof(pcmBuf);

    int handle = sceMp3ReserveMp3Handle( &mp3Init );
    if (handle<0)
    {
        ERRORMSG("ERROR: sceMp3ReserveMp3Handle returned 0x%08X\n", handle);
    }

    // Fill the stream buffer with some data so that sceMp3Init has something to work with
    fillStreamBuffer( fd, handle );

    status = sceMp3Init( handle );
    if (status<0)
    {
        ERRORMSG("ERROR: sceMp3Init returned 0x%08X\n", status);
    }

    int channel = -1;
    int samplingRate = sceMp3GetSamplingRate( handle );
    int numChannels = sceMp3GetMp3ChannelNum( handle );
    int lastDecoded = 0;
    int volume = PSP_AUDIO_VOLUME_MAX;
    int numPlayed = 0;
    int paused = 0;
    int lastButtons = 0;
    int loop = 0;
    while (isrunning)
    {
        sceDisplayWaitVblankStart();
        pspDebugScreenSetXY(0, 0);
        printf("PSP Mp3 Sample v1.0 by Raphael\n\n");
        printf("Playing '%s'...\n", MP3FILE);
        printf(" %i Hz\n", samplingRate);
        printf(" %i kbit/s\n", sceMp3GetBitRate( handle ));
        printf(" %s\n", numChannels==2?"Stereo":"Mono");
        printf(" %s\n\n", loop==0?"No loop":"Loop");
        int playTime = samplingRate>0?numPlayed / samplingRate:0;
        printf(" Playtime: %02i:%02i\n", playTime/60, playTime%60 );
        printf("\n\n\nPress CIRCLE to Pause/Resume playback\nPress TRIANGLE to reset playback\nPress CROSS to switch loop mode\nPress SQUARE to stop playback and quit\n");

        if (!paused)
        {
            // Check if we need to fill our stream buffer
            if (sceMp3CheckStreamDataNeeded( handle )>0)
            {
                fillStreamBuffer( fd, handle );
            }

            // Decode some samples
            short* buf;
            int bytesDecoded;
            int retries = 0;
            // We retry in case it's just that we reached the end of the stream and need to loop
            for (; retries<1; retries++)
            {
                bytesDecoded = sceMp3Decode( handle, &buf );
                if (bytesDecoded>0)
                    break;

                if (sceMp3CheckStreamDataNeeded( handle )<=0)
                    break;

                if (!fillStreamBuffer( fd, handle ))
                {
                    numPlayed = 0;
                }
            }
            if (bytesDecoded<0 && bytesDecoded!=0x80671402)
            {
                ERRORMSG("ERROR: sceMp3Decode returned 0x%08X\n", bytesDecoded);
            }

            // Nothing more to decode? Must have reached end of input buffer
            if (bytesDecoded==0 || bytesDecoded==0x80671402)
            {
                paused = 1;
                sceMp3ResetPlayPosition( handle );
                numPlayed = 0;
            }
            else
            {
                // Reserve the Audio channel for our output if not yet done
                if (channel<0 || lastDecoded!=bytesDecoded)
                {
                    if (channel>=0)
                        sceAudioSRCChRelease();

                    channel = sceAudioSRCChReserve( bytesDecoded/(2*numChannels), samplingRate, numChannels );
                }
                // Output the decoded samples and accumulate the number of played samples to get the playtime
                numPlayed += sceAudioSRCOutputBlocking( volume, buf );
            }
        }

        sceCtrlPeekBufferPositive(&pad, 1);

        if (pad.Buttons!=lastButtons)
        {
            if (pad.Buttons & PSP_CTRL_CIRCLE)
            {
                paused ^= 1;
            }

            if (pad.Buttons & PSP_CTRL_TRIANGLE)
            {
                // Reset the stream and playback status
                sceMp3ResetPlayPosition( handle );
                numPlayed = 0;
            }

            if (pad.Buttons & PSP_CTRL_CROSS)
            {
                loop = (loop==0?-1:0);
                status = sceMp3SetLoopNum( handle, loop );
                if (status<0)
                {
                    ERRORMSG("ERROR: sceMp3SetLoopNum returned 0x%08X\n", status);
                }
            }

            if (pad.Buttons & PSP_CTRL_SQUARE)
            {
                break;
            }

            lastButtons = pad.Buttons;
        }
    }

    // Cleanup time...
    if (channel>=0)
        sceAudioSRCChRelease();

    status = sceMp3ReleaseMp3Handle( handle );
    if (status<0)
    {
        ERRORMSG("ERROR: sceMp3ReleaseMp3Handle returned 0x%08X\n", status);
    }

    status = sceMp3TermResource();
    if (status<0)
    {
        ERRORMSG("ERROR: sceMp3TermResource returned 0x%08X\n", status);
    }

    status = sceIoClose( fd );
    if (status<0)
    {
        ERRORMSG("ERROR: sceIoClose returned 0x%08X\n", status);
    }

    sceKernelExitGame();

    return 0;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    SceCtrlData pad;
    u32 buttonsold = 0;
    int ret;
    int outputmode = PSP_IRKBD_OUTPUT_MODE_VT100;

    /*
        possible output modes
                PSP_IRKBD_OUTPUT_MODE_ASCII
                PSP_IRKBD_OUTPUT_MODE_RAW
                PSP_IRKBD_OUTPUT_MODE_SCANCODE
                PSP_IRKBD_OUTPUT_MODE_VT100    
    */

	SetupCallbacks();
	pspDebugScreenInit();
    printf("PSP Irda Keyboard test\n");

    ret = pspIrKeybInit( CONFIG_FILE, KERNELMODE );
    if( ret == PSP_IRKBD_RESULT_OK )
    {
        pspIrKeybOutputMode( outputmode );

        if( outputmode == PSP_IRKBD_OUTPUT_MODE_ASCII )
            outputAsciiTest();
        else if( outputmode == PSP_IRKBD_OUTPUT_MODE_RAW )
            outputRawTest();
        else if( outputmode == PSP_IRKBD_OUTPUT_MODE_SCANCODE )
            outputScanCodeTest();
        else if( outputmode == PSP_IRKBD_OUTPUT_MODE_VT100 )
            outputVT100Test();

        if( pspIrKeybFinish() == 0 )
            printf( "\nclosed IR keyboard\n" );
        else
            printf( "\nerror: closing IR keyboard\n" );
    } else {
        switch( ret )
        {
            case PSP_IRKBD_RESULT_CANT_OPEN_DEVICE:
                printf( "error: can't open device\n" );
                break;
            case PSP_IRKBD_RESULT_CANT_OPEN_MAPFILE:
                printf( "error: can't open mapfile\n" );
                break;
            case PSP_IRKBD_RESULT_MAPFILE_MAXDEPTHLEVEL:
                printf( "error: mapfile max include level reached - recursion?\n" );
                break;
            case PSP_IRKBD_RESULT_CANT_OPEN_MAPFILE_INCLUDE:
                printf( "error: can't open include in mapfile\n" );
                break;
            case PSP_IRKBD_RESULT_CANT_SET_BAUDTATE:
                printf( "error: can't set baudrate - you need kernel support\n" );
                break; 
            case PSP_IRKBD_RESULT_CONFIG_FILE_NOT_FOUND:
                printf( "error: can't read config file\n" );
                break; 
            case PSP_IRKBD_RESULT_UNKNOW_KEYBOARD:
                printf( "error: unknown keyboard\n" );
                break;
            case PSP_IRKBD_RESULT_FAILED:
            default:
                printf( "error: init failed\n" );
                break;
        }
    }

    printf( "\n bye... (PRESS psp button to quit)\n" );

    while (1) {
        sceCtrlReadBufferPositive(&pad, 1);
        if (pad.Buttons != buttonsold) {
            /* Exit */
            sceKernelExitGame();
        }
    }


	return 0;
}
Exemplo n.º 4
0
int adhocReconnect(char *ssid)
{
	int err = 0;

	// Disconnect Wifi
	if(g_NetAdhocctlConnect)
	{		
		printf2("sceNetAdhocctlDisconnect\n");
		err = sceNetAdhocctlDisconnect();
		if(err != 0)
		{
			pspDebugScreenInit();
			printf(" returned %x\n", err);
		}
		g_NetAdhocctlConnect = false;
	}

	if(g_NetAdhocPdpCreate)
	{
		printf2("sceNetAdhocPdpDelete\n");
		err = sceNetAdhocPdpDelete(pdpId,0);
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocPdpDelete returned %x\n", err);
		}
		g_NetAdhocPdpCreate = false;
	}

	if(g_NetAdhocMatchingStart)
	{
		printf2("sceNetAdhocMatchingStop\n");
		err = sceNetAdhocMatchingStop(matchingId);
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocMatchingStop returned %x\n", err);
		}
		g_NetAdhocMatchingStart = false;
	}

	if(g_NetAdhocMatchingCreate)
	{
		printf2("sceNetAdhocMatchingDelete\n");
		err = sceNetAdhocMatchingDelete(matchingId);
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocMatchingDelete returned %x\n", err);
		}
		g_NetAdhocMatchingCreate = false;
	}
	
	if(g_NetAdhocMatchingInit)
	{
		printf2("sceNetAdhocMatchingTerm\n");
		err = sceNetAdhocMatchingTerm();
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocMatchingTerm returned %x\n", err);
		}
		g_NetAdhocMatchingInit = false;
	}

    int stateLast = -1;
    while (1)
    {
        int state;
        err = sceNetAdhocctlGetState(&state);
        if (err != 0)
        {
        	pspDebugScreenInit();
            printf("sceNetApctlGetState returns $%x\n", err);
            sceKernelDelayThread(10*1000000); // 10sec to read before exit
			return -1;
        }
        if (state > stateLast)
        {
        	sprintf(temp,"  connection state %d of 1\n", state);
            printf2(temp);
            stateLast = state;
        }
        if (state == 0)
            break;  // connected

        // wait a little before polling again
        sceKernelDelayThread(50*1000); // 50ms
    }

	// Now connect to the PSP using a new SSID
    // Connect
    err = sceNetAdhocctlConnect(ssid);
    if (err != 0)
	{
		pspDebugScreenInit();
		printf("err=%x\n", err);
		for(;;)
			sceDisplayWaitVblankStart();
        return err;
	}
	g_NetAdhocctlConnect = true;
	
    stateLast = -1;
    printf2("Connecting...\n");
    while (1)
    {
        int state;
        err = sceNetAdhocctlGetState(&state);
        if (err != 0)
        {
        	pspDebugScreenInit();
            printf("sceNetApctlGetState returns $%x\n", err);
            sceKernelDelayThread(10*1000000); // 10sec to read before exit
			return -1;
        }
        if (state > stateLast)
        {
        	sprintf(temp,"  connection state %d of 1\n", state);
            printf2(temp);
            stateLast = state;
        }
        if (state == 1)
            break;  // connected

        // wait a little before polling again
        sceKernelDelayThread(50*1000); // 50ms
    }

	char macAddr[10];
	sceWlanGetEtherAddr(macAddr);

	printf2("sceNetAdhocPdpCreate\n");
	pdpId = sceNetAdhocPdpCreate(macAddr,
		     0x309,		// 0x309 in lumines
		     0x800, 	// 0x400 in lumines
		     0);		// 0 in lumines
	if(pdpId <= 0)
	{
		pspDebugScreenInit();
		printf("pdpId = %x\n", pdpId);
		return -1;
	}
	g_NetAdhocPdpCreate = true;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	SceCtrlData pad;
	int oldButtons = 0;
#define SECOND	   1000000
#define REPEAT_START (1 * SECOND)
#define REPEAT_DELAY (SECOND / 5)
	struct timeval repeatStart;
	struct timeval repeatDelay;

	repeatStart.tv_sec = 0;
	repeatStart.tv_usec = 0;
	repeatDelay.tv_sec = 0;
	repeatDelay.tv_usec = 0;

	pspDebugScreenInit();
	pspDebugScreenPrintf("Press Cross to start the IO Test\n");

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

		if (pad.Buttons == oldButtons)
		{
			struct timeval now;
			gettimeofday(&now, NULL);
			if (repeatStart.tv_sec == 0)
			{
				repeatStart.tv_sec = now.tv_sec;
				repeatStart.tv_usec = now.tv_usec;
				repeatDelay.tv_sec = 0;
				repeatDelay.tv_usec = 0;
			}
			else
			{
				long usec = (now.tv_sec - repeatStart.tv_sec) * SECOND;
				usec += (now.tv_usec - repeatStart.tv_usec);
				if (usec >= REPEAT_START)
				{
					if (repeatDelay.tv_sec != 0)
					{
						usec = (now.tv_sec - repeatDelay.tv_sec) * SECOND;
						usec += (now.tv_usec - repeatDelay.tv_usec);
						if (usec >= REPEAT_DELAY)
						{
							repeatDelay.tv_sec = 0;
						}
					}

					if (repeatDelay.tv_sec == 0)
					{
						buttonDown = pad.Buttons;
						repeatDelay.tv_sec = now.tv_sec;
						repeatDelay.tv_usec = now.tv_usec;
					}
				}
			}
		}
		else
		{
			repeatStart.tv_sec = 0;
		}

		if (buttonDown & PSP_CTRL_CROSS)
		{
			sceKernelSetCompiledSdkVersion(0x307FFFF);
			runTest();
			sceKernelSetCompiledSdkVersion(0x307FFFF + 1);
			runTest();
		}

		if (buttonDown & PSP_CTRL_TRIANGLE)
		{
			done = 1;
		}

		oldButtons = pad.Buttons;
	}

	sceGuTerm();

	sceKernelExitGame();
	return 0;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    SceCtrlData pad;
    int oldButtons = 0;
#define SECOND	   1000000
#define REPEAT_START (1 * SECOND)
#define REPEAT_DELAY (SECOND / 5)
    struct timeval repeatStart;
    struct timeval repeatDelay;

    repeatStart.tv_sec = 0;
    repeatStart.tv_usec = 0;
    repeatDelay.tv_sec = 0;
    repeatDelay.tv_usec = 0;

    pspDebugScreenInit();
    pspDebugScreenPrintf("Press Cross to start the Task Scheduler Test\n");
    pspDebugScreenPrintf("Press Circle to start the CpuSuspendIntr/CpuResumeIntr Test\n");
    pspDebugScreenPrintf("Press Square to start the Task with thread of same priority\n");
    pspDebugScreenPrintf("Press Left to start the Task Dispatcher Test\n");
    pspDebugScreenPrintf("Press Triangle to Exit\n");

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

        if (pad.Buttons == oldButtons)
        {
            struct timeval now;
            gettimeofday(&now, NULL);
            if (repeatStart.tv_sec == 0)
            {
                repeatStart.tv_sec = now.tv_sec;
                repeatStart.tv_usec = now.tv_usec;
                repeatDelay.tv_sec = 0;
                repeatDelay.tv_usec = 0;
            }
            else
            {
                long usec = (now.tv_sec - repeatStart.tv_sec) * SECOND;
                usec += (now.tv_usec - repeatStart.tv_usec);
                if (usec >= REPEAT_START)
                {
                    if (repeatDelay.tv_sec != 0)
                    {
                        usec = (now.tv_sec - repeatDelay.tv_sec) * SECOND;
                        usec += (now.tv_usec - repeatDelay.tv_usec);
                        if (usec >= REPEAT_DELAY)
                        {
                            repeatDelay.tv_sec = 0;
                        }
                    }

                    if (repeatDelay.tv_sec == 0)
                    {
                        buttonDown = pad.Buttons;
                        repeatDelay.tv_sec = now.tv_sec;
                        repeatDelay.tv_usec = now.tv_usec;
                    }
                }
            }
        }
        else
        {
            repeatStart.tv_sec = 0;
        }

        if (buttonDown & PSP_CTRL_CROSS)
        {
            SceUID lowThid = sceKernelCreateThread("Low Prio Thread", threadLowPrio, 0x70, 0x1000, 0, 0);
            SceUID mediumThid = sceKernelCreateThread("Medium Prio Thread", threadMediumPrio, 0x30, 0x1000, 0, 0);
            SceUID highThid = sceKernelCreateThread("High Prio Thread", threadHighPrio, 0x10, 0x1000, 0, 0);
            SceUID busyThid = sceKernelCreateThread("Busy Thread", threadBusy, 0x30, 0x1000, 0, 0);
            testDone = 0;
            highPrioCounter = 0;
            mediumPrioCounter = 0;
            lowPrioCounter = 0;
            sceKernelStartThread(lowThid, 0, 0);
            sceKernelStartThread(mediumThid, 0, 0);
            sceKernelStartThread(busyThid, 0, 0);
            sceKernelStartThread(highThid, 0, 0);
            int totalDelay = 5000000;
            sceKernelDelayThread(totalDelay);
            testDone = 1;
            sceKernelWaitThreadEnd(busyThid, NULL);
            sceKernelWaitThreadEnd(mediumThid, NULL);
            sceKernelWaitThreadEnd(highThid, NULL);
            sceKernelWaitThreadEnd(lowThid, NULL);
            pspDebugScreenPrintf("Counters: high=%d (%d us), medium=%d, low=%d\n", highPrioCounter, (totalDelay / highPrioCounter), mediumPrioCounter, lowPrioCounter);
        }

        if (buttonDown & PSP_CTRL_CIRCLE)
        {
            msg = buffer;
            strcpy(msg, "");
            SceUID sleepingThid = sceKernelCreateThread("Sleeping Thread", sleepingThread, 0x10, 0x1000, 0, 0);
            sceKernelStartThread(sleepingThid, 0, 0);
            sceKernelDelayThread(100000);
            int intr = sceKernelCpuSuspendIntr();
            sceKernelWakeupThread(sleepingThid);
            strcat(msg, "Main Thread with disabled interrupts\n");
            sceKernelCpuResumeIntr(intr);
            strcat(msg, "Main Thread with enabled interrupts\n");
            pspDebugScreenPrintf("%s", msg);
        }

        if (buttonDown & PSP_CTRL_SQUARE)
        {
            msg = buffer;
            strcpy(msg, "");
            // Two threads having the same priority
            SceUID thread1 = sceKernelCreateThread("Thread 1", threadPrio_1, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0);
            SceUID thread2 = sceKernelCreateThread("Thread 2", threadPrio_2, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0);
            // Test that thread1 will be scheduled before thread2
            sceKernelStartThread(thread1, 0, 0);
            sceKernelStartThread(thread2, 0, 0);
            strcat(msg, "1 ");
            sceKernelDelayThread(10000);
            strcat(msg, "4");
            sceKernelWaitThreadEnd(thread1, NULL);
            sceKernelWaitThreadEnd(thread2, NULL);
            pspDebugScreenPrintf("Starting 2 threads at same priority: %s\n", msg);

            // Now with a different order for create & start
            strcpy(msg, "");
            SceUID thread3 = sceKernelCreateThread("Thread 3", threadPrio_3, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0);
            SceUID thread4 = sceKernelCreateThread("Thread 4", threadPrio_4, sceKernelGetThreadCurrentPriority(), 0x1000, 0, 0);
            // Test that thread4 will be scheduled before thread3
            sceKernelStartThread(thread4, 0, 0);
            sceKernelStartThread(thread3, 0, 0);
            strcat(msg, "1 ");
            sceKernelDelayThread(10000);
            strcat(msg, "4");
            sceKernelWaitThreadEnd(thread3, NULL);
            sceKernelWaitThreadEnd(thread4, NULL);
            pspDebugScreenPrintf("Starting 2 threads with a different order create/start: %s\n", msg);
        }

        if (buttonDown & PSP_CTRL_LEFT)
        {
            msg = buffer;
            strcpy(msg, "");
            int state = sceKernelSuspendDispatchThread();
            // High priority thread
            SceUID thread = sceKernelCreateThread("Thread 1", threadHello, 0x10, 0x1000, 0, 0);
            strcat(msg, "1 ");
            // sceKernelStartThread resumes the thread dispatcher
            sceKernelStartThread(thread, 0, 0);
            strcat(msg, "2 ");
            sceKernelDelayThread(10000);
            strcat(msg, "3 ");
            sceKernelResumeDispatchThread(state);
            sceKernelWaitThreadEnd(thread, NULL);
            pspDebugScreenPrintf("Starting high prio thread with a disabled dispatcher (state=0x%X): %s\n", state, msg);

            msg = buffer;
            strcpy(msg, "");
            state = sceKernelSuspendDispatchThread();
            // Low priority thread
            thread = sceKernelCreateThread("Thread 1", threadHello, 0x70, 0x1000, 0, 0);
            strcat(msg, "1 ");
            // sceKernelStartThread resumes the thread dispatcher
            sceKernelStartThread(thread, 0, 0);
            strcat(msg, "2 ");
            sceKernelDelayThread(10000);
            strcat(msg, "3 ");
            sceKernelResumeDispatchThread(state);
            sceKernelWaitThreadEnd(thread, NULL);
            pspDebugScreenPrintf("Starting low prio thread with a disabled dispatcher (state=0x%X): %s\n", state, msg);
        }

        if (buttonDown & PSP_CTRL_TRIANGLE)
        {
            done = 1;
        }

        oldButtons = pad.Buttons;
    }

    sceGuTerm();

    sceKernelExitGame();
    return 0;
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
	SceCtrlData pad;
	int oldButtons = 0;
#define SECOND	   1000000
#define REPEAT_START (1 * SECOND)
#define REPEAT_DELAY (SECOND / 5)
	struct timeval repeatStart;
	struct timeval repeatDelay;

	repeatStart.tv_sec = 0;
	repeatStart.tv_usec = 0;
	repeatDelay.tv_sec = 0;
	repeatDelay.tv_usec = 0;

	logFd = sceIoOpen("compilerPerf.log", PSP_O_WRONLY | PSP_O_CREAT, 0777);

	pspDebugScreenInit();
	pspDebugScreenPrintf("Press Cross to start the Performance Test\n");
	pspDebugScreenPrintf("Press Circle to change the CPU Clock\n");

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

		if (pad.Buttons == oldButtons)
		{
			struct timeval now;
			gettimeofday(&now, NULL);
			if (repeatStart.tv_sec == 0)
			{
				repeatStart.tv_sec = now.tv_sec;
				repeatStart.tv_usec = now.tv_usec;
				repeatDelay.tv_sec = 0;
				repeatDelay.tv_usec = 0;
			}
			else
			{
				long usec = (now.tv_sec - repeatStart.tv_sec) * SECOND;
				usec += (now.tv_usec - repeatStart.tv_usec);
				if (usec >= REPEAT_START)
				{
					if (repeatDelay.tv_sec != 0)
					{
						usec = (now.tv_sec - repeatDelay.tv_sec) * SECOND;
						usec += (now.tv_usec - repeatDelay.tv_usec);
						if (usec >= REPEAT_DELAY)
						{
							repeatDelay.tv_sec = 0;
						}
					}

					if (repeatDelay.tv_sec == 0)
					{
						buttonDown = pad.Buttons;
						repeatDelay.tv_sec = now.tv_sec;
						repeatDelay.tv_usec = now.tv_usec;
					}
				}
			}
		}
		else
		{
			repeatStart.tv_sec = 0;
		}

		if (buttonDown & PSP_CTRL_CROSS)
		{
			runTest();
		}

		if (buttonDown & PSP_CTRL_CIRCLE)
		{
			cpuFreq += 111;
			if (cpuFreq > 333)
			{
				cpuFreq = 111;
			}

			int result = scePowerSetCpuClockFrequency(cpuFreq);
			if (result == 0)
			{
				pspDebugScreenPrintf("CPU Clock set to %d MHz\n", cpuFreq);
			}
			else
			{
				pspDebugScreenPrintf("Could not set CPU Clock set to %d MHz\n", cpuFreq);
			}
		}

		if (buttonDown & PSP_CTRL_TRIANGLE)
		{
			done = 1;
		}

		oldButtons = pad.Buttons;
	}

	sceGuTerm();

	sceIoClose(logFd);

	sceKernelExitGame();
	return 0;
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
    SceCtrlData pad;
    u32 buttonsold = 0;
    int kernelmode = 0;       /* only 0 works for now - some keyboards need baud change */
    const char *config_file = NULL; /* this will force ms0:/seplugins/pspirkeyb.ini */

	SetupCallbacks();

    pspDebugScreenInit();
    printf("PSP Irda Keyboard test - ASCii input \n");

	if (sceKernelDevkitVersion() >= 0x03080010)
	{
        /* Load irda PRX for CFW >= 3.80 - Thanks, ZX81! */
        u32 mod_id = sceKernelLoadModule("flash0:/kd/irda.prx", 0, NULL);
        sceKernelStartModule(mod_id, 0, NULL, NULL, NULL);
	}

    if( pspIrKeybInit( config_file, kernelmode ) != 0 )
    {
        printf( "error: can't inialize the keyboard\n" );
        printf( "       check keyboard type/map in ms0:/seplugins/pspirkeyb.ini\n" );
    }
    else
    {
        unsigned char termchar = 'X';
        unsigned char buffer[255];
        int i, length=0;

        printf("\npress %c on keyboard or any PSP button to exit\n", termchar );

        /* setup output method to ASCii */
        pspIrKeybOutputMode( PSP_IRKBD_OUTPUT_MODE_ASCII );

        while(1) {
            length = 0;
            /* non blocking read */
            if( pspIrKeybReadinput(buffer, &length) >= 0 )
            {
                for( i=0; i < length; i++ )
                    printf( "%c", buffer[i] );
                if( length == 1 && buffer[0] == termchar )
                    break;
            }
            else
            {
                sceKernelDelayThread(10*1000);
                sceCtrlReadBufferPositive(&pad, 1);
                if (pad.Buttons != buttonsold)
                    break;
            }
        }

        /* bye keyboard */
        pspIrKeybFinish();
    }

    printf( "\n bye... (PRESS psp button to quit)\n" );

    buttonsold = 0;
    while (1) {
        sceCtrlReadBufferPositive(&pad, 1);
        if (pad.Buttons != buttonsold) {
            /* Exit */
            sceKernelExitGame();
        }
    }

	return 0;
}
Exemplo n.º 9
0
Arquivo: main.c Projeto: CDragu/pspsdk
int main(void)
{
	SceCtrlData pad;

	pspDebugScreenInit();
	SetupCallbacks();

	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

	while(!done){
		pspDebugScreenSetXY(0, 2);

    		sceCtrlReadBufferPositive(&pad, 1); 

		printf("Analog X = %d ", pad.Lx);
		printf("Analog Y = %d \n", pad.Ly);

		if (pad.Buttons != 0){
			if (pad.Buttons & PSP_CTRL_SQUARE){
				printf("Square pressed \n");
			}
			if (pad.Buttons & PSP_CTRL_TRIANGLE){
				printf("Triangle pressed \n");
			} 
			if (pad.Buttons & PSP_CTRL_CIRCLE){
				printf("Cicle pressed \n");
			} 
			if (pad.Buttons & PSP_CTRL_CROSS){
				printf("Cross pressed \n");
			} 

			if (pad.Buttons & PSP_CTRL_UP){
				printf("Up pressed \n");
			} 
			if (pad.Buttons & PSP_CTRL_DOWN){
				printf("Down pressed \n");
			} 
			if (pad.Buttons & PSP_CTRL_LEFT){
				printf("Left pressed \n");
			} 
			if (pad.Buttons & PSP_CTRL_RIGHT){
				printf("Right pressed \n");
			}      

			if (pad.Buttons & PSP_CTRL_START){
				printf("Start pressed \n");
			}
			if (pad.Buttons & PSP_CTRL_SELECT){
				printf("Select pressed \n");
			}
			if (pad.Buttons & PSP_CTRL_LTRIGGER){
				printf("L-trigger pressed \n");
			}
			if (pad.Buttons & PSP_CTRL_RTRIGGER){
				printf("R-trigger pressed \n");
			}      
		}
	}

	sceKernelExitGame();
	return 0;
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
    SceCtrlData pad;
    int result;
    int oldButtons = 0;
    int cbid = -1;
    int waitStatThid = -1;

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

    printf("Triangle - Exit\n");
    printf("Left - sceUmdActivate\n");
    printf("Right - sceUmdDeactivate\n");
    printf("Cross - Delay CB\n");
    printf("Circle - Display umd info\n");
    printf("Square - Refer umd callback\n");
    printf("L-Trigger - IO test\n");
    printf("R-Trigger - Start/Stop wait stat test\n");

    SetupCallbacks();

    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

    {
        printUmdInfo();

        // result:
        // callback events are generated if we launch from iso or immediately after psplink has reset
        cbid = sceKernelCreateCallback("UMD Callback (not active)", umd_callback, (void*)0x34343434);
        result = sceUmdRegisterUMDCallBack(cbid);
        printf("sceUmdRegisterUMDCallBack result %08X\n", result);

		// Register a second UMD callback: it will overwrite the first one.
		cbid = sceKernelCreateCallback("UMD Callback", umd_callback, (void*)0x11111111);
		result = sceUmdRegisterUMDCallBack(cbid);
        printf("sceUmdRegisterUMDCallBack result %08X\n", result);
    }

    while (!done)
    {
        sceCtrlReadBufferPositive(&pad, 1); // context switch in here
        //sceCtrlPeekBufferPositive(&pad, 1); // no context switch version
        int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons;

        if (buttonDown & PSP_CTRL_LEFT)
        {
            result = sceUmdActivate(1, "disc0:");
            printf("sceUmdActivate result %08x\n", result);
        }

        if (buttonDown & PSP_CTRL_RIGHT)
        {
            result = sceUmdDeactivate(1, "disc0:");
            printf("sceUmdDeactivate result %08x\n", result);
        }

        if (buttonDown & PSP_CTRL_CROSS)
        {
            printf("sceKernelDelayThreadCB ...\n");
            sceKernelDelayThreadCB(10000);
        }

        if (buttonDown & PSP_CTRL_CIRCLE)
        {
            printUmdInfo();
        }

        if (buttonDown & PSP_CTRL_SQUARE)
        {
            SceKernelCallbackInfo info;
            memset(&info, 0xee, sizeof(info));
            info.size = sizeof(info);
            result = sceKernelReferCallbackStatus(cbid, &info);
            printf("sceKernelReferCallbackStatus result %08x\n", result);
            printf("  size %d (%d)\n", info.size, sizeof(info));
            printf("  name '%s'\n", info.name);
            printf("  threadId %08x (%08x)\n", info.threadId, sceKernelGetThreadId());
            printf("  callback %p common %p\n", info.callback, info.common);
            printf("  notifyCount %08x\n", info.notifyCount);
            printf("  notifyArg %08x\n", info.notifyArg);
        }

        if (buttonDown & PSP_CTRL_LTRIGGER)
        {
            test_io();
        }

        if (buttonDown & PSP_CTRL_RTRIGGER)
        {
            if (waitStatThid >= 0)
            {
                printf("Cleaning up wait stat test ...\n");

                referThread(waitStatThid);

                result = sceUmdCancelWaitDriveStat();
                printf("sceUmdCancelWaitDriveStat result %08x\n", result);

                referThread(waitStatThid);

                result = sceKernelDeleteThread(waitStatThid);
                printf("sceKernelDeleteThread result %08x\n", result);

                //result = sceKernelTerminateDeleteThread(waitStatThid);
                //printf("sceKernelTerminateDeleteThread result %08x\n", result);

                waitStatThid = -1;
            }
            else
            {
                printf("Starting wait stat test ...\n");

                // test timeout:
                // Press Right (deactivate UMD)
                // Press R-Trigger:
                // - Press R-Trigger again before 3 seconds:
                //   0x800201a9 wait cancelled
                // - Or wait 3 seconds:
                //   0x800201a8 wait timeout
                struct WaitStatParams params = { 0x20, 3000000 };

                // test internal workings:
                // - (wantStat & curStat) == wantStat
                // - (wantStat & curStat) != 0 <-- looks like this is the correct one
                //struct WaitStatParams params = { 0xFF, 3000000 };

                waitStatThid = sceKernelCreateThread("WaitUMDStat", waitstat_thread, 0x20, 0x4000, 0, 0);
                printf("sceKernelCreateThread result %08x\n", waitStatThid);
                if (waitStatThid >= 0)
                {
                    result = sceKernelStartThread(waitStatThid, sizeof(params), &params);
                    printf("sceKernelStartThread result %08x\n", result);
                }
            }
        }

        if (buttonDown & PSP_CTRL_TRIANGLE)
            done = 1;

        oldButtons = pad.Buttons;
        sceDisplayWaitVblank(); // only catch callback when we press Cross (sceKernelDelayThreadCB)
        //sceDisplayWaitVblankCB(); // catch all callback events
    }

    sceKernelExitGame();
    return 0;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
0
int main() {
	SceUID video_thid; //int xx, yy, nubspeed; 
	SetupCallbacks(); pspDebugScreenInit(); initGraphics();
	SceCtrlData pad, oldpad; oldpad.Buttons = 0xFFFFFFFF;
	sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

	// Start the video thread to draw objects to screen and manage video input.
	video_thid = sceKernelCreateThread("video_thread", video_thread, 0x12, 512 * 1024, 0, NULL);
	if (video_thid > 0) sceKernelStartThread(video_thid, 0, NULL);
	
	while (!connected) { sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons) connected = 1; }

	// Wait for camera to be aligned to playing area and for game to start.
	while (running && (!aligned || menu)) {
		// Uncomment the following lines to include analog stick and button input during alignment.
		/*sceCtrlPeekBufferPositive(&pad, 1);
		xx = pad.Lx - 128; yy = pad.Ly - 128;
		nubspeed = sqrt((xx * xx) + (yy * yy)) / (2 * sqrt(sqrt((xx * xx) + (yy * yy))));
		if (xx > 30) cursorx += nubspeed; else if (xx < -30) cursorx -= nubspeed;
		if (yy > 30) cursory += nubspeed; else if (yy < -30) cursory -= nubspeed;
		if (cursorx > 480) cursorx = 480; else if (cursorx < 0) cursorx = 0;
		if (cursory > 272) cursory = 272; else if (cursory < 0) cursory = 0;

		// Detect changes in button input.
		if (pad.Buttons != oldpad.Buttons) {
		}
		oldpad.Buttons = pad.Buttons;*/
		sceKernelDelayThread(50000);
	}

	int x;
	// Initialize global data.
	_highScore    = 0;
	_score        = 0;
	_ballCount    = 0;
	_resBalls     = START_RES_BALLS;
	_gameState    = GAME_RUNNING;
	_pauseSem     = sceKernelCreateSema("PauseSem", 0, 1, 1, 0);

	// Initialize array used to keep track of balls in play.
	for (x = 0; x < MAX_BALLS; x++) { _activeBalls[x] = 0; }

	// Initialize the paddle
	(&_paddle)->h       = 60;
	(&_paddle)->w       = 8;
	(&_paddle)->xPos    = 3;
	(&_paddle)->yPos    = 136;
	(&_paddle)->xPosOld = 250;
	(&_paddle)->yPosOld = 250;
	(&_paddle)->speed   = 10;
	(&_paddle)->dir     = 1;
	(&_paddle)->color   = COLOR_LIGHT_BLUE;

	while (running) {
		// Uncomment the following lines to include analog stick and button input.
		// Defeats the purpose as holding the PSP or touching it shakes the camera
		// and makes the laser pointer input very inaccurate. Could be useful with
		// the PSP remote control to allow games to be played using the remote
		// for D-Pad movement and the laser pointer for looking/aiming.
		/*sceCtrlPeekBufferPositive(&pad, 1);
		xx = pad.Lx - 128; yy = pad.Ly - 128;
		nubspeed = sqrt((xx * xx) + (yy * yy)) / (2 * sqrt(sqrt((xx * xx) + (yy * yy))));
		if (xx > 30) cursorx += nubspeed; else if (xx < -30) cursorx -= nubspeed;
		if (yy > 30) cursory += nubspeed; else if (yy < -30) cursory -= nubspeed;
		if (cursorx > 480) cursorx = 480; else if (cursorx < 0) cursorx = 0;
		if (cursory > 272) cursory = 272; else if (cursory < 0) cursory = 0;

		// Detect changes in button input.
		if (pad.Buttons != oldpad.Buttons) {
		}
		oldpad.Buttons = pad.Buttons;*/

		// Change sprite speeds, positions and behaviors here.
		CreateBall(); // Create a ball and put it in play.
		while (_gameState == GAME_RUNNING) { CheckUserInput(); }
		while (_gameState == GAME_CONTINUE) { sceKernelDelayThread(2000); }
		while (_gameState == GAME_OVER) { sceKernelDelayThread(2000); }

		sceKernelDelayThread(200);
		//CreateBall(); // Create a ball and put it in play.
	}

	StopApp();
	sceKernelExitGame();
	return 0;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
    SceCtrlData pad;
    int result;
    int oldButtons = 0;

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

    printf("Triangle - Exit\n");
    printf("Square - Set lower 16-bits\n");
    printf("Circle - Clear lower 16-bits\n");
    printf("Cross - Delay + refer status\n");
    printf("R-Trigger - Cancel event flag\n\n");
    printf("L-Trigger - Delete event flag\n\n");

    SetupCallbacks();

    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

    evid = sceKernelCreateEventFlag("test_ef", PSP_EVENT_WAITMULTIPLE, INITIAL_PATTERN, 0);
    //evid = sceKernelCreateEventFlag("test_ef", 0, INITIAL_PATTERN, 0);
    printf("EVID: %08x pattern %08x\n", evid, INITIAL_PATTERN);
    if (evid >= 0)
    {
        createStartThread("and", and_thread);
        createStartThread("or", or_thread);
        createStartThread("clear", clear_thread);

#if 0
        // testing context switch timing
        sceKernelSetEventFlag(evid, 0x0000FFFF);
        //int buf[64]; for(;;) sceCtrlReadLatch(buf); // sceCtrlReadLatch does not context switch
        for(;;) sceKernelDelayThread(0); // does not wait forever
#else
        while(!done)
        {
            sceCtrlReadBufferPositive(&pad, 1); // context switch in here
            int buttonDown = (oldButtons ^ pad.Buttons) & pad.Buttons;

            if (buttonDown & PSP_CTRL_SQUARE)
            {
                result = sceKernelSetEventFlag(evid, 0x0000FFFF);
                printf("\nsceKernelSetEventFlag result %08x\n", result);
                printSceKernelEventFlagInfo(evid);
            }

            if (buttonDown & PSP_CTRL_CIRCLE)
            {
                //result = sceKernelClearEventFlag(evid, 0x0000FFFF); // bits to clear - bad
                result = sceKernelClearEventFlag(evid, 0xFFFF0000); // bits to keep - ok
                printf("\nsceKernelClearEventFlag result %08x\n", result);
                printSceKernelEventFlagInfo(evid);
            }

            if (buttonDown & PSP_CTRL_CROSS)
            {
                printf("\nsceKernelDelayThreadCB ...\n");
                sceKernelDelayThreadCB(1000);
                printSceKernelEventFlagInfo(evid);
            }

            if (buttonDown & PSP_CTRL_RTRIGGER)
            {
                //result = sceKernelCancelEventFlag(evid, newPattern, addr);
                result = sceKernelCancelEventFlag(evid, INITIAL_PATTERN, 0);
                printf("sceKernelCancelEventFlag result %08x\n", result);
                printSceKernelEventFlagInfo(evid);
            }

            if (buttonDown & PSP_CTRL_LTRIGGER)
            {
                //result = sceKernelCancelEventFlag(evid, newPattern, addr);
                result = sceKernelDeleteEventFlag(evid);
                printf("sceKernelDeleteEventFlag result %08x\n", result);
                evid = 0;
            }

            if (buttonDown & PSP_CTRL_TRIANGLE)
                done = 1;

            oldButtons = pad.Buttons;
            //sceKernelDelayThread(0); // ok, not infinite :)
        }
#endif
    }
    else
    {
        printf("sceKernelCreateEventFlag failed %08x\n", evid);
        sceKernelSleepThreadCB();
    }

    sceKernelExitGame();
    return 0;
}
Exemplo n.º 15
0
int main_thread(SceSize args, void *argp) {
sceKernelDelayThread(3000000);
        u32 keycombination;
    SceCtrlData pad;
    u32 oldButtons = 0;
       int extra = 0;
         keycombination = PSP_CTRL_RTRIGGER; //Button to start interpreter (Basic)
         u32 keycombination2 = PSP_CTRL_RTRIGGER + PSP_CTRL_LTRIGGER; // Button to start interpreter (Extra PSP Go)
        while(1){
            oldButtons = pad.Buttons;
            if (go==0){
             sceCtrlPeekBufferPositive(&pad, 1);
                          if(oldButtons != pad.Buttons)
                          {
            if(pad.Buttons & keycombination2)
			{
			pauseGame(thid1);
                    go=1;
					extra=1;
                    pspDebugScreenInit();
                    pspDebugScreenClear();
                    oldButtons = pad.Buttons;
			}else if(pad.Buttons & keycombination)
            {
                	pauseGame(thid1);
                    go=1;
                    pspDebugScreenInit();
                    pspDebugScreenClear();
                    oldButtons = pad.Buttons;
            }
            }
            }
                if (go ==1){
    pspDebugScreenSetXY(0,0);
    pspDebugScreenSetTextColor(0xffffff);
       
        int go2=1;
        SceUID id;
        if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){
		if (extra==1){
		id = sceIoDopen("ms0:/seplugins/script"); //PSP Go MS Support
		}else{
        id = sceIoDopen("ef0:/seplugins/script"); //PSP Go Internal HD Support
		}
        }else{
        id = sceIoDopen("ms0:/seplugins/script");
        }
                                 SceIoDirent entry;
                                 int script_files = -2;
                                 memset(&entry, 0, sizeof(SceIoDirent));
                             while (sceIoDread(id, &entry) > 0)
                                {
                                        script_files = script_files+1;
                                        memset(&entry, 0, sizeof(SceIoDirent));
                                }
                                sceIoDclose(id);
                                char script[256];
                                if (((kuKernelGetModel() + 1) == 4) || ((kuKernelGetModel() + 1) == 5)){
								if (extra==1){
								strcpy(script,"ms0:/seplugins/script/index.lua"); //PSP Go MS Support
								}else{
                                strcpy(script,"ef0:/seplugins/script/index.lua"); //PSP Go Internal HD Support
                                }
								}else{
                                 strcpy(script,"ms0:/seplugins/script/index.lua");
                                 }
        while(go2==1)
        {
                                 
                                const char *errMsg;
                                if (script_files>1){            
                                errMsg = runScript(extralibs, true);
                                }else{
    SceUID fp = sceIoOpen(script, PSP_O_RDONLY,0777);  
    int size = sceIoLseek(fp, 0, SEEK_END);
    sceIoLseek(fp, 0, SEEK_SET);
    unsigned char *buffer;
    buffer = malloc((size+1) * sizeof (char));
    sceIoRead(fp, buffer, size);
        buffer[size]=0;
    sceIoClose(fp);
    errMsg = runScript(buffer, true);
    free(buffer);
    }
	// System.restart sourcecode
	if (strstr(errMsg, "lpp_restart")){
    go2=0;
	// End System.restart sources
    // Temp replacing for loadfile/dofile functions: System.protodofile
    }else if (strstr(errMsg, "lpp_open")){
    char dum1[20], dum2[20], dum3[20];
    char script_path2[256];
    sscanf( errMsg, "%s %s %s %s", dum1, dum2, dum3, script_path2 );
    strcpy(script,script_path2);
    script_files=1;
    // End System.protodofile sources
                                }else if (strstr(errMsg, "resumeThread")){
                                go=0;
                                go2=0;
                                }else{
                if (errMsg != NULL);
                {
                                                pspDebugScreenClear();
                                                pspDebugScreenSetTextColor(0xffffff);
                        debugOutput("\nError: %s\n", errMsg);
                }
                debugOutput("\nPress start to restart\nPress select to resume thread\n");
                SceCtrlData pad;
               
                                int restore = 0;
                while(restore==0){
                                sceCtrlPeekBufferPositive(&pad, 1);
                                if (pad.Buttons&PSP_CTRL_START){
                                restore=1;
                                go2=0;
                                }
                                if (pad.Buttons&PSP_CTRL_SELECT){
                                resumeGame(thid1);
                                restore=1;
                                go=0;
                                go2=0;
                                }
                                }
                                }
        }


}
sceDisplayWaitVblankStart();
        }
       
        sceKernelSleepThread();
return 0;
}
Exemplo n.º 16
0
/* Our default handler in case nothing else is installed */
static void _pspDebugDefaultHandler(PspDebugRegBlock *regs)
{
	pspDebugScreenInit();
	pspDebugDumpException(regs);
}
Exemplo n.º 17
0
int main()
{

	pspDebugScreenInit();
	
	pspDebugScreenSetBackColor(0xFF0000);
	pspDebugScreenSetTextColor(0x00FFFF);
	pspDebugScreenClear();

	printf("Recovery Mode by Dark_Alex, in-eboot by BlackSith\n\n\n\n");
	printf("Press start to activate USB Mass.\n");
	printf("Press triangle to flash ms0:/index.dat to flash0.\n");
	printf("Press cross to start the program under ms0:/PSP/GAME/UPDATE/EBOOT.PBP\n");
	printf("Press home to exit.\n\n\n\n");

	sceIoUnassign("flash0:");
	sceIoAssign("flash0:", "lflash0:0,0", "flashfat0:", IOASSIGN_RDWR, NULL, 0);

	while (1)
	{
		SceCtrlData pad;

		int keyprocessed = 0;

		sceCtrlReadBufferPositive(&pad, 1);

		if (pad.Buttons & PSP_CTRL_START)
		{
			start_usb();
			printf("Usb started.\n");
			keyprocessed = 1;
		}
		else if (pad.Buttons & PSP_CTRL_TRIANGLE)
		{
			if (copy_file("ms0:/index.dat", "flash0:/vsh/etc/index.dat") < 0)
				printf("Cannot copy file. (file missing?).\n");
			else
				printf("File copied succesfully.\n");

			keyprocessed = 1;
		}
		else if (pad.Buttons & PSP_CTRL_CROSS)
		{
			struct SceKernelLoadExecParam param;

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

			param.size = sizeof(param);
			param.args = strlen(PROGRAM)+1;
			param.argp = PROGRAM;
			param.key = "updater";

			printf("Starting program...\n");
			sceKernelLoadExec(PROGRAM, &param);

			keyprocessed = 1;
		}
		else if (pad.Buttons & PSP_CTRL_HOME)
		{
			break;
		}

		sceKernelDelayThread((keyprocessed) ? 200000 : 50000);
	}

	sceKernelExitGame();

	return 0;
}
Exemplo n.º 18
0
int main(void)
{
	int err = 0;
	scePowerSetClockFrequency(333, 333, 166);
	pspDebugScreenInit();
	
	printf("####  PSCRYPTER v2.0 by Carlosgs  ####\nEncrypt EBOOT.PBP files directly from the PSP\nUses the code made by 'bbtgp' and parts of the PSPSDK\nv2.0 added realocation fixing by JJS\nTHANK YOU!\n\n");
	
	
	sceIoMkdir("./sign/", 0777);
	
	chdir("./sign/");
	
	sceIoRemove("EBOOT_signed.PBP");
	sceIoRemove("param.sfo");
	sceIoRemove("icon0.png");
	sceIoRemove("icon1.pmf");
	sceIoRemove("pic0.png");
	sceIoRemove("pic1.png");
	sceIoRemove("snd0.at3");
	sceIoRemove("data.psp");
	sceIoRemove("data_unsigned.psp");
	sceIoRemove("data.psar");
	
	printf("Unpacking EBOOT file...\n");
	
	err = main_unpack_pbp();
	if(err != 0)
	{
		printf("Error while unpacking: %d\n",err);
		myexit();
	}
	
	printf("\nFixing PRX realocations...\n");
	
	err = main_fix_realocations();
	if(err != 0)
	{
		printf("Error while fixing realocations: %d\n",err);
		myexit();
	}
	
	printf("\nCrypting PRX file...\n");
	
	err = main_crypter();
	if(err != 0)
	{
		printf("Error while crypting: %d\n",err);
		myexit();
	}
	
	
	printf("\nPacking new EBOOT file...\n");
	
	err = main_pack_pbp(10, filename_list);
	if(err != 0)
	{
		printf("Error while packing: %d\n",err);
		myexit();
	}
	
	
	printf("\n\nFinished! Hope it works!\n");
	
	myexit();
	return 0;
}
Exemplo n.º 19
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;
}
Exemplo n.º 20
0
//entry point
int main(int argc, char * argv[])
{
	pspDebugScreenInit();

	psp_fw_version = sceKernelDevkitVersion();

#if defined(CONFIG_660) || defined(CONFIG_661)
	if((psp_fw_version == FW_660) || (psp_fw_version == FW_661)) {
		goto version_OK;
	}
#endif

#ifdef CONFIG_639
	if(psp_fw_version == FW_639) {
		goto version_OK;
	}
#endif

#ifdef CONFIG_620
	if(psp_fw_version == FW_620) {
		goto version_OK;
	}
#endif

#ifdef CONFIG_635
	if(psp_fw_version == FW_635) {
		goto version_OK;
	}
#endif

	pspDebugScreenPrintf("Sorry. This program doesn't support your FW(0x%08X).\n", (uint)psp_fw_version);
	sceKernelDelayThread(5*1000000);
	goto exit;

version_OK:
	setup_patch_offset_table(psp_fw_version);
	
	//puzzle installer path
	strcpy(installerpath, argv[0]);

	char * slash = strrchr(installerpath, '/');
	if (slash) slash[1] = '\0';
	
	write_files(installerpath);
	strcat(installerpath, "installer.prx");

	printk_init("ms0:/launcher.txt");
	printk("Hello exploit\n");

	if(sctrlHENGetVersion() >= 0) {
		install_in_cfw();

		return 0;
	}

#if defined(CONFIG_660) || defined(CONFIG_661)
	if((psp_fw_version == FW_660) || (psp_fw_version == FW_661)) {
		do_exploit_660();
	}
#endif

#ifdef CONFIG_639
	if(psp_fw_version == FW_639) {
		do_exploit_639();
	}
#endif

#if defined(CONFIG_620) || defined(CONFIG_635)
	if(psp_fw_version == FW_620 || psp_fw_version == FW_635) {
		do_exploit();
	}
#endif

exit:
	//trigger reboot
	sceKernelExitGame();

	//kill thread
	sceKernelExitDeleteThread(0);

	//return
	return 0;
}
Exemplo n.º 21
0
int adhocInit(char *MatchingData)
{
	char mac[6];
	struct productStruct product;

	ClearPspList();

	strcpy(product.product, "ULUS99999");
	product.unknown = 0;

    u32 err;
	printf2("sceNetInit()\n");
    err = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);
    if (err != 0)
        return err;
	g_NetInit = true;

	printf2("sceNetAdhocInit()\n");
    err = sceNetAdhocInit();
    if (err != 0)
        return err;
	g_NetAdhocInit = true;
	
	printf2("sceNetAdhocctlInit()\n");
    err = sceNetAdhocctlInit(0x2000, 0x20, &product);
    if (err != 0)
        return err;
	g_NetAdhocctlInit = true;

    // Connect
    err = sceNetAdhocctlConnect("");
    if (err != 0)
        return err;
	g_NetAdhocctlConnect = true;

    int stateLast = -1;
    printf2("Connecting...\n");
    while (1)
    {
        int state;
        err = sceNetAdhocctlGetState(&state);
        if (err != 0)
        {
        		pspDebugScreenInit();
            printf("sceNetApctlGetState returns $%x\n", err);
            sceKernelDelayThread(10*1000000); // 10sec to read before exit
			return -1;
        }
        if (state > stateLast)
        {
        		sprintf(temp,"  connection state %d of 1\n", state);
            printf2(temp);
            stateLast = state;
        }
        if (state == 1)
            break;  // connected

        // wait a little before polling again
        sceKernelDelayThread(50*1000); // 50ms
    }
    printf2("Connected!\n");
    
    
	sceWlanGetEtherAddr(mac);
	
	
    printf2("sceNetAdhocPdpCreate\n");
    
    
	pdpId = sceNetAdhocPdpCreate(mac,
		     0x309,		// 0x309 in lumines
		     0x400, 	// 0x400 in lumines
		     0);		// 0 in lumines
	if(pdpId <= 0)
	{
		
		pspDebugScreenInit();
		printf("pdpId = %x\n", pdpId);
		return -1;
	}
	g_NetAdhocPdpCreate = true;

	printf2("sceNetAdhocMatchingInit()\n");
	
	err = sceNetAdhocMatchingInit(0x20000);
	if(err != 0)
	{
		pspDebugScreenInit();
		printf("error = %x\n", err);
	}
	g_NetAdhocMatchingInit = true;
	
	printf2("sceNetAdhocMatchingCreate()\n");
	matchingId = sceNetAdhocMatchingCreate( 3,
											0xa,
											0x22b,
											0x800,
											0x2dc6c0,
											0x5b8d80,
											3,
											0x7a120,
											matchingCallback);

	if(matchingId < 0)
	{
		sprintf(temp,"matchingId = %x\n", matchingId);
		printf2(temp);
	}
	g_NetAdhocMatchingCreate = true;

	/*char tempStr[100];
	tempStr[0] = '\0';	
	if(strlen(MatchingData))
	{
		strncpy(tempStr, strrchr(MatchingData, '/')+1, 100);
		strrchr(tempStr, '.')[0] = '\0';
	}*
	printf("tempStr=%s\n", tempStr);*/

	printf2("sceNetAdhocMatchingStart()\n");
	
	err = sceNetAdhocMatchingStart(matchingId, 	// 1 in lumines (presuming what is returned from create)
			 0x10,		// 0x10
			 0x2000,		// 0x2000
			 0x10,		// 0x10
			 0x2000,		// 0x2000
			 strlen(MatchingData)+1,
			 MatchingData);		
	if(err != 0)
	{
		pspDebugScreenInit();
		printf("error = %x\n", err);
	}
	
	g_NetAdhocMatchingStart = true;

	// All the init functions have passed
	return 0;
}
Exemplo n.º 22
0
Arquivo: main.c Projeto: CDragu/pspsdk
int main(int argc, char *argv[])
{
	SceUID thid;
	int error;
	void *data;

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

	/* Create a messagebox */
	myMessagebox = sceKernelCreateMbx("pspSDK-testMBX", 0, 0);
	printf("MAIN: created messagebox %08x\n", myMessagebox);

	/* Create a task that will post in the messagebox */
	thid = sceKernelCreateThread("subthread", SubThread, 17, 8192, THREAD_ATTR_USER, 0);
	sceKernelStartThread(thid, 0, NULL);
	printf("MAIN: started task %08x\n", thid);

	/* Wait for a message */
	printf("MAIN: waiting for message\n");
	error = sceKernelReceiveMbx(myMessagebox, &data, NULL);
	if(error < 0)
		printf("MAIN: ERROR %08x\n", error);
	else
		printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text);

	/* Wait for a message with timeout */
	printf("MAIN: waiting with timeout (will fail the first couple of times)\n");
	for(;;) {
		SceUInt timeout = 300000; /* microseconds */
		error = sceKernelReceiveMbx(myMessagebox, &data, &timeout);
		if(error < 0)
			printf("MAIN: ERROR %08x\n", error);
		else {
			printf("MAIN: got message: \"%s\" (timeout remaining %d us)\n",
			       ((MyMessage *)data)->text, timeout);
			break;
		}
	}

	/* Poll for messages */
	printf("MAIN: polling for message (non-blocking)\n");
	for(;;) {
		error = sceKernelPollMbx(myMessagebox, &data);
		if(error < 0) {
			printf("MAIN: ERROR %08x\n", error);
			/* Sleep for a little while to give the message
			   a chance to arrive */
			sceKernelDelayThread(300000);			
		} else {
			printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text);
			break;
		}		
	}

	/* This call to sceKernelReceiveMbx() will be interrupted
	   by the sub task without a message being sent */
	printf("MAIN: waiting for a message that will not arrive\n");
	error = sceKernelReceiveMbx(myMessagebox, &data, NULL);
	if(error < 0)
		printf("MAIN: ERROR %08x\n", error);
	else
		printf("MAIN: got message: \"%s\"\n", ((MyMessage *)data)->text);	

	/* Prepare to shutdown */
	printf("MAIN: waiting for sub task to exit\n");
	sceKernelWaitThreadEnd(thid, NULL);
	printf("MAIN: sub task exited, deleting messagebox\n");
	error = sceKernelDeleteMbx(myMessagebox);
	if(error < 0)
		printf("MAIN: ERROR %08x\n", error);
	else
		printf("MAIN: all done\n");

	sceKernelSleepThread();

	return 0;
}
Exemplo n.º 23
0
// The order that procedures are called was taken by patching
// Lumines network procs
int adhocTerm()
{
    u32 err;

	if(g_NetAdhocctlConnect)
	{
		printf2("sceNetAdhocctlDisconnect\n");
		err = sceNetAdhocctlDisconnect();
		if(err != 0)
		{
			pspDebugScreenInit();
			printf(" returned %x\n", err);
		}
		g_NetAdhocctlConnect = false;
	}

	if(g_NetAdhocPdpCreate)
	{
		printf2("sceNetAdhocPdpDelete\n");
		err = sceNetAdhocPdpDelete(pdpId,0);
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocPdpDelete returned %x\n", err);
		}
		g_NetAdhocPdpCreate = false;
	}

	if(g_NetAdhocMatchingStart)
	{
		printf2("sceNetAdhocMatchingStop\n");
		err = sceNetAdhocMatchingStop(matchingId);
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocMatchingStop returned %x\n", err);
		}
		g_NetAdhocMatchingStart = false;
	}

	if(g_NetAdhocMatchingCreate)
	{
		printf2("sceNetAdhocMatchingDelete\n");
		err = sceNetAdhocMatchingDelete(matchingId);
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocMatchingDelete returned %x\n", err);
		}
		g_NetAdhocMatchingCreate = false;
	}
	
	if(g_NetAdhocMatchingInit)
	{
		printf2("sceNetAdhocMatchingTerm\n");
		err = sceNetAdhocMatchingTerm();
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocMatchingTerm returned %x\n", err);
		}
		g_NetAdhocMatchingInit = false;
	}
	
	if(g_NetAdhocctlInit)
	{
		printf2("sceNetAdhocctlTerm\n");
		err = sceNetAdhocctlTerm();
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocctlTerm returned %x\n", err);
		}
		g_NetAdhocctlInit = false;
	}

	if(g_NetAdhocInit)
	{
		printf2("sceNetAdhocTerm\n");
		err = sceNetAdhocTerm();
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetAdhocTerm returned %x\n", err);
		}
		g_NetAdhocInit = false;
	}

	if(g_NetInit)
	{
		printf2("sceNetTerm\n");
		err = sceNetTerm();
		if(err != 0)
		{
			pspDebugScreenInit();
			printf("sceNetTerm returned %x\n", err);
		}
		g_NetInit = false;
	}

    return 0; // assume it worked
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
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;
}
Exemplo n.º 26
0
int main() 
{

   	pspDebugScreenInit();
	int devkit = sceKernelDevkitVersion(),
	cursor = 0;
	
		if(devkit != 0x06060010)
		Exit("This program supports only 6.60!");

    printf("USB Mod Flasher\n\n");    
	setcolor(RED);
	printf("This Mod is only for the TN-V8 eCFW for the PS Vita!");
	setcolor(WHITE);
	printf("\n\n\n\n\n\n\n\n\n\n\n\nCredits:\nXMB Mod by The Z\nInstaller Port by KanadeEngel\n\nSpecial Thanks to:\nfrostegater");

	while(1)
	{
		if(cursor > 2)
			cursor = 0;
		else if(cursor < 0)
			cursor = 2;

		if(cursor == 0) setbcolor(GRAY);
		printfc(3, 4, " Install XMB Mod.                       ");
		setbcolor(BLACK);
		if(cursor == 1) setbcolor(GRAY);
		printfc(3, 5, " Restore Original Files.                ");
		setbcolor(BLACK);
		if(cursor == 2) setbcolor(GRAY);
		printfc(3, 6, " Exit.                                  ");
		setbcolor(BLACK);

		int i;
		for(i = 0; i < 4; i++)
			printfc(1, 4 + i, " ");

		setcolor(BLUE);
		printfc(1, 4 + cursor, ">");

		unsigned int Buttons = wait_press(PSP_CTRL_CROSS | PSP_CTRL_UP | PSP_CTRL_DOWN);
		wait_release(PSP_CTRL_CROSS | PSP_CTRL_UP | PSP_CTRL_DOWN);

		SceCtrlData pad;
		sceCtrlReadBufferPositive(&pad, 1);

		if(Buttons & PSP_CTRL_CROSS)
		{
			if(cursor != 2)
			{
				setc(0, 9);
				if(assign_flash_zero() < 0)
					Exit("\n Error in 'flash0:/' assign.");
	

					{
						if(cursor == 0)//Install Mod Module
						{
							flash_file("flash0:/vsh/resource/topmenu_icon.rco", _660_install_X_icon, size__660_install_X_icon);
						}
	                    else if(cursor == 1)//Restore Original Module
							flash_file("flash0:/vsh/resource/topmenu_icon.rco", _660_original_X_icon, size__660_original_X_icon);
						}
					}
			else
				Exit("");

			break;
		}
		else if(Buttons & PSP_CTRL_UP)
			cursor--;
		else if(Buttons & PSP_CTRL_DOWN)
			cursor++;
	}

	Exit("Done.");
   sceKernelExitGame();
	return 0;
}
Exemplo n.º 27
0
int main(int argc, char *argv[])
{
    SceCtrlData pad;
    int oldButtons = 0;
    int i;
#define SECOND       1000000
#define REPEAT_START (1 * SECOND)
#define REPEAT_DELAY (SECOND / 5)
    struct timeval repeatStart;
    struct timeval repeatDelay;

    repeatStart.tv_sec = 0;
    repeatStart.tv_usec = 0;
    repeatDelay.tv_sec = 0;
    repeatDelay.tv_usec = 0;

    for (i = 0; i < SAMPLE_SIZE; i += 2)
    {
	buffer1[i+0] = 0x00;
	buffer1[i+1] = 0x70;
	buffer2[i+0] = 0x00;
	buffer2[i+1] = 0x10;
    }

    pspDebugScreenInit();

    printf("Triangle - Exit\n");
    printf("Cross - Test Blocking Audio\n");
    printf("Square - Test non-Blocking Audio\n");
    printf("Circle - Test Audio2\n");

    channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, SAMPLE_SIZE, PSP_AUDIO_FORMAT_STEREO);
    if (channel < 0)
    {
        sceKernelExitGame();
    }

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

	if (pad.Buttons == oldButtons)
	{
		struct timeval now;
		gettimeofday(&now, NULL);
		if (repeatStart.tv_sec == 0)
		{
			repeatStart.tv_sec = now.tv_sec;
			repeatStart.tv_usec = now.tv_usec;
			repeatDelay.tv_sec = 0;
			repeatDelay.tv_usec = 0;
		}
		else
		{
			long usec = (now.tv_sec - repeatStart.tv_sec) * SECOND;
			usec += (now.tv_usec - repeatStart.tv_usec);
			if (usec >= REPEAT_START)
			{
				if (repeatDelay.tv_sec != 0)
				{
					usec = (now.tv_sec - repeatDelay.tv_sec) * SECOND;
					usec += (now.tv_usec - repeatDelay.tv_usec);
					if (usec >= REPEAT_DELAY)
					{
						repeatDelay.tv_sec = 0;
					}
				}

				if (repeatDelay.tv_sec == 0)
				{
					buttonDown = pad.Buttons;
					repeatDelay.tv_sec = now.tv_sec;
					repeatDelay.tv_usec = now.tv_usec;
				}
			}
		}
	}
	else
	{
		repeatStart.tv_sec = 0;
	}

        if (buttonDown & PSP_CTRL_CROSS)
        {
		strcpy(text, "Start Test:\n");
		gettimeofday(&previousAudioOutput, NULL);
		for (i = 0; i < 10; i++)
		{
			audioOutput(buffer1, 1);
			audioOutput(buffer2, 1);
		}
		strcat(text, "\n");

		printf(text);
        }

        if (buttonDown & PSP_CTRL_SQUARE)
        {
		strcpy(text, "Start Test:\n");
		gettimeofday(&previousAudioOutput, NULL);
		for (i = 0; i < 10; i++)
		{
			audioOutput(buffer1, 0);
			audioOutput(buffer2, 0);
		}
		strcat(text, "\n");

		printf(text);
        }

        if (buttonDown & PSP_CTRL_CIRCLE)
        {
		sceAudioOutput2Reserve(SAMPLE_SIZE / 2);

		audioOutput2(buffer1, 0xFFFFF);
		sceKernelDelayThread(1 * 1000000);
		audioOutput2(buffer1, 0x20000);
		sceKernelDelayThread(1 * 1000000);
		audioOutput2(buffer1, 0x10000);
		sceKernelDelayThread(1 * 1000000);
		audioOutput2(buffer1, 0x08000);
		sceKernelDelayThread(1 * 1000000);
		audioOutput2(buffer1, 0x04000);
		sceKernelDelayThread(1 * 1000000);
		audioOutput2(buffer1, 0x02000);
		sceKernelDelayThread(1 * 1000000);
		audioOutput2(buffer1, 0x01000);
		sceKernelDelayThread(1 * 1000000);
		audioOutput2(buffer1, 0x00800);
        }

        if (buttonDown & PSP_CTRL_RIGHT)
        {
        }

        if (buttonDown & PSP_CTRL_UP)
        {
        }

        if (buttonDown & PSP_CTRL_DOWN)
        {
        }


        if (buttonDown & PSP_CTRL_TRIANGLE)
	{
        	done = 1;
	}

        oldButtons = pad.Buttons;
	sceDisplayWaitVblank();
    }

    sceKernelExitGame();
    return 0;
}
Exemplo n.º 28
0
int main(void)
{
	SceCtrlData pad, lastpad;

	int maxchan = 128;
	BOOL outputEnabled;
	MODULE *mf = NULL;
	SAMPLE *sf = NULL;
	int voice = 0;
	int pan = 127;
	int vol = 127;
	int freq = 22000;

	pspDebugScreenInit();
	SetupCallbacks();

	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(1);
	if (!MikMod_InitThreads()) {
		printf("MikMod thread init failed\n");
	}

	MikMod_RegisterErrorHandler(my_error_handler);
	/* register all the drivers */
	MikMod_RegisterAllDrivers();
	/* register all the module loaders */
	MikMod_RegisterAllLoaders();

	/* initialize the library */
	md_mode = DMODE_16BITS|DMODE_STEREO|DMODE_SOFT_SNDFX|DMODE_SOFT_MUSIC; 
	md_reverb = 0;
	md_pansep = 128;
	if (MikMod_Init("")) {
		printf("Could not initialize sound, reason: %s\n", MikMod_strerror(MikMod_errno));
		sceKernelExitGame();
		return 0;
	}

	MikMod_SetNumVoices(-1, 8);
	/* get ready to play */
	sf = Sample_Load("ms0:/sound.wav");

	printf("Starting.\n");
	MikMod_EnableOutput();
	outputEnabled = 1;

	if ((mikModThreadID = sceKernelCreateThread("MikMod" ,(void*)&AudioChannelThread,0x12,0x10000,0,NULL)) > 0) {
		sceKernelStartThread(mikModThreadID, 0 , NULL);
	}
	else {
		printf("Play thread create failed!\n");
	}

	sceCtrlReadBufferPositive(&lastpad, 1);
	do {
		sceCtrlReadBufferPositive(&pad, 1);

		if(pad.Buttons != lastpad.Buttons) {
			if(pad.Buttons & PSP_CTRL_CROSS) {
				voice = Sample_Play(sf,0,0);
				Voice_SetPanning(voice, pan);
			}

			if(pad.Buttons & PSP_CTRL_SQUARE) {
				outputEnabled = !outputEnabled;
				if(outputEnabled)
					MikMod_EnableOutput();
				else	MikMod_DisableOutput();
			}

			if(pad.Buttons & PSP_CTRL_CIRCLE) {
				mf = Player_Load("ms0:/MUSIC.XM", maxchan, 0);
				if (NULL != mf) {
					mf->wrap = 1;
					Player_Start(mf);
				}
			}

			if(pad.Buttons & PSP_CTRL_TRIANGLE) {
				if (NULL != mf) {
					Player_Stop();
					Player_Free(mf); /* To stop the song for real, it needs to be freed. I know, weird... */
					mf = NULL;
				}
			}

			if(pad.Buttons & PSP_CTRL_SELECT)
				printf("Player is %s\n", Player_Active()?"On":"Off");

			lastpad = pad;
		}

		if(pad.Buttons & PSP_CTRL_LTRIGGER) {
			Voice_SetPanning(voice, (pan<2)?pan:--pan);
			printf("pan is %d\n", pan);
		}

		if(pad.Buttons & PSP_CTRL_RTRIGGER) {
			Voice_SetPanning(voice, (pan>254)?pan:++pan);
			printf("pan is %d\n", pan);
		}

		if(pad.Buttons & PSP_CTRL_UP) {
			Voice_SetVolume(voice, (vol>254)?vol:++vol);
			printf("vol is %d\n", vol);
		}

		if(pad.Buttons & PSP_CTRL_DOWN) {
			Voice_SetVolume(voice, (vol<2)?vol:--vol);
			printf("vol is %d\n", vol);
		}

		if(pad.Buttons & PSP_CTRL_LEFT) {
			Voice_SetFrequency(voice, (freq<1001)?freq:(freq -=1000));
			printf("freq is %d\n", freq);
		}

		if(pad.Buttons & PSP_CTRL_RIGHT) {
			Voice_SetFrequency(voice, (freq>44000)?freq:(freq +=1000));
			printf("freq is %d\n", freq);
		}
		sceDisplayWaitVblankStart();
		
	} while(!((pad.Buttons & PSP_CTRL_START) || done));

	printf("Stopping.\n");

	/* allow audio thread to terminate cleanly */
	done = 1;
	if (mikModThreadID > 0) {
		SceUInt timeout = 100000;
		sceKernelWaitThreadEnd(mikModThreadID, &timeout);
		/* not 100% sure if this is necessary after a clean exit,
		 * but just to make sure any resources are freed: */
		sceKernelDeleteThread(mikModThreadID);
	}
	Player_Stop();
	Player_Free(mf);
	MikMod_Exit();

	sceKernelExitGame();
	return 0;
}
Exemplo n.º 29
0
Arquivo: main.c Projeto: 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;
} 
Exemplo n.º 30
0
//*************************************************************************************
//
//*************************************************************************************
static bool	Initialize()
{
	strcpy(gDaedalusExePath, DAEDALUS_PSP_PATH( "" ));

	printf( "Cpu was: %dMHz, Bus: %dMHz\n", scePowerGetCpuClockFrequency(), scePowerGetBusClockFrequency() );
	if (scePowerSetClockFrequency(333, 333, 166) != 0)
	{
		printf( "Could not set CPU to 333MHz\n" );
	}
	printf( "Cpu now: %dMHz, Bus: %dMHz\n", scePowerGetCpuClockFrequency(), scePowerGetBusClockFrequency() );

	// Set up our Kernel Home button
	//ToDo: This doesn't work properly for Vita, there's no longer a "home" button available
	InitHomeButton();

	// If (o) is pressed during boot the Emulator will use 32bit
	// else use default 16bit color mode
	SceCtrlData pad;
	sceCtrlPeekBufferPositive(&pad, 1);
	if( pad.Buttons & PSP_CTRL_CIRCLE ) g32bitColorMode = true;
	else g32bitColorMode = false;

	// Check for unsupported FW >=4.01 (We use M33 SDK 4.01)
	// Otherwise PSP model can't be detected correctly
	DaedalusFWCheck();

	// Initiate MediaEngine
	//Note: Media Engine is not available for Vita
	bool bMeStarted = InitialiseJobManager();

// Disable for profiling
//	srand(time(0));

	//Set the debug output to default
	if( g32bitColorMode ) pspDebugScreenInit();
	else pspDebugScreenInitEx( NULL , GU_PSM_5650, 1); //Sets debug output to 16bit mode

// This Breaks gdb, better disable it in debug build
//
#ifndef DAEDALUS_DEBUG_CONSOLE
	initExceptionHandler();
#endif

	_DisableFPUExceptions();

	//Init Panic button thread
	SetupPanic();

	// Init volatile memory
	VolatileMemInit();

#ifdef DAEDALUS_CALLBACKS
	//Set up callback for our thread
	SetupCallbacks();
#endif

	//Set up the DveMgr (TV Display) and Detect PSP Slim /3K/ Go
	if ( kuKernelGetModel() > PSP_MODEL_STANDARD )
	{
		// Can't use extra memory if ME isn't available
		if( bMeStarted )
			PSP_IS_SLIM = true;

		HAVE_DVE = CModule::Load("dvemgr.prx");
		if (HAVE_DVE >= 0)
			PSP_TV_CABLE = pspDveMgrCheckVideoOut();
		if (PSP_TV_CABLE == 1)
			PSP_TV_LACED = 1; // composite cable => interlaced
		else if( PSP_TV_CABLE == 0 )
			CModule::Unload( HAVE_DVE );	// Stop and unload dvemgr.prx since if no video cable is connected
	}

	HAVE_DVE = (HAVE_DVE < 0) ? 0 : 1; // 0 == no dvemgr, 1 == dvemgr

    sceCtrlSetSamplingCycle(0);
    sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

	// Init the savegame directory
	strcpy( g_DaedalusConfig.mSaveDir, DAEDALUS_PSP_PATH( "SaveGames/" ) );

	if (!System_Init())
		return false;

	return true;
}