bool aptMainLoop() { while(1) { //if(__system_runflags&RUNFLAG_APTWORKAROUND)__handle_notification(); switch(aptGetStatus()) { case APP_RUNNING: return true; case APP_EXITING: return false; case APP_SUSPENDING: aptReturnToMenu(); break; case APP_APPLETSTARTED: aptAppletStarted(); break; case APP_APPLETCLOSED: aptAppletClosed(); break; case APP_PREPARE_SLEEPMODE: aptSignalReadyForSleep(); // Fall through default: //case APP_NOTINITIALIZED: //case APP_SLEEPMODE: aptWaitStatusEvent(); break; } } }
void system_checkPolls() { APP_STATUS status; while((status=aptGetStatus()) != APP_RUNNING) { if(status == APP_SUSPENDING) { aptReturnToMenu(); } else if(status == APP_PREPARE_SLEEPMODE) { aptSignalReadyForSleep(); aptWaitStatusEvent(); } else if (status == APP_SLEEPMODE) { } else if (status == APP_EXITING) { system_cleanup(); exit(0); } gspWaitForVBlank(); } gfxFlushBuffers(); gfxMySwapBuffers(); consoleCheckFramebuffers(); }
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; }
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; }
bool aptMainLoop(void) { while(1) { //if(aptIsCrippled())__handle_notification(); switch(aptGetStatus()) { case APP_RUNNING: return true; case APP_EXITING: aptCallHook(APTHOOK_ONEXIT); return false; case APP_SUSPENDING: aptCallHook(APTHOOK_ONSUSPEND); aptReturnToMenu(); if (aptGetStatus() == APP_RUNNING) aptCallHook(APTHOOK_ONRESTORE); break; case APP_APPLETSTARTED: aptAppletStarted(); break; case APP_APPLETCLOSED: aptAppletClosed(); aptCallHook(APTHOOK_ONRESTORE); break; case APP_PREPARE_SLEEPMODE: aptCallHook(APTHOOK_ONSLEEP); aptSignalReadyForSleep(); // Fall through default: //case APP_NOTINITIALIZED: //case APP_SLEEPMODE: aptWaitStatusEvent(); aptCallHook(APTHOOK_ONWAKEUP); break; } } }
void system_checkPolls() { APT_AppStatus status; while((status=aptGetStatus()) != APP_RUNNING) { if(status == APP_SUSPENDING) { aptReturnToMenu(); } else if(status == APP_PREPARE_SLEEPMODE) { aptSignalReadyForSleep(); aptWaitStatusEvent(); } else if (status == APP_SLEEPMODE) { } else if (status == APP_EXITING) { handy_3ds_quit(); } } }
/* Main function that runs all the stuff */ void gui_MainMenuRun(MENU *menu) { APT_AppStatus status; MENUITEM *mi; done = 0; while(!done) { mi = menu->m + menu->itemCur; // pointer to highlite menu option while((status=aptGetStatus()) != APP_RUNNING) { if(status == APP_SUSPENDING) { aptReturnToMenu(); } else if(status == APP_PREPARE_SLEEPMODE) { aptSignalReadyForSleep(); aptWaitStatusEvent(); } else if (status == APP_SLEEPMODE) { } else if (status == APP_EXITING) { return; } } hidScanInput(); u32 keydown = hidKeysDown(); if (keydown & KEY_A) if(mi->itemOnA != NULL) { // gui_ClearScreen(); (*mi->itemOnA)(); } // B - exit or back to previous menu if (keydown & KEY_B) return; // UP - arrow down if (keydown & KEY_UP) if(--menu->itemCur < 0) menu->itemCur = menu->itemNum - 1; // DOWN - arrow up if (keydown & KEY_DOWN) if(++menu->itemCur == menu->itemNum) menu->itemCur = 0; // LEFT - decrease parameter value if (keydown & KEY_LEFT) { if(mi->itemPar != NULL && *mi->itemPar > 0) *mi->itemPar -= 1; } // RIGHT - increase parameter value if (keydown & KEY_RIGHT) { if(mi->itemPar != NULL && *mi->itemPar < mi->itemParMaxValue) *mi->itemPar += 1; } sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); if(!done) { ShowMenu(menu); // show menu items } sf2d_end_frame(); gui_DrawTopScreen(); sf2d_swapbuffers(); } }
int load_file(char **wildcards, char *result, bool startup) { Handle dirHandle; FS_DirectoryEntry entry; char current_dir_name[MAX__PATH]; char prev_dir_name[MAX__PATH]; char current_dir_short[81]; u32 current_dir_length; u32 total_filenames_allocated; u32 total_dirnames_allocated; char **file_list; char **dir_list; u32 num_files; u32 num_dirs; char *file_name; u32 file_name_length; u32 ext_pos = -1; s32 return_value = 1; u32 current_file_selection; u32 current_file_scroll_value; u32 current_dir_selection; u32 current_dir_scroll_value; u32 current_file_in_scroll; u32 current_dir_in_scroll; u32 current_file_number, current_dir_number; u32 current_column = 0; u32 repeat; u32 i; strcpy(current_dir_name, config_roms_path); strcpy(prev_dir_name, current_dir_name); while(return_value == 1) { current_file_selection = 0; current_file_scroll_value = 0; current_dir_selection = 0; current_dir_scroll_value = 0; current_file_in_scroll = 0; current_dir_in_scroll = 0; total_filenames_allocated = 32; total_dirnames_allocated = 32; file_list = (char **)malloc(sizeof(char *) * 32); dir_list = (char **)malloc(sizeof(char *) * 32); memset(file_list, 0, sizeof(char *) * 32); memset(dir_list, 0, sizeof(char *) * 32); num_files = 0; num_dirs = 0; file_name= (char*) malloc(0x105); FS_Path dirPath = (FS_Path){PATH_ASCII, strlen(current_dir_name)+1, (u8*)current_dir_name}; FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath); // DEBUG printf("Current directory: %s\n", current_dir_name); u32 nread = 0; do { if(dirHandle) FSDIR_Read(dirHandle, &nread, 1, &entry); if(nread) { //(current_file) { strncpy_u2a(file_name, entry.name, 0x105); //utf-16 to ascii function yoinked from blargSNES file_name_length = strlen(file_name); if(((file_name[0] != '.') || (file_name[1] == '.'))) { //if(S_ISDIR(file_info.st_mode)) { //!!!!!!!! if(entry.attributes & FS_ATTRIBUTE_DIRECTORY) { if((strcmp(file_name, "filer") != 0) && (strcmp(file_name, "Nintendo 3DS") != 0) && (strcmp(file_name, "private") != 0)) { dir_list[num_dirs] = (char *)malloc(file_name_length + 1); strcpy(dir_list[num_dirs], file_name); num_dirs++; } } else { // Must match one of the wildcards, also ignore the . if(file_name_length >= 4) { if(file_name[file_name_length - 4] == '.') ext_pos = file_name_length - 4; else if(file_name[file_name_length - 3] == '.') ext_pos = file_name_length - 3; else ext_pos = 0; for(i = 0; wildcards[i] != NULL; i++) { if(!strcasecmp((file_name + ext_pos), wildcards[i])) { file_list[num_files] = (char *)malloc(file_name_length + 1); strcpy(file_list[num_files], file_name); num_files++; break; } } } } } if(num_files == total_filenames_allocated) { file_list = (char **)realloc(file_list, sizeof(char *) * total_filenames_allocated * 2); memset(file_list + total_filenames_allocated, 0, sizeof(char *) * total_filenames_allocated); total_filenames_allocated *= 2; } if(num_dirs == total_dirnames_allocated) { dir_list = (char **)realloc(dir_list, sizeof(char *) * total_dirnames_allocated * 2); memset(dir_list + total_dirnames_allocated, 0, sizeof(char *) * total_dirnames_allocated); total_dirnames_allocated *= 2; } } } while(nread); qsort((void *)file_list, num_files, sizeof(char *), sort_function); qsort((void *)dir_list, num_dirs, sizeof(char *), sort_function); FSDIR_Close(dirHandle); current_dir_length = strlen(current_dir_name); if(current_dir_length > 80) { memcpy(current_dir_short, "...", 3); memcpy(current_dir_short + 3, current_dir_name + current_dir_length - 77, 77); current_dir_short[80] = 0; } else { memcpy(current_dir_short, current_dir_name, current_dir_length + 1); } repeat = 1; if(num_files == 0) current_column = 1; if(num_dirs == 0) current_column = 0; char print_buffer[81]; while(repeat) { sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); //!! sftd_draw_text(font, 0, 4, COLOR_ACTIVE_ITEM, 10, current_dir_short); const char strMsg[] = "[A] Select Rom [X] Run BIOS [Y] Dir up [B] Back"; guitextwidth = sftd_get_text_width(font, 10, strMsg); sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, strMsg); for(i = 0, current_file_number = i + current_file_scroll_value; i < FILE_LIST_ROWS; i++, current_file_number++) { if(current_file_number < num_files) { strncpy(print_buffer,file_list[current_file_number], 30); //38); print_buffer[30] = 0; //38] = 0; if((current_file_number == current_file_selection) && (current_column == 0)) { sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer); } else { sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer); } } } for(i = 0, current_dir_number = i + current_dir_scroll_value; i < FILE_LIST_ROWS; i++, current_dir_number++) { if(current_dir_number < num_dirs) { strncpy(print_buffer,dir_list[current_dir_number], 8); //13); print_buffer[9] = 0; //14] = 0; if((current_dir_number == current_dir_selection) && (current_column == 1)) { sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer); } else { sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer); } } } // Catch input // change to read key state later if (aptGetStatus() == APP_PREPARE_SLEEPMODE) { aptSignalReadyForSleep(); aptWaitStatusEvent(); } else if (aptGetStatus() == APP_SUSPENDING) { aptReturnToMenu(); } hidScanInput(); u32 keydown = hidKeysDown(); if (keydown & KEY_A) { if(current_column == 1) { if(num_dirs != 0) { repeat = 0; strcpy(prev_dir_name, current_dir_name); if (strlen(current_dir_name)>1) strcat(current_dir_name, "/"); strcat(current_dir_name, dir_list[current_dir_selection]); } } else { if(num_files != 0) { repeat = 0; return_value = 0; //strcpy(result, file_list[current_file_selection]); sprintf(result, "%s/%s", current_dir_name, file_list[current_file_selection]); break; } } } if (keydown & KEY_Y) { repeat = 0; char* findpath = strrchr(current_dir_name,'/'); if(findpath > current_dir_name) findpath[0] = '\0'; else findpath[1] = '\0'; } if (keydown & KEY_B ) { return_value = -1; repeat = 0; break; } if (keydown & KEY_X ) { return_value = 1; repeat = 0; break; } if (keydown & KEY_UP) { if(current_column == 0) { if(current_file_selection) { current_file_selection--; if(current_file_in_scroll == 0) { //clear_screen(COLOR_BG); current_file_scroll_value--; } else { current_file_in_scroll--; } } } else { if(current_dir_selection) { current_dir_selection--; if(current_dir_in_scroll == 0) { //clear_screen(COLOR_BG); current_dir_scroll_value--; } else { current_dir_in_scroll--; } } } } if (keydown & KEY_DOWN) { if(current_column == 0) { if(current_file_selection < (num_files - 1)) { current_file_selection++; if(current_file_in_scroll == (FILE_LIST_ROWS - 1)) { //clear_screen(COLOR_BG); current_file_scroll_value++; } else { current_file_in_scroll++; } } } else { if(current_dir_selection < (num_dirs - 1)) { current_dir_selection++; if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) { //clear_screen(COLOR_BG); current_dir_scroll_value++; } else { current_dir_in_scroll++; } } } } if (keydown & KEY_L) { if(current_column == 0) { if(current_file_selection>FILE_LIST_ROWS) { current_file_selection-=FILE_LIST_ROWS; current_file_scroll_value -= FILE_LIST_ROWS; if (current_file_in_scroll>current_file_selection){ //clear_screen(COLOR_BG); current_file_scroll_value=0; current_file_in_scroll=current_file_selection; } } else { current_file_selection=0; current_file_scroll_value=0; current_file_in_scroll=0; } } else { if(current_dir_selection) { current_dir_selection--; if(current_dir_in_scroll == 0) { //clear_screen(COLOR_BG); current_dir_scroll_value--; } else { current_dir_in_scroll--; } } } } if (keydown & KEY_R) { if(current_column == 0) { if(current_file_selection < (num_files - 1 - FILE_LIST_ROWS)) { current_file_selection+=FILE_LIST_ROWS; current_file_scroll_value+=FILE_LIST_ROWS; if (current_file_scroll_value>(num_files - FILE_LIST_ROWS)){ //clear_screen(COLOR_BG); current_file_scroll_value=num_files - FILE_LIST_ROWS; current_file_in_scroll= FILE_LIST_ROWS - (num_files - current_file_selection); } //clear_screen(COLOR_BG); } else { current_file_selection = num_files - 1; current_file_in_scroll = (num_files<=FILE_LIST_ROWS - 1)?num_files:FILE_LIST_ROWS - 1; current_file_scroll_value = (num_files > FILE_LIST_ROWS)?num_files - FILE_LIST_ROWS:0; } } else { if(current_dir_selection < (num_dirs - 1)) { current_dir_selection++; if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) { //clear_screen(COLOR_BG); current_dir_scroll_value++; } else { current_dir_in_scroll++; } } } } if (keydown & KEY_LEFT) { if(current_column == 1) { if(num_files != 0) current_column = 0; } } if (keydown & KEY_RIGHT) { if(current_column == 0) { if(num_dirs != 0) current_column = 1; } } sf2d_end_frame(); gui_DrawTopScreen(); sf2d_swapbuffers(); } // free pointers for(i = 0; i < num_files; i++) free(file_list[i]); free(file_list); for(i = 0; i < num_dirs; i++) free(dir_list[i]); free(dir_list); free(file_name); } return return_value; }