void hidExit() { if(!hidInitialised) return; // Unmap HID sharedmem and close handles. u8 val=0; int i; for(i=0; i<5; i++)svcCloseHandle(hidEvents[i]); svcUnmapMemoryBlock(hidMemHandle, (u32)hidSharedMem); svcCloseHandle(hidMemHandle); svcCloseHandle(hidHandle); APT_CheckNew3DS(NULL, &val); if(val) { irrstExit(); } if(hidSharedMem != NULL) { mappableFree((void*) hidSharedMem); hidSharedMem = NULL; } hidInitialised = false; }
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; }
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; }
void hidExit(void) { if (AtomicDecrement(&hidRefCount)) return; // Unmap HID sharedmem and close handles. u8 val=0; int i; for(i=0; i<5; i++)svcCloseHandle(hidEvents[i]); svcUnmapMemoryBlock(hidMemHandle, (u32)hidSharedMem); svcCloseHandle(hidMemHandle); svcCloseHandle(hidHandle); APT_CheckNew3DS(&val); if(val) { irrstExit(); } if(hidSharedMem != NULL) { mappableFree((void*) hidSharedMem); hidSharedMem = NULL; } }
int main(int argc, char **argv) { srvInit(); aptInit(); gfxInit(); acInit(); initCfgu(); ptmInit(); hidInit(NULL); irrstInit(NULL); fsInit(); hbInit(); Handle fileHandle; u64 size; u32 bytesRead; int restore; // 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 }else{ strcpy(start_dir,"/"); strcpy(cur_dir,"/"); // Set current dir for GW Mode } while(aptMainLoop()) { restore=0; char error[256]; errMsg = runScript((const char*)index_lua, true); if (errMsg != NULL); { // Fake error to force interpreter shutdown if (strstr(errMsg, "lpp_exit_04")){ break; } strcpy(error,"Error: "); strcat(error,errMsg); strcat(error,"\n\nPress A to restart\nPress B to exit"); } while (restore==0){ gspWaitForVBlank(); RefreshScreen(); ClearScreen(0); ClearScreen(1); DebugOutput(error); hidScanInput(); if(hidKeysDown() & KEY_A){ strcpy(cur_dir,start_dir); restore=1; }else if(hidKeysDown() & KEY_B){ restore=2; } gfxFlushBuffers(); gfxSwapBuffers(); } if (restore==2){ break; } } fsExit(); irrstExit(); hidExit(); ptmExit(); hbExit(); acExit(); exitCfgu(); gfxExit(); aptExit(); srvExit(); 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(); Result ir = irrstInit(); //consoleInit(GFX_BOTTOM, NULL); irrstEnabled = (ir) ? false : true; 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. //in general, make the LovePotion folder cause ye mkdir(path, 0777); // 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 (irrstEnabled) irrstExit(); if (soundEnabled) ndspExit(); if (romfsExists) romfsExit(); return 0; }