Exemplo n.º 1
0
void exitServices()
{
    gpuExit();
    gfxExit();
    sdmcExit();
    hidExit();
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: Cruel/ctrulib
int main()
{
	initSrv();
	
	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	aptSetupEventHandler();

	APP_STATUS status;
	while((status=aptGetStatus())!=APP_EXITING)
	{
		if(status==APP_RUNNING)
		{
			u32 PAD=hidSharedMem[7];
			
			u32 regData=PAD|0x01000000;
			GSPGPU_WriteHWRegs(NULL, 0x202A04, (u32*)&regData, 4);

			renderEffect();
			swapBuffers();
			copyBuffer();
		}
		svc_sleepThread(16666666);
	}

	hidExit();
	gspGpuExit();
	aptExit();
	svc_exitProcess();
	return 0;
}
Exemplo n.º 3
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();
}
Exemplo n.º 4
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
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
void __attribute__((weak)) __appExit(void)
{
    // Cleanup default services.
    fsdevUnmountAll();
    fsExit();
    timeExit();
    hidExit();
    appletExit();
    smExit();
}
Exemplo n.º 7
0
	void __appExit() {
		// Exit services
		pxiDevExit();
		sdmcExit();
		fsExit();
		hidExit();
		gfxExit();
		aptExit();
		srvExit();
	}
Exemplo n.º 8
0
void system_cleanup() {
    mgr_save();
    mgr_exit();

    CSND_shutdown();

    fsExit();
    gfxExit();
    hidExit();
    aptExit();
    srvExit();
}
Exemplo n.º 9
0
int main()
{
	srvInit();
	aptInit();
	hidInit(NULL);
	irrstInit(NULL);
	gfxInitDefault();

	yeti_init(
		&yeti,
		(framebuffer_t*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL),
		(framebuffer_t*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL),
		textures, palette, lua
	);

	gfxSet3D(true);

	game_init(&yeti);

	while(aptMainLoop())
	{
		int i;
		for(i=0;i<2;i++)
		{
			yeti.viewport.front = yeti.viewport.back;
			yeti.viewport.back = (framebuffer_t*)gfxGetFramebuffer(GFX_TOP, leftOrRight?GFX_LEFT:GFX_RIGHT, NULL, NULL);

			game_draw(&yeti);

			leftOrRight^=1;
		}

		yetiUpdateKeyboard(&yeti);
		game_tick(&yeti);

		if(hidKeysDown()&KEY_START)break;

		gfxFlushBuffers();
		gfxSwapBuffers();

		gspWaitForEvent(GSPEVENT_VBlank0, true);
	}

	gfxExit();
	irrstExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
Exemplo n.º 10
0
int main()
{
    gfxInitDefault();
    hidInit(NULL);

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

    glViewport(0, 0, 240, 400);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float near = 0.1f;
    float far = 100.0f;
    float fov = 90.0f;
    float aspect = 240.0f / 400.0f;
    float t = tan(fov * 3.14159 / 360.0) * near;
    float b = -t;
    float l = aspect * b;
    float r = aspect * t;
    glFrustumf(l, r, b, t, near, far);
    //3DS' framebuffers are sideways
    glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);

    while (aptMainLoop())
    {
        hidScanInput();

        if (keysDown() & KEY_START)
            break;

        DrawGLScene();

        gfxFlush(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL));
        gfxFlushBuffers();
        gfxSwapBuffersGpu();
        gspWaitForVBlank();
    }

    // Exit services
    gfxExit();
    hidExit();
    return 0;
}
Exemplo n.º 11
0
void handy_3ds_quit(void)
{
    emulation   = -1;

	handy_3ds_video_quit();
	handy_3ds_audio_quit();

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

    exit(EXIT_SUCCESS);

}
Exemplo n.º 12
0
Arquivo: main.c Projeto: codlab/ftpony
int main()
{
	srvInit();	
	aptInit();
	hidInit(NULL);
	irrstInit(NULL);
	gfxInit();

	gfxSet3D(false);

	srand(svcGetSystemTick());

	curQuote=rand()%numQuotes;
	superStr[0]=0;
	ftp_init();

	int connfd=ftp_getConnection();

	APP_STATUS status;
	while((status=aptGetStatus())!=APP_EXITING)
	{
		if(status == APP_RUNNING)
		{
			ftp_frame(connfd);
			drawFrame();

			hidScanInput();
			if(hidKeysDown()&KEY_B)break;
		}
		else if(status == APP_SUSPENDING)
		{
			aptReturnToMenu();
		}
		else if(status == APP_SLEEPMODE)
		{
			aptWaitStatusEvent();
		}
		gspWaitForEvent(GSPEVENT_VBlank0, false);
	}

	ftp_exit();
	gfxExit();
	irrstExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
Exemplo n.º 13
0
int main()
{
	//Grab the status of the app (running, suspending, sleeping, exiting)
	APP_STATUS status;

	//Initialize 3ds services
	srvInit();
	fsInit();
	aptInit();
	gfxInit();
	hidInit(NULL);
	//Setup event handler to listen for changes in status
	aptSetupEventHandler();


	while ((status = aptGetStatus()) != APP_EXITING)
	{

		if (status == APP_RUNNING)
		{
			//If the app is currently in the forground running, execute the program.
			program();
		}
		else if (status == APP_SUSPENDING)
		{
			//If the app is currently suspended in the background, return to the home menu.
			aptReturnToMenu();
		}
		else if (status == APP_SLEEPMODE)
		{
			//If the app is currently suspended in sleep mode, wait.
			aptWaitStatusEvent();
		}

		//Wait for GPU
		gspWaitForVBlank();

	}

	//Close all opened services.
	hidExit();
	gfxExit();
	aptExit();
	srvExit();
	//Kill the process.
	svcExitProcess();
	return 0;
}
Exemplo n.º 14
0
Arquivo: main.c Projeto: ThibG/ctrulib
int main()
{
	Result ret=0;
	httpcContext context;

	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInit();
	//gfxSet3D(true); // uncomment if using stereoscopic 3D
	httpcInit();

	ret = httpcOpenContext(&context, "http://10.0.0.3/httpexample_rawimg.bin", 0);//Change this to your own URL.

	if(ret==0)
	{
		ret=http_download(&context);
		httpcCloseContext(&context);
	}

	// Main loop
	while (aptMainLoop())
	{
		gspWaitForVBlank();
		hidScanInput();

		// Your code goes here

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

		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();
	}

	// Exit services
	httpcExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
Exemplo n.º 15
0
int main()
{
	initSrv();
		
	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	Handle fsuHandle;
	srv_getServiceHandle(NULL, &fsuHandle, "fs:USER");
	FSUSER_Initialize(fsuHandle);

	Handle fileHandle;
	u32 bytesRead;
	FS_archive sdmcArchive=(FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}};
	FS_path filePath=(FS_path){PATH_CHAR, 10, (u8*)"/test.bin"};
	FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)gspHeap, 0x46500);
	FSFILE_Close(fileHandle);

	aptSetupEventHandler();
	
	while(!aptGetStatus())
	{
		u32 PAD=hidSharedMem[7];
		renderEffect();
		swapBuffers();
		copyBuffer();
		u32 regData=PAD|0x01000000;
		GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
		svc_sleepThread(1000000000);
	}

	svc_closeHandle(fsuHandle);
	hidExit();
	gspGpuInit();
	aptExit();
	svc_exitProcess();
	return 0;
}
int main()
{
	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInitDefault();

	// Main loop
	while (aptMainLoop())
	{
		//As nop90 suggested
		getFB();

		//Gets input (keys and touch)
		getInput();

		//Prints the GUI
		printGUI();  

		//Do stuff
		app();

		//Exit code
		if (input & KEY_START) break;
	
		// Flush and swap framebuffers
		gfxFlushBuffers();
		gfxSwapBuffers();

		//Wait for VBlank
		gspWaitForVBlank();

	}

	// Exit services
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	return 0;
}
Exemplo n.º 17
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
}
Exemplo n.º 18
0
s32 main (void) {
	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInitDefault();
	fsInit();
	sdmcInit();
	hbInit();
	qtmInit();
	
	Handle fileHandle;
	u32 bytesRead;
    FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
    FS_path filePath=FS_makePath(PATH_CHAR, "/rxTools.dat");
    Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	if(ret) goto EXIT;
    FSFILE_Read(fileHandle, &bytesRead, 0x20000, 0x14400000, 320*1024);
    FSFILE_Close(fileHandle);
	
	consoleInit(GFX_BOTTOM, NULL);
	if (brahma_init()) {
		quick_boot_firm(1);
		printf("[!] Quickload failed\n");
		brahma_exit();

	} else {
		printf("* BRAHMA *\n\n[!]Not enough memory\n");
		wait_any_key();
	}
  EXIT:
	hbExit();
	sdmcExit();
	fsExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	// Return to hbmenu
	return 0;
}
Exemplo n.º 19
0
s32 main(void) {
	// Initialize services
	srvInit();
	aptInit();
	hidInit(NULL);
	gfxInitDefault();
	gfxSet3D(true);
	fsInit();
	sdmcInit();
	hbInit();
	qtmInit();
	gfxSwapBuffers();

	Handle fileHandle;
	u32 bytesRead;
	FS_archive sdmcArchive = (FS_archive){ ARCH_SDMC, (FS_path){ PATH_EMPTY, 1, (u8*)"" } };
	FS_path filePath = FS_makePath(PATH_CHAR, "/" CODE_PATH);
	Result ret = FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
	if (ret) goto EXIT;
	FSFILE_Read(fileHandle, &bytesRead, 0x14000, 0x14400000, 320 * 1024);
	FSFILE_Close(fileHandle);


	if (brahma_init())
	{
		quick_boot_firm(1);
		brahma_exit();
	}

EXIT:
	hbExit();
	sdmcExit();
	fsExit();
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	// Return to hbmenu
	return 0;
}
Exemplo n.º 20
0
int main() {
    // Initialize services
    srvInit();
    aptInit();
    hidInit(NULL);
    gfxInit();
    //gfxSet3D(true); // uncomment if using stereoscopic 3D
    
    char* a = "";

    // Main loop
    while (aptMainLoop() && strcmp(a, "q") != 0)
    {
        gspWaitForVBlank();
        hidScanInput();

        // Your code goes here

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

        a = bbHandleKeyboardBlocking("");
        
        u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
        memset(fb, 0, 240*400*3);
        tsDrawWord(GFX_TOP, GFX_LEFT, a, 40, 50, 255, 255, 255);

        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    // Exit services
    gfxExit();
    hidExit();
    aptExit();
    srvExit();
    return 0;
}
Exemplo n.º 21
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;
}
Exemplo n.º 22
0
int main() {
    // Initialize services
    srvInit();
    aptInit();
    hidInit(NULL);
    gfxInit();
    CSND_initialize(NULL);
    srand(osGetTime());
    //gfxSet3D(true); // uncomment if using stereoscopic 3D
    
    u8 *audiobuf = linearAlloc(sadloop_bin_size);
    int i;
    for (i=0;i<sadloop_bin_size;i++) {
        memcpy(&audiobuf[i], &sadloop_bin[i], 1);    
    }
    
    bool flip = false;
    u64 nextflip = osGetTime()+500;
    u8 *crow = linearAlloc(crow1_bin_size);
    for (i=0;i<crow1_bin_size;i++) {
        memcpy(&crow[i], &crow1_bin[i], 1);    
    }
    
    CSND_setchannel_playbackstate(0x8, 0);
    CSND_sharedmemtype0_cmdupdatestate(0);
    
    u64 nextsong = osGetTime()+68000;
    CSND_playsound(0x8, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, 22050, (u32*)audiobuf, NULL, sadloop_bin_size, 2, 0);

    char* fact;
    u64 nextfact = osGetTime()+newFact(&fact);
    
    // Main loop
    while (aptMainLoop())
    {
        gspWaitForVBlank();
        hidScanInput();
        u64 now = osGetTime();
        
        
        if (now >= nextsong) {
            nextsong = now+68000;
            
            CSND_playsound(0x8, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, 22050, (u32*)audiobuf, NULL, sadloop_bin_size, 2, 0);
        }
        if (now >= nextflip) {
            nextflip = now+500;
            if (flip) {
                for (i=0;i<crow1_bin_size;i++) {
                    memcpy(&crow[i], &crow1_bin[i], 1);    
                }
                flip = false;
            } else {
                for (i=0;i<crow1_bin_size;i++) {
                    memcpy(&crow[i], &crow2_bin[i], 1);    
                }
                flip = true;
            }
        }
        if (now >= nextfact) {
            nextfact = now+newFact(&fact);
        }
        
        
        u32 kDown = hidKeysDown();
        if (kDown & KEY_START)
            break; // break in order to return to hbmenu
        
        // Please note that the 3DS screens are sideways (thus 240x400 and 240x320)
        u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
        memset(fb, 0, 240*400*3);
        
        tsDrawWord(GFX_TOP, GFX_LEFT, "Fact Crow says:", 30, 180, 255, 255, 255);
        drawFact(fact);
        gfxDrawSprite(GFX_TOP, GFX_LEFT, crow, 37, 37, 138, 30);

        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    CSND_shutdown();
    linearFree(audiobuf);
    
    // Exit services
    gfxExit();
    hidExit();
    aptExit();
    srvExit();
    return 0;
}
Exemplo n.º 23
0
int main()
{
    char level_data_line[20*16];
    LEVELDATA this_level_data = {
        {&level_data_line[0],   &level_data_line[20], &level_data_line[40], &level_data_line[60],
         &level_data_line[80], &level_data_line[100],&level_data_line[120],&level_data_line[140],
         &level_data_line[160],&level_data_line[180],&level_data_line[200],&level_data_line[220],
         &level_data_line[240],&level_data_line[260],&level_data_line[280],&level_data_line[300]},
        19,11
    };
    // Initializations
    srvInit();  // services
    aptInit();  // applets
    hidInit();  // input
	gfxInitDefault();
//	gfxSet3D(true); // uncomment if using stereoscopic 3D
    gfxSetDoubleBuffering(GFX_TOP, true);
    gfxSetDoubleBuffering(GFX_BOTTOM, false);

    PrintConsole /*topScreen, */bottomScreen;
    consoleInit(GFX_BOTTOM, &bottomScreen);
//    consoleInit(GFX_TOP, &topScreen);
    clear_char_stack();
    int level = 0;
    int mode = MODE_INIT;
//    int mode_status  = 0;
    hcount = 0;

int timer = 0;
    // Main loop
    while (aptMainLoop())
    {
        hidScanInput();
        u32 kDown = hidKeysDown();
        u32 kUp   = hidKeysUp();
        u32 kHeld = hidKeysHeld();
        if (kDown & KEY_START){
            break; // break in order to return to hbmenu
        }

        if (mode == MODE_INIT){
//            consoleSelect(&topScreen);
//            printf("\033[2J");
            copyGame(level,&this_level_data);
            gspWaitForVBlank();
            printGame(&this_level_data);
            mode = MODE_GAME;
        }else if (mode == MODE_CLEAR){
            if ((kUp & KEY_A) || (kUp & KEY_B) || (kUp & KEY_X) || (kUp & KEY_Y)){
                level++;
                if (level >= sizeof(level_data)/sizeof(LEVELDATA)) {
                    mode = MODE_ALL_CLEAR;
                }else{
                    mode = MODE_INIT;
                }
            }
            if (level < sizeof(level_data)/sizeof(LEVELDATA)) {
                consoleSelect(&bottomScreen);
                printf("\033[2J");
                printf("\x1b[21;12HStage cleared!!");
                printf("\x1b[23;12HPush A to next Next Stage");
            }
        }else if (mode == MODE_ALL_CLEAR){
            level = 0;
            consoleSelect(&bottomScreen);
            printf("\033[2J");
            printf("\x1b[21;12HGame cleared!!!");
            printf("\x1b[23;12HPush Start to exit game");
            mode = MODE_NULL;
        }else if (mode == MODE_GAME){

        // Your code goes here


#ifdef DEBUG
consoleSelect(&bottomScreen);
if (timer%10==0){
//if (1    != 0){printf("\x1b[10;12HkUp  =%08x",(unsigned int)kUp);}
//if (1    != 0){printf("\x1b[11;12HkDown=%08x",(unsigned int)kDown);}
//if (1    != 0){printf("\x1b[12;12HkHeld=%08x",(unsigned int)kHeld);}
//printf("\x1b[22;12HKEY_CPAD_UP=%x",KEY_UP);
//printf("\x1b[23;12HKEY_CPAD_DN=%x",KEY_DOWN);
printf("\x1b[20;12HRest: [SELECT]");
printf("\x1b[22;12HExit: [START]");
printf("\x1b[24;12HTime: %08d",timer);
}
timer++;
#endif
            if (kDown != 0 || kHeld != 0){
                if (kDown & KEY_SELECT){
                    mode = MODE_INIT;
                }else{
                    moveMan(kDown, kHeld,level,&this_level_data);
                    if(checkCleared(&this_level_data,level)==0){ mode = MODE_CLEAR;}
                    gspWaitForVBlank();
                    draw_char_stack(this_level_data,spriteData, sizeof(spriteData)/sizeof(SPRITEDATA));
                }
            }else{
                gspWaitForVBlank();
            }
        }

        // Flush and swap framebuffers
        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    gfxExit();
    hidExit();
    aptExit();
    srvExit();
	return 0;
}
Exemplo n.º 24
0
int main(void) {
	irmemloc = (u32*) memalign(0x1000, 0x1000);
	resultStartup = IRU_Initialize(irmemloc, 0x1000);
	resultSetBit = IRU_SetBitRate(0xB);
	recordedIR = (u32*) malloc(REC_SIZE * NUM_OF_BUTTONS); //Currently there are 11(NUM_OF_BUTTONS) recordable buttons. (start switches mode)
	recentIR = (u32*) calloc(REC_SIZE, 0x1); //Whatever was last viewed in memory
	resultGetStatus = irucmd_GetTransferState(&StatusIR);
	srvInit();        // services
	aptInit();        // applets
	hidInit(NULL);    // input
	gfxInitDefault(); // gfx
	
	gfxSetDoubleBuffering(GFX_TOP, true);
	gfxSetDoubleBuffering(GFX_BOTTOM, true);
	bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
	top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
	
	if(setjmp(exitJmp)) goto exit;
	
	clearScreen();
	gfxFlushBuffers();
	gfxSwapBuffers();
	
	bool startToggle = false;
	bool upToggle = false;
	bool downToggle = false;
	
	while(aptMainLoop()) {
		bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
		top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
		hidScanInput();
		irrstScanInput();
		
		u32 kHeld = hidKeysHeld();
		circlePosition circlePad;
		circlePosition cStick;
		hidCstickRead(&cStick);
		hidCircleRead(&circlePad);
		touchPosition touch;
		touchRead(&touch);
		
		clearScreen();
		
		char keys[30] = "ABXY URDL SEST LR ZLZR";
		
		if(kHeld & KEY_A) {
			keys[0] = '*';
			ir('A');
		}
		if(kHeld & KEY_B) {
			keys[1] = '*';
			ir('B');
		}
		if(kHeld & KEY_X) {
			keys[2] = '*';
			ir('X');
		}
		if(kHeld & KEY_Y) {
			keys[3] = '*';
			ir('Y');
		}
		if(kHeld & KEY_DUP) {
			keys[5] = '*';
			if(upToggle) {
				if(bitrate < 18) {
					bitrate++;
					resultSetBit = IRU_SetBitRate(bitrate);
				}
				upToggle = false;
			}
		} else {
			upToggle = true;
		}
		if(kHeld & KEY_DRIGHT) {
			keys[6] = '*';
			ir('R');
		}
		if(kHeld & KEY_DDOWN) {
			keys[7] = '*';
			if(downToggle) {
				if(bitrate > 3) {
					bitrate--;
					resultSetBit = IRU_SetBitRate(bitrate);
				}
				downToggle = false;
			}
		} else {
			downToggle = true;
		}
		if(kHeld & KEY_DLEFT) {
			keys[8] = '*';
			ir('L');
		}
		if(kHeld & KEY_SELECT) {
			keys[10] = '*';
			keys[11] = '*';
			ir('S');
		}
		if(kHeld & KEY_START) {
			keys[12] = '*';
			keys[13] = '*';
			if(startToggle) {
				rec = !rec;
				startToggle = false;
			}
		} else {
			startToggle = true;
		}
		if(kHeld & KEY_L) {
			keys[15] = '*';
			ir('L');
		}
		if(kHeld & KEY_R) {
			keys[16] = '*';
			ir('R');
		}
		if(kHeld & KEY_ZL) {
			keys[18] = '*';
			keys[19] = '*';
			ir('1');
		}
		if(kHeld & KEY_ZR) {
			keys[20] = '*';
			keys[21] = '*';
			ir('2');
		}
		drawString(top, 10, 10, keys);
		drawString(top, 10, 20, "Circle Pad   x: %04+d, y: %04+d", circlePad.dx, circlePad.dy);
		drawString(top, 10, 30, "Touch        x: %04d, y: %04d", touch.px, touch.py );
		if(resultStartup == 0) {
			drawString(top, 10, 40, "IR started!");
		} else {
			drawString(top, 10, 40, "IR Init     |Error: %x", resultStartup);
		}
		if(resultSetBit == 0) {
			drawString(top, 10, 50, "IR bit rate works!");
		} else {
			drawString(top, 10, 50, "IR bit rate |Error: %x", resultSetBit);
		}
		if(resultTransferIR == 0) {
			drawString(top, 10, 60, "IR transfer works!");
		} else {
			drawString(top, 10, 60, "IR transfer |Error: %x", resultTransferIR);
		}
		irucmd_GetTransferState(&StatusIR);
		drawString(top, 10, 70, "IR mode: %x", StatusIR);
		drawString(top, 10, 80, "Got %d bytes", TransIR);
		drawString(top, 10, 90, "Bitrate: %d (see IRU:SetBitRate)", bitrate);
		printMemory(NULL,REC_SIZE,10, false); //might be dangerous?
		
		if(rec) {
			drawString(top, 10, 210, "Recording mode active.");
		}else{
			drawString(top, 10, 210, "Sending mode active.");
		}
		drawString(top, 10, 220, "Start + Select to exit.");
		
		if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1);
		gfxFlushBuffers();
		gspWaitForVBlank();
		gfxSwapBuffers();
	}
	
	exit: //I should really be fixing these.
	
	free(recordedIR); //Crashes the program. Should free on release.
	free(irmemloc); //Crashes the program. Should free on release.
	free(recentIR); //Crashes the program. Should free on release.
	
	IRU_Shutdown(); //Crashes the program. Should free on release.
	gfxExit();
	hidExit();
	aptExit();
	srvExit();
	
	return 0;
}
Exemplo n.º 25
0
int main(int argc, char **argv)
{
    (void) argc, (void) argv;

    Result res = MAKERESULT(RL_SUCCESS, RS_SUCCESS, 0, RD_SUCCESS);

    gfxInitDefault();

    PrintConsole top;
    consoleInit(GFX_TOP, &top);

    util_debug_init();
    consoleSelect(&top);

    if (R_FAILED(res = acInit())) {
        util_presult("acInit failed", res);
        goto ac_failure;
    }

    u32 wifi = 0;
    if (R_FAILED(res = ACU_GetWifiStatus(&wifi))) {
        util_presult("ACU_GetWifiStatus failed", res);
        fprintf(stderr, "Did you enable Wifi?\n");
        goto wifi_check_failure;
    }
    if (!wifi) {
        fprintf(stderr, "Wifi disabled.\n");
        goto wifi_check_failure;
    }

    if ((sock_ctx = memalign(SOCU_BUFSZ, SOCU_ALIGN)) == NULL) {
        util_perror("Allocating SOC buffer");
        res = MAKERESULT(
            RL_PERMANENT, RS_OUTOFRESOURCE, RM_SOC, RD_OUT_OF_MEMORY);
        goto soc_alloc_failure;
    }

    if (R_FAILED(res = socInit(sock_ctx, SOCU_BUFSZ))) {
        util_presult("socInit failed", res);
        goto soc_failure;
    }

    if (R_FAILED(res = hidInit())) {
        util_presult("hidInit failed", res);
        goto hid_failure;
    }
    if (R_FAILED(res = HIDUSER_EnableAccelerometer())) {
        util_presult("Failed to enable accelerometer", res);
        goto accel_failure;
    }

    if (R_FAILED(res = ctrollerInit())) {
        fprintf(stderr, "Do you have a valid IP in\n '" CFG_FILE "'?");
        goto failure;
    }

    bool isHomebrew = envIsHomebrew();
    printf("Press %s to exit.\n", isHomebrew ? EXIT_DESC : "HOME");
    fflush(stdout);

    while (aptMainLoop()) {

        if (isHomebrew) {
            if (hidKeysHeld() == EXIT_KEYS) {
                res = RL_SUCCESS;
                break;
            }
        }

        if (ctrollerSendHIDInfo()) {
            util_perror("Sending HID info");
            fflush(stderr);
            for (int i = 3; i > 0; i--) {
                util_debug_printf("\rRetrying in %ds... ", i);
                svcSleepThread(1000000000L);
            }
            util_debug_printf("\rRetrying now.\x1b[K\n");
        }

        gspWaitForVBlank();

        gfxFlushBuffers();
        gfxSwapBuffers();
    }

    puts("Exiting...");
failure:
    HIDUSER_DisableAccelerometer();
accel_failure:
    hidExit();
hid_failure:
    socExit();
soc_failure:
    free(sock_ctx);
soc_alloc_failure:
wifi_check_failure:
    acExit();
ac_failure:
    if (R_FAILED(res)) {
        util_hang(res);
    }
    gfxExit();
    return res;
}
Exemplo n.º 26
0
// Main part of the coding, where everything works (or not)
int main(void) {
    init();

    // Main loop
    while (aptMainLoop()) {

        // Verify button presses
        hidScanInput();

        // Unsigned variables for different types of button presses
        u32 kDown = hidKeysDown();
        u32 kHeld = hidKeysHeld();
        // u32 kUp = hidKeysUp();

        // Exit homebrew
        if (kDown & KEY_START) {
            break;
        }

        // Activate first easter egg
        else if (kDown & KEY_SELECT) {
            easterEgg = !easterEgg;
        }

        // Change pages for the easterEgg/debug menu.
        else if (kDown & KEY_R) {
            if (++easterPage > MAX_PAGE) easterPage = 0;
        }
        else if (kDown & KEY_L) {
            if (--easterPage < 0) easterPage = MAX_PAGE;
        }


        timerStep();

        // If no movement, set the sprite timer to 0
        if (kDown & KEY_UP || kDown & KEY_DOWN || kDown & KEY_LEFT || kDown & KEY_RIGHT) {
            sprTimer = 0;
        }

        // Reset horizontal and vertical speeds
        vsp = 0;
        hsp = 0;

        // Player movement (pretty easy to understand)
        // TODO: Would it be possible to make this less... iffy?
        if (kHeld & KEY_UP) {
            if (!(kHeld & KEY_DOWN)) {
                vsp = -.5; // Vertical speed to negative .5
                playerDir = BACK; // Player direction = back
            }
        }

        if (kHeld & KEY_DOWN) {
            vsp = .5; // Vertical speed to .5
            playerDir = FORWARD; // Player direction = up
        }

        if (kHeld & KEY_LEFT) {
            if (!(kHeld & KEY_RIGHT)) {
                hsp = -.5; // Vertical speed to negative .5
                playerDir = LEFT; // Player direction = left
            }
        }

        if (kHeld & KEY_RIGHT) {
            hsp = .5; // Vertical speed to .5
            playerDir = RIGHT; // Player direction = right
        }

        // Diagonal movement speed fix
        if (vsp != 0) {
            if (hsp != 0) {
                vsp *= .8;
                hsp *= .8;
            }
        }

        // Movement calculation... AND proper room colision.
        // TODO: Consider a function for translating and/or clamping coordinates directly?
        player_pos.x = fclamp(player_pos.x + hsp * dt,
                              rooms[room].collision[0].x,
                              rooms[room].collision[1].x);

        player_pos.y = fclamp(player_pos.y + vsp * dt,
                              rooms[room].collision[0].y,
                              rooms[room].collision[1].y);

        // Scrolling calculation.
        // TODO: Make these constants better/customizable.
        if (player_pos.x - camera_pos.x >= 300) {
            camera_pos.x = player_pos.x - 300;
        }
        else if (player_pos.x - camera_pos.x <= 100) {
            camera_pos.x = player_pos.x - 100;
        }
        camera_pos.x = fclamp(camera_pos.x, 0, rooms[room].scroll_max.x);

        if (player_pos.y - camera_pos.y >= 200) {
            camera_pos.y = player_pos.y - 200;
        }
        else if (player_pos.y - camera_pos.y <= 50) {
            camera_pos.y = player_pos.y - 50;
        }
        camera_pos.y = fclamp(camera_pos.y, 0, rooms[room].scroll_max.y);

        // Player sprites
        if (hsp == 0 && vsp == 0) curr_tex = tex_arr_friskWalk[playerDir][0];

        else curr_tex = tex_arr_friskWalk[playerDir][(int)floor(sprTimer)];

        // Sprite animation timer
        // TODO: Why .15 * .03 * actual time?
        sprTimer += (.03 * dt);

        while (sprTimer >= 4) {
            sprTimer -= 4;
        }

        if (!next_exit){
            if (roomTimer < 255) {
                roomTimer = fmin(roomTimer + (4 * dt), 255);
            }
            next_exit = exit_room(room, &player_pos);
        }
        else {
            roomTimer -= 4 * dt;
            if (roomTimer <= 0) {
                room = next_exit->room_id;
                player_pos = next_exit->entrance;
                next_exit = NULL;
                roomTimer = 0;
            }
        }

        render();

        // Swap sf2d framebuffers and wait for VBlank
        sf2d_swapbuffers();
    }

    // Free images/textures/fonts from memory

    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            sf2d_free_texture(tex_arr_friskWalk[i][j]);
        }
    }

    for (int i = 0; i < 3; ++i) {
        sf2d_free_texture(rooms[i].bg.tex);
    }

    sftd_free_font(font);

    // Exit services
    sf2d_fini();
    sftd_fini();
    sound_stop(home);
    audio_stop();
    hidExit();
    aptExit();
    srvExit();

    return 0;
}
Exemplo n.º 27
0
Arquivo: main.c Projeto: Tybus/3Dfrogr
int main()
{
	initSrv();

	aptInit(APPID_APPLICATION);

	gspGpuInit();

	hidInit(NULL);

	Handle fsuHandle;
	srv_getServiceHandle(NULL, &fsuHandle, "fs:USER");
	FSUSER_Initialize(fsuHandle);

	aptSetupEventHandler();
    init_map();
    int i;
    int j;
    int p=4;
    int d=0;
    int q;
    int frogx = 0;
    int frogy = 0;
    int carx[6][9];
    int logx[5][6];

    // Cant use rand.
    //for(d=1;d<6;d++){
    //    while(p>4){
    //        p = rand();
    //    }
    //    carx[d]=26+p;

     for(d=0;d<8;d++){
        carx[0][d]=26;
        if(d<5){
            logx[0][d]=26;
        }
        d++;
    }
    for(d=1;d<8;d++){
        if(d<5){
            logx[0][d]=0;
        }
        carx[0][d]=0;
        d++;
    }
    for(q=0;q<8;q++){

        for(d=1; d<6; d++){
            if(q<5){
                if(d<5){
                    logx[d][q]=26+p+6;
                }
            }
            carx[d][q]=26+p +6;
            p=p+6;
        }
        p=0;
        q++;
    }
    p= 0;
    for(q=1;q<8;q++){

        for(d=1;d<5;d++){
            if(q<5){
                if(d<5){
                    logx[d][q] = p-6;
                }
            }
            carx[d][q]=p-6;
            p=p-6;
        }
        p=0;
        q++;
     }

	while(!aptGetStatus()){
		u32 PAD=hidSharedMem[7];
		if (PAD == BUTTON_UP){
            frogy+= 1;
            }
        else if (PAD == BUTTON_DOWN){
            frogy+= -1;
            }
        else if (PAD == BUTTON_LEFT){
            frogx+= -1;
            }
        else if (PAD == BUTTON_RIGHT){
            frogx+=1;
            }

		u32 regData=PAD|0x01000000;
		init_map();
        for(i=0;i<6;i++){
            for(j=0;j<8;j++){
                draw_car(carx[i][j],15+j*15);
                if(i<5){
                    if(j<5){
                        draw_logs(logx[i][j],150+j*15);
                        }
                }
            }
        }
        draw_frog(frogx,frogy);
		//Checks Colition
        for(i=0;i<6;i++){
            for(j=0;j<8;j++){
                if(frogy==j+1){
                    if(frogx==carx[i][j]){
                        frogy =0;
                        frogx =0;
                    }
                }
            }
        }
        //Checks if frog in poodle
         if(frogy >9){
            for(i=0;i<5;i++){
                for(j=0;j<5;j++){
                    if(frogy==j+10){
                        if(frogx==logx[i][j] || frogx==logx[i][j]+1 || frogx==logx[i][j]+2){
                                frogx= frogx -1;
                        }
                        else{
                            frogx =0;
                            frogy =0;
                            }
                    }
                }
            }
        }
        //reinitialize the cars :D
        // Cant use f*****g rand
        //for(p=0;p<6;p++){
        //    if(carx[p]==0){
        //        d=5;
        //        while(d>4){
        //            d = rand();
        //        }
        //        carx[p]= 26+d;
        //     }
        //    else {
        //    carx[p]=carx[p]-1;
        //    }
        //}
        for(i=0;i<6;i++){
            for(j=0;j<9;j=j+2){
                if(i<5){
                    if(j<5){
                        if(logx[i][j]==0){
                            logx[i][j]=26;
                        }
                        else{
                        logx[i][j]=logx[i][j]-1;
                        }
                    }
                }
                if(carx[i][j]==0){
                    carx[i][j] =26;
                }
                else{
                    carx[i][j]=carx[i][j]-1;
                }
            }
        }
        for(i=0;i<6;i++){
            for(j=1;j<9;j=j+2){
                if(i<5){
                    if(j<5){
                        if(logx[i][j]==26){
                            logx[i][j]=0;
                        }
                        else{
                        logx[i][j]=logx[i][j]+1;
                        }
                    }
                }
                if(carx[i][j]==26){
                    carx[i][j]=0;
                    }
                else{
                    carx[i][j]= carx[i][j]+1;
                }
            }
        }
		copyBuffer();
		swapBuffers();
		GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
        svc_sleepThread(220000000);


    }

	svc_closeHandle(fsuHandle);
	hidExit();
	gspGpuInit();
	aptExit();
	svc_exitProcess();
	return 0;
}
Exemplo n.º 28
0
int main(int argc, const char* argv[])
{
    /* Sadly svchax crashes too much, so only allow install mode when running as a CIA
    // Trigger svchax so we can install CIAs
    if(argc > 0) {
        svchax_init(true);
        if(!__ctr_svchax || !__ctr_svchax_srv) {
            bSvcHaxAvailable = false;
            //printf("Failed to acquire kernel access. Install mode disabled.\n");
        }
    }
    */
    
    // argc is 0 when running as a CIA, and 1 when running as a 3dsx
    if (argc > 0)
    {
        bSvcHaxAvailable = false;
    }

    u32 *soc_sharedmem, soc_sharedmem_size = 0x100000;
    gfxInitDefault();
    consoleInit(GFX_TOP, NULL);

    httpcInit(0);
    soc_sharedmem = (u32 *)memalign(0x1000, soc_sharedmem_size);
    socInit(soc_sharedmem, soc_sharedmem_size);
    sslcInit(0);
    hidInit();
    acInit();
    cfguInit();

    if (bSvcHaxAvailable)
    {
        amInit();
        AM_InitializeExternalTitleDatabase(false);
    }

    init_menu(GFX_TOP);

    // Make sure all CIAngel directories exists on the SD card
    mkpath("/CIAngel", 0777);
    mkpath("/CIAngel/tmp/", 0777);
    loadConfig();
    
    // Set up the reading of json
    check_JSON();
    load_JSON_data();
    
    menu_main();

    if (bSvcHaxAvailable)
    {
        amExit();
    }

    cfguExit();
    acExit();
    gfxExit();
    hidExit();
    httpcExit();
    socExit();
    sslcExit();
}
Exemplo n.º 29
0
/*----------------*/
int main(int argc, char *argv[])
{
    APP_STATUS status;

    srvInit();
    aptInit(APPID_APPLICATION);
    gfxInit();
    hidInit(NULL);
    fsInit();

    svcCreateEvent(&new_cmd_event, 0);
    svcCreateEvent(&cmd_done_event, 0);
    svcCreateThread(&thread, cmd_thread_func, 0x0,
                    (u32*)((char*)thread_stack + sizeof(thread_stack)),
                    0x31, 0xfffffffe);

    int where = 0;
    u32 ret = SOC_Initialize((u32*)0x08000000, 0x48000);

    if(ret == 0) {
        listen_socket = socket(AF_INET, SOCK_STREAM, 0);
        if(listen_socket == -1) {
            where = 1;
            ret = SOC_GetErrno();
        }
        else {
            u32 tmp = fcntl(listen_socket, F_GETFL);
            fcntl(listen_socket, F_SETFL, tmp | O_NONBLOCK);

            struct sockaddr_in addr;
            addr.sin_family = AF_INET;
            addr.sin_port = __swap16(PORT);
            addr.sin_addr.s_addr = INADDR_ANY;

            ret = bind(listen_socket, (struct sockaddr *)&addr, sizeof(addr));
            if(ret != 0) {
                where = 2;
                ret = SOC_GetErrno();
            }
            else {
                ret = listen(listen_socket, 1);
                if(ret == -1) {
                    ret = SOC_GetErrno();
                    where = 3;
                }
            }
        }

    }

    u32 it = 0;
    int accept_errno = 0;
    int first = 1;


    while((status = aptGetStatus()) != APP_EXITING)
    {
        hidScanInput();
        consoleClear(&top);

        print(&top, "newver\n");
        print(&top, "ret: %08x, where: %d\n", ret, where);
        print(&top, "frame: %08x\n", it);
        u32 ip = gethostid();
        print(&top, "ip: %d.%d.%d.%d\n", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
                
        if(accept_errno != 0) print(&top, "accept returned errno %d\n", accept_errno);

        if(!first) {
            int s = accept(listen_socket, NULL, NULL);
            if(s == -1) {
                int err = SOC_GetErrno();

                if(err != -EWOULDBLOCK)
                    accept_errno = err;
            }
            else {
                sock = s;
                conn_main();
                closesocket(sock);
            }
        }

        it++;
        first = 0;
        if(enable_draw)
            renderFrame(); 

        u32 keys = hidKeysUp();
        if(keys & KEY_A)
            break;
    }

    thread_exit = 1;
    svcSignalEvent(new_cmd_event);
    svcWaitSynchronization(thread, U64_MAX);
    svcCloseHandle(thread);

    svcCloseHandle(new_cmd_event);
    svcCloseHandle(cmd_done_event);

    SOC_Shutdown();
    fsExit();
    hidExit();
    gfxExit();
    aptExit();
    srvExit();
    return 0;
}
Exemplo n.º 30
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;
}