Esempio n. 1
0
int main(int argc, char *argv[]) {
	// Initialize basic libctru stuff
	gfxInitDefault();
	cfguInit();
	osSetSpeedupEnable(true);
// 	consoleInit(GFX_TOP, NULL);

	g_system = new _3DS::OSystem_3DS();
	assert(g_system);

	// Invoke the actual ScummVM main entry point
// 	if (argc > 2)
// 		res = scummvm_main(argc-2, &argv[2]);
// 	else
// 		res = scummvm_main(argc, argv);
	scummvm_main(0, nullptr);

	delete dynamic_cast<_3DS::OSystem_3DS*>(g_system);
	
	// Turn on both screen backlights before exiting.
	if (R_SUCCEEDED(gspLcdInit())) {
		GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTH);
		gspLcdExit();
	}
	
	cfguExit();
	gfxExit();
	return 0;
}
Esempio n. 2
0
int main (int argc, char **argv)
{
	float		time, oldtime;

	APT_CheckNew3DS(&isN3DS);
	if(isN3DS)
		osSetSpeedupEnable(true);

	gfxInit(GSP_RGB565_OES,GSP_RGB565_OES,false);
	gfxSetDoubleBuffering(GFX_TOP, false);
	gfxSetDoubleBuffering(GFX_BOTTOM, false);
	gfxSet3D(true);
	consoleInit(GFX_BOTTOM, NULL);

	#ifdef _3DS_CIA
		if(chdir("sdmc:/3ds/ctrQuake") != 0)
			Sys_Error("Could not find folder: sdmc:/3ds/ctrQuake");
	#endif

	static quakeparms_t    parms;

	parms.memsize = 24*1024*1024;
	parms.membase = malloc (parms.memsize);
	parms.basedir = ".";

	COM_InitArgv (argc, argv);

	parms.argc = com_argc;
	parms.argv = com_argv;
	Host_Init (&parms);
	
	Sys_Init();

	oldtime = Sys_FloatTime() -0.1;
	while (aptMainLoop())
	{
		time = Sys_FloatTime();
		separation_distance = osGet3DSliderState();
		Host_Frame (time - oldtime);
		oldtime = time;
	}
	gfxExit();
	return 0;
}
void Player::Init(int argc, char *argv[]) {
	static bool init = false;
	frames = 0;

	if (init) return;

	// Display a nice version string
	std::stringstream header;
	std::string addtl_ver(PLAYER_ADDTL);
	header << "EasyRPG Player " << PLAYER_VERSION;
	if (!addtl_ver.empty())
		header << " " << addtl_ver;
	header << " started";
	Output::Debug(header.str().c_str());

	unsigned int header_width = header.str().length();
	header.str("");
	header << std::setfill('=') << std::setw(header_width) << "=";
	Output::Debug(header.str().c_str());

#ifdef GEKKO
	// Init libfat (Mount SD/USB)
	if (!fatInitDefault()) {
		Output::Error("Couldn't mount any storage medium!");
	}
#elif defined(_3DS)
	// Starting debug console
	gfxInitDefault();
	consoleInit(GFX_BOTTOM, NULL);

	APT_SetAppCpuTimeLimit(30);
	if (osGetKernelVersion() <  SYSTEM_VERSION(2, 48, 3)) khaxInit(); // Executing libkhax just to be sure...
	consoleClear();

	// Check if we already have access to csnd:SND, if not, we will perform a kernel privilege escalation
	Handle csndHandle = 0;
	use_dsp = false;
#ifndef FORCE_DSP
	srvGetServiceHandleDirect(&csndHandle, "csnd:SND");
	if (csndHandle) {
		Output::Debug("csnd:SND has been selected as audio service.");
		svcCloseHandle(csndHandle);
	} else {
		Output::Debug("csnd:SND is unavailable...");
#endif
		srvGetServiceHandleDirect(&csndHandle, "dsp::DSP");
		if (csndHandle) {
			Output::Debug("dsp::DSP has been selected as audio service.");
			use_dsp = true;
			svcCloseHandle(csndHandle);
		} else {
			Output::Error("dsp::DSP is unavailable. Please dump a DSP firmware to use EasyRPG Player. If the problem persists, please report us the issue.");
		}
#ifndef FORCE_DSP
	}
#endif

	fsInit();
	sdmcInit();
#ifndef CITRA3DS_COMPATIBLE
	romfsInit();
#endif

	hidInit();

	// Enable 804 Mhz mode if on N3DS
	bool isN3DS;
	APT_CheckNew3DS(&isN3DS);
	if (isN3DS) {
		osSetSpeedupEnable(true);
	}
#endif

#if (defined(_WIN32) && defined(NDEBUG) && defined(WINVER) && WINVER >= 0x0600)
	InitMiniDumpWriter();
#endif

	srand(time(NULL));

	ParseCommandLine(argc, argv);

#ifdef EMSCRIPTEN
	Output::IgnorePause(true);

	// Create initial directory structure in our private area
	// Retrieve save directory from persistent storage
	EM_ASM(

		FS.mkdir("easyrpg");
		FS.chdir("easyrpg");

		var dirs = ['Backdrop', 'Battle', 'Battle2', 'BattleCharSet', 'BattleWeapon', 'CharSet', 'ChipSet', 'FaceSet', 'Frame', 'GameOver', 'Monster', 'Movie', 'Music', 'Panorama', 'Picture', 'Sound', 'System', 'System2', 'Title', 'Save'];
		dirs.forEach(function(dir) { FS.mkdir(dir) });

		FS.mount(IDBFS, {}, 'Save');

		FS.syncfs(true, function(err) {
		});
	);
Esempio n. 4
0
int main(int argc, char** argv) {
#ifdef _3DS
	UNUSED(_mPerfShutdown);
    gfxInitDefault();
    osSetSpeedupEnable(true);
	consoleInit(GFX_BOTTOM, NULL);
	if (!allocateRomBuffer()) {
		return 1;
	}
#elif defined(__SWITCH__)
	UNUSED(_mPerfShutdown);
	gfxInitDefault();
	consoleInit(NULL);
#else
	signal(SIGINT, _mPerfShutdown);
#endif
	int didFail = 0;

	struct mLogger logger = { .log = _log };
	mLogSetDefaultLogger(&logger);

	struct PerfOpts perfOpts = { false, false, false, 0, 0, 0, false };
	struct mSubParser subparser = {
		.usage = PERF_USAGE,
		.parse = _parsePerfOpts,
		.extraOptions = PERF_OPTIONS,
		.opts = &perfOpts
	};

	struct mArguments args = {};
	bool parsed = parseArguments(&args, argc, argv, &subparser);
	if (!args.fname) {
		parsed = false;
	}
	if (!parsed || args.showHelp) {
		usage(argv[0], PERF_USAGE);
		didFail = !parsed;
		goto cleanup;
	}

	if (args.showVersion) {
		version(argv[0]);
		goto cleanup;
	}

	if (perfOpts.savestate) {
		_savestate = VFileOpen(perfOpts.savestate, O_RDONLY);
		free(perfOpts.savestate);
	}

	_outputBuffer = malloc(256 * 256 * 4);
	if (perfOpts.csv) {
		puts("game_code,frames,duration,renderer");
	}
	if (perfOpts.server) {
		didFail = !_mPerfRunServer(args.fname, &args, &perfOpts);
	} else {
		didFail = !_mPerfRunCore(args.fname, &args, &perfOpts);
	}
	free(_outputBuffer);

	if (_savestate) {
		_savestate->close(_savestate);
	}
	cleanup:
	freeArguments(&args);

#ifdef _3DS
	gfxExit();
	acExit();
#elif defined(__SWITCH__)
	gfxExit();
#endif

	return didFail;
}
Esempio n. 5
0
int main() {
    cfguInit();
    CFGU_GetSystemModel(&MODEL_3DS);
	FILE * file;
	shouldRenderDebug = true;
	if ((file = fopen("settings.bin", "r"))) {
        fread(&shouldRenderDebug,sizeof(bool),1,file);
        fread(&shouldSpeedup,sizeof(bool),1,file);
        osSetSpeedupEnable(shouldSpeedup);
		fclose(file);
	}
    
	sf2d_init();
	csndInit();
	noItem = newItem(ITEM_NULL, 0);
	
	currentMenu = MENU_TITLE;
	currentSelection = 0;
	quitGame = false;

	icons = sfil_load_PNG_buffer(icons2_png, SF2D_PLACE_RAM);
	font = sfil_load_PNG_buffer(Font_png, SF2D_PLACE_RAM);
	bottombg = sfil_load_PNG_buffer(bottombg_png, SF2D_PLACE_RAM);
	
	dirtColor[0] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 0)); 
	dirtColor[1] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 1)); 
	dirtColor[2] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 2)); 
	dirtColor[3] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 3)); 
	dirtColor[4] = SWAP_UINT32(sf2d_get_pixel(icons, 16, 4)); 

	loadSound(&snd_playerHurt, "resources/playerhurt.raw");
	loadSound(&snd_playerDeath, "resources/playerdeath.raw");
	loadSound(&snd_monsterHurt, "resources/monsterhurt.raw");
	loadSound(&snd_test, "resources/test.raw");
	loadSound(&snd_pickup, "resources/pickup.raw");
	loadSound(&snd_bossdeath, "resources/bossdeath.raw");
	loadSound(&snd_craft, "resources/craft.raw");
	
	bakeLights();
	
	int i;
	for (i = 0; i < 5; ++i) {
		minimap[i] = sf2d_create_texture(128, 128, TEXFMT_RGBA8,
				SF2D_PLACE_RAM);
		sf2d_texture_tile32(minimap[i]);
	}
	
	sf2d_set_vblank_wait(true);

	sf2d_set_clear_color(0xFF000000);

	k_up.input = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP;
	k_down.input = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN;
	k_left.input = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT;
	k_right.input = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT;
	k_attack.input = KEY_A | KEY_B | KEY_L | KEY_ZR;
	k_menu.input = KEY_X | KEY_Y | KEY_R | KEY_ZL;
	k_pause.input = KEY_START;
	k_accept.input = KEY_A;
	k_decline.input = KEY_B;
	k_delete.input = KEY_X;
	k_menuNext.input = KEY_R;
	k_menuPrev.input = KEY_L;

	if ((file = fopen("btnSave.bin", "rb"))) {
		fread(&k_up.input, sizeof(int), 1, file);
		fread(&k_down.input, sizeof(int), 1, file);
		fread(&k_left.input, sizeof(int), 1, file);
		fread(&k_right.input, sizeof(int), 1, file);
		fread(&k_attack.input, sizeof(int), 1, file);
		fread(&k_menu.input, sizeof(int), 1, file);
		fread(&k_pause.input, sizeof(int), 1, file);
		fread(&k_accept.input, sizeof(int), 1, file);
		fread(&k_decline.input, sizeof(int), 1, file);
		fread(&k_delete.input, sizeof(int), 1, file);
		fread(&k_menuNext.input, sizeof(int), 1, file);
		fread(&k_menuPrev.input, sizeof(int), 1, file);
		fclose(file);
	}
	
	if ((file = fopen("lastTP.bin", "r"))) {
		char fnbuf[256];
		fgets(fnbuf, 256, file); // get directory to texturepack
		loadTexturePack(fnbuf);   
		fclose(file);
	}

	tickCount = 0;
	initRecipes();
	defineTables();
	while (aptMainLoop()) {
		++tickCount;
		hidScanInput();
		tickKeys(hidKeysHeld(), hidKeysDown());

		if (quitGame) break;

		if (initGame > 0) setupGame(initGame == 1 ? true : false);

		if (currentMenu == 0) {
			tick();
			sf2d_start_frame(GFX_TOP, GFX_LEFT);

			offsetX = xscr;
			offsetY = yscr;
			sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //RGBA8(12, 12, 12, 255)); //You might think "real" black would be better, but it actually looks better that way
			renderLightsToStencil();

			renderBackground(xscr, yscr);
			renderEntities(player.x, player.y, &eManager);
			renderPlayer();
			
			resetStencilStuff();
			offsetX = 0;
			offsetY = 0;
			
			if(shouldRenderDebug){
			    sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(), player.x, player.y, eManager.lastSlot[currentLevel]);
			    drawText(fpsstr, 2, 225);
            }
			
			sf2d_end_frame();

            sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
                if(!shouldRenderMap){
                    sf2d_draw_texture(bottombg, 0, 0);
                    renderGui();
                } else {
                    renderZoomedMap();
                }
            sf2d_end_frame();
		} else {
			tickMenu(currentMenu);
			renderMenu(currentMenu, xscr, yscr);
		}

		sf2d_swapbuffers();
	}

	freeRecipes();

	freeLightBakes();
	sf2d_free_texture(icons);
	sf2d_free_texture(minimap[0]);
	sf2d_free_texture(minimap[1]);
	sf2d_free_texture(minimap[2]);
	sf2d_free_texture(minimap[3]);
	sf2d_free_texture(minimap[4]);
	freeSounds();
	csndExit();
    cfguExit();
	sf2d_fini();
	return 0;
}
Esempio n. 6
0
static int exec_3dsx_actual(const char* path, const char** args, bool appendPath){
	struct stat sBuff; 
	argData_s newProgramArgs;
	unsigned int argChars = 0;
	unsigned int argNum = 0;
	bool fileExists;
	bool inited;
	
	if(path == NULL || path[0] == '\0'){
		errno = EINVAL;
		return -1;
	}
	
	fileExists = stat(path, &sBuff) == 0;
	if(!fileExists){
		errno = ENOENT;
		return -1;
	}
	else if(S_ISDIR(sBuff.st_mode)){
		errno = EINVAL;
		return -1;
	}

	//args the string functions write to the passed string, this will cause a write to read only memory sot the string must be cloned
	memset(newProgramArgs.buf, '\0', sizeof(newProgramArgs.buf));
	newProgramArgs.dst = (char*)&newProgramArgs.buf[1];
	if(appendPath){
		strcpy(newProgramArgs.dst, path);
		newProgramArgs.dst += strlen(path) + 1;
		newProgramArgs.buf[0]++;
		
	}
	while(args[argNum] != NULL){
		strcpy(newProgramArgs.dst, args[argNum]);
		newProgramArgs.dst += strlen(args[argNum]) + 1;
		newProgramArgs.buf[0]++;
		argNum++;
	}
	
	inited = loader_Rosalina.init();
	launch_3dsx = loader_Rosalina.launchFile;
	
	if(!inited){
		inited = loader_Ninjhax2.init();
		launch_3dsx = loader_Ninjhax2.launchFile;
	}

	if(!inited){
		inited = loader_Ninjhax1.init();
		launch_3dsx = loader_Ninjhax1.launchFile;
	}
	
	if(inited){
		osSetSpeedupEnable(false);
		launch_3dsx(path, &newProgramArgs, NULL);
		exit(0);
	}
	
	//should never be reached
	errno = ENOTSUP;
	return -1;
}
Esempio n. 7
0
int main() {

	L = luaL_newstate();
	luaL_openlibs(L);
	luaL_requiref(L, "love", initLove, 1);

	sf2d_init(); // 2D Drawing lib.
	sftd_init(); // Text Drawing lib.
	cfguInit();
	ptmuInit();

	// consoleInit(GFX_BOTTOM, NULL);

	sf2d_set_clear_color(RGBA8(0x0, 0x0, 0x0, 0xFF)); // Reset background color.

	osSetSpeedupEnable(true); // Enables CPU speedup for a free performance boost.

	// Detect if we are running on a .cia, because if we are
	// we load from RomFS rather than the SD Card.
	// TODO: Load RomFS from .3dsx's aswell.

	Result rc = romfsInit();

	romfsExists = (rc) ? false : true;

	// Change working directory

	if (romfsExists) {

		chdir("romfs:/");

	} else {

		char cwd[256];
		getcwd(cwd, 256);
		char newCwd[261];

		strcat(newCwd, cwd);
		strcat(newCwd, "game");
		chdir(newCwd);

	}

	luaL_dobuffer(L, boot_lua, boot_lua_size, "boot"); // Do some setup Lua side.

	// If main.lua exists, execute it.
	// If not then just load the nogame screen.

	if (fileExists("main.lua")) {
		if (luaL_dofile(L, "main.lua")) displayError();
	} else {
		if (luaL_dobuffer(L, nogame_lua, nogame_lua_size, "nogame")) displayError();
	}
	
	if (luaL_dostring(L, "love.timer.step()")) displayError();

	if (luaL_dostring(L, "if love.load then love.load() end")) displayError();

	while (aptMainLoop()) {

		if (shouldQuit) {

			if (forceQuit) break;

			bool shouldAbort = false;

			// lua_getfield(L, LUA_GLOBALSINDEX, "love");
			// lua_getfield(L, -1, "quit");
			// lua_remove(L, -2);

			// if (!lua_isnil(L, -1)) {

			// 	lua_call(L, 0, 1);
			// 	shouldAbort = lua_toboolean(L, 1);
			// 	lua_pop(L, 1);

			// }; TODO: Do this properly.

			if (luaL_dostring(L, "if love.quit then love.quit() end")) displayError();

			if (!shouldAbort && !errorOccured) break;

		} // Quit event

		if (!errorOccured) {

			if (luaL_dostring(L,
				"love.keyboard.scan()\n"
				"love.timer.step()\n"
				"if love.update then love.update(love.timer.getDelta()) end")) {
					displayError();
			}

			// Top screen
			// Left side

			sf2d_start_frame(GFX_TOP, GFX_LEFT);

				if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError();

			sf2d_end_frame();

			// Right side

			if (is3D) {

				sf2d_start_frame(GFX_TOP, GFX_RIGHT);

					if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError();

				sf2d_end_frame();

			}

			// Bot screen

			sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);

				if (luaL_dostring(L, "if love.draw then love.draw() end")) displayError();

			sf2d_end_frame();

			luaL_dostring(L, "love.graphics.present()");

		} else {

			hidScanInput();
			u32 kTempDown = hidKeysDown();
			if (kTempDown & KEY_START) {
				forceQuit = true;
				shouldQuit = true;
			}

			char *errMsg = lua_tostring(L, -1);

			sf2d_start_frame(GFX_TOP, GFX_LEFT);

				lua_getfield(L, LUA_GLOBALSINDEX, "love");
				lua_getfield(L, -1, "errhand");
				lua_remove(L, -2);

				if (!lua_isnil(L, -1)) {

					lua_pushstring(L, errMsg);
					lua_call(L, 1, 0);

				}

			sf2d_end_frame();

			sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);

				lua_getfield(L, LUA_GLOBALSINDEX, "love");
				lua_getfield(L, -1, "errhand");
				lua_remove(L, -2);

				if (!lua_isnil(L, -1)) {

					lua_pushstring(L, errMsg);
					lua_call(L, 1, 0);

				}

			sf2d_end_frame();

			luaL_dostring(L, "love.graphics.present()");

		}

	}

	luaL_dostring(L, "love.audio.stop()");

	lua_close(L);

	sftd_fini();
	sf2d_fini();
	cfguExit();
	ptmuExit();

	if (soundEnabled) ndspExit();
	if (romfsExists) romfsExit();

	return 0;

}
Esempio n. 8
0
int main()
{
   static char load_filename[512];
    char    *romname = NULL;
	float audioStart; // this is a float to count the half sample per frame needed ho have precise timing
	u32 audioTarget, audioEnd;

    srvInit();
    aptInit();
    hidInit();

	APT_CheckNew3DS(&isN3DS);
	
	if(isN3DS) 
		osSetSpeedupEnable(true);

	get_config_path();

	sprintf(savename, "%s/Handy3ds.cfg", config_base_path);  // using savename char buffer to save memory
	do_config(savename);

	handy_3ds_video_init();

    sprintf(bios_path_and_name, "%s/%s", config_bios_path, "lynxboot.img");

    // Call filebrowser
       if(gui_LoadFile(load_filename)!= -1)  {
            romname = (char *)&load_filename;
            do {
                hidScanInput();
            } while (hidKeysHeld());
        } else {
			handy_3ds_quit();
        }

    // Primary initalise of Handy - should be called AFTER _Init() but BEFORE handy_3ds_video_setup()
    handy_3ds_core_init(romname);

    // Initialise Handy 3ds video 
    handy_3ds_video_setup(1, 0, 0, 32, LynxScale, 0, 0);

    // Initialise Handy 3ds audio
    printf("\nInitialising 3DS Audio...     ");
    gAudioEnabled = handy_3ds_audio_init();

    printf("[DONE]\n");


    // Setup of Handy Core video
    handy_3ds_video_reinit(32);

    printf("Starting Lynx Emulation...\n");
	
    bool touched = false;
    audioStart =  gAudioBufferPointer;  // both should be 0 at this point

	// initialize timers
	u64 tickcurr, syncticknext,synctickres; 
	u64 fpsticknext,fpstickres;
	int frameSyncPeriod;

	if(isN3DS) 
		frameSyncPeriod = 1;
	else	
		frameSyncPeriod = 12;

	fpstickres= TICKS_PER_SEC; 
	synctickres = TICKS_PER_FRAME * frameSyncPeriod; // on o3ds the sync is every 12 frame, i.e. 5 times every sec
	tickcurr=svcGetSystemTick();
	fpsticknext = tickcurr + fpstickres;
	syncticknext = tickcurr + synctickres;
	int fpscnt = 0, synccnt = 0;
	
	gThrottleMaxPercentage = isN3DS?100:50; //  !! TO DO: check if 50 is the best value.

    while(!emulation)
    {
        // Initialise Handy button events
        int OldKeyMask, KeyMask = mpLynx->GetButtonData();
        OldKeyMask = KeyMask;

        // Getting events for keyboard and/or joypad handling
        hidScanInput();
        if (hidKeysHeld() & KEY_TOUCH) {
            touched = true;
        } else {
            if (touched) {
				handy_3ds_audio_pause();
                gui_Run();
                KeyMask = 0;
                touched = false;
//				audioStart =  gAudioBufferPointer;
                do {
                    hidScanInput();
                } while (hidKeysHeld());

				gThrottleMaxPercentage = isN3DS?100:50; //  !! Loading a savestate overrides this value, so we force it again exiting menu

				fpscnt = 0;
				synccnt = 0;
				tickcurr=svcGetSystemTick();
				fpsticknext = tickcurr + fpstickres;
				syncticknext = tickcurr + synctickres;
            } else {
                touched = false;
            }
        }
        KeyMask = handy_3ds_on_key_down(hidKeysHeld(), KeyMask);

        // Check if there are handling events and then update the Handy button events.
        if (OldKeyMask != KeyMask)
            mpLynx->SetButtonData(KeyMask);

        // Update TimerCount
        gTimerCount++;

        while( handy_3ds_update() )
        {
            
            //!!
            hidScanInput();
            u32 held = hidKeysHeld();
            if (held & KEY_SELECT) {
//				handy_3ds_video_quit();
//				handy_3ds_audio_quit();
//              exit(EXIT_SUCCESS);   //break;
				touched = true; // enter menu
            }
            //!!
 
           
            if(!gSystemHalt)
            {
				if (!handy_3ds_audio_getstate()) {
					audioStart=0.0; // reset counter
					gAudioBufferPointer = 0; // reset buffer. really not needed since we set it to 0 in handy_3ds_audio_pause().
				}	

				// increase sound samples counter - 367,5 samples per frame at 60 fps
                audioEnd =  (int)(audioStart + 367.5) % HANDY_AUDIO_BUFFER_SIZE;
				 // filling 1 half of the buffer, roughly enough for slow frames on o3DS without risk of buffer head to reach the tail during the 10 frames before resync.
                audioTarget =  (int)(audioStart + HANDY_AUDIO_BUFFER_SIZE/2.1) % HANDY_AUDIO_BUFFER_SIZE;
				if (audioTarget>audioStart)
				  while (gAudioBufferPointer<audioTarget) mpLynx->Update();  
                else
				  while ((gAudioBufferPointer>audioStart)||(gAudioBufferPointer<audioTarget)) mpLynx->Update();
				  
				if(Handy_cfg_Throttle && Handy_cfg_Sound && gAudioEnabled) {
					if (handy_3ds_audio_getstate())
						handy_3ds_audio_callback(audioStart, (int)(audioTarget-audioStart));  
					else
						handy_3ds_audio_start(22050, audioStart);  
				}	
				audioStart = audioEnd;
            }
            else
            {
                printf("gSystemHalt : %ld\n", gSystemHalt);
                gTimerCount++;
            }
			system_checkPolls();
        }

// Timing

		fpscnt++;
		synccnt++;

		if (Handy_cfg_Throttle) {
			if (synccnt==frameSyncPeriod){
				svcSleepThread((syncticknext - svcGetSystemTick()) / TICKS_PER_NSEC); 
			}
		}

		tickcurr=svcGetSystemTick();
 		
		if (tickcurr >= syncticknext) {
			syncticknext += synctickres;
			synccnt = 0;
		} 
		if (tickcurr >= fpsticknext) {
			fpsticknext += fpstickres;
			fps_counter = fpscnt;
			fpscnt = 0;
		} 

    }   // while(!emulation)

	osSetSpeedupEnable(true);
	return 0;
}