void device_io() { if ( render_audio() && --scanDC == 0 ) { scanDC = bufsPerScan; // reload downcounter to next scan /* scan keys */ if ( curKey >= 0 ) { if ( ! readKey( curKey ) ) { console.postKeyUp( curKey, 0 ); scanKeys(); } } else scanKeys(); /* scan buttons */ for ( byte i = 0; i < NumButs; i++ ) scanBut(i); /* read next pot */ readPot( nextPot ); if ( ++nextPot >= NumPots ) nextPot = 0; } }
int main(void) { videoSetMode(MODE_5_2D); consoleDemoInit(); scanKeys(); int c = keysHeld(); Sfondo(); CreaPG(); while(true) { swiWaitForVBlank(); if(c!=0) { KeysPress(c); //iprintf("-key:%i\n",c); c = 0; } else {//Nessun tasto premuto scanKeys(); c = keysHeld(); } } return 0; }
int main(void) { consoleDemoInit(); Keyboard *kbd = keyboardDemoInit(); kbd->OnKeyPressed = OnKeyPressed; while(1) { char myName[256]; iprintf("What is your name?\n"); scanf("%s", myName); iprintf("\nHello %s", myName); scanKeys(); while(!keysDown())scanKeys(); swiWaitForVBlank(); consoleClear(); } return 0; }
void waitfor(int keys) { scanKeys(); while((keysDown() & keys) == 0) { swiWaitForVBlank(); scanKeys(); } }
void Menu::NX(int sock) { int volume = 77; while(1) { consoleClear(); iprintf("\n netxmms-nds\n ___________\n\n" " A - PLAY\n" " B - PAUSE\n" " Y - STOP\n" " R - NEXT\n" " L - PREVIOUS\n" " < - VOLUME-\n" " > - VOLUME+\n\n" " VOLUME: %d%%", volume); while(1) { swiWaitForVBlank(); scanKeys(); int pressed = keysDown(); int held = keysHeld(); if(pressed & KEY_A) NX::Play(sock); if(pressed & KEY_B) NX::Pause(sock); if(pressed & KEY_Y) NX::Stop(sock); if(pressed & KEY_R) NX::Next(sock); if(pressed & KEY_L) NX::Previous(sock); if(pressed & KEY_LID) { int s = REG_POWERCNT; REG_POWERCNT = 0; while(1) { scanKeys(); if(keysUp() & KEY_LID) { REG_POWERCNT = s; break; } } } if(held & KEY_LEFT && volume > 0) { volume--; NX::Volume(sock, volume); break; } else if(held & KEY_RIGHT && volume < 100) { volume++; NX::Volume(sock, volume); break; } } } }
void Update() { //@NOTE: scanKeys() and keysDown() must only be called once per frame, never more scanKeys(); gKeysPressed = gRawKeysPressed = keysDown(); gKeysHeld = keysHeld(); if (gKeysPressed & PauseKey) { gIsPaused = !gIsPaused; } gUnpauseOneFrame = false; if (gKeysPressed & UnpauseOneFrameKey) { gUnpauseOneFrame = true; } // Pause key only queryable via IsPaused() gKeysPressed &= (~PauseKey & ~UnpauseOneFrameKey); // When paused, for debugging purposes, it's useful to consider // held keys as pressed keys if (gIsPaused) { gKeysPressed |= gKeysHeld; } }
void input(){ //Fonction de test des touches touchPosition touchXY; do{ scanKeys(); if(keysHeld() & KEY_A) iprintf("\x1b[4;0HAppui A"); //Bouton A else if(keysHeld() & KEY_B) iprintf("\x1b[5;0HAppui B"); //Bouton B else if(keysHeld() & KEY_X) iprintf("\x1b[6;0HAppui X"); //Bouton X else if(keysHeld() & KEY_Y) iprintf("\x1b[7;0HAppui Y"); //Bouton Y else if(keysHeld() & KEY_L) iprintf("\x1b[8;0HAppui L"); //Bouton L else if(keysHeld() & KEY_R) iprintf("\x1b[9;0HAppui R"); //Bouton R else if(keysHeld() & KEY_START) iprintf("\x1b[10;0HAppui START"); //Bouton START else if(keysHeld() & KEY_SELECT) iprintf("\x1b[11;0HAppui SELECT"); //Bouton SELECT else{ int i; //Effaçage zone for(i=4;i<=11;i++){ iprintf("\x1b[%u;0H ",i); } } touchRead(&touchXY); }while((touchXY.px>=0x00)&&(touchXY.py>=0x00)&&(touchXY.py<0xB4)&&(touchXY.py<0xFF)); }
void updateInput(touchPosition * touch) { // Update the key registers with current values. scanKeys(); // Update the touch screen values. touchRead(touch); }
void Menu::Main() { consoleClear(); printf("\n netxmms-nds\n ___________\n\n" " A - CONNECT\n" " B - CONFIGURE\n\n" " START - INFORMATION"); while(1) { swiWaitForVBlank(); scanKeys(); u32 entry = keysDown(); if(entry & KEY_A) { Menu::ConnectWifi(); return; } else if(entry & KEY_B) { Menu::Configuration(); return; } else if(entry & KEY_START) { Menu::Information(); return; } } }
LevelId LevelSelector::select_level() { touchPosition stylus; level.set_current_level(level.get_level(selected_button).id); level.load(); draw(); while (true) { scanKeys(); touchRead(&stylus); if (button_ok.update(stylus) == BUTTON_CLICKED) { return level.get_level(selected_button).id; } for (u8 current_button = 0; current_button < num_buttons; current_button++) { if (buttons[current_button]->update(stylus) == BUTTON_CLICKED) { u8 last_selected_button = selected_button; set_selected_level(level.get_level(current_button).id); buttons[last_selected_button]->draw(); buttons[selected_button]->draw(); level.set_current_level(level.get_level(selected_button).id); level.load(); level.draw(LEVEL_X, LEVEL_Y); } } swiWaitForVBlank(); } }
void NDS_PumpEvents(_THIS) { scanKeys(); int i; SDL_keysym keysym; keysym.mod=KMOD_NONE; for(i=0;i<NDS_NUMKEYS;i++) { keysym.scancode=i; keysym.sym=keymap[i]; if(keysHeld()&(1<<i) && !keymem[i]) { keymem[i]=1; //printf("key released %d\n",i); SDL_PrivateKeyboard(SDL_RELEASED, &keysym); } if(!(keysHeld()&(1<<i)) && keymem[i]) { keymem[i]=0; //printf("key pressed %d\n",i); SDL_PrivateKeyboard(SDL_PRESSED, &keysym); } } //touchPosition touch; //touch=touchReadXY(); //if (touch.px!=0 || touch.py!=0) // SDL_PrivateMouseMotion(SDL_PRESSED, 0, touch.px, touch.py); }
//----------------------------------------------------------------- // process input //----------------------------------------------------------------- void processInput( void ) //----------------------------------------------------------------- { scanKeys(); int keysh = keysHeld(); // process user input if( keysh & KEY_UP ) // check if UP is pressed { if ( g_ball.y == c_platform_level ) g_ball.yvel = -y_tweak; else if ( (g_ball.yvel < 0) && (g_ball.y < 4 + c_platform_level) ) g_ball.yvel -= y_tweak/14; } if( keysh & KEY_DOWN ) // check if DOWN is pressed { // tweak y velocity of ball g_ball.yvel += y_tweak; } if( keysh & KEY_LEFT ) // check if LEFT is pressed { // tweak x velocity g_ball.xvel -= x_tweak; } if( keysh & KEY_RIGHT ) // check if RIGHT is pressed { // tweak y velocity g_ball.xvel += x_tweak; } }
/* DS_VBlank_IRQ Vertical blank interrupt callback. */ LOCALPROC DS_VBlank_IRQ(void) { scanKeys(); KeysHeld = keysHeld(); if (++VBlankCounter == 60) { VBlankCounter = 0; } /* TODO: Rewrite this at some point, I'm not sure I like it. */ if (0 != (KeysHeld & KEY_LEFT)) { --CursorX; } else if (0 != (KeysHeld & KEY_RIGHT)) { ++CursorX; } if (0 != (KeysHeld & KEY_UP)) { --CursorY; } else if (0 != (KeysHeld & KEY_DOWN)) { ++CursorY; } CursorX = CursorX < 0 ? 0 : CursorX; CursorX = CursorX > vMacScreenWidth ? vMacScreenWidth : CursorX; CursorY = CursorY < 0 ? 0 : CursorY; CursorY = CursorY > vMacScreenHeight ? vMacScreenHeight : CursorY; DS_ScrollBackground(); bgUpdate(); }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- consoleDemoInit(); //setup the sub screen for printing keyboardDemoInit(); keyboardShow(); while(1) { int key = keyboardUpdate(); if(key > 0) iprintf("%c", key); swiWaitForVBlank(); scanKeys(); int pressed = keysDown(); if(pressed & KEY_START) break; } return 0; }
/* Try to connect to given AP and get an IP via DHCP */ int connect_ap(Wifi_AccessPoint * ap) { int ret; int status = ASSOCSTATUS_DISCONNECTED; clear_main(); /* Ask for DHCP */ Wifi_SetIP(0, 0, 0, 0, 0); ret = Wifi_ConnectAP(ap, WEPMODE_NONE, 0, NULL); if (ret) { print_to_debug("error connecting"); return ASSOCSTATUS_CANNOTCONNECT; } while (status != ASSOCSTATUS_ASSOCIATED && status != ASSOCSTATUS_CANNOTCONNECT) { int oldStatus = status; status = Wifi_AssocStatus(); if (oldStatus != status) printf_to_main("\n%s", (char *)ASSOCSTATUS_STRINGS[status]); else printf_to_main("."); scanKeys(); if (keysDown() & KEY_B) break; swiWaitForVBlank(); } return status; }
//--------------------------------------------------------------------------------- void waitButtonA() { //--------------------------------------------------------------------------------- while(1) { scanKeys(); swiWaitForVBlank(); if (keysDown() & KEY_A) break; } }
int main() { // Setup the Main screen for 3D videoSetMode(MODE_0_3D); // initialize the geometry engine glInit(); // enable antialiasing glEnable(GL_ANTIALIAS); // setup the rear plane glClearColor(0,0,0,31); // BG must be opaque for AA to work glClearPolyID(63); // BG must have a unique polygon ID for AA to work glClearDepth(0x7FFF); // Set our viewport to be the same size as the screen glViewport(0,0,255,191); // setup the view glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 100); //ds specific, several attributes can be set here glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); while (1) { // Set the current matrix to be the model matrix glMatrixMode(GL_MODELVIEW); glColor3f(1, 1, 1); // Set the color..not in nehe source...ds gl default will be black //Push our original Matrix onto the stack (save state) glPushMatrix(); DrawGLScene(); // Pop our Matrix from the stack (restore state) glPopMatrix(1); //a handy little built in function to wait for a screen refresh swiWaitForVBlank(); // flush to screen glFlush(0); scanKeys(); int pressed = keysDown(); if(pressed & KEY_START) break; } return 0; }
int main() { // REG_WAITCNT = 0x46d6; // lets set some cool waitstates... REG_WAITCNT = 0x46da; // lets set some cool waitstates... irqInit(); irqEnable(IRQ_VBLANK); consoleInit(0, 4, 0, NULL, 0, 15); BG_COLORS[0] = RGB5(0, 0, 0); BG_COLORS[241] = RGB5(31, 31, 31); REG_DISPCNT = MODE_0 | BG0_ON; gbfs_init(1); pimp_sample_bank sb; FILE *fp = fopen("dxn-oopk.xm", "rb"); if (!fp) { fprintf(stderr, "file not found\n"); return 1; } pimp_module *mod = load_module_xm(fp, &sb); fclose(fp); fp = NULL; if (NULL == mod) { fprintf(stderr, "failed to load module\n"); return 1; } pimp_gba_init(mod, sb.data); pimp_gba_set_callback(callback); irqSet(IRQ_TIMER3, timer3); irqEnable(IRQ_TIMER3); REG_TM3CNT_L = 0; REG_TM3CNT_H = TIMER_START | TIMER_IRQ | 2; irqSet(IRQ_VBLANK, vblank); irqEnable(IRQ_VBLANK); while (1) { VBlankIntrWait(); scanKeys(); int keys = keysDown(); if (keys & KEY_UP) pimp_gba_set_pos(0, pimp_gba_get_order() - 1); if (keys & KEY_DOWN) pimp_gba_set_pos(0, pimp_gba_get_order() + 1); if (keys & KEY_RIGHT) pimp_gba_set_pos(pimp_gba_get_row() + 8, pimp_gba_get_order()); if (keys & KEY_LEFT) pimp_gba_set_pos(pimp_gba_get_row() - 8, pimp_gba_get_order()); iprintf("%d %d\n", pimp_gba_get_order(), pimp_gba_get_row()); } pimp_gba_close(); return 0; }
void update(){ scanKeys(); touchRead(&stylus); keyDown = keysDownRepeat(); //Play::get_state()->run(); swiWaitForVBlank(); }
void EventHandler::Update() { scanKeys(); touchRead(&m_touchPos); m_held = keysHeld(); m_pressed = keysDown(); }
int main() { consoleDemoInit(); uint ticks = 0; TimerStates state = timerState_Stop; int down = keysDown(); while(!(down & KEY_START)) { swiWaitForVBlank(); consoleClear(); scanKeys(); down = keysDown(); if(state == timerState_Running) { ticks += timerElapsed(0); } if(down & KEY_A) { if(state == timerState_Stop) { timerStart(0, ClockDivider_1024, 0, NULL); state = timerState_Running; } else if(state == timerState_Pause) { timerUnpause(0); state = timerState_Running; } else if(state == timerState_Running) { ticks += timerPause(0); state = timerState_Pause; } } else if(down & KEY_B) { timerStop(0); ticks = 0; state = timerState_Stop; } iprintf("Press A to start and pause the \ntimer, B to clear the timer \nand start to quit the program.\n\n"); iprintf("ticks: %u\n", ticks); iprintf("second: %u:%u\n", ticks/TIMER_SPEED, ((ticks%TIMER_SPEED)*1000) /TIMER_SPEED); } if(state != timerState_Stop) { timerStop(0); } return 0; }
void console_pause() { while(1) { scanKeys(); if(keysDown() & KEY_A)exit(0); swiWaitForVBlank(); } }
int main() { int fadeToggle = 1; irqInit(); irqSet( IRQ_TIMER1, kradInterrupt ); // not really needed, as kragInit also enables IRQ_TIMER1 irqEnable( IRQ_TIMER1 ); REG_IME = 1; SetMode( MODE_0 | BG0_ON ); kragInit( KRAG_INIT_STEREO ); // init krawall krapCallback( callback ); krapPlay( &mod_secondpm, 0, 0 ); // play module while( 1 ) { // wait for line 0 while( !REG_VCOUNT ); while( REG_VCOUNT ); // rasterbar start BG_COLORS[0] = rasterbar_color; kramWorker(); // do the stuff // rasterbar stop BG_COLORS[0] = 0; scanKeys(); int keys_pressed = keysDown(); if( keys_pressed & KEY_A ) { if( krapIsPaused() ) { // if resuming, force volume to max krapSetMusicVol( 128, 0 ); krapUnpause(); } else krapPause( 1 ); } if( keys_pressed & KEY_B ) { if( fadeToggle ) { // see callback function, when silence is reached // the tune is paused krapSetMusicVol( 0, 1 ); } else { krapSetMusicVol( 128, 1 ); } fadeToggle ^= 1; } } return 0; }
void anykey() { iprintf("Press any key to exit...\n"); for(;;) { scanKeys(); if (keysDown()) break; } }
void editorFrame(void) { scanKeys(); GFX_CLEAR_COLOR=RGB15(27,27,27)|(31<<16); updateRoomEditor(); drawRoomEditor(); swiWaitForVBlank(); }
//--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- //set the mode for 2 text layers and two extended background layers videoSetMode(MODE_5_2D); //set the first two banks as background memory and the third as sub background memory //D is not used..if you need a bigger background then you will need to map //more vram banks consecutivly (VRAM A-D are all 0x20000 bytes in size) vramSetPrimaryBanks( VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, VRAM_C_SUB_BG , VRAM_D_LCD); consoleDemoInit(); iprintf("\n\n\tHello DS devers\n"); iprintf("\twww.drunkencoders.com\n"); iprintf("\tdouble buffer demo"); int bg = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0,0); u16 colorMask = 0x1F; u16* backBuffer = (u16*)bgGetGfxPtr(bg) + 256*256; while(1) { //draw a box (60,60,196,136) for(int iy = 60; iy < 196 - 60; iy++) for(int ix = 60; ix < 256 - 60; ix++) backBuffer[iy * 256 + ix] = (rand() & colorMask) | BIT(15); swiWaitForVBlank(); scanKeys(); if (keysDown()&KEY_START) break; //swap the back buffer to the current buffer backBuffer = (u16*)bgGetGfxPtr(bg); //swap the current buffer by changing the base. Each base //represents 16KB of offset and each screen is 256x256x2 (128KB) //this requires a map base seperation of 8 (could get away with smaller //as the screen is really only showing 256x192 (96KB or map base 6) if(bgGetMapBase(bg) == 8) { bgSetMapBase(bg, 0); } else { bgSetMapBase(bg, 8); } colorMask ^= 0x3FF; } }
void menu_print_page (const page_t *page) { int i, cur; u32 keys, keys_; cur = 0; while (1) { consoleClear(); iprintf("-- %s\n\n", page->title); const entry_t *sel_entry = &page->entries[cur]; for (i = 0; i < page->entries_no; i++) { const entry_t *entry = &page->entries[i]; iprintf("%c %s %s\n", (i == cur) ? '>' : ' ', entry->label, (entry->opts_no) ? entry->opts[*entry->opt_ptr] : ""); } scanKeys(); keys = keysDown(); keys_ = keysDownRepeat(); if (keys_&KEY_UP) { cur--; if (cur < 0) cur = page->entries_no - 1; } if (keys_&KEY_DOWN) { cur++; if (cur == page->entries_no) cur = 0; } if (sel_entry->opts_no && (keys_&(KEY_LEFT|KEY_RIGHT))) { if (keys_&KEY_LEFT && *sel_entry->opt_ptr > 0) (*sel_entry->opt_ptr)--; if (keys_&KEY_RIGHT && *sel_entry->opt_ptr < sel_entry->opts_no - 1) (*sel_entry->opt_ptr)++; if (!sel_entry->confirm && sel_entry->cb) sel_entry->cb(*sel_entry->opt_ptr); } if (keys&KEY_A && sel_entry->cb) { sel_entry->cb(*sel_entry->opt_ptr); return; } if (keys&(KEY_B|KEY_START)) return; swiWaitForVBlank(); } }
// Populate the key list. bool Keypad::getKeys() { bool keyActivity = false; // Limit how often the keypad is scanned. This makes the loop() run 10 times as fast. if ( (millis()-startTime)>debounceTime ) { scanKeys(); keyActivity = updateList(); startTime = millis(); } return keyActivity; }
bool yesNoBox::getResult( const char* p_text, bool p_textAtOnce ) { s16 x = 8 + 64 * !!_isNamed; s16 y = 8; if( p_text && !p_textAtOnce ) regularFont->printStringD( p_text, x, y, true ); else if( p_text ) regularFont->printString( p_text, x, y, true ); u8 selIdx = (u8) -1; draw( 2, selIdx ); bool result; loop( ) { swiWaitForVBlank( ); touchPosition t; touchRead( &t ); scanKeys( ); int pressed = keysCurrent( ); if( GET_AND_WAIT( KEY_LEFT ) ) { selIdx = 0; draw( 2, selIdx ); } else if( GET_AND_WAIT( KEY_RIGHT ) ) { selIdx = 1; draw( 2, selIdx ); } else if( selIdx != (u8) -1 && GET_AND_WAIT( KEY_A ) ) { result = !selIdx; break; } if( t.px >= 28 && t.py >= 102 && t.px <= 122 && t.py <= 134 ) { draw( 0, selIdx ); if( !waitForTouchUp( 28, 102, 122, 134 ) ) { draw( 2, selIdx ); continue; } draw( 2, selIdx ); swiWaitForVBlank( ); result = true; break; } else if( t.px >= 134 && t.py >= 102 && t.px <= 228 && t.py <= 134 ) { draw( 1, selIdx ); if( !waitForTouchUp( 134, 102, 228, 134 ) ) { draw( 2, selIdx ); continue; } draw( 2, selIdx ); swiWaitForVBlank( ); result = false; break; } } return result; }
void Menu::Continue() { printf(" A - RETURN\n"); while(1) { swiWaitForVBlank(); scanKeys(); if(keysDown() & KEY_A) break; } }