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; }
Result hidInit(void) { u8 val=0; Result ret=0; if (AtomicPostIncrement(&hidRefCount)) return 0; // Request service. ret = srvGetServiceHandle(&hidHandle, "hid:USER"); if (R_FAILED(ret)) ret = srvGetServiceHandle(&hidHandle, "hid:SPVR"); if (R_FAILED(ret)) goto cleanup0; // Get sharedmem handle. if(R_FAILED(ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1; // Map HID shared memory. hidSharedMem=(vu32*)mappableAlloc(0x2b0); if(!hidSharedMem) { ret = -1; goto cleanup1; } if(R_FAILED(ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2; APT_CheckNew3DS(&val); if(val) { ret = irrstInit(); } // Reset internal state. kOld = kHeld = kDown = kUp = 0; return ret; cleanup2: svcCloseHandle(hidMemHandle); if(hidSharedMem != NULL) { mappableFree((void*) hidSharedMem); hidSharedMem = NULL; } cleanup1: svcCloseHandle(hidHandle); cleanup0: AtomicDecrement(&hidRefCount); return ret; }
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(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; }
int main(int argc, char **argv) { srvInit(); aptInit(); gfxInitDefault(); acInit(); cfguInit(); httpcInit(); ptmuInit(); hidInit(); irrstInit(); aptOpenSession(); Result ret=APT_SetAppCpuTimeLimit(30); aptCloseSession(); fsInit(); ftp_state = false; isTopLCDOn = true; isBottomLCDOn = true; Handle fileHandle; u64 size; u32 bytesRead; int restore; // Check user build and enables kernel access if (nsInit()==0){ CIA_MODE = true; nsExit(); }else CIA_MODE = false; isNinjhax2 = false; if (!hbInit()) khaxInit(); else isNinjhax2 = true; // Select Audio System (csnd:SND preferred) if (csndInit() == 0){ csndAccess = true; csndExit(); }else csndAccess = false; // Init Audio-Device int i = 0; for (i=0;i < 32; i++){ audioChannels[i] = false; if (!isNinjhax2 && (i < 0x08)) audioChannels[i] = true; else if (csndAccess && (i < 0x08)) audioChannels[i] = true; } // Set main script char path[256]; if (argc > 0){ int latest_slash = 0; int i=5; while (argv[0][i] != '\0'){ if (argv[0][i] == '/') latest_slash = i; i++; } strcpy(path,&argv[0][5]); path[latest_slash-5] = 0; strcpy(start_dir,path); strcpy(cur_dir,path); // Set current dir strcat(path,"/index.lua"); }else{ strcpy(start_dir,"/"); strcpy(cur_dir,"/"); // Set current dir for GW Mode strcpy(path,"/index.lua"); } while(aptMainLoop()) { restore=0; char error[2048]; // Load main script FS_Path filePath=fsMakePath(PATH_ASCII, path); FS_Archive script=(FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}}; Result ret = FSUSER_OpenFileDirectly(&fileHandle, script, filePath, FS_OPEN_READ, 0x00000000); if (!ret){ FSFILE_GetSize(fileHandle, &size); buffer = (unsigned char*)(malloc((size+1) * sizeof (char))); FSFILE_Read(fileHandle, &bytesRead, 0x0, buffer, size); buffer[size]=0; FSFILE_Close(fileHandle); svcCloseHandle(fileHandle); errMsg = runScript((const char*)buffer, true); free(buffer); }else errMsg = "index.lua file not found."; // Force LCDs power on if ((!isTopLCDOn) || (!isBottomLCDOn)){ gspLcdInit(); if (!isTopLCDOn) GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_TOP); if (!isBottomLCDOn) GSPLCD_PowerOnBacklight(GSPLCD_SCREEN_BOTTOM); gspLcdExit(); isTopLCDOn = true; isBottomLCDOn = true; } // Fake error to force interpreter shutdown if (strstr(errMsg, "lpp_exit_04")) break; if (ftp_state) ftp_exit(); ftp_state = false; int connfd; while (restore==0){ gspWaitForVBlank(); RefreshScreen(); ClearScreen(0); ClearScreen(1); strcpy(error,"Error: "); strcat(error,errMsg); if (ftp_state){ u32 ip=(u32)gethostid(); char ip_address[64]; strcat(error,"\n\nPress A to restart\nPress B to exit\nPress Y to enable FTP server\n\nFTP state: ON\nIP: "); sprintf(ip_address,"%lu.%lu.%lu.%lu", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF); strcat(error,ip_address); strcat(error,"\nPort: 5000"); if(connfd<0)connfd=ftp_getConnection(); else{ int ret=ftp_frame(connfd); if(ret==1) connfd=-1; } }else strcat(error,"\n\nPress A to restart\nPress B to exit\nPress Y to enable FTP server\n\nFTP state: OFF"); DebugOutput(error); hidScanInput(); if(hidKeysDown() & KEY_A){ strcpy(cur_dir,start_dir); restore=1; }else if(hidKeysDown() & KEY_B){ restore=2; }else if(hidKeysDown() & KEY_Y){ if (!ftp_state){ u32 wifiStatus; if ((u32)ACU_GetWifiStatus(&wifiStatus) != 0xE0A09D2E){ if (wifiStatus != 0){ ftp_init(); connfd = -1; ftp_state = true; } } } } gfxFlushBuffers(); gfxSwapBuffers(); } if (ftp_state) ftp_exit(); if (isCSND){ if (csndAccess) csndExit(); else ndspExit(); isCSND = false; } if (restore==2){ break; } }