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() { int i, x, y; touchPosition lastTouch; u32 repeatkeys = 0; int repeatstate = 0; int repeatcount = 0; running = 0; pause = 0; exitemu = 0; PPU_Init(); srvInit(); aptInit(); aptOpenSession(); APT_SetAppCpuTimeLimit(NULL, 30); // enables syscore usage aptCloseSession(); gfxInit(); hidInit(NULL); fsInit(); GPU_Init(NULL); gpuCmdSize = 0x40000; gpuCmd = (u32*)linearAlloc(gpuCmdSize*4); GPU_Reset(gxCmdBuf, gpuCmd, gpuCmdSize); shader = SHDR_ParseSHBIN((u32*)blarg_shbin, blarg_shbin_size); GX_SetMemoryFill(gxCmdBuf, (u32*)gpuOut, 0x404040FF, (u32*)&gpuOut[0x2EE00], 0x201, (u32*)gpuDOut, 0x00000000, (u32*)&gpuDOut[0x2EE00], 0x201); gfxSwapBuffersGpu(); UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL)); BorderTex = (u32*)linearAlloc(512*256*4); MainScreenTex = (u32*)linearAlloc(512*256*4); SubScreenTex = (u32*)linearAlloc(512*256*4); BrightnessTex = (u8*)linearAlloc(8*256); borderVertices = (float*)linearAlloc(5*3 * 2 * sizeof(float)); screenVertices = (float*)linearAlloc(7*3 * 2 * sizeof(float)); float* fptr = &vertexList[0]; for (i = 0; i < 5*3*2; i++) borderVertices[i] = *fptr++; for (i = 0; i < 7*3*2; i++) screenVertices[i] = *fptr++; sdmcArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}}; FSUSER_OpenArchive(NULL, &sdmcArchive); if (!LoadBorder("/blargSnesBorder.bmp")) CopyBitmapToTexture(defaultborder, BorderTex, 400, 240, 0xFF, 0, 64, true); CopyBitmapToTexture(screenfill, PPU_MainBuffer, 256, 224, 0, 16, 64, false); memset(PPU_SubBuffer, 0, 256*256*4); memset(PPU_Brightness, 0xFF, 224); UI_Switch(&UI_ROMMenu); svcCreateEvent(&SPCSync, 0); aptSetupEventHandler(); APP_STATUS status; while((status = aptGetStatus()) != APP_EXITING) { if(status == APP_RUNNING) { svcSignalEvent(SPCSync); hidScanInput(); u32 press = hidKeysDown(); u32 held = hidKeysHeld(); u32 release = hidKeysUp(); GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0); RenderTopScreen(); GPUCMD_Finalize(); GPUCMD_Run(gxCmdBuf); if (running) { // emulate CPU_Run(); // runs the SNES for one frame. Handles PPU rendering. // SRAM autosave check // TODO: also save SRAM under certain circumstances (pausing, returning to home menu, etc) framecount++; if (!(framecount & 7)) SNES_SaveSRAM(); } else { // update UI if (held & KEY_TOUCH) { hidTouchRead(&lastTouch); UI_Touch(true, lastTouch.px, lastTouch.py); held &= ~KEY_TOUCH; } else if (release & KEY_TOUCH) { UI_Touch(false, lastTouch.px, lastTouch.py); release &= ~KEY_TOUCH; } if (press) { UI_ButtonPress(press); // key repeat repeatkeys = press & (KEY_UP|KEY_DOWN|KEY_LEFT|KEY_RIGHT); repeatstate = 1; repeatcount = 15; } else if (held == repeatkeys) { repeatcount--; if (!repeatcount) { repeatcount = 7; if (repeatstate == 2) UI_ButtonPress(repeatkeys); else repeatstate = 2; } } } UI_SetFramebuffer(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL)); UI_Render(); /*GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0); RenderTopScreen(); GPUCMD_Finalize(); GPUCMD_Run(gxCmdBuf);*/ // flush the bottomscreen cache while the PICA200 is busy rendering GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), 0x38400); // wait for the PICA200 to finish drawing gspWaitForP3D(); // copy new screen textures // SetDisplayTransfer with flags=2 converts linear graphics to the tiled format used for textures GX_SetDisplayTransfer(gxCmdBuf, PPU_MainBuffer, 0x01000200, MainScreenTex, 0x01000200, 0x2); gspWaitForPPF(); GX_SetDisplayTransfer(gxCmdBuf, PPU_SubBuffer, 0x01000200, SubScreenTex, 0x01000200, 0x2); gspWaitForPPF(); // copy brightness. // TODO do better u8* bptr = BrightnessTex; for (i = 0; i < 224;) { u32 pixels = *(u32*)&PPU_Brightness[i]; i += 4; *bptr = (u8)pixels; pixels >>= 8; bptr += 2; *bptr = (u8)pixels; pixels >>= 8; bptr += 6; *bptr = (u8)pixels; pixels >>= 8; bptr += 2; *bptr = (u8)pixels; pixels >>= 8; bptr += 22; } // transfer the final color buffer to the LCD and clear it // we can mostly overlap those two operations GX_SetDisplayTransfer(gxCmdBuf, gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000); svcSleepThread(20000); GX_SetMemoryFill(gxCmdBuf, gpuOut, 0x404040FF, &gpuOut[0x2EE00], 0x201, gpuDOut, 0x00000000, &gpuDOut[0x2EE00], 0x201); gspWaitForPPF(); gspWaitForPSC0(); gspWaitForEvent(GSPEVENT_VBlank0, false); gfxSwapBuffersGpu(); } else if(status == APP_SUSPENDING)
int main() { static char load_filename[512]; char *romname = NULL; float audioStart; // this is a float to count the half sample per frame needed ho have precise timing u32 audioTarget, audioEnd; srvInit(); aptInit(); hidInit(); APT_CheckNew3DS(&isN3DS); if(isN3DS) osSetSpeedupEnable(true); get_config_path(); sprintf(savename, "%s/Handy3ds.cfg", config_base_path); // using savename char buffer to save memory do_config(savename); handy_3ds_video_init(); sprintf(bios_path_and_name, "%s/%s", config_bios_path, "lynxboot.img"); // Call filebrowser if(gui_LoadFile(load_filename)!= -1) { romname = (char *)&load_filename; do { hidScanInput(); } while (hidKeysHeld()); } else { handy_3ds_quit(); } // Primary initalise of Handy - should be called AFTER _Init() but BEFORE handy_3ds_video_setup() handy_3ds_core_init(romname); // Initialise Handy 3ds video handy_3ds_video_setup(1, 0, 0, 32, LynxScale, 0, 0); // Initialise Handy 3ds audio printf("\nInitialising 3DS Audio... "); gAudioEnabled = handy_3ds_audio_init(); printf("[DONE]\n"); // Setup of Handy Core video handy_3ds_video_reinit(32); printf("Starting Lynx Emulation...\n"); bool touched = false; audioStart = gAudioBufferPointer; // both should be 0 at this point // initialize timers u64 tickcurr, syncticknext,synctickres; u64 fpsticknext,fpstickres; int frameSyncPeriod; if(isN3DS) frameSyncPeriod = 1; else frameSyncPeriod = 12; fpstickres= TICKS_PER_SEC; synctickres = TICKS_PER_FRAME * frameSyncPeriod; // on o3ds the sync is every 12 frame, i.e. 5 times every sec tickcurr=svcGetSystemTick(); fpsticknext = tickcurr + fpstickres; syncticknext = tickcurr + synctickres; int fpscnt = 0, synccnt = 0; gThrottleMaxPercentage = isN3DS?100:50; // !! TO DO: check if 50 is the best value. while(!emulation) { // Initialise Handy button events int OldKeyMask, KeyMask = mpLynx->GetButtonData(); OldKeyMask = KeyMask; // Getting events for keyboard and/or joypad handling hidScanInput(); if (hidKeysHeld() & KEY_TOUCH) { touched = true; } else { if (touched) { handy_3ds_audio_pause(); gui_Run(); KeyMask = 0; touched = false; // audioStart = gAudioBufferPointer; do { hidScanInput(); } while (hidKeysHeld()); gThrottleMaxPercentage = isN3DS?100:50; // !! Loading a savestate overrides this value, so we force it again exiting menu fpscnt = 0; synccnt = 0; tickcurr=svcGetSystemTick(); fpsticknext = tickcurr + fpstickres; syncticknext = tickcurr + synctickres; } else { touched = false; } } KeyMask = handy_3ds_on_key_down(hidKeysHeld(), KeyMask); // Check if there are handling events and then update the Handy button events. if (OldKeyMask != KeyMask) mpLynx->SetButtonData(KeyMask); // Update TimerCount gTimerCount++; while( handy_3ds_update() ) { //!! hidScanInput(); u32 held = hidKeysHeld(); if (held & KEY_SELECT) { // handy_3ds_video_quit(); // handy_3ds_audio_quit(); // exit(EXIT_SUCCESS); //break; touched = true; // enter menu } //!! if(!gSystemHalt) { if (!handy_3ds_audio_getstate()) { audioStart=0.0; // reset counter gAudioBufferPointer = 0; // reset buffer. really not needed since we set it to 0 in handy_3ds_audio_pause(). } // increase sound samples counter - 367,5 samples per frame at 60 fps audioEnd = (int)(audioStart + 367.5) % HANDY_AUDIO_BUFFER_SIZE; // filling 1 half of the buffer, roughly enough for slow frames on o3DS without risk of buffer head to reach the tail during the 10 frames before resync. audioTarget = (int)(audioStart + HANDY_AUDIO_BUFFER_SIZE/2.1) % HANDY_AUDIO_BUFFER_SIZE; if (audioTarget>audioStart) while (gAudioBufferPointer<audioTarget) mpLynx->Update(); else while ((gAudioBufferPointer>audioStart)||(gAudioBufferPointer<audioTarget)) mpLynx->Update(); if(Handy_cfg_Throttle && Handy_cfg_Sound && gAudioEnabled) { if (handy_3ds_audio_getstate()) handy_3ds_audio_callback(audioStart, (int)(audioTarget-audioStart)); else handy_3ds_audio_start(22050, audioStart); } audioStart = audioEnd; } else { printf("gSystemHalt : %ld\n", gSystemHalt); gTimerCount++; } system_checkPolls(); } // Timing fpscnt++; synccnt++; if (Handy_cfg_Throttle) { if (synccnt==frameSyncPeriod){ svcSleepThread((syncticknext - svcGetSystemTick()) / TICKS_PER_NSEC); } } tickcurr=svcGetSystemTick(); if (tickcurr >= syncticknext) { syncticknext += synctickres; synccnt = 0; } if (tickcurr >= fpsticknext) { fpsticknext += fpstickres; fps_counter = fpscnt; fpscnt = 0; } } // while(!emulation) osSetSpeedupEnable(true); return 0; }
int main() { srvInit(); aptInit(); hidInit(NULL); gfxInitDefault(); resetGame(); int x; while (aptMainLoop()) { hidScanInput(); hidTouchRead(&touch); u32 kDown = hidKeysDown(); //u32 kHeld = hidKeysHeld(); Not used an otherwise you'll get warning during compile, this makes compile more pleasant to look at yea! if (state != 0 && cur_row != 7) { if (secretCode() && state != 3) cheat=1; if (kDown & KEY_TOUCH) { cur_visable=false; } if (kDown & KEY_RIGHT) { cur_field+=1; if (cur_field > 3) cur_field=0; cur_visable=true; } if (kDown & KEY_LEFT) { cur_field-=1; if (cur_field < 0) cur_field=3; cur_visable=true; } if (kDown & KEY_UP) { local_field[cur_field]+=1; if (local_field[cur_field] > col_amount) local_field[cur_field]=1; cur_visable=true; } if (kDown & KEY_DOWN) { local_field[cur_field]-=1; if (local_field[cur_field] < 1) local_field[cur_field]=col_amount; cur_visable=true; } if (kDown & KEY_A) submitTry(); if (touchInBox(touch,231,163,84,44)) submitTry(); if (touchInBox(touch,7,28,71,16)) { local_field[0]+=1; if (local_field[0] > col_amount) local_field[0]=1; } if (touchInBox(touch,85,28,71,16)) { local_field[1]+=1; if (local_field[1] > col_amount) local_field[1]=1; } if (touchInBox(touch,163,28,71,16)) { local_field[2]+=1; if (local_field[2] > col_amount) local_field[2]=1; } if (touchInBox(touch,241,28,71,16)) { local_field[3]+=1; if (local_field[3] > col_amount) local_field[3]=1; } if (touchInBox(touch,7,119,71,16)) { local_field[0]-=1; if (local_field[0] <= 0) local_field[0]=col_amount; } if (touchInBox(touch,85,119,71,16)) { local_field[1]-=1; if (local_field[1] <= 0) local_field[1]=col_amount; } if (touchInBox(touch,163,119,71,16)) { local_field[2]-=1; if (local_field[2] <= 0) local_field[2]=col_amount; } if (touchInBox(touch,241,119,71,16)) { local_field[3]-=1; if (local_field[3] <= 0) local_field[3]=col_amount; } if (state != 2) { for (x=0; x < 4; x++) { full_field[cur_row*4+x]=local_field[x]; } } } else if (state == 0) { if (touchInBox(touch,65,66,98,34)) modeselector=1; if (touchInBox(touch,65,102,98,34)) modeselector=2; if (modeselector != 0) { if (touchInBox(touch,168,65,88,22)) { difficulty=0; startGame(modeselector); } if (touchInBox(touch,168,90,88,22)) { difficulty=1; startGame(modeselector); } if (touchInBox(touch,168,125,88,22)) { difficulty=2; startGame(modeselector); } } } if (touchInBox(touch,0,211,320,30)) { resetGame(); state=0; modeselector=0; } if (touchInBox(touch,0,0,74,21)) break; render(full_field, full_judgement, local_field, cur_field, cur_row, cur_visable, ans, win, cheat, state, modeselector); gfxFlushBuffers(); gfxSwapBuffers(); gspWaitForEvent(GSPEVENT_VBlank0, false); } gfxExit(); hidExit(); aptExit(); srvExit(); 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; } }