int main() { gfxInitDefault(); consoleInit(GFX_TOP, NULL); Result rc = romfsInit(); if (rc) printf("romfsInit: %08lX\n", rc); else { printf("romfs Init Successful!\n"); printfile("romfs:/folder/file.txt"); // Test reading a file with non-ASCII characters in the name printfile("romfs:/フォルダ/ファイル.txt"); } // Main loop while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu } romfsExit(); gfxExit(); return 0; }
int main(int argc, char **argv) { romfsInit(); #if _3DS_MODE == _3DS_MODE_REPL main_repl(argc, argv); #elif _3DS_MODE == _3DS_MODE_NETLOAD main_netload(argc, argv); #elif _3DS_MODE == _3DS_MODE_ROMFS main_romfs(argc, argv); #elif _3DS_MODE == _3DS_MODE_ARGS main_args(argc, argv); #endif romfsExit(); // ensure all services are exited to be a good citizen mod_citrus_exit_all(); return 0; }
void cleanup() { task_quit_all(); ui_exit(); screen_exit(); socExit(); if(soc_buffer != NULL) { free(soc_buffer); soc_buffer = NULL; } amExit(); httpcExit(); ptmuExit(); acExit(); cfguExit(); romfsExit(); gfxExit(); }
void cleanup() { clipboard_clear(); task_exit(); ui_exit(); screen_exit(); socExit(); if(soc_buffer != NULL) { free(soc_buffer); soc_buffer = NULL; } amExit(); httpcExit(); ptmuExit(); acExit(); cfguExit(); romfsExit(); gfxExit(); }
int main() { gfxInitDefault(); gfxSet3D(false); PrintConsole topConsole, botConsole; consoleInit(GFX_TOP, &topConsole); consoleInit(GFX_BOTTOM, &botConsole); consoleSelect(&topConsole); consoleClear(); state_t current_state = STATE_NONE; state_t next_state = STATE_INITIALIZE; FS_ProductInfo product_info; char exploitname[64] = {0}; char titlename[64] = {0}; char versiondir[64] = {0}; char displayversion[64] = {0}; u32 flags_bitmask = 0; static char top_text[2048]; char top_text_tmp[256]; top_text[0] = '\0'; int firmware_version[6] = {0}; int firmware_selected_value = 0; int selected_slot = 0; int selected_version = 0; u32 selected_remaster = 0; AM_TitleEntry update_title; bool update_exists = false; int version_maxnum = 0; void* payload_buffer = NULL; size_t payload_size = 0; u64 program_id = 0; while(aptMainLoop()) { hidScanInput(); if(hidKeysDown() & KEY_START) break; // transition function if(next_state != current_state) { memset(top_text_tmp, 0, sizeof(top_text_tmp)); switch(next_state) { case STATE_INITIALIZE: strncat(top_text, "Initializing... You may press START at any time\nto return to menu.\n\n", sizeof(top_text) - 1); break; case STATE_INITIAL: strncat(top_text, "Welcome to sploit_installer: SALT edition!\nPlease proceed with caution, as you might lose\ndata if you don't.\n\nPress A to continue.\n\n", sizeof(top_text) - 1); break; case STATE_SELECT_VERSION: snprintf(top_text_tmp, sizeof(top_text_tmp) - 1, "Auto-detected %s version: %s\nD-Pad to select, A to continue.\n\n", titlename, displayversion); break; case STATE_SELECT_SLOT: snprintf(top_text_tmp, sizeof(top_text_tmp) - 1, "Please select the savegame slot %s will be\ninstalled to. D-Pad to select, A to continue.\n", exploitname); break; case STATE_SELECT_FIRMWARE: strncat(top_text, "Please select your console's firmware version.\nOnly select NEW 3DS if you own a New 3DS (XL).\nD-Pad to select, A to continue.\n", sizeof(top_text) - 1); break; case STATE_DOWNLOAD_PAYLOAD: snprintf(top_text, sizeof(top_text) - 1, "%s\n\n\nDownloading payload...\n", top_text); break; case STATE_COMPRESS_PAYLOAD: strncat(top_text, "Processing payload...\n", sizeof(top_text) - 1); break; case STATE_INSTALL_PAYLOAD: strncat(top_text, "Installing payload...\n\n", sizeof(top_text) - 1); break; case STATE_INSTALLED_PAYLOAD: snprintf(top_text_tmp, sizeof(top_text_tmp) - 1, "Done!\n%s was successfully installed.", exploitname); break; case STATE_ERROR: strncat(top_text, "Looks like something went wrong. :(\n", sizeof(top_text) - 1); break; default: break; } if(top_text_tmp[0]) strncat(top_text, top_text_tmp, sizeof(top_text) - 1); current_state = next_state; } consoleSelect(&topConsole); printf("\x1b[0;%dHsploit_installer: SALT edition\n\n\n", (50 - 31) / 2); printf(top_text); // state function switch(current_state) { case STATE_INITIALIZE: { fsInit(); // get an fs:USER session as the game Result ret = srvGetServiceHandleDirect(&save_session, "fs:USER"); if(R_SUCCEEDED(ret)) ret = FSUSER_Initialize(save_session); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get game fs:USER session.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = httpcInit(0); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize httpc.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } OS_VersionBin nver_versionbin, cver_versionbin; ret = osGetSystemVersionData(&nver_versionbin, &cver_versionbin); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the system version.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = cfguInit(); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize cfgu.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } u8 region = 0; ret = CFGU_SecureInfoGetRegion(®ion); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the system region.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } cfguExit(); bool is_new3ds = false; APT_CheckNew3DS(&is_new3ds); firmware_version[0] = is_new3ds; firmware_version[5] = region; firmware_version[1] = cver_versionbin.mainver; firmware_version[2] = cver_versionbin.minor; firmware_version[3] = cver_versionbin.build; firmware_version[4] = nver_versionbin.mainver; u32 pid = 0; ret = svcGetProcessId(&pid, CUR_PROCESS_HANDLE); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the process ID for the current process.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = FSUSER_GetProductInfo(&product_info, pid); selected_remaster = product_info.remasterVersion; if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the product info for the current process.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = APT_GetProgramID(&program_id); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to get the program ID for the current process.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } u64 update_program_id = 0; if(((program_id >> 32) & 0xFFFF) == 0) update_program_id = program_id | 0x0000000E00000000ULL; if(update_program_id) { ret = amInit(); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize AM.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = AM_GetTitleInfo(1, 1, &update_program_id, &update_title); amExit(); if(R_SUCCEEDED(ret)) update_exists = true; } ret = romfsInit(); if(R_FAILED(ret)) { snprintf(status, sizeof(status) - 1, "Failed to initialize romfs for this application (romfsInit()).\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = load_exploitlist_config("romfs:/exploitlist_config", &program_id, exploitname, titlename, &flags_bitmask); if(ret) { snprintf(status, sizeof(status) - 1, "Failed to select the exploit.\n Error code: %08lX", ret); if(ret == 1) strncat(status, " Failed to\nopen the config file in romfs.", sizeof(status) - 1); if(ret == 2) strncat(status, " This title is not supported.", sizeof(status) - 1); next_state = STATE_ERROR; break; } int version_index = 0; u32 this_remaster = 0; char this_displayversion[64] = {0}; while(true) { ret = load_exploitversion(exploitname, &program_id, version_index, &this_remaster, this_displayversion); if(ret) break; if(this_remaster == selected_remaster) { strncpy(displayversion, this_displayversion, 63); selected_version = version_index; } version_index++; } if(version_index == 0) { snprintf(status, sizeof(status) - 1, "Failed to read remaster versions from config."); next_state = STATE_ERROR; break; } version_maxnum = version_index - 1; next_state = STATE_INITIAL; } break; case STATE_INITIAL: { if(hidKeysDown() & KEY_A) { if(version_maxnum != 0) next_state = STATE_SELECT_VERSION; else if(flags_bitmask & 0x10) next_state = STATE_SELECT_FIRMWARE; else next_state = STATE_SELECT_SLOT; } } break; case STATE_SELECT_VERSION: { if(hidKeysDown() & KEY_UP) selected_version++; if(hidKeysDown() & KEY_DOWN) selected_version--; if(hidKeysDown() & KEY_A) { if(flags_bitmask & 0x10) next_state = STATE_SELECT_FIRMWARE; else next_state = STATE_SELECT_SLOT; } if(selected_version < 0) selected_version = 0; if(selected_version > version_maxnum) selected_version = version_maxnum; Result ret = load_exploitversion(exploitname, &program_id, selected_version, &selected_remaster, displayversion); if(ret) { snprintf(status, sizeof(status) - 1, "Failed to read remaster version from config."); next_state = STATE_ERROR; break; } printf((selected_version >= version_maxnum) ? " \n" : " ^\n"); printf(" Selected version: %s \n", displayversion); printf((!selected_version) ? " \n" : " v\n"); } break; case STATE_SELECT_SLOT: { if(hidKeysDown() & KEY_UP) selected_slot++; if(hidKeysDown() & KEY_DOWN) selected_slot--; if(hidKeysDown() & KEY_A) next_state = STATE_SELECT_FIRMWARE; if(selected_slot < 0) selected_slot = 0; if(selected_slot > 2) selected_slot = 2; printf((selected_slot >= 2) ? " \n" : " ^\n"); printf(" Selected slot: %d \n", selected_slot + 1); printf((!selected_slot) ? " \n" : " v\n"); } break; case STATE_SELECT_FIRMWARE: { if(hidKeysDown() & KEY_LEFT) firmware_selected_value--; if(hidKeysDown() & KEY_RIGHT) firmware_selected_value++; if(firmware_selected_value < 0) firmware_selected_value = 0; if(firmware_selected_value > 5) firmware_selected_value = 5; if(hidKeysDown() & KEY_UP) firmware_version[firmware_selected_value]++; if(hidKeysDown() & KEY_DOWN) firmware_version[firmware_selected_value]--; int firmware_maxnum = 256; if(firmware_selected_value == 0) firmware_maxnum = 2; if(firmware_selected_value == 5) firmware_maxnum = 7; if(firmware_version[firmware_selected_value] < 0) firmware_version[firmware_selected_value] = 0; if(firmware_version[firmware_selected_value] >= firmware_maxnum) firmware_version[firmware_selected_value] = firmware_maxnum - 1; if(hidKeysDown() & KEY_A) next_state = STATE_DOWNLOAD_PAYLOAD; int offset = 26; if(firmware_selected_value) { offset += 7; for(int i = 1; i < firmware_selected_value; i++) { offset += 2; if(firmware_version[i] >= 10) offset++; } } printf((firmware_version[firmware_selected_value] < firmware_maxnum - 1) ? "%*s^%*s" : "%*s-%*s", offset, " ", 50 - offset - 1, " "); printf(" Selected firmware: %s %d-%d-%d-%d %s \n", firmware_version[0] ? "New3DS" : "Old3DS", firmware_version[1], firmware_version[2], firmware_version[3], firmware_version[4], regions[firmware_version[5]]); printf((firmware_version[firmware_selected_value] > 0) ? "%*sv%*s" : "%*s-%*s", offset, " ", 50 - offset - 1, " "); } break; case STATE_DOWNLOAD_PAYLOAD: { httpcContext context; static char in_url[512]; static char out_url[512]; snprintf(in_url, sizeof(in_url) - 1, "http://smea.mtheall.com/get_payload.php?version=%s-%d-%d-%d-%d-%s", firmware_version[0] ? "NEW" : "OLD", firmware_version[1], firmware_version[2], firmware_version[3], firmware_version[4], regions[firmware_version[5]]); char user_agent[64]; snprintf(user_agent, sizeof(user_agent) - 1, "salt_sploit_installer-%s", exploitname); Result ret = get_redirect(in_url, out_url, 512, user_agent); if(R_FAILED(ret)) { sprintf(status, "Failed to grab payload url\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = httpcOpenContext(&context, HTTPC_METHOD_GET, out_url, 0); if(R_FAILED(ret)) { sprintf(status, "Failed to open http context\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } ret = download_file(&context, &payload_buffer, &payload_size, user_agent); if(R_FAILED(ret)) { sprintf(status, "Failed to download payload\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } if(flags_bitmask & 0x1) next_state = STATE_COMPRESS_PAYLOAD; else next_state = STATE_INSTALL_PAYLOAD; } break; case STATE_COMPRESS_PAYLOAD: payload_buffer = BLZ_Code(payload_buffer, payload_size, &payload_size, BLZ_NORMAL); next_state = STATE_INSTALL_PAYLOAD; break; case STATE_INSTALL_PAYLOAD: { u32 selected_remaster_version = 0; Result ret = load_exploitconfig(exploitname, &program_id, selected_remaster, update_exists ? &update_title.version : NULL, &selected_remaster_version, versiondir, displayversion); if(ret) { snprintf(status, sizeof(status) - 1, "Failed to find your version of\n%s in the config / config loading failed.\n Error code: %08lX", titlename, ret); if(ret == 1) strncat(status, " Failed to\nopen the config file in romfs.", sizeof(status) - 1); if(ret == 2 || ret == 4) strncat(status, " The romfs config file is invalid.", sizeof(status) - 1); if(ret == 3) { snprintf(status, sizeof(status) - 1, "this update-title version (v%u) of %s is not compatible with %s, sorry\n", update_title.version, titlename, exploitname); next_state = STATE_ERROR; break; } if(ret == 5) { snprintf(status, sizeof(status) - 1, "this remaster version (%04lX) of %s is not compatible with %s, sorry\n", selected_remaster_version, titlename, exploitname); next_state = STATE_ERROR; break; } next_state = STATE_ERROR; break; } if(flags_bitmask & 0x8) { fsUseSession(save_session); Result ret = FSUSER_FormatSaveData(ARCHIVE_SAVEDATA, (FS_Path){PATH_EMPTY, 1, (u8*)""}, 0x200, 10, 10, 11, 11, true); fsEndUseSession(); if(ret) { sprintf(status, "Failed to format savedata.\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } } if(flags_bitmask & 0x2) { Result ret = parsecopy_saveconfig(versiondir, firmware_version[0], selected_slot); if(ret) { sprintf(status, "Failed to install the savefiles with romfs %s savedir.\n Error code: %08lX", firmware_version[0] == 0?"Old3DS" : "New3DS", ret); next_state = STATE_ERROR; break; } } if(flags_bitmask & 0x4) { Result ret = parsecopy_saveconfig(versiondir, 2, selected_slot); if(ret) { sprintf(status, "Failed to install the savefiles with romfs %s savedir.\n Error code: %08lX", "common", ret); next_state = STATE_ERROR; break; } } } { Result ret; if(payload_embed.enabled) { void* buffer = NULL; size_t size = 0; ret = read_savedata(payload_embed.path, &buffer, &size); if(ret) { sprintf(status, "Failed to embed payload\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } if((payload_embed.offset + payload_size + sizeof(u32)) >= size) { sprintf(status, "Failed to embed payload (too large)\n 0x%X >= 0x%X", (payload_embed.offset + payload_size + sizeof(u32)), size); next_state = STATE_ERROR; break; } *(u32*)(buffer + payload_embed.offset) = payload_size; memcpy(buffer + payload_embed.offset + sizeof(u32), payload_buffer, payload_size); ret = write_savedata(payload_embed.path, buffer, size); free(buffer); } else ret = write_savedata("/payload.bin", payload_buffer, payload_size); if(ret) { sprintf(status, "Failed to install payload\n Error code: %08lX", ret); next_state = STATE_ERROR; break; } next_state = STATE_INSTALLED_PAYLOAD; } break; case STATE_INSTALLED_PAYLOAD: next_state = STATE_NONE; break; default: break; } consoleSelect(&botConsole); printf("\x1b[0;0H Current status:\n %s\n", status); gspWaitForVBlank(); } if(payload_buffer) free(payload_buffer); romfsExit(); httpcExit(); svcCloseHandle(save_session); fsExit(); gfxExit(); return 0; }
int main() { //gfxInitDefault(); sf2d_init(); sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF)); consoleInit(GFX_TOP, NULL); Result rc = _srvGetServiceHandle(&romfsRealHandle, "fs:USER"); printf("realHandle: %08lX\n", rc); rc = FSUSER_Initialize(&romfsRealHandle); printf("initReal: %08lX\n", rc); // Regular RomFS u8 zeros[0xC]; memset(zeros, 0, sizeof(zeros)); FS_archive arch = { ARCH_ROMFS, { PATH_EMPTY, 1, (u8*)"" }, 0, 0 }; FS_path path = { PATH_BINARY, sizeof(zeros), zeros }; Handle romFS_file; rc = FSUSER_OpenFileDirectly(&romfsRealHandle, &romFS_file, arch, path, FS_OPEN_READ, FS_ATTRIBUTE_NONE); printf("romfsOpen: %08lX\n", rc); rc = romfsInitFromFile(romFS_file, 0); u8 *decomp_out; u8 *darc_decomp; u32 decomp_size; u32 darc_decomp_size; sf2d_texture **mon; char *mon_garc; char *box_garc; if (rc) { printf("romfsInit: %08lX\n", rc); mon_garc = "sdmc:/1"; box_garc = "sdmc:/3_box"; } else { printf("romfs Init Successful!\n"); mon_garc = "romfs:/a/0/9/3"; //Pokemon X/Y box_garc = "romfs:/a/1/0/4"; //Pokemon X/Y u32 num_mon = gnumrecords(mon_garc); if(!num_mon) { mon_garc = "sdmc:/1"; num_mon = gnumrecords(mon_garc); } u32 box_test = gnumrecords(box_garc); if(!box_test) { box_garc = "sdmc:/3_box"; } } u32 num_mon = gnumrecords(mon_garc); mon = (sf2d_texture**)malloc(num_mon * sizeof(sf2d_texture*)); printf("Loading sprites..."); int i; for(i = 0; i < 32; i++) { gfread(mon_garc, i, &decomp_out, &decomp_size); sf2d_texture *mon_sprite = create_texture_from_xy7_clim(decomp_out, decomp_size); mon[i] = mon_sprite; free(decomp_out); } printf("Pokemon sprites read.\n"); gfread(box_garc, 0, &darc_decomp, &darc_decomp_size); printf("Box sprites read.\n"); u32 box_clim_size; u32 box_bg_size; u32 box_name_size; void *box_clim; void *box_bg_clim; void *box_name; if(darc_decomp) { printf("darc_file: %x\n", box_clim); } printf("All read!\n"); sf2d_texture *cursor = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "cursol01.bclim"); sf2d_texture *wallpaper = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "box_wp02.bclim"); sf2d_texture *name_box = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "box_name02.bclim"); sf2d_texture *mode01 = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "mode01.bclim"); sf2d_texture *mode02 = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "mode02.bclim"); sf2d_texture *mode03 = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "mode03.bclim"); sf2d_texture *left_button = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "left_button.bclim"); sf2d_texture *right_button = load_texture_from_darc(pokedarc_get_darc(darc_decomp), "right_button.bclim"); float cursor_spot = 0; u8 cursor_direction = 1; float cursor_add = 0.4f; u8 cursor_mon_x = 3; u8 cursor_mon_y = 2; // Main loop while (aptMainLoop()) { hidScanInput(); if(cursor_direction) { cursor_spot += cursor_add; if(cursor_spot >= 5.0f) cursor_direction--; } else { cursor_spot -= cursor_add; if(cursor_spot <= 0.0f) cursor_direction++; } sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); clim_draw_texture(wallpaper, 0, 0); clim_draw_texture(mode01, 25, 0); clim_draw_texture(mode02, 25+50+10, 0); clim_draw_texture(mode03, 25+50+10+50+10, 0); clim_draw_texture(name_box, 20, 20); clim_draw_texture(left_button, 5, 20); clim_draw_texture(right_button, 20+name_box->width, 20); int x, y; int i = 1; for(y = 0; y < 5; y++) { for(x = 0; x < 6; x++) { clim_draw_texture(mon[i], 10+(x*32), 45+(y*30)); i++; } } clim_draw_texture(cursor, (int)(10-5+((cursor_mon_x + 1) * 32)-cursor_spot), (int)(45+5+((cursor_mon_y - 1) * 30)+cursor_spot)); sf2d_end_frame(); u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu sf2d_swapbuffers(); } sf2d_fini(); romfsExit(); gfxExit(); return 0; }
int main(void) { Result ret = 0, error = 0; sf2d_init(); sftd_init(); romfsInit(); srand(osGetTime()); // consoleInit(GFX_TOP, NULL); // TODO: Comment it! // consoleInit(GFX_BOTTOM, NULL); // TODO: Comment it! printf("> Loading texture manager\n"); PHBanku::texture = new TextureManager(); ret = PHBanku::texture->load(); if (R_FAILED(ret)) { // Graphics error |= ERR_GRAPHICS; } printf("> Loading font manager\n"); PHBanku::font = new FontManager(); ret = PHBanku::font->load(); if (R_FAILED(ret)) { // Font error |= ERR_FONT; } printf("> Loading data manager\n"); PHBanku::data = new DataManager(); ret = PHBanku::data->load(); if (R_FAILED(ret)) { // Data error |= ERR_DATA; } #ifdef __cia printf("> Starting title selector\n"); while (!error && TS_Loop()) { // Draw the static loading screen again because of ts.h PHBanku::texture->drawStaticLoadingScreen(); printf("> Loading filesystem services\n"); ret = FSCIA_Init(titleEntry.titleid, titleEntry.mediatype); if (R_FAILED(ret)) { // Filesystem error |= ERR_FILESYSTEM; } #else // __3dsx printf("> Loading filesystem services\n"); ret = FS_Init(); if (R_FAILED(ret)) { // Filesystem error |= ERR_FILESYSTEM; } #endif printf("> Loading save manager\n"); PHBanku::save = new SaveManager(); ret = PHBanku::save->load(); if (R_FAILED(ret)) { // Save error |= ERR_SAVE; } if (!error) { printf("> Starting box viewer...\n"); Viewer* viewer = new BoxViewer(); ViewState state = Viewer::startMainLoop(viewer); if (state == ViewState::Saving) { // TODO Remove when better save display! consoleInit(GFX_TOP, NULL); printf("Saving...\n"); // ^ PHBanku::save->save(); } else { // TODO Remove when better exit display! consoleInit(GFX_TOP, NULL); printf("Exiting...\n"); // ^ } delete viewer; } delete PHBanku::save; #ifdef __cia FSCIA_Exit(); consoleExit(GFX_TOP, NULL); break; // TODO Remove! The app crash itself after the 2nd ts, unknown cause. } // while (TS_LOOP()) if (!error) { // TODO Remove when better exit display! consoleInit(GFX_BOTTOM, NULL); // ^ printf("\nThe app execution ended!\n"); printf("Thanks for being awesome!\n"); } #else FS_Exit(); #endif if (error) { // TODO Remove when better error display! consoleInit(GFX_TOP, NULL); // ^ printf("\nProblem happened: 0x%lx\n", error); if (error & ERR_SAVE) printf(" \a Save\n"); if (error & ERR_DATA) printf(" \a Data\n"); if (error & ERR_FONT) printf(" \a Font\n"); if (error & ERR_GRAPHICS) printf(" \a Graphics\n"); if (error & ERR_FILESYSTEM) printf(" \a Filesystem\n"); printf("PHBank version: %08x\n", VERSION); printf("Can't start the viewer.\n"); printf("Press any key to exit\n"); waitKey(KEY_ANY); } delete PHBanku::data; delete PHBanku::font; delete PHBanku::texture; romfsExit(); sftd_fini(); sf2d_fini(); return 0; }
int main() { gfxInitDefault(); consoleInit(GFX_TOP, NULL); char* srcName; //open directory DIR *pdir; struct dirent *pent; int err = 0; pdir=opendir("/3ds/mips43ds/"); printf("Files in /3ds/mips43ds/ : \n"); if (pdir){ char dir_name[50][512]; int i = 0; while ((pent=readdir(pdir))!=NULL) { if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0) continue; if(pent->d_type != DT_DIR) { printf("%d. %s\n", i+1, pent->d_name); strcpy(dir_name[i], pent->d_name); i++; } } //select file printf("Please select a file to load (Left/Right keys):\n"); int select = 0; int selected = 0; printf("< %d. %s >\n", 1, dir_name[0]); while(selected == 0) { gspWaitForVBlank(); hidScanInput(); u32 kDown = hidKeysDown(); if (kDown & KEY_DRIGHT) { select++; if (select < 0) select = i; if (select > i) select = 0; printf("< %d. %s >\n", select+1, dir_name[select]); } else if (kDown & KEY_DLEFT) { select--; if (select < 0) select = i; if (select > i) select = 0; printf("< %d. %s >\n",select+1, dir_name[select]); } if (kDown & KEY_A) { selected = true; srcName = dir_name[select]; } if (kDown & KEY_START){ romfsExit(); gfxExit(); return 0; } } printf("\nSelected file %s.\n", dir_name[select]); closedir(pdir); } else { iprintf ("opendir() failure; terminating\nPress Start to Exit\n"); while (1) { u32 kDown = hidKeysDown(); gspWaitForVBlank(); hidScanInput(); if (kDown & KEY_START){ romfsExit(); gfxExit(); return 0; } } } mips_mem_h m=mips_mem_create_ram(0x20000, 4); mips_cpu_h c=mips_cpu_create(m); //char* srcName = "test_mips_fibonacci.bin"; FILE *src=fopen(srcName,"rb"); if(!src){ fprintf(stderr, "Cannot load source file '%s', try specifying the relative path to '%s'.\nPress Start to Exit\n", srcName, srcName); while (1) { u32 kDown = hidKeysDown(); gspWaitForVBlank(); hidScanInput(); if (kDown & KEY_START){ romfsExit(); gfxExit(); return 0; } } } uint32_t v; uint32_t offset=0; while(1==fread(&v, 4, 1, src)){ if(mips_mem_write(m, offset, 4, (uint8_t*)&v)){ fprintf(stderr, "Memory error while loading binary.\nPress Start to Exit\n"); while (1) { u32 kDown = hidKeysDown(); gspWaitForVBlank(); hidScanInput(); if (kDown & KEY_START){ romfsExit(); gfxExit(); return 0; } } } offset+=4; } fprintf(stderr, "Loaded %d bytes of binary at address 0.\n", offset); fclose(src); uint32_t n=12; // Value we will calculate fibonacci of uint32_t sentinelPC=0x10000000; mips_cpu_set_register(c, 31, sentinelPC); // set return address to something invalid mips_cpu_set_register(c, 4, n); // Set input argument mips_cpu_set_register(c, 29, 0x1000); // Create a stack pointer uint32_t steps=0; fprintf(stderr, "Executing... "); while(!mips_cpu_step(c)){ //fprintf(stderr, "Step %d.\n", steps); ++steps; uint32_t pc; mips_cpu_get_pc(c, &pc); if(pc==sentinelPC) break; } fprintf(stderr, "Done!\n"); //uint32_t fib_n; //mips_cpu_get_register(c, 2, &fib_n); // Get the result back //uint32_t fib_n_ref=f_fibonacci(n); //fprintf(stderr, "fib(%d) = %d, expected = %d\n", n, fib_n, fib_n_ref); fprintf(stderr, "Final register values:\n"); uint32_t reg_val; for (int i=0; i < 32; i+=2) { mips_cpu_get_register(c, i, ®_val); // Get the result back fprintf(stderr, "$%d = %d,\t\t\t\t\t\t", i, reg_val); mips_cpu_get_register(c, i+1, ®_val); // Get the result back fprintf(stderr, "$%d = %d\n", i+1, reg_val); } fprintf(stderr, "\n\nPress Start to Exit\n"); //} // Main loop while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu } romfsExit(); gfxExit(); return 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; }
int main() { Result ret=0; int draw=1; int ready=0; int type=0; gfxInit(GSP_RGB565_OES,GSP_BGR8_OES,false); consoleInit(GFX_BOTTOM, NULL); ret = romfsInit(); if(R_FAILED(ret)) { printf("romfsInit() failed: 0x%08x\n", (unsigned int)ret); ready = -1; } if(ready==0) { inaddr = linearMemAlign(0x1000000, 0x40); outaddr = linearMemAlign(0x100000, 0x40); if(!(inaddr && outaddr)) { ready = -2; printf("Failed to allocate memory.\n"); } } // Main loop while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); if(draw && type==0) { consoleClear(); draw = 0; if(ready==0)printf("mvd example\n"); printf("Press START to exit.\n"); if(ready==0) { printf("Press A for color-format-conversion.\n"); printf("Press B for video(no sound).\n"); } } u32 kDown = hidKeysDown(); if(type) { if(kDown & KEY_A) { type = 0; continue; } } if(type)continue; if (kDown & KEY_START) break; // break in order to return to hbmenu if(ready==0) { type = 0; if (kDown & KEY_A)type = 1; if (kDown & KEY_B)type = 2; if(type) { memset(inaddr, 0, 0x100000); memset(outaddr, 0, 0x100000); if(type==1)mvd_colorconvert(); if(type==2)mvd_video(); draw = 1; printf("Press A to continue.\n"); } } } if(inaddr)linearFree(inaddr); if(outaddr)linearFree(outaddr); if(ready!=-1)romfsExit(); gfxExit(); return 0; }