예제 #1
0
파일: gameMain.c 프로젝트: SamRH/openTRI
/* Entry point */
int main(int argc, char **argv)
{
	if(!triAt3Init()) triError("Error starting atrac3 playback");
	
	if(!triNetInit()) triError("Error starting net");

	// Set up callbacks
	SetupCallbacks();
	
	// Game inits
	if(!triLogInit()) triError("Error starting Logging");
	triInit( GU_PSM_8888 );
	tri3dInit();
	if(!triInputInit()) triError("Error starting input");
	triModelManagerInit();
	if(!triWavInit()) triError("Error starting WAV playback");
	
	if(!gameLoadModels()) triError("Error loading models");
	
	while (gameRunning)
	{
		// Game state stuff
	}
	
	// Game shutdown
	triModelManagerFreeAll();
	triInputShutdown();
	triClose();
	tri3dClose();
	triMemoryShutdown();

	sceKernelExitGame();
	
	return 0;
}
예제 #2
0
파일: main.c 프로젝트: esxgx/hidmouse
int main (int argc, char **argv)
{
  int res, status;

  SetupCallbacks ();
  pspDebugScreenInit ();
  
  printf ("Loading modules... ");
  modid = load_module ("hidmouse.prx", 0, 0);
  if (modid < 0) {
    printf ("failed with 0x%08X\n", modid);
    return -1;
  }

  printf ("OK\n");
  printf ("Starting modules... ");

  res = sceKernelStartModule (modid, 0, NULL, &status, NULL);
  if (res < 0) {
    printf ("failed with 0x%08X\n", res);
    return -1;
  }

  if (status) {
    printf ("failed with status = 0x%08X\n", status);
    return -1;
  }

  printf ("OK\n");
  return 0;
}
예제 #3
0
파일: main.c 프로젝트: CDragu/pspsdk
int main(void)
{
	int i;

	pspDebugScreenInit();
	SetupCallbacks();

	/* Clear the existing profile regs */
	pspDebugProfilerClear();
	/* Enable profiling */
	pspDebugProfilerEnable();

	for(i = 0; i < 600; i++)
	{
		pspDebugScreenSetXY(0, 0);
		/* Print profile information to the screen */
		pspDebugProfilerPrint();
		sceDisplayWaitVblankStart();
	}

	/* Let's bug out */
	sceKernelExitDeleteThread(0);

	return 0;
}
예제 #4
0
파일: psp.cpp 프로젝트: Bananattack/verge3
void psp_init() {
	SetupCallbacks();

	sceGuInit();

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


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

}
예제 #5
0
int main(void) {
	//change clock rate to 333mhz
	scePowerSetClockFrequency(333, 333, 166);

	PowerManager::instance();	// Setup power manager

	SetupCallbacks();

	static const char *argv[] = { "scummvm", NULL };
	static int argc = sizeof(argv) / sizeof(char *) - 1;

	g_system = new OSystem_PSP();
	assert(g_system);

#ifdef DYNAMIC_MODULES
	PluginManager::instance().addPluginProvider(new PSPPluginProvider());
#endif

/* unit/speed tests */
#if defined (PSP_ENABLE_UNIT_TESTS) || defined (PSP_ENABLE_SPEED_TESTS)
	PSP_INFO_PRINT("running tests\n");
	psp_tests();
	sceKernelSleepThread();	// that's it. That's all we're doing
#endif

	int res = scummvm_main(argc, argv);

	g_system->quit();	// TODO: Consider removing / replacing this!

	PowerManager::destroy();	// get rid of PowerManager

	sceKernelSleepThread();

	return res;
}
예제 #6
0
파일: main.c 프로젝트: libcg/PSP_Bot
int main()
{
  SetupCallbacks();

  initLanguage();
  initLevel();
  initGame();
  initDisp();

  sceKernelSleepThread();
  return 0;
}
예제 #7
0
파일: main.c 프로젝트: joshdekock/jim-psp
int main(int argc, char *argv[])
{
	pspDebugScreenInit();
	if (argc > 0) {
		printf("Bootpath: %s\n", argv[0]);
	}
	SetupCallbacks();
	printf("\nMain Thread Status:\n");
	dump_threadstatus();
	sceKernelSleepThread();

	return 0;
}
예제 #8
0
int main(){	
pspDebugScreenInit();
SetupCallbacks(); 
	printf("I Love you Mariah!");
	printf("I Love you Mariah!");
	printf("I Love you Mariah!");
	printf("I Love you Mariah!");
	printf("I Love you Mariah!");
	printf("I Love you Mariah!");
	printf("I Love you Mariah!");
	printf("I Love you Mariah!");
	sceKernelSleepThread(); 
	return 0;
}
예제 #9
0
int xmain(int ra)
{
	SetupCallbacks();

	pgInit();
	pgScreenFrame(1, 0);
	pgFillvram(0);

	mainImpl();
	
	pgWaitVn(500);
	sceKernelExitGame();

	return 0;
}
예제 #10
0
void App_Initialize( void )
{
	
	Gamepad gamepad;
	
	dList = malloc( 262144 );
	sceneList = malloc( 262144 );
	fbp0  = 0;
 
	sceKernelDcacheWritebackAll();
	pspDebugScreenInit();


	myScene = new Scene(SCR_WIDTH, SCR_HEIGHT);
	///////////////////////////////////////////////////
	// Load Resources
	///////////////////////////////////////////////////
	char *sceneName = "courtyard.lws";
	printf("Loading Lightwave Scene: %s\n", sceneName);
	loadLWS(*myScene, sceneName);	
	
	// printf("Caching CVR scene: %s\n", sceneName);
	// myScene->cache(true);

	
	printf("Retrieving scene motion controller: %s\n", sceneName);
	mySceneMotion = &myScene->motion(sceneName);
	
	///////////////////////////////////////////////////
	// END Load Resources
	///////////////////////////////////////////////////
	printf("\n\n--------------------------\n");
	printf("   Press X to start...\n");
	printf("--------------------------\n\n\n");
	
	while(!gamepad.ButtonDown(PSP_CTRL_CROSS))
	{
		gamepad.Poll();
	}
	
	InitGU();
	SetupProjection();
	SetupCallbacks();
}
void USocketIOClientComponent::InitializeComponent()
{
	Super::InitializeComponent();
	{
		//Because our connections can last longer than game world 
		//end, we let plugin-scoped structures manage our memory
		if (bPluginScopedConnection)
		{
			NativeClient = ISocketIOClientModule::Get().ValidSharedNativePointer(PluginScopedId);
		}
		else
		{
			NativeClient = ISocketIOClientModule::Get().NewValidNativePointer();
		}
		
		SetupCallbacks();
	}

}
예제 #12
0
파일: main.c 프로젝트: joshdekock/jim-psp
int main(void)
{
	SceCtrlData pad;
	pspDebugScreenInit();
	SetupCallbacks();

	/* Install our custom exception handler. If this was NULL then the default would be used */
	pspDebugInstallErrorHandler(MyExceptionHandler);
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);

	pspDebugScreenPrintf("Exception Sample\n\n");
	pspDebugScreenPrintf("You have two choices, press O for a bus error or X for a breakpoint\n\n");

	while(1)
	{
		sceCtrlReadBufferPositive(&pad, 1);
		if(pad.Buttons & PSP_CTRL_CIRCLE)
		{
			/* Cause a bus error */
			_sw(0, 0);
		}

		if(pad.Buttons & PSP_CTRL_CROSS)
		{
			/* Cause a break exception */
			asm(
				"break\r\n"
			  );
		}

		sceDisplayWaitVblankStart();
	}


	/* We will never end up here, hopefully */
	printf("End\n");

	sceKernelExitDeleteThread(0);

	return 0;
}
예제 #13
0
void mainloop_batch(simulation_data *sim)
{
    char filebase[100];
    const char *extractvars[] = {"q", "xc", "radius", NULL};
    double origin[] = {5., 5., 5.}, normal[] = {0., 0.707, 0.707};
    double isos[] = {0.2, 0.5, 0.8};
    double v0[] = {1.,1.,1.}, v1[] = {5., 1.5, 7.}, v2[] = {8., 2., 5.};
    
    /* Explicitly load VisIt runtime functions and install callbacks. */
    VisItInitializeRuntime();
    SetupCallbacks(sim);

    while(!sim->done)
    {  
        /* Update the simulation data for this iteration.*/     
        simulation_data_update(sim);

        /* Tell VisIt that some metadata changed.*/
        VisItTimeStepChanged();

        /* Make some extracts. */
        sprintf(filebase, "slice3v_%04d", sim->cycle);
        extract_slice_3v(filebase, v0, v1, v2, extractvars);

        sprintf(filebase, "sliceON_%04d", sim->cycle);
        extract_slice_origin_normal(filebase, origin, normal, extractvars);

        sprintf(filebase, "sliceX_%04d", sim->cycle);
        extract_slice(filebase, 0, 0.5, extractvars);

        sprintf(filebase, "sliceY_%04d", sim->cycle);
        extract_slice(filebase, 1, 2.5, extractvars);

        sprintf(filebase, "sliceZ_%04d", sim->cycle);
        extract_slice(filebase, 2, 5., extractvars);

        sprintf(filebase, "iso_%04d", sim->cycle);
        extract_iso(filebase, "q", isos, 3, extractvars);

        simulation_advance(sim);
    }
}
예제 #14
0
파일: main.c 프로젝트: IgorMac/gSquare
int main(int argc, char* argv[])
{
  SetupCallbacks();
  #ifdef DEBUG
    usbStorage();
  #endif

  strcpy(cwd,argv[0]);
  cwd[strlen(cwd)-strlen("/eboot.pbp")] = '\0';

  configLoad();
  initLanguage();
  initAudio();
  initLua();
  initGame();
  initDisp();

  sceKernelSleepThread();
  return 0;
}
예제 #15
0
파일: main.c 프로젝트: CrossCRS/pspsdk
int main(void) {
    unsigned char buffer[0x1e]; /* Buffer */

    pspDebugScreenInit();
    SetupCallbacks();

    pspDebugScreenPrintf("Idstorage sample by harleyg\nThanks to Dark_AleX and Mathieulh\n\n");
    /* Read idstorage key 0x050 (serial) */
    sceIdStorageLookup(0x050, 0x0, buffer, 0x1e); /* key, offset, buffer, length */

    /* Print the serial */
    pspDebugScreenPrintf("Serial: %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
                         buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5],
                         buffer[6], buffer[7], buffer[8], buffer[9], buffer[10], buffer[11],
                         buffer[12], buffer[13], buffer[14], buffer[15], buffer[16], buffer[17],
                         buffer[18], buffer[19], buffer[20], buffer[21], buffer[22], buffer[23],
                         buffer[24], buffer[25], buffer[26], buffer[27], buffer[28], buffer[29]);

    sceKernelSleepThread();
    return 0;
}
예제 #16
0
int os_fb_init(int argc, char** argv) {
	int i;
	if (os_byte_fb != NULL)
		return 1;
	//os_byte_fb = //(os_byte_t*) malloc(640*480*4);
	os_byte_fb = pixels;

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

	pspDebugScreenInit();
	SetupCallbacks();

	sceGuInit();

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

	sceDisplayWaitVblankStart();
	sceGuDisplay(1);

	return 0;
///	return x11_display_init(640, 480, "dacube2", argc, argv);
}
예제 #17
0
파일: main.c 프로젝트: kernelzin/xxpub
int main() 
{
	//call psp stuff
	pspDebugScreenInit();
    SetupCallbacks();
    initGraphics();
    
	char bafer[200];
	
	//Image definido no graphics.h
    Image* nossaImage;
	
	//joga caminho no bafer
	sprintf(bafer, "media/prince_ascii.png");
	nossaImage = loadImage(bafer);
    
    	//checar se imagem existe!!
    	if (!nossaImage) 
    	{
        	//Image load failed
        	printf("Ta lah nao! \n");
        } 
        else 
        {
        	
        	int x = 0;
            int y = 0;
            
            sceDisplayWaitVblankStart();
                      
           	blitAlphaImageToScreen(0 ,0 , 480, 272, nossaImage, x, y);
            
            flipScreen();
            
         } 
	
	sceKernelSleepThread();
    return 0;
}
예제 #18
0
int main() {
    pspDebugScreenInit();
    SetupCallbacks();
    scePowerSetClockFrequency(333, 333, 166);
    
    pspAudioInit();
    SceCtrlData pad;
    int i;

    tzset();
    printf("Hello World\n");
    time_t now;
    now = time(NULL);
    printf("Started %s\n", ctime(&now));

    MP3_Init(1);
    MP3_Load("test.mp3");
    MP3_Play();
    while(1) {
            sceCtrlReadBufferPositive(&pad, 1);
            if(pad.Buttons & PSP_CTRL_CROSS) {
                      break;
            } else if(pad.Buttons & PSP_CTRL_CIRCLE) {
                      MP3_Pause();
                      for(i=0; i<10; i++) {
                                sceDisplayWaitVblankStart();
                      }
            }

            if (MP3_EndOfStream() == 1) {
                      MP3_Stop();
            }
    }
    MP3_Stop();
    MP3_FreeTune();
    sceKernelSleepThread();
    return 0;
    }
예제 #19
0
파일: main.c 프로젝트: joshdekock/jim-psp
int main(int argc, char *argv[])
{
    SceUID thid;

    save_argv0 = strdup(argv[0]);

    SetupCallbacks();

#ifdef DEBUG
    pspDebugScreenInit();
#endif

    if(pspSdkLoadInetModules() < 0)
       return 1;

    thid = sceKernelCreateThread("python_thread", main_thread, 0x18, 0x10000,
                                 PSP_THREAD_ATTR_USER|PSP_THREAD_ATTR_VFPU, NULL);
    sceKernelStartThread(thid, 0, NULL);

    sceKernelExitDeleteThread(0);

    return 0;
}
예제 #20
0
파일: contest.c 프로젝트: SamRH/openTRI
/* Simple thread */
int main(int argc, char **argv)
{
	SetupCallbacks();
	
	triLogInit();
	triConsoleInit();
	
	CVARF( cl_fps, 60.0 );
	CVARS( cl_name, "Raphael" );
	CVARS_RD( sv_name, "triEngine" );
	
	triCVarRegister( &cl_fps );
	triCVarRegister( &cl_name );
	triCVarRegister( &sv_name );
	

	printf("\nPlease type 'tty' to connect to the ingame console.\n");
	printf("\nType '~.' to return to PSPLink shell.\n");
	printf("Inside the console, type 'exit' to quit the program.\n");
	printf("Type 'cmds' to get a list of available commands.\n");
	printf("Type 'cvars' to get a list of registered cvars.\n");
	
	triConsoleToggle();
	
	while (triConsoleVisible())
	{
		triConsoleUpdate();
		
		sceKernelDelayThread(250*1000);
	}

	triConsoleClose();
	triMemoryShutdown();
	sceKernelExitGame();
	return 0;
}
예제 #21
0
파일: fonttest.c 프로젝트: SamRH/openTRI
/* Simple thread */
int main(int argc, char **argv)
{
	SetupCallbacks();
	
	triLogInit();
	triInit( GU_PSM_8888, 1 );
	//triEnable( TRI_VBLANK );
	
	// Colors
	enum colors
	{
		RED =	0xFF0000FF,
		GREEN =	0xFF00FF00,
		BLUE =	0xFFFF0000,
		WHITE =	0xFFFFFFFF
	};

	// Init font library
	triFontInit();

	// Make Debug font mono spaced at width 7
	triFontSetMono( 0, 7 );
	
	// Load first font, 12 point, 128x128 texture, in VRAM
	triFont *verdana12 = triFontLoad("./verdana.ttf", 12, TRI_FONT_SIZE_POINTS, 128, TRI_FONT_VRAM);
	//triFont *verdana12 = triFontLoadTRF("./verdana12.trf");

    // Load second font, 20 pixels, 128x128 texture, in VRAM
	triFont *impact20 = triFontLoad("./impact.ttf", 20, TRI_FONT_SIZE_PIXELS, 128, TRI_FONT_VRAM);

	// Make sure the fonts are loaded
	if(!verdana12 || !impact20)
		sceKernelExitGame();

	//triFontSaveTRF( verdana12, "verdana12.trf" );
	while (isrunning)
	{
		triClear( 0 );

		// Activate our first font
		triFontActivate(verdana12);

		// Draw our character set using the first font
		triFontPrint(160, 40, RED, " .,!?:;0123456789");
		triFontPrint(160, 60, GREEN, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
		triFontPrint(160, 80, BLUE, "abcdefghijklmnopqrstuvwxyz");
		triFontPrint(160, 100, WHITE, "@#$%^&*+-()[]{}<>/\\|~`\"\n\ttabs and \tline breaks\n\tare \t\t\tsupported now!");

		// Activate our second font
		triFontActivate(impact20);

		// Draw our character set using the second font
		triFontPrint(160, 150, RED, " .,!?:;0123456789");
		triFontPrint(160, 170, GREEN, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
		triFontPrint(160, 190, BLUE, "abcdefghijklmnopqrstuvwxyz");
		triFontPrint(160, 210, WHITE, "@#$%^&*+-()[]{}<>/\\|~`\"\n\ttabs and \tline breaks\n\tare \t\t\t\tsupported now!");
		
		// Activate the internal debug font
		triFontActivate(0);
		triFontPrintf(2, 2, WHITE, "FPS: %.2f - FPS Max: %.2f - FPS Min: %.2f", triFps(), triFpsMax(), triFpsMin());

		triDrawRectOutline( 4, 39 152, 212, WHITE );
		triFontPrintAlign( 5, 40, 150, 210, WHITE, TRI_FONT_ALIGN_JUSTIFY, "This is some\njustified text.\nJustification!");
		triFontPrintAlign( 5, 40, 150, 210, WHITE, TRI_FONT_ALIGN_BOTTOM|TRI_FONT_ALIGN_RIGHT, "This is bottom\nand right aligned.");
		
		triSwapbuffers();
	}

	// Unload our first font
	triFontUnload(verdana12);

	// Unload our second font
	triFontUnload(impact20);

	// Shutdown font library
	triFontShutdown();

	triClose();
	triMemoryShutdown();
	triLogShutdown();
	sceKernelExitGame();
	return 0;
}
예제 #22
0
파일: main.c 프로젝트: joshdekock/jim-psp
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;
}
예제 #23
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*) );
	defaultFiles.load( __defaultfiles, sizeof(__defaultfiles) / 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 */
	serverSock.setType( SOCKET_TYPE_SERVER );
	serverSock.setProtocol( SOCKET_PROTOCOL_TCP );
	serverSock.setOptions( SOCKET_OPTION_NONBLOCKING );
	serverSock.setDescription( "serverSock" );
	CString empty;
	if ( serverSock.init( empty, serverPort ) )
		return 1;

	// Connect server socket.
	if ( serverSock.connect() )
	{
		errorOut("errorlog.txt", CString() << "SOCK ERROR: Unable to listen on port: " << serverPort);
		return 1;
	}

	/* 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: %s\nServer version: Build %s\n\n", serverPort.text(), 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(10);
		}

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

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

		// 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);
			}
		}
	}
}
예제 #24
0
int main(int argc, char** argv)
{
	pspDebugScreenInit();
	pspDebugScreenEnableBackColor(0);
	
	SetupCallbacks();
	
	char* scriptFilename = "script.lua";
	
	lua_State *L;
	L = lua_open();
	luaL_openlibs(L);
	
	Aalib_init(L);
	Color_init(L);
	g2D_init(L);
	intraFont_init(L);
	Ctrl_init(L);
	Power_init(L);
	Time_init(L);
	Timer_init(L);
	Savedata_init(L);
	sceIo_init(L);
	Utility_init(L);
	USB_init(L);
	Xtream_init(L);
	
	
	SceCtrlData keys, oldkeys;
	int status = 0, i;
	
	while (1)
	{
	status = luaL_loadfile(L, scriptFilename);
		
	if (status == 0) 
		status = lua_pcall(L, 0, LUA_MULTRET, 0);
	

		if (status != 0) //If an error has occured
		{
		sceCtrlReadBufferPositive(&oldkeys, 1);
		
		pspDebugScreenInit();
		pspDebugScreenEnableBackColor(1);
		
			while (1)
			{			
				sceCtrlReadBufferPositive(&keys, 1);
			
				pspDebugScreenSetXY(0,0);
				printf("Lua Error:\n%s\n", lua_tostring(L, -1));
				printf("Press Start to reset.\n");
				
				if ((keys.Buttons &PSP_CTRL_START) && !(oldkeys.Buttons &PSP_CTRL_START))
					break;
				
				oldkeys = keys;
				
				for (i = 0; i < 10; i++)
					sceDisplayWaitVblankStart();
			}
			
		pspDebugScreenInit();
		pspDebugScreenEnableBackColor(0);
		
		lua_pop(L, 1);
		}
	}
		
	lua_close(L);

	intraFontShutdown();
	g2dTerm();
	cleanUSBDrivers();

	sceKernelExitGame();

	return 0;
}
예제 #25
0
파일: main.c 프로젝트: Bracket-/psp-ports
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;
}
예제 #26
0
파일: main.c 프로젝트: CrossCRS/pspsdk
/* 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;
}
예제 #27
0
파일: main.c 프로젝트: sum2012/JPCSP-Mirror
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;
}
예제 #28
0
파일: main.c 프로젝트: acidrain42/misc
int main() {
    int fin=0, touche, action;
    Partie partie;
    Dalek *daleks = NULL;
    Doc doc;
    Surfaces surfce;
    
    /*Initialisations*/
    SDL_Init(SDL_INIT_VIDEO);
    TTF_Init();
    srand(time(NULL));
    #ifdef PSP
    pspDebugScreenInit();
    SetupCallbacks();
    #endif
    
    /*Initialisation de l'ecran principal*/
    surfce.screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
    #ifndef PSP /*Titre si pas sur le PSP*/
        SDL_WM_SetCaption("Daleks-SDL", NULL);
    #endif
    
    /*Affichage de l'intro, sert de loading Screen*/
    afficherIntro(surfce.screen);
    
    /*Creation de la partie*/
    partie = nouvellePartie();
    
    /*Initialisation des personnages*/
    initNiveau(partie, &doc, &daleks);
    
    /*Initialisation des surfaces SDL*/
    if (initialiserSurfaces(&surfce) != 0) {
        exit(EXIT_FAILURE);
    }
    
    /*Le loading est fini, on attend une touche de l'utilisateur*/
    while (lireTouche() == -1) {
    }
    
    /*Sert a annuler la touche enfoncee precedement*/
    afficherPartie(partie, surfce, doc, daleks);
    
    while (!fin) {
        /**********
            ETAPES
            1. Lire la touche
            2. Effectuer l'action
            3. Bouger les daleks
            4. Verifier les morts
            5. Verifier l'etat de la partie
            6. Afficher le jeu
          **********/
        action = 1; /*Pour savoir si il y a eu une action ce tour*/
        touche = lireTouche();
        switch (touche) {
            case KEY_UP:
                if (moveDoc(0, -1, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_DOWN:
                if (moveDoc(0, 1, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_LEFT:
                if (moveDoc(-1, 0, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_RIGHT:
                if (moveDoc(1, 0, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_UP_LEFT:
                if (moveDoc(-1, -1, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_UP_RIGHT:
                if (moveDoc(1, -1, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_DOWN_LEFT:
                if (moveDoc(-1, 1, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_DOWN_RIGHT:
                if (moveDoc(1, 1, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_STAY:
                if (moveDoc(0, 0, &doc, daleks, partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_ZAP:
                if (zapper(doc, daleks, &partie) != 0) {
                    action = 0;
                }
                break;
            case KEY_TELEPORT:
                teleportDoc(&doc, daleks, partie);
                break;
            case KEY_RUN:
                run(&doc, daleks, &partie, surfce);
                action = 0; /*Les daleks ont deja bouge*/
                break;
            case KEY_QUIT:
                fin = 1;
            default: /*aucune action*/
                action = 0;
        }
        
        /*Les daleks bougent seulement si le doc a fait une action*/
        if (action) {
            moveDaleks(daleks, doc, partie);
            checkMorts(&doc, daleks, &partie);
        }
        
        if (getStatutPartie(doc, daleks, partie) == 1) {
            afficherPartie(partie, surfce, doc, daleks); /*Affichage de la partie avant d'afficher lvlUp*/
            afficherLevelUp(surfce.screen);                 /*Parce que l'affichage est long*/
            monterNiveau(&partie);
            initNiveau(partie, &doc, &daleks);
        } else if (getStatutPartie(doc, daleks, partie) == 2) {
            afficherPartie(partie, surfce, doc, daleks); /*Affichage de la partie avant d'afficher la mort*/
            afficherDead(surfce.screen);                    /*Parce que l'affichage est long*/
            reset(&partie);
            initNiveau(partie, &doc, &daleks);
        }
        
        afficherPartie(partie, surfce, doc, daleks);
    }
    
    libererSurfaces(surfce);
    TTF_Quit();
    SDL_Quit();
    
    #ifdef PSP
        sceKernelExitGame();
    #endif
    return 0;
}
예제 #29
0
int main (int argc, char **argv)
{
#if WRITE_LOG
	FILE *log = NULL;
#endif
	u32 ticks_per_s;
	int oldtime;

	SetupCallbacks();

#if WRITE_LOG
	// Wipe log file.
	log = fopen("log.txt", "w");
	if (log != NULL)
	{
		fputs("LOG START\n\n", log);
		fclose(log);
		log = NULL;
	}
#endif

	// Calculate the clock resolution.
	sceRtcGetCurrentTick(&first_ticks);
	ticks_per_s = sceRtcGetTickResolution();
	ticks_per_ms = ticks_per_s / 1000.0;

	// TODO Move elsewhere.
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);

	// Initialise Quake.
	Qcommon_Init (argc, argv);

	oldtime = Sys_Milliseconds();

	// Run the main loop.
	while (go)
	{
		SceCtrlData pad;

		curtime = Sys_Milliseconds();
		sys_frame_time = curtime;

		if (curtime < oldtime)
		{
			Sys_Error("curtime (%d) < oldtime (%d)\n", curtime, oldtime);
		}

		sceCtrlPeekBufferPositive(&pad, 1);
		if (pad.Buttons & PSP_CTRL_CROSS)
		{
			go = false;
		}

		if (curtime != oldtime)
		{
			Qcommon_Frame(curtime - oldtime);

			oldtime = curtime;
		}
	}

	sceKernelExitGame();

	return 0;
}
예제 #30
0
파일: sceat3.cool.c 프로젝트: rnbpsp/pmc
int main(void)
{
	SetupCallbacks();
	
	int result = pspSdkLoadStartModule("flash0:/kd/audiocodec.prx", PSP_MEMORY_PARTITION_KERNEL);
	pspSdkFixupImports(result);
	
	SceUID at3_handle = sceIoOpen("ms0:/Test.AT3", PSP_O_RDONLY, 0777);
	if (  ! at3_handle )
		goto wait;
	
	u32 riff_header[2];
	if ( sceIoRead( at3_handle, riff_header, 8 ) != 8 ) 
		goto wait;
	if ( riff_header[0] != 0x46464952 )
		goto wait;
	u32 wavefmt_header[3];
	if ( sceIoRead( at3_handle, wavefmt_header, 12 ) != 12 ) 
		goto wait;
	if ( wavefmt_header[0] != 0x45564157 || wavefmt_header[1] != 0x20746D66 )
		goto wait;
	u8* wavefmt_data = (u8*)malloc(wavefmt_header[2]);
	if ( wavefmt_data == NULL )
		goto wait;
	if ( sceIoRead( at3_handle, wavefmt_data, wavefmt_header[2] ) != wavefmt_header[2] ) {
		free(wavefmt_data);
		goto wait;
	}
	at3_type = *((u16*)wavefmt_data);
	at3_channels = *((u16*)(wavefmt_data+2));
	at3_samplerate = *((u32*)(wavefmt_data+4));
	at3_data_align = *((u16*)(wavefmt_data+12));
	
	if ( at3_type == TYPE_ATRAC3PLUS) {
		at3_at3plus_flagdata[0] = wavefmt_data[42];
		at3_at3plus_flagdata[1] = wavefmt_data[43];
	}
	
	free(wavefmt_data);
	
	u32 data_header[2];
	if ( sceIoRead( at3_handle, data_header, 8 ) != 8 ) 
		goto wait;
	while(data_header[0] != 0x61746164 ) {
		sceIoLseek32(at3_handle, data_header[1], PSP_SEEK_CUR);
		if ( sceIoRead( at3_handle, data_header, 8 ) != 8 ) 
			goto wait;
	}
	
	at3_data_start = sceIoLseek32(at3_handle, 0, PSP_SEEK_CUR);
	at3_data_size = data_header[1];
	
	if ( at3_data_size % at3_data_align != 0 )
		goto wait;
	
	memset(at3_codec_buffer, 0, sizeof(at3_codec_buffer));
	
	if ( at3_type == TYPE_ATRAC3 ) {
		at3_channel_mode = 0x0;
		if ( at3_data_align == 0xC0 ) // atract3 have 3 bitrate, 132k,105k,66k, 132k align=0x180, 105k align = 0x130, 66k align = 0xc0
			at3_channel_mode = 0x1;
		at3_sample_per_frame = 1024; 
		at3_data_buffer = (u8*)memalign(64, 0x180);
		if ( at3_data_buffer == NULL)
			goto wait;
		at3_codec_buffer[26] = 0x20;
		if ( sceAudiocodecCheckNeedMem(at3_codec_buffer, 0x1001) < 0 ) 
			goto wait;
		if ( sceAudiocodecGetEDRAM(at3_codec_buffer, 0x1001) < 0 )
			goto wait;
		at3_getEDRAM = 1;
		at3_codec_buffer[10] = 4;
		at3_codec_buffer[44] = 2;
		if ( at3_data_align == 0x130 )
			at3_codec_buffer[10] = 6;
		if ( sceAudiocodecInit(at3_codec_buffer, 0x1001) < 0 ) {
			goto wait;
		}
	}
	else if ( at3_type == TYPE_ATRAC3PLUS ) {
		at3_sample_per_frame = 2048;
		int temp_size = at3_data_align+8;
		int mod_64 = temp_size & 0x3f;
		if (mod_64 != 0) temp_size += 64 - mod_64;
		at3_data_buffer = (u8*)memalign(64, temp_size);
		if ( at3_data_buffer == NULL)
			goto wait;
		at3_codec_buffer[5] = 0x1;
		at3_codec_buffer[10] = at3_at3plus_flagdata[1];
		at3_codec_buffer[10] = (at3_codec_buffer[10] << 8 ) | at3_at3plus_flagdata[0];
		at3_codec_buffer[12] = 0x1;
		at3_codec_buffer[14] = 0x1;
		if ( sceAudiocodecCheckNeedMem(at3_codec_buffer, 0x1000) < 0 ) 
			goto wait;
		if ( sceAudiocodecGetEDRAM(at3_codec_buffer, 0x1000) < 0 )
			goto wait;
		at3_getEDRAM = 1;
		if ( sceAudiocodecInit(at3_codec_buffer, 0x1000) < 0 ) {
			goto wait;
		}
	}
	else
		goto wait;
	
	int eof = 0;	
	while( !eof ) {
		int samplesdecoded;
		memset(at3_mix_buffer, 0, 2048*2*2);
		unsigned long decode_type = 0x1001;
		if ( at3_type == TYPE_ATRAC3 ) {
			memset( at3_data_buffer, 0, 0x180);
			if (sceIoRead( at3_handle, at3_data_buffer, at3_data_align ) != at3_data_align) {
				eof = 1;
				continue;
			}
			if ( at3_channel_mode ) {
				memcpy(at3_data_buffer+at3_data_align, at3_data_buffer, at3_data_align);
			}
			decode_type = 0x1001;
		}
		else {
			memset( at3_data_buffer, 0, at3_data_align+8);
			at3_data_buffer[0] = 0x0F;
			at3_data_buffer[1] = 0xD0;
			at3_data_buffer[2] = at3_at3plus_flagdata[0];
			at3_data_buffer[3] = at3_at3plus_flagdata[1];
			if (sceIoRead( at3_handle, at3_data_buffer+8, at3_data_align ) != at3_data_align) {
				eof = 1;
				continue;
			}
			decode_type = 0x1000;
		}
	
		at3_codec_buffer[6] = (unsigned long)at3_data_buffer;
		at3_codec_buffer[8] = (unsigned long)at3_mix_buffer;
	
		int res = sceAudiocodecDecode(at3_codec_buffer, decode_type);
		if ( res < 0 ) {
			eof = 1;
			continue;
		}
		samplesdecoded = at3_sample_per_frame;
	}

wait:
	
	if ( at3_handle ) {
		sceIoClose(at3_handle);
	}
	if ( at3_data_buffer) {
		free(at3_data_buffer);
	}
	if ( at3_getEDRAM ) {
		sceAudiocodecReleaseEDRAM(at3_codec_buffer);
	}
	
	sceCtrlReadBufferPositive(&input, 1);
	while(!(input.Buttons & PSP_CTRL_TRIANGLE))
	{
		sceKernelDelayThread(10000);	// wait 10 milliseconds
		sceCtrlReadBufferPositive(&input, 1);
	}
	
	sceKernelExitGame();
	return 0;
}