예제 #1
0
static void frontend_ctr_deinit(void *data)
{
   (void)data;
#ifndef IS_SALAMANDER
   global_t *global   = global_get_ptr();
   global->verbosity = true;

#ifdef HAVE_FILE_LOGGER
   if (global->log_file)
      fclose(global->log_file);
   global->log_file = NULL;
#endif

   wait_for_input();

   csndExit();
   gfxExit();

#if 0
   sdmcExit();
   fsExit();
   hidExit();
   aptExit();
   srvExit();
#endif
#endif
}
예제 #2
0
void exitServices() {
    if (titlemenuIsUpdating) {
        //Stop the title menu loading process, causing the thread to exit
        cancelTitleLoading();

        //Wait a little bit (two seconds) longer to allow the thread to actually terminate
        svcSleepThread(2000000000ULL);
    }

    if (titleThreadNeedsRelease) {
        releaseTitleThread();
    }

    // cleanup whatever we have to cleanup
	audio_stop();
	csndExit();

    freeThemeImages();
    netloader_exit();
    titlesExit();
    ptmuExit();
    acExit();
    hidExit();
    gfxExit();
    closeSDArchive();
    exitFilesystem();
    aptExit();
    srvExit();
}
예제 #3
0
int main(int argc, char **argv)

{
	
	//Initialize some sounds for high quality sounding moans and SCREAMS from the ACTION!
	srvInit();
	aptInit();
	hidInit();
	csndInit();
	gfxInitDefault();
	consoleInit(GFX_TOP, NULL);



	printf("\x1b[1;5HGuess who is the freshest squid around?");
	wait(10000);
	printf("           ");
	printf("\x1b[5;19H\x1b[32m\ Marie Squid\x1b[0m\n");
	printf("\x1b[16;3HPress Start to know that such fresh exists.");
	printf("\x1b[17;3HPress A to get INTO IT!");

	

	// Main loop
	while (aptMainLoop())
	{
		//Scan all the inputs. This should be done once for each frame mostly for the shoots
		hidScanInput();
		

		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
		hidScanInput();
		u32 kDown = hidKeysDown();
		if (kDown & KEY_START){   //PRESS START TO RETURN TO HBL
		}
		if (kDown & KEY_A){   // PRESS A TO PLAY
			audio_load("squit.bin");
		}
		
		
		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();

		//Wait for VBlank
		gspWaitForVBlank();
	}

	// Exit services... I know you want to come back...

	audio_stop();
	audio_stop();
	csndExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
예제 #4
0
void pm_3ds_sound_quit(void)
{
		CSND_SetPlayState(0x8, 0);//Stop audio playback.
		csndExecCmds(0);

   if (stream) {
		linearFree(stream);
    }
	csndExit();
}
예제 #5
0
void Audio_DeInit()
{
	if (Audio_Type == 1)
	{
		CSND_SetPlayState(8, 0);
		CSND_SetPlayState(9, 0);

		csndExecCmds(0);
		csndExit();
	}
	isPlaying = false;
}
예제 #6
0
void S_Exit() {
	Result ret;
	if (!audio_initialized) {
		return;
	}

	S_StopMusic();
	S_Stop();
	MIX_exit();
	mus_exit();
	//flush csnd command buffers
	csndExecCmds(true);
	csndExit();
	//svcSleepThread(5000000000LL);
}
예제 #7
0
static void frontend_ctr_deinit(void *data)
{
   extern PrintConsole* currentConsole;
   Handle lcd_handle;
   u8 not_2DS;
   (void)data;
#ifndef IS_SALAMANDER
   global_t *global   = global_get_ptr();
   global->verbosity = true;

#ifdef HAVE_FILE_LOGGER
   if (global->log_file)
      fclose(global->log_file);
   global->log_file = NULL;
#endif

   if(gfxBottomFramebuffers[0] == (u8*)currentConsole->frameBuffer)
      wait_for_input();

   CFGU_GetModelNintendo2DS(&not_2DS);
   if(not_2DS && srvGetServiceHandle(&lcd_handle, "gsp::Lcd") >= 0)
   {
      u32 *cmdbuf = getThreadCommandBuffer();
      cmdbuf[0] = 0x00110040;
      cmdbuf[1] = 2;
      svcSendSyncRequest(lcd_handle);
      svcCloseHandle(lcd_handle);
   }

   exitCfgu();
   csndExit();
   gfxExit();

#if 0
   sdmcExit();
   fsExit();
   hidExit();
   aptExit();
   srvExit();
#endif
#endif
}
예제 #8
0
int main()
{
	sf2d_init(); //Graphics Load
	csndInit(); //Audio Load
	
	TouhouController touhou_controller = touhou_controller_init(); //Create Touhou Game	

    while (aptMainLoop()) { //Program loop

		if (touhou_controller->flag_exit == 1) break; //Exit Application
		touhou_controller_handle_state(touhou_controller);
		
		

		
		
	}
	//sleep(1000); //ZZZ Code to let audio finish
	csndExit(); //Audio Exit
	sf2d_fini(); //Graphics Exit
    return 0;
}
예제 #9
0
int main()
{
    // Inits
    srvInit();
    aptInit();
    hidInit();
    bool stop = 0;


    csndInit();//start Audio Lib
    u32 kDown;

    while (aptMainLoop()) {

        hidScanInput();
        kDown = hidKeysDown();
        if (kDown & KEY_START) {  //PRESS START TO RETURN TO HBL
            stop=1;
        }
        if (kDown & KEY_A) {  // PRESS A TO PLAY
            audio_load("audio/original_raw.bin");
        }
        if (stop) {
            break;
        }
    }

    audio_stop();
    audio_stop();
    csndExit();

    hidExit();
    aptExit();
    srvExit();

    return 0;
}
예제 #10
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;
}
예제 #11
0
파일: sfx.c 프로젝트: gatuno/ThinIce3DS
void exitSound (void) {
	if (soundEnabled) csndExit();
}
예제 #12
0
int main()
{
	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);
	
	//consoleInit(GFX_BOTTOM, NULL);
   // printf("Press 'Start' to exit.\n");

	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");
    
    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(0xFF);
	
	/* Default inputs */
	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;
    FILE * file;
    
    /* If btnSave exists, then use that. */
    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);
        fclose(file);
    }
	
	//screenShot = false;
	
    tickCount=0;
    initRecipes();
    defineTables();
	while (aptMainLoop()) {
		++tickCount;
		hidScanInput();
		tickKeys(hidKeysHeld(),hidKeysDown());

		//if (quitGame || hidKeysHeld() & KEY_SELECT) break;
		if (quitGame) break;
		//if (hidKeysDown() & (KEY_L | KEY_R)) screenShot = true;
	//	else screenShot = false;
        
        if(initGame > 0) setupGame(initGame == 1 ? true : false);
        
        if(currentMenu == 0){
            tick();
            sprintf(fpsstr, " FPS: %.0f, X:%d, Y:%d, E:%d", sf2d_get_fps(),player.x, player.y,eManager.lastSlot[currentLevel]);
		    sf2d_start_frame(GFX_TOP, GFX_LEFT);
                if(currentLevel == 0){ 
                    sf2d_draw_texture_part_scale(minimap[1],(-xscr/3)-256,(-yscr/3)-32,0,0,128,128,12.5,7.5);
                    sf2d_draw_rectangle(0,0,400,240, 0xDFDFDFAF);
                }
	            offsetX = xscr;offsetY = yscr;
		        renderBackground(xscr,yscr);
		        renderEntities(player.x, player.y, &eManager);
		        renderPlayer();
	            offsetX = 0;offsetY = 0;
		        renderItemWithText(player.p.activeItem, 10, 205);
		       // drawText(debugText,2,208);
		        drawText(fpsstr,2,225);
		    sf2d_end_frame();
		      
		    sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);	
		        if(currentLevel == 0 && airWizardHealthDisplay > 0){ 
                    sprintf(bossHealthText, "BOSS: %.0f%%", ((float)airWizardHealthDisplay/2000.0)*100);
                    drawText(bossHealthText,2,225);
                }
		        renderGui();
                sf2d_draw_texture(minimap[currentLevel], 192, 112);//y:56
            sf2d_end_frame();
        } else{ 
            tickMenu(currentMenu);
            renderMenu(currentMenu,xscr,yscr);
        }
        
		sf2d_swapbuffers();
	}
	
    freeRecipes();
	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();
	sf2d_fini();
	return 0;
}
예제 #13
0
int main()
{
   // Initialize services
   srvInit();
   aptInit();
   hidInit(NULL);
   ptmInit();
   gfxInitDefault();
   // consoleInit(GFX_TOP, NULL);
   csndInit();
   // fsInit();
   // sdmcInit();

   chdir("sdmc:/");

   void *device = gfxCreateDevice(240, 320);
   gfxMakeCurrent(device);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);

   glTranslatef(0.5f, 0.5f, 0.0f);
   glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
   glTranslatef(-0.5f, -0.5f, 0.0f);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glGenTextures(1, &play_button);
   glGenTextures(1, &pause_button);
   glGenTextures(1, &loop_button);
   glGenTextures(1, &loop_disable_button);
   glGenTextures(1, &power_icon);

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   int x, y, n;
   u8* image_data = stbi_load_from_memory(play_3_png, play_3_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, play_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(pause_2_png, pause_2_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, pause_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(loop_png, loop_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, loop_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(loop_disable_png, loop_disable_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, loop_disable_button);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   image_data = stbi_load_from_memory(power_png, power_png_size, &x, &y, &n, 4);
   glBindTexture(GL_TEXTURE_2D, power_icon);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
   stbi_image_free(image_data);

   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   void *top_device = gfxCreateDevice(240, 400);
   gfxMakeCurrent(top_device);
   initfont_goth();
   initfont_anita();
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);

   glTranslatef(0.5f, 0.5f, 0.0f);
   glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
   glTranslatef(-0.5f, -0.5f, 0.0f);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glEnable(GL_BLEND);
   glEnable(GL_TEXTURE_2D);

   int frames = 0;
   int channel = 0x8;


   while (aptMainLoop())
   {
      gspWaitForVBlank();
      hidScanInput();
      gfxMakeCurrent(top_device);
      glClear(GL_COLOR_BUFFER_BIT);
      glLoadIdentity();
      glScalef(1.0/400.0, 1.0/240.0, 1.0);
      state_man();
      gfxFlush(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL));
      u8 plevel;
      u8 charge;
      PTMU_GetBatteryLevel(NULL, &plevel);
      PTMU_GetBatteryChargeState(NULL, &charge);
      if (plevel != power_level) {
         power_level = plevel;
         // draw_ui = true;
      }
      if (charge != is_charging) {
         is_charging = charge;
         //draw_ui = true;
      }

      gfxMakeCurrent(device);
      u8* fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
      render();
      gfxFlush(fb);
      // Your code goes here

      u32 kDown = hidKeysDown();
      if (kDown & KEY_START)
         break; // break in order to return to hbmenu

      // Flush and swap framebuffers
      if (audiobuf && !paused) {
         if(frames >= 50) {
            frames = 0;
            int n = 0;
            if (decode_mode == AUDIO_MODE_VORBIS) {
               n = stb_vorbis_get_samples_short_interleaved(v, 2, audiobuf, Samples * 2);
            } else {
               while (audiobuf_index < Samples * 2) {
                  n = FLAC__stream_decoder_process_single(FLAC_decoder);
                  if (FLAC__stream_decoder_get_state(FLAC_decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) break;
               }
               audiobuf_index = 0;
            }

            if(n == 0) {
               if (decode_mode == AUDIO_MODE_VORBIS) {
                  stb_vorbis_close(v);
               } else {
                  FLAC__stream_decoder_delete(FLAC_decoder);
               }
               linearFree(audiobuf);
               audiobuf = NULL;
               v = NULL;
               FLAC_decoder = NULL;
               if (loop_flag) play_file_from_filename(currently_playing);
            }

            GSPGPU_FlushDataCache(NULL, (u8*)audiobuf, audiobuf_size);
            if (channel == 0x8) channel = 0x6;
            if (channel == 0x6) channel = 0x8;
            csndPlaySound(SOUND_CHANNEL(channel), SOUND_ONE_SHOT | SOUND_LINEAR_INTERP | SOUND_FORMAT_16BIT, Samples * 2, 10.0, 0.0, (u32*)audiobuf, (u32*)audiobuf, audiobuf_size);

         }
         frames++;
      }

      gfxFlushBuffers();
      gfxSwapBuffersGpu();
   }

   // Exit services
   if (FLAC_decoder) {
      FLAC__stream_decoder_delete(FLAC_decoder);
   }
   csndExit();
   gfxExit();
   ptmExit();
   hidExit();
   aptExit();
   srvExit();
   return 0;
}
예제 #14
0
파일: main.c 프로젝트: yuriks/mgba
int main() {
	hasSound = !csndInit();

	rotation.d.sample = _sampleRotation;
	rotation.d.readTiltX = _readTiltX;
	rotation.d.readTiltY = _readTiltY;
	rotation.d.readGyroZ = _readGyroZ;

	stream.postVideoFrame = 0;
	stream.postAudioFrame = 0;
	stream.postAudioBuffer = _postAudioBuffer;

	if (!allocateRomBuffer()) {
		return 1;
	}

	if (hasSound) {
		audioLeft = linearAlloc(AUDIO_SAMPLES * sizeof(int16_t));
		audioRight = linearAlloc(AUDIO_SAMPLES * sizeof(int16_t));
	}

	sf2d_init();
	sf2d_set_clear_color(0);
	tex = sf2d_create_texture(256, 256, TEXFMT_RGB565, SF2D_PLACE_RAM);
	memset(tex->data, 0, 256 * 256 * 2);

	sdmcArchive = (FS_archive) {
		ARCH_SDMC,
		(FS_path) { PATH_EMPTY, 1, (const u8*)"" },
		0, 0
	};
	FSUSER_OpenArchive(0, &sdmcArchive);

	logFile = VFileOpen("/mgba.log", O_WRONLY | O_CREAT | O_TRUNC);
	struct GUIFont* font = GUIFontCreate();

	if (!font) {
		goto cleanup;
	}

	struct GBAGUIRunner runner = {
		.params = {
			320, 240,
			font, "/",
			_drawStart, _drawEnd, _pollInput,
			0, 0,

			GUI_PARAMS_TRAIL
		},
		.setup = _setup,
		.teardown = 0,
		.gameLoaded = _gameLoaded,
		.gameUnloaded = _gameUnloaded,
		.prepareForFrame = 0,
		.drawFrame = _drawFrame,
		.pollGameInput = _pollGameInput
	};
	GBAGUIInit(&runner, 0);
	GBAGUIRunloop(&runner);
	GBAGUIDeinit(&runner);

cleanup:
	linearFree(renderer.outputBuffer);

	if (logFile) {
		logFile->close(logFile);
	}

	sf2d_free_texture(tex);
	sf2d_fini();

	if (hasSound) {
		linearFree(audioLeft);
		linearFree(audioRight);
	}
	csndExit();
	return 0;
}
예제 #15
0
파일: main.cpp 프로젝트: Voka/lpp-3ds
int main(int argc, char **argv)
{
	srvInit();	
	aptInit();
	gfxInitDefault();
	acInit();
	cfguInit();
	httpcInit();
	ptmuInit();
	hidInit();
	irrstInit();
	aptOpenSession();
	Result ret=APT_SetAppCpuTimeLimit(30);
	aptCloseSession();
	fsInit();
	ftp_state = false;
	isTopLCDOn = true;
	isBottomLCDOn = true;
	Handle fileHandle;
	u64 size;
	u32 bytesRead;
	int restore;
	
	// Check user build and enables kernel access
	if (nsInit()==0){
		CIA_MODE = true;
		nsExit();
	}else CIA_MODE = false;
	isNinjhax2 = false;
	if (!hbInit()) khaxInit();
	else isNinjhax2 = true;
	
	// Select Audio System (csnd:SND preferred)
	if (csndInit() == 0){
		csndAccess = true;
		csndExit();
	}else csndAccess = false;
	
	// Init Audio-Device
	int i = 0;
	for (i=0;i < 32; i++){
		audioChannels[i] = false;
		if (!isNinjhax2 && (i < 0x08))  audioChannels[i] = true;
		else if (csndAccess && (i < 0x08)) audioChannels[i] = true;
	}
	
	// Set main script
	char path[256];
	if (argc > 0){
		int latest_slash = 0;
		int i=5;
		while (argv[0][i]  != '\0'){
			if (argv[0][i] == '/') latest_slash = i;
			i++;
		}
		strcpy(path,&argv[0][5]);
		path[latest_slash-5] = 0;
		strcpy(start_dir,path);
		strcpy(cur_dir,path); // Set current dir
		strcat(path,"/index.lua");
	}else{
		strcpy(start_dir,"/");
		strcpy(cur_dir,"/"); // Set current dir for GW Mode
		strcpy(path,"/index.lua");
	}
	
	while(aptMainLoop())
	{
		restore=0;		
		char error[2048];		
		
		// Load main script
		FS_Path filePath=fsMakePath(PATH_ASCII, path);
		FS_Archive script=(FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}};
		Result ret = FSUSER_OpenFileDirectly(&fileHandle, script, filePath, FS_OPEN_READ, 0x00000000);
		if (!ret){
			FSFILE_GetSize(fileHandle, &size);
			buffer = (unsigned char*)(malloc((size+1) * sizeof (char)));
			FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size);
			buffer[size]=0;
			FSFILE_Close(fileHandle);
			svcCloseHandle(fileHandle);
			errMsg = runScript((const char*)buffer, true);
			free(buffer);
		}else errMsg = "index.lua file not found.";
		
		// Force LCDs power on
		if ((!isTopLCDOn) || (!isBottomLCDOn)){
			gspLcdInit();
			if (!isTopLCDOn) GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_TOP);
			if (!isBottomLCDOn) GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTTOM);
			gspLcdExit();
			isTopLCDOn = true;
			isBottomLCDOn = true;
		}
		
		// Fake error to force interpreter shutdown
		if (strstr(errMsg, "lpp_exit_04")) break;
			
		if (ftp_state) ftp_exit();
		ftp_state = false;
		int connfd;
		while (restore==0){
			gspWaitForVBlank();
			RefreshScreen();
			ClearScreen(0);
			ClearScreen(1);
			strcpy(error,"Error: ");
			strcat(error,errMsg);
			if (ftp_state){ 
				u32 ip=(u32)gethostid();
				char ip_address[64];
				strcat(error,"\n\nPress A to restart\nPress B to exit\nPress Y to enable FTP server\n\nFTP state: ON\nIP: ");
				sprintf(ip_address,"%lu.%lu.%lu.%lu", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
				strcat(error,ip_address);
				strcat(error,"\nPort: 5000");
				if(connfd<0)connfd=ftp_getConnection();
				else{
					int ret=ftp_frame(connfd);
					if(ret==1) connfd=-1;
				}
			}else strcat(error,"\n\nPress A to restart\nPress B to exit\nPress Y to enable FTP server\n\nFTP state: OFF");
			DebugOutput(error);
			hidScanInput();
			if(hidKeysDown() & KEY_A){
				strcpy(cur_dir,start_dir);
				restore=1;
			}else if(hidKeysDown() & KEY_B){
				restore=2;
			}else if(hidKeysDown() & KEY_Y){
				if (!ftp_state){
					u32 wifiStatus;
					if ((u32)ACU_GetWifiStatus(&wifiStatus) !=  0xE0A09D2E){
						if (wifiStatus != 0){
							ftp_init();
							connfd = -1;
							ftp_state = true;
						}
					}
				}
			}
			
			gfxFlushBuffers();
			gfxSwapBuffers();
		}
		if (ftp_state) ftp_exit();
		if (isCSND){
			if (csndAccess) csndExit();
			else ndspExit();
			isCSND = false;
		}
		if (restore==2){
			break;
		}
	}