int main() { initSrv(); aptInit(APPID_APPLICATION); gspGpuInit(); hidInit(NULL); aptSetupEventHandler(); APP_STATUS status; while((status=aptGetStatus())!=APP_EXITING) { if(status==APP_RUNNING) { u32 PAD=hidSharedMem[7]; u32 regData=PAD|0x01000000; GSPGPU_WriteHWRegs(NULL, 0x202A04, (u32*)®Data, 4); renderEffect(); swapBuffers(); copyBuffer(); } svc_sleepThread(16666666); } hidExit(); gspGpuExit(); aptExit(); svc_exitProcess(); return 0; }
void reboot() { aptInit(); aptOpenSession(); APT_HardwareResetAsync(NULL); aptCloseSession(); aptExit(); }
int main() { getSrvHandle(&srvHandle); aptInit(); gspGpuInit(); Handle hidHandle; Handle hidMemHandle; srv_getServiceHandle(srvHandle, &hidHandle, "hid:USER"); HIDUSER_GetInfo(hidHandle, &hidMemHandle); svc_mapMemoryBlock(hidMemHandle, 0x10000000, 0x1, 0x10000000); HIDUSER_Init(hidHandle); while(1) { u32 PAD=((u32*)0x10000000)[7]; renderEffect(); swapBuffers(); copyBuffer(); u32 regData=PAD|0x01000000; GSPGPU_WriteHWRegs(gspGpuHandle, 0x202A04, (u8*)®Data, 4); svc_sleepThread(1000000000); } svc_exitProcess(); return 0; }
int main(int argc, char **argv) { //Initialize some sounds for high quality sounding moans and SCREAMS from the ACTION! srvInit(); aptInit(); hidInit(); csndInit(); gfxInitDefault(); consoleInit(GFX_TOP, NULL); printf("\x1b[1;5HGuess who is the freshest squid around?"); wait(10000); printf(" "); printf("\x1b[5;19H\x1b[32m\ Marie Squid\x1b[0m\n"); printf("\x1b[16;3HPress Start to know that such fresh exists."); printf("\x1b[17;3HPress A to get INTO IT!"); // Main loop while (aptMainLoop()) { //Scan all the inputs. This should be done once for each frame mostly for the shoots hidScanInput(); //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) hidScanInput(); u32 kDown = hidKeysDown(); if (kDown & KEY_START){ //PRESS START TO RETURN TO HBL } if (kDown & KEY_A){ // PRESS A TO PLAY audio_load("squit.bin"); } // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); //Wait for VBlank gspWaitForVBlank(); } // Exit services... I know you want to come back... audio_stop(); audio_stop(); csndExit(); gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
void __appInit() { // Initialize services srvInit(); aptInit(); gfxInitDefault(); hidInit(); fsInit(); sdmcInit(); pxiDevInit(); consoleInit(GFX_TOP, NULL); }
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() { //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; }
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() { Result ret=0; httpcContext context; // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInit(); //gfxSet3D(true); // uncomment if using stereoscopic 3D httpcInit(); ret = httpcOpenContext(&context, "http://10.0.0.3/httpexample_rawimg.bin", 0);//Change this to your own URL. if(ret==0) { ret=http_download(&context); httpcCloseContext(&context); } // Main loop while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); // Your code goes here u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); } // Exit services httpcExit(); gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
void init(void) { // Starting services sf2d_init(); sf2d_set_vblank_wait(0); sftd_init(); srvInit(); aptInit(); hidInit(); audio_init(); //romfsInit(); // Configuring the right font to use (8bitoperator), and its proprieties font = sftd_load_font_file("font/eightbit.ttf"); // Configuring graphics in general (images, textures, etc) sf2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF)); /* Load Frisk textures Loop over every element in tex_arr_friskWalk and load the PNG buffer. */ for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { tex_arr_friskWalk[i][j] = loadTexture(friskFilenames[i][j]); } } room_init(); // Reusing 'i' from above. // Load room textures. for (int i = 0; i < 3; ++i) fillTexture(&rooms[i].bg); // TODO: Add actual save loading logic. For now, just assume this room. player_pos = rooms[room].exits[0].entrance; // Play music home = sound_create(BGM); if (home != NULL) audio_load_ogg("sound/music/house1.ogg", home); else home->status = -1; timerStep(); }
int main() { // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInitDefault(); // Main loop while (aptMainLoop()) { //As nop90 suggested getFB(); //Gets input (keys and touch) getInput(); //Prints the GUI printGUI(); //Do stuff app(); //Exit code if (input & KEY_START) break; // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); //Wait for VBlank gspWaitForVBlank(); } // Exit services gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
int main() { initSrv(); aptInit(APPID_APPLICATION); gspGpuInit(); hidInit(NULL); Handle fsuHandle; srv_getServiceHandle(NULL, &fsuHandle, "fs:USER"); FSUSER_Initialize(fsuHandle); Handle fileHandle; u32 bytesRead; FS_archive sdmcArchive=(FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}}; FS_path filePath=(FS_path){PATH_CHAR, 10, (u8*)"/test.bin"}; FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE); FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)gspHeap, 0x46500); FSFILE_Close(fileHandle); aptSetupEventHandler(); while(!aptGetStatus()) { u32 PAD=hidSharedMem[7]; renderEffect(); swapBuffers(); copyBuffer(); u32 regData=PAD|0x01000000; GSPGPU_WriteHWRegs(NULL, 0x202A04, ®Data, 4); svc_sleepThread(1000000000); } svc_closeHandle(fsuHandle); hidExit(); gspGpuInit(); aptExit(); svc_exitProcess(); return 0; }
s32 main (void) { // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInitDefault(); fsInit(); sdmcInit(); hbInit(); qtmInit(); Handle fileHandle; u32 bytesRead; FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}}; FS_path filePath=FS_makePath(PATH_CHAR, "/rxTools.dat"); Result ret=FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE); if(ret) goto EXIT; FSFILE_Read(fileHandle, &bytesRead, 0x20000, 0x14400000, 320*1024); FSFILE_Close(fileHandle); consoleInit(GFX_BOTTOM, NULL); if (brahma_init()) { quick_boot_firm(1); printf("[!] Quickload failed\n"); brahma_exit(); } else { printf("* BRAHMA *\n\n[!]Not enough memory\n"); wait_any_key(); } EXIT: hbExit(); sdmcExit(); fsExit(); gfxExit(); hidExit(); aptExit(); srvExit(); // Return to hbmenu return 0; }
s32 main(void) { // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInitDefault(); gfxSet3D(true); fsInit(); sdmcInit(); hbInit(); qtmInit(); gfxSwapBuffers(); Handle fileHandle; u32 bytesRead; FS_archive sdmcArchive = (FS_archive){ ARCH_SDMC, (FS_path){ PATH_EMPTY, 1, (u8*)"" } }; FS_path filePath = FS_makePath(PATH_CHAR, "/" CODE_PATH); Result ret = FSUSER_OpenFileDirectly(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE); if (ret) goto EXIT; FSFILE_Read(fileHandle, &bytesRead, 0x14000, 0x14400000, 320 * 1024); FSFILE_Close(fileHandle); if (brahma_init()) { quick_boot_firm(1); brahma_exit(); } EXIT: hbExit(); sdmcExit(); fsExit(); gfxExit(); hidExit(); aptExit(); srvExit(); // Return to hbmenu return 0; }
int main() { // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInit(); //gfxSet3D(true); // uncomment if using stereoscopic 3D char* a = ""; // Main loop while (aptMainLoop() && strcmp(a, "q") != 0) { gspWaitForVBlank(); hidScanInput(); // Your code goes here u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu a = bbHandleKeyboardBlocking(""); u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); memset(fb, 0, 240*400*3); tsDrawWord(GFX_TOP, GFX_LEFT, a, 40, 50, 255, 255, 255); // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); } // Exit services gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
static void frontend_ctr_init(void *data) { #ifndef IS_SALAMANDER (void)data; global_t *global = global_get_ptr(); global->verbosity = true; #if 0 srvInit(); aptInit(); hidInit(); fsInit(); sdmcInit(); APT_SetAppCpuTimeLimit(NULL, 80); gfxInitDefault(); #endif gfxInit(GSP_BGR8_OES,GSP_RGB565_OES,false); csndInit(); gfxSet3D(false); consoleInit(GFX_BOTTOM, NULL); #endif }
int main() { // Inits srvInit(); aptInit(); hidInit(); bool stop = 0; csndInit();//start Audio Lib u32 kDown; while (aptMainLoop()) { hidScanInput(); kDown = hidKeysDown(); if (kDown & KEY_START) { //PRESS START TO RETURN TO HBL stop=1; } if (kDown & KEY_A) { // PRESS A TO PLAY audio_load("audio/original_raw.bin"); } if (stop) { break; } } audio_stop(); audio_stop(); csndExit(); hidExit(); aptExit(); srvExit(); return 0; }
int main() { // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInitDefault(); fsInit(); sdmcInit(); hbInit(); qtmInit(); hidScanInput(); u32 kDown = hidKeysDown(); u32 kHeld = hidKeysHeld(); //Load the configuration loadConfiguration(); //Check kernel version getSystemVersion(); //checks if the CFW has to boot right away or open the GUI if(auto_boot == '2') auto_boot = '2'; //here it checks if the "force GUI" is set, and preservs it if it is set else if(kHeld & KEY_L) auto_boot = '0'; //here it will start the GUI only this time else auto_boot = '1'; //here it won't show the GUI //checks if the CFW has to disable firmlaunch if (kHeld & KEY_R && firmlaunch == '0') firmlaunch = '2'; //here we enable the firmlaunch only this time else if (kHeld & KEY_R && firmlaunch == '1')firmlaunch = '3'; //here we disable the firmlaunch only this time //Then we save the configuration saveConfiguration(); //Proceeds to launch the loader.bin bootCFW_FirstStage(); }
int main() { // Initialize services srvInit(); aptInit(); hidInit(NULL); gfxInit(); CSND_initialize(NULL); srand(osGetTime()); //gfxSet3D(true); // uncomment if using stereoscopic 3D u8 *audiobuf = linearAlloc(sadloop_bin_size); int i; for (i=0;i<sadloop_bin_size;i++) { memcpy(&audiobuf[i], &sadloop_bin[i], 1); } bool flip = false; u64 nextflip = osGetTime()+500; u8 *crow = linearAlloc(crow1_bin_size); for (i=0;i<crow1_bin_size;i++) { memcpy(&crow[i], &crow1_bin[i], 1); } CSND_setchannel_playbackstate(0x8, 0); CSND_sharedmemtype0_cmdupdatestate(0); u64 nextsong = osGetTime()+68000; CSND_playsound(0x8, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, 22050, (u32*)audiobuf, NULL, sadloop_bin_size, 2, 0); char* fact; u64 nextfact = osGetTime()+newFact(&fact); // Main loop while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); u64 now = osGetTime(); if (now >= nextsong) { nextsong = now+68000; CSND_playsound(0x8, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, 22050, (u32*)audiobuf, NULL, sadloop_bin_size, 2, 0); } if (now >= nextflip) { nextflip = now+500; if (flip) { for (i=0;i<crow1_bin_size;i++) { memcpy(&crow[i], &crow1_bin[i], 1); } flip = false; } else { for (i=0;i<crow1_bin_size;i++) { memcpy(&crow[i], &crow2_bin[i], 1); } flip = true; } } if (now >= nextfact) { nextfact = now+newFact(&fact); } u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu // Please note that the 3DS screens are sideways (thus 240x400 and 240x320) u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); memset(fb, 0, 240*400*3); tsDrawWord(GFX_TOP, GFX_LEFT, "Fact Crow says:", 30, 180, 255, 255, 255); drawFact(fact); gfxDrawSprite(GFX_TOP, GFX_LEFT, crow, 37, 37, 138, 30); // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); } CSND_shutdown(); linearFree(audiobuf); // Exit services gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
int main() { initSrv(); aptInit(APPID_APPLICATION); gspGpuInit(); hidInit(NULL); Handle fsuHandle; srv_getServiceHandle(NULL, &fsuHandle, "fs:USER"); FSUSER_Initialize(fsuHandle); aptSetupEventHandler(); init_map(); int i; int j; int p=4; int d=0; int q; int frogx = 0; int frogy = 0; int carx[6][9]; int logx[5][6]; // Cant use rand. //for(d=1;d<6;d++){ // while(p>4){ // p = rand(); // } // carx[d]=26+p; for(d=0;d<8;d++){ carx[0][d]=26; if(d<5){ logx[0][d]=26; } d++; } for(d=1;d<8;d++){ if(d<5){ logx[0][d]=0; } carx[0][d]=0; d++; } for(q=0;q<8;q++){ for(d=1; d<6; d++){ if(q<5){ if(d<5){ logx[d][q]=26+p+6; } } carx[d][q]=26+p +6; p=p+6; } p=0; q++; } p= 0; for(q=1;q<8;q++){ for(d=1;d<5;d++){ if(q<5){ if(d<5){ logx[d][q] = p-6; } } carx[d][q]=p-6; p=p-6; } p=0; q++; } while(!aptGetStatus()){ u32 PAD=hidSharedMem[7]; if (PAD == BUTTON_UP){ frogy+= 1; } else if (PAD == BUTTON_DOWN){ frogy+= -1; } else if (PAD == BUTTON_LEFT){ frogx+= -1; } else if (PAD == BUTTON_RIGHT){ frogx+=1; } u32 regData=PAD|0x01000000; init_map(); for(i=0;i<6;i++){ for(j=0;j<8;j++){ draw_car(carx[i][j],15+j*15); if(i<5){ if(j<5){ draw_logs(logx[i][j],150+j*15); } } } } draw_frog(frogx,frogy); //Checks Colition for(i=0;i<6;i++){ for(j=0;j<8;j++){ if(frogy==j+1){ if(frogx==carx[i][j]){ frogy =0; frogx =0; } } } } //Checks if frog in poodle if(frogy >9){ for(i=0;i<5;i++){ for(j=0;j<5;j++){ if(frogy==j+10){ if(frogx==logx[i][j] || frogx==logx[i][j]+1 || frogx==logx[i][j]+2){ frogx= frogx -1; } else{ frogx =0; frogy =0; } } } } } //reinitialize the cars :D // Cant use f*****g rand //for(p=0;p<6;p++){ // if(carx[p]==0){ // d=5; // while(d>4){ // d = rand(); // } // carx[p]= 26+d; // } // else { // carx[p]=carx[p]-1; // } //} for(i=0;i<6;i++){ for(j=0;j<9;j=j+2){ if(i<5){ if(j<5){ if(logx[i][j]==0){ logx[i][j]=26; } else{ logx[i][j]=logx[i][j]-1; } } } if(carx[i][j]==0){ carx[i][j] =26; } else{ carx[i][j]=carx[i][j]-1; } } } for(i=0;i<6;i++){ for(j=1;j<9;j=j+2){ if(i<5){ if(j<5){ if(logx[i][j]==26){ logx[i][j]=0; } else{ logx[i][j]=logx[i][j]+1; } } } if(carx[i][j]==26){ carx[i][j]=0; } else{ carx[i][j]= carx[i][j]+1; } } } copyBuffer(); swapBuffers(); GSPGPU_WriteHWRegs(NULL, 0x202A04, ®Data, 4); svc_sleepThread(220000000); } svc_closeHandle(fsuHandle); hidExit(); gspGpuInit(); aptExit(); svc_exitProcess(); return 0; }
/*----------------*/ int main(int argc, char *argv[]) { APP_STATUS status; srvInit(); aptInit(APPID_APPLICATION); gfxInit(); hidInit(NULL); fsInit(); svcCreateEvent(&new_cmd_event, 0); svcCreateEvent(&cmd_done_event, 0); svcCreateThread(&thread, cmd_thread_func, 0x0, (u32*)((char*)thread_stack + sizeof(thread_stack)), 0x31, 0xfffffffe); int where = 0; u32 ret = SOC_Initialize((u32*)0x08000000, 0x48000); if(ret == 0) { listen_socket = socket(AF_INET, SOCK_STREAM, 0); if(listen_socket == -1) { where = 1; ret = SOC_GetErrno(); } else { u32 tmp = fcntl(listen_socket, F_GETFL); fcntl(listen_socket, F_SETFL, tmp | O_NONBLOCK); struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = __swap16(PORT); addr.sin_addr.s_addr = INADDR_ANY; ret = bind(listen_socket, (struct sockaddr *)&addr, sizeof(addr)); if(ret != 0) { where = 2; ret = SOC_GetErrno(); } else { ret = listen(listen_socket, 1); if(ret == -1) { ret = SOC_GetErrno(); where = 3; } } } } u32 it = 0; int accept_errno = 0; int first = 1; while((status = aptGetStatus()) != APP_EXITING) { hidScanInput(); consoleClear(&top); print(&top, "newver\n"); print(&top, "ret: %08x, where: %d\n", ret, where); print(&top, "frame: %08x\n", it); u32 ip = gethostid(); print(&top, "ip: %d.%d.%d.%d\n", ip & 0xFF, (ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF); if(accept_errno != 0) print(&top, "accept returned errno %d\n", accept_errno); if(!first) { int s = accept(listen_socket, NULL, NULL); if(s == -1) { int err = SOC_GetErrno(); if(err != -EWOULDBLOCK) accept_errno = err; } else { sock = s; conn_main(); closesocket(sock); } } it++; first = 0; if(enable_draw) renderFrame(); u32 keys = hidKeysUp(); if(keys & KEY_A) break; } thread_exit = 1; svcSignalEvent(new_cmd_event); svcWaitSynchronization(thread, U64_MAX); svcCloseHandle(thread); svcCloseHandle(new_cmd_event); svcCloseHandle(cmd_done_event); SOC_Shutdown(); fsExit(); hidExit(); gfxExit(); aptExit(); srvExit(); return 0; }
int main() { char level_data_line[20*16]; LEVELDATA this_level_data = { {&level_data_line[0], &level_data_line[20], &level_data_line[40], &level_data_line[60], &level_data_line[80], &level_data_line[100],&level_data_line[120],&level_data_line[140], &level_data_line[160],&level_data_line[180],&level_data_line[200],&level_data_line[220], &level_data_line[240],&level_data_line[260],&level_data_line[280],&level_data_line[300]}, 19,11 }; // Initializations srvInit(); // services aptInit(); // applets hidInit(); // input gfxInitDefault(); // gfxSet3D(true); // uncomment if using stereoscopic 3D gfxSetDoubleBuffering(GFX_TOP, true); gfxSetDoubleBuffering(GFX_BOTTOM, false); PrintConsole /*topScreen, */bottomScreen; consoleInit(GFX_BOTTOM, &bottomScreen); // consoleInit(GFX_TOP, &topScreen); clear_char_stack(); int level = 0; int mode = MODE_INIT; // int mode_status = 0; hcount = 0; int timer = 0; // Main loop while (aptMainLoop()) { hidScanInput(); u32 kDown = hidKeysDown(); u32 kUp = hidKeysUp(); u32 kHeld = hidKeysHeld(); if (kDown & KEY_START){ break; // break in order to return to hbmenu } if (mode == MODE_INIT){ // consoleSelect(&topScreen); // printf("\033[2J"); copyGame(level,&this_level_data); gspWaitForVBlank(); printGame(&this_level_data); mode = MODE_GAME; }else if (mode == MODE_CLEAR){ if ((kUp & KEY_A) || (kUp & KEY_B) || (kUp & KEY_X) || (kUp & KEY_Y)){ level++; if (level >= sizeof(level_data)/sizeof(LEVELDATA)) { mode = MODE_ALL_CLEAR; }else{ mode = MODE_INIT; } } if (level < sizeof(level_data)/sizeof(LEVELDATA)) { consoleSelect(&bottomScreen); printf("\033[2J"); printf("\x1b[21;12HStage cleared!!"); printf("\x1b[23;12HPush A to next Next Stage"); } }else if (mode == MODE_ALL_CLEAR){ level = 0; consoleSelect(&bottomScreen); printf("\033[2J"); printf("\x1b[21;12HGame cleared!!!"); printf("\x1b[23;12HPush Start to exit game"); mode = MODE_NULL; }else if (mode == MODE_GAME){ // Your code goes here #ifdef DEBUG consoleSelect(&bottomScreen); if (timer%10==0){ //if (1 != 0){printf("\x1b[10;12HkUp =%08x",(unsigned int)kUp);} //if (1 != 0){printf("\x1b[11;12HkDown=%08x",(unsigned int)kDown);} //if (1 != 0){printf("\x1b[12;12HkHeld=%08x",(unsigned int)kHeld);} //printf("\x1b[22;12HKEY_CPAD_UP=%x",KEY_UP); //printf("\x1b[23;12HKEY_CPAD_DN=%x",KEY_DOWN); printf("\x1b[20;12HRest: [SELECT]"); printf("\x1b[22;12HExit: [START]"); printf("\x1b[24;12HTime: %08d",timer); } timer++; #endif if (kDown != 0 || kHeld != 0){ if (kDown & KEY_SELECT){ mode = MODE_INIT; }else{ moveMan(kDown, kHeld,level,&this_level_data); if(checkCleared(&this_level_data,level)==0){ mode = MODE_CLEAR;} gspWaitForVBlank(); draw_char_stack(this_level_data,spriteData, sizeof(spriteData)/sizeof(SPRITEDATA)); } }else{ gspWaitForVBlank(); } } // Flush and swap framebuffers gfxFlushBuffers(); gfxSwapBuffers(); } gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
int main(void) { irmemloc = (u32*) memalign(0x1000, 0x1000); resultStartup = IRU_Initialize(irmemloc, 0x1000); resultSetBit = IRU_SetBitRate(0xB); recordedIR = (u32*) malloc(REC_SIZE * NUM_OF_BUTTONS); //Currently there are 11(NUM_OF_BUTTONS) recordable buttons. (start switches mode) recentIR = (u32*) calloc(REC_SIZE, 0x1); //Whatever was last viewed in memory resultGetStatus = irucmd_GetTransferState(&StatusIR); srvInit(); // services aptInit(); // applets hidInit(NULL); // input gfxInitDefault(); // gfx gfxSetDoubleBuffering(GFX_TOP, true); gfxSetDoubleBuffering(GFX_BOTTOM, true); bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); if(setjmp(exitJmp)) goto exit; clearScreen(); gfxFlushBuffers(); gfxSwapBuffers(); bool startToggle = false; bool upToggle = false; bool downToggle = false; while(aptMainLoop()) { bot = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); hidScanInput(); irrstScanInput(); u32 kHeld = hidKeysHeld(); circlePosition circlePad; circlePosition cStick; hidCstickRead(&cStick); hidCircleRead(&circlePad); touchPosition touch; touchRead(&touch); clearScreen(); char keys[30] = "ABXY URDL SEST LR ZLZR"; if(kHeld & KEY_A) { keys[0] = '*'; ir('A'); } if(kHeld & KEY_B) { keys[1] = '*'; ir('B'); } if(kHeld & KEY_X) { keys[2] = '*'; ir('X'); } if(kHeld & KEY_Y) { keys[3] = '*'; ir('Y'); } if(kHeld & KEY_DUP) { keys[5] = '*'; if(upToggle) { if(bitrate < 18) { bitrate++; resultSetBit = IRU_SetBitRate(bitrate); } upToggle = false; } } else { upToggle = true; } if(kHeld & KEY_DRIGHT) { keys[6] = '*'; ir('R'); } if(kHeld & KEY_DDOWN) { keys[7] = '*'; if(downToggle) { if(bitrate > 3) { bitrate--; resultSetBit = IRU_SetBitRate(bitrate); } downToggle = false; } } else { downToggle = true; } if(kHeld & KEY_DLEFT) { keys[8] = '*'; ir('L'); } if(kHeld & KEY_SELECT) { keys[10] = '*'; keys[11] = '*'; ir('S'); } if(kHeld & KEY_START) { keys[12] = '*'; keys[13] = '*'; if(startToggle) { rec = !rec; startToggle = false; } } else { startToggle = true; } if(kHeld & KEY_L) { keys[15] = '*'; ir('L'); } if(kHeld & KEY_R) { keys[16] = '*'; ir('R'); } if(kHeld & KEY_ZL) { keys[18] = '*'; keys[19] = '*'; ir('1'); } if(kHeld & KEY_ZR) { keys[20] = '*'; keys[21] = '*'; ir('2'); } drawString(top, 10, 10, keys); drawString(top, 10, 20, "Circle Pad x: %04+d, y: %04+d", circlePad.dx, circlePad.dy); drawString(top, 10, 30, "Touch x: %04d, y: %04d", touch.px, touch.py ); if(resultStartup == 0) { drawString(top, 10, 40, "IR started!"); } else { drawString(top, 10, 40, "IR Init |Error: %x", resultStartup); } if(resultSetBit == 0) { drawString(top, 10, 50, "IR bit rate works!"); } else { drawString(top, 10, 50, "IR bit rate |Error: %x", resultSetBit); } if(resultTransferIR == 0) { drawString(top, 10, 60, "IR transfer works!"); } else { drawString(top, 10, 60, "IR transfer |Error: %x", resultTransferIR); } irucmd_GetTransferState(&StatusIR); drawString(top, 10, 70, "IR mode: %x", StatusIR); drawString(top, 10, 80, "Got %d bytes", TransIR); drawString(top, 10, 90, "Bitrate: %d (see IRU:SetBitRate)", bitrate); printMemory(NULL,REC_SIZE,10, false); //might be dangerous? if(rec) { drawString(top, 10, 210, "Recording mode active."); }else{ drawString(top, 10, 210, "Sending mode active."); } drawString(top, 10, 220, "Start + Select to exit."); if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1); gfxFlushBuffers(); gspWaitForVBlank(); gfxSwapBuffers(); } exit: //I should really be fixing these. free(recordedIR); //Crashes the program. Should free on release. free(irmemloc); //Crashes the program. Should free on release. free(recentIR); //Crashes the program. Should free on release. IRU_Shutdown(); //Crashes the program. Should free on release. gfxExit(); hidExit(); aptExit(); srvExit(); return 0; }
int main() { // Initialize services srvInit(); aptInit(); hidInit(NULL); ptmInit(); gfxInitDefault(); // consoleInit(GFX_TOP, NULL); csndInit(); // fsInit(); // sdmcInit(); chdir("sdmc:/"); void *device = gfxCreateDevice(240, 320); gfxMakeCurrent(device); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0); glTranslatef(0.5f, 0.5f, 0.0f); glRotatef(90.0f, 0.0f, 0.0f, 1.0f); glTranslatef(-0.5f, -0.5f, 0.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glGenTextures(1, &play_button); glGenTextures(1, &pause_button); glGenTextures(1, &loop_button); glGenTextures(1, &loop_disable_button); glGenTextures(1, &power_icon); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); int x, y, n; u8* image_data = stbi_load_from_memory(play_3_png, play_3_png_size, &x, &y, &n, 4); glBindTexture(GL_TEXTURE_2D, play_button); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); stbi_image_free(image_data); image_data = stbi_load_from_memory(pause_2_png, pause_2_png_size, &x, &y, &n, 4); glBindTexture(GL_TEXTURE_2D, pause_button); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); stbi_image_free(image_data); image_data = stbi_load_from_memory(loop_png, loop_png_size, &x, &y, &n, 4); glBindTexture(GL_TEXTURE_2D, loop_button); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); stbi_image_free(image_data); image_data = stbi_load_from_memory(loop_disable_png, loop_disable_png_size, &x, &y, &n, 4); glBindTexture(GL_TEXTURE_2D, loop_disable_button); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); stbi_image_free(image_data); image_data = stbi_load_from_memory(power_png, power_png_size, &x, &y, &n, 4); glBindTexture(GL_TEXTURE_2D, power_icon); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); stbi_image_free(image_data); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); void *top_device = gfxCreateDevice(240, 400); gfxMakeCurrent(top_device); initfont_goth(); initfont_anita(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0); glTranslatef(0.5f, 0.5f, 0.0f); glRotatef(90.0f, 0.0f, 0.0f, 1.0f); glTranslatef(-0.5f, -0.5f, 0.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); int frames = 0; int channel = 0x8; while (aptMainLoop()) { gspWaitForVBlank(); hidScanInput(); gfxMakeCurrent(top_device); glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glScalef(1.0/400.0, 1.0/240.0, 1.0); state_man(); gfxFlush(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL)); u8 plevel; u8 charge; PTMU_GetBatteryLevel(NULL, &plevel); PTMU_GetBatteryChargeState(NULL, &charge); if (plevel != power_level) { power_level = plevel; // draw_ui = true; } if (charge != is_charging) { is_charging = charge; //draw_ui = true; } gfxMakeCurrent(device); u8* fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); render(); gfxFlush(fb); // Your code goes here u32 kDown = hidKeysDown(); if (kDown & KEY_START) break; // break in order to return to hbmenu // Flush and swap framebuffers if (audiobuf && !paused) { if(frames >= 50) { frames = 0; int n = 0; if (decode_mode == AUDIO_MODE_VORBIS) { n = stb_vorbis_get_samples_short_interleaved(v, 2, audiobuf, Samples * 2); } else { while (audiobuf_index < Samples * 2) { n = FLAC__stream_decoder_process_single(FLAC_decoder); if (FLAC__stream_decoder_get_state(FLAC_decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) break; } audiobuf_index = 0; } if(n == 0) { if (decode_mode == AUDIO_MODE_VORBIS) { stb_vorbis_close(v); } else { FLAC__stream_decoder_delete(FLAC_decoder); } linearFree(audiobuf); audiobuf = NULL; v = NULL; FLAC_decoder = NULL; if (loop_flag) play_file_from_filename(currently_playing); } GSPGPU_FlushDataCache(NULL, (u8*)audiobuf, audiobuf_size); if (channel == 0x8) channel = 0x6; if (channel == 0x6) channel = 0x8; csndPlaySound(SOUND_CHANNEL(channel), SOUND_ONE_SHOT | SOUND_LINEAR_INTERP | SOUND_FORMAT_16BIT, Samples * 2, 10.0, 0.0, (u32*)audiobuf, (u32*)audiobuf, audiobuf_size); } frames++; } gfxFlushBuffers(); gfxSwapBuffersGpu(); } // Exit services if (FLAC_decoder) { FLAC__stream_decoder_delete(FLAC_decoder); } csndExit(); gfxExit(); ptmExit(); 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() { 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; }
static PSD n3ds888_open(PSD psd) { PSUBDRIVER subdriver; /* init driver variables depending on ega/vga mode*/ psd->xres = psd->xvirtres = 240; psd->yres = psd->yvirtres = 340; psd->planes = 1; psd->bpp = 24; psd->ncolors = psd->bpp >= 24? (1 << 24): (1 << psd->bpp); psd->pixtype = MWPF_TRUECOLOR888; psd->portrait = MWPORTRAIT_NONE; psd->data_format = set_data_format(psd); /* Calculate the correct size and pitch from xres, yres and bpp*/ GdCalcMemGCAlloc(psd, psd->xres, psd->yres, psd->planes, psd->bpp, &psd->size, &psd->pitch); psd->flags = PSF_SCREEN; /* * set and initialize subdriver into screen driver * psd->size is calculated by subdriver init */ // Currently attempting to use FB16 subdriver subdriver = select_fb_subdriver(psd); // Check that a valid subdriver exists if (!subdriver) { EPRINTF("No driver for screen bpp %d\n", psd->bpp); return NULL; } psd->orgsubdriver = subdriver; set_subdriver(psd, subdriver); //FB_BOT_1 // psd->addr = (void*) 0x0008CA00//launcher 0x202118E0; srvInit(); // mandatory aptInit(); // mandatory hidInit(NULL); // input (buttons, screen) gfxInit(); // screenBottom=0x48F000; // screenBottom=gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL); psd->addr = (void*) gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL); printf('nano-x --> n3ds888_open \n'); gfxFlushBuffers(); // 0x1E6000-0x22C500 -- top screen 3D left framebuffer 0(240x400x3) (The "3D right first-framebuf" addr stored in the LCD register is set to this, when the 3D is set to "off") // 0x22C800-0x272D00 -- top screen 3D left framebuffer 1(240x400x3) // 0x273000-0x2B9500 -- top screen 3D right framebuffer 0(240x400x3) // 0x2B9800-0x2FFD00 -- top screen 3D right framebuffer 1(240x400x3) // 0x48F000-0x4C7400 -- bottom screen framebuffer 0(240x320x3) // 0x4C7800-0x4FF800 -- bottom screen framebuffer 1(240x320x3) return psd; }
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; } }
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; }