u16 nds_keysDownRepeat() { while (nds_power_state() == POWER_STATE_ASLEEP) { swiWaitForVBlank(); } return _nds_handedness_swap(keysDownRepeat()); }
void update(){ scanKeys(); touchRead(&stylus); keyDown = keysDownRepeat(); //Play::get_state()->run(); swiWaitForVBlank(); }
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(); } }
static int play(void *userData) { srand(time(NULL)); int scroll = 0; int quit = 0; int down; int redraw = 0; int mapNum = 0; touchPosition touch; gui = new Gui(); console = new Console(); try { anagram = new Anagram(); } catch (const char* err) { delete console; delete gui; return EXIT_FAILURE; } //copy bg tiles decompress(map[mapNum], bgGetMapPtr(1)); reset(); scroll = printList(scroll); console->flush(); keysSetRepeat(30, 6); while(!quit) { swiWaitForVBlank(); bgScrollf(1, -48, 48); bgUpdate(); scanKeys(); if(redraw) { scroll = printList(scroll); console->flush(); } redraw = 0; down = keysDown() | (keysDownRepeat() & (KEY_UP|KEY_DOWN)); if(down & KEY_UP) redraw = 1, scroll--; else if(down & KEY_DOWN) redraw = 1, scroll++; else if(down & KEY_B) redraw = 1, quit = 1; else if(down & KEY_START) redraw = 1, scroll = reset(); else if(down & KEY_X) { redraw = 1; strfry(choices); if(strlen(choices) == strlen(solution)) strcpy(solution, choices); } else if(down & KEY_Y) { mapNum = (mapNum+1)%NUM_MAPS; decompress(map[mapNum], bgGetMapPtr(1)); } if(down & KEY_TOUCH) touchRead(&touch); else memset(&touch, 0, sizeof(touch)); if(gui->update(choices, guess, touch) == GuiRC_Submit) { if(strlen(guess) > 2) { anagram->attempt(guess); addHistory(guess); } memset(guess, 0, sizeof(guess)); memset(choices, 0, sizeof(choices)); strcpy(choices, solution); redraw = 1; } } delete gui; delete console; delete anagram; return EXIT_SUCCESS; }
int main() { /* ドロイド君の x, y 座標 */ s16 dx = 120, dy = 120; /* りんごの x, y 座標 */ const s16 ax = 160, ay = 120; /* 窓の x, y 座標 */ const s16 wx = 40, wy = 40; /* タイルのベースアドレス */ u16* tile = (u16*)TILE_BASE_ADR(0); /* * ドロイド君の状態。 * 0 => 待機 * 1 => ジャンプ準備中 * 2 => ジャンプ中 */ int state = 0; /* 歩き状態 (0, 1, 2) */ int wstate = 0; /* ドロイド君の y 方向の速度 */ float vy = 0; /* フレーム数用の変数 */ u16 f = 0; /* 表示するキャラクタ */ u16 ch = 0; /* キー状態取得用変数 */ u16 kd = 0; u16 kdr = 0; u16 ku = 0; u16 kh = 0; /* 汎用変数 */ u16 i, xx, yy; /* フレーム数初期化 */ frame = 0; /* 割り込みの初期化 */ irqInit(); /* * VBLANK 割り込みを有効化 * これによって VBlankIntrWait() が使えるようになる */ irqEnable(IRQ_VBLANK); /* * モードの設定。 * MODE 0、スプライト有効化、BG0 有効化 */ SetMode(MODE_0 | OBJ_ENABLE | BG0_ON); /* スプライトのメモリ領域(OAM)にスプライトデータをコピー */ GbaGraphics::setSpriteData(spritesTiles, spritesTilesLen / 2); /* スプライトと BG のパレットのメモリ領域にパレットデータをコピー */ GbaGraphics::setSpritePalette(spritesPal, 16); GbaGraphics::setBGPalette(spritesPal, 16); GbaGraphics::setBGColor(RGB5(15,15,31)); /* スプライトの初期化 */ GbaGraphics::initSprites(); /* ドロイド君の準備 */ GbaGraphics::Sprite droid(0, 0, Sprite_16x16); droid.setPosition(dx, dy); droid.draw(); /* りんごの準備 */ GbaGraphics::Sprite apple(1, (2 * 32), Sprite_16x16); apple.setPosition(ax, ay); apple.draw(); /* 窓の準備 */ GbaGraphics::Sprite window(2, 2 + (2 * 32), Sprite_16x16); window.setPosition(wx, wy); window.draw(); /* BG 0 の設定 */ BGCTRL[0] = BG_MAP_BASE(31) | BG_16_COLOR | BG_SIZE_0 | TILE_BASE(0) | BG_PRIORITY(0); /* BG0 を初期化 */ for ( xx = 0; xx < 32; xx++ ) { for ( yy = 0; yy < 32; yy++ ) { MAP[31][yy][xx] = 6 * 32; } } /* 画像をタイルにコピー */ for ( i = 0; i < spritesTilesLen / 2; i++ ) { tile[i] = spritesTiles[i]; } /* BG0 をセット */ MAP[31][17][0] = 5 * 32; MAP[31][17][29] = 2 + 5 * 32; for ( i = 1; i < 29; i++ ) { MAP[31][17][i] = 1 + 5 * 32; } for ( xx = 0; xx < 30; xx++ ) { for ( yy = 18; yy < 32; yy++ ) { MAP[31][yy][xx] = 3 + 5 * 32; } } // コンソール出力のテスト cprintf("droid(%d, %d), apple(%d, %d), window(%d, %d), %s", dx, dy, ax, ay, wx, wy, "console test."); /* メインループ */ while (1) { /* VBLANK 割り込み待ち */ VBlankIntrWait(); /* フレーム数カウント */ frame += 1; /* キー状態取得 */ scanKeys(); kd = keysDown(); kdr = keysDownRepeat(); ku = keysUp(); kh = keysHeld(); switch(state) { case 0: /* 待機中 */ if( (kd & KEY_UP) ) { state = 1; f = 0; ch = 0; break; } if( (kh & KEY_LEFT) ) { dx--; droid.setHFlip(true); } if( (kh & KEY_RIGHT) ) { dx++; droid.setHFlip(false); } if( dx < -16 ) { dx = SCREEN_WIDTH; } if( kd & ( KEY_LEFT | KEY_RIGHT ) ) { wstate = 0; f = 0; } if( ku & ( KEY_LEFT | KEY_RIGHT ) ) { ch = 0; } if ( SCREEN_WIDTH < dx ) { dx = -16; } if ( kh & ( KEY_LEFT | KEY_RIGHT ) ) { /* 歩きモーション */ if ( 5 < f++ ) { switch ( wstate ) { case 0: wstate = 1; ch = 2; break; case 1: wstate = 2; ch = 0; break; case 2: wstate = 3; ch = 4; break; default: wstate = 0; ch = 0; break; } f = 0; } } if ( dy == (ay - 13) ) { if ( !(((ax - 11) < dx) && (dx < (ax + 11))) ) { /* りんごから落ちる */ vy = -0.; state = 2; wstate = 0; break; } } droid.setCharacter(ch); droid.setPosition(dx, dy); break; case 1: case 3: /* ジャンプ準備 */ droid.setCharacter(6); if( 3 < f++ ) { vy = 4.; if ( 1 == state ) state = 2; else state = 4; } break; case 2: case 4: /* ジャンプ中 */ if( (kd & KEY_UP) ) { /* 二段ジャンプ */ if ( state == 2 ) { state = 3; f = 0; break; } } if( kh & KEY_LEFT ) { dx--; droid.setHFlip(true); } if( kh & KEY_RIGHT ) { dx++; droid.setHFlip(false); } if( dx < -16 ) { dx = SCREEN_WIDTH; } if ( SCREEN_WIDTH < dx ) { dx = -16; } if( (0.5 < vy) && ( kh & KEY_UP ) ) { vy += 0.2; } dy -= (s16)vy; if(vy < 0) { droid.setCharacter(10); } else { droid.setCharacter(8); } if ( dy < 0 ) { dy = 0; vy = -0.; } if ( (vy < 0) && ((ax - 11) < dx) && (dx < (ax + 11)) ) { if ( ay - 13 < dy ) { /* りんごに乗る */ dy = ay - 13; state = 0; } } if ( 120 < dy ) { /* 着地 */ dy = 120; state = 0; } droid.setPosition(dx, dy); vy = vy - 0.3; break; } droid.draw(); } }
//--------------------------------------------------------------------------------- // Program entry point //--------------------------------------------------------------------------------- int main(void) { //--------------------------------------------------------------------------------- // the vblank interrupt must be enabled for VBlankIntrWait() to work // since the default dispatcher handles the bios flags no vblank handler // is required irqInit(); irqEnable(IRQ_VBLANK); // set mode 0, 1D mapping REG_DISPCNT = MODE_0 | OBJ_1D_MAP; init_oam(obj_buffer, 128); // copy sprites to appropriate memory spots u16 *palette_end = SPRITE_PALETTE; u16 *tiles_end =SPRITE_GFX; // blue slime memcpy(palette_end, blueslimePal, blueslimePalLen); memcpy(tiles_end, blueslimeTiles, blueslimeTilesLen); palette_end += blueslimePalLen/2; tiles_end += blueslimeTilesLen/2; // drakee memcpy(palette_end, drakeePal, drakeePalLen); memcpy(tiles_end, drakeeTiles, drakeeTilesLen); palette_end += drakeePalLen/2; tiles_end += drakeeTilesLen/2; // orange slime memcpy(palette_end, orangeslimePal, orangeslimePalLen); memcpy(tiles_end, orangeslimeTiles, orangeslimeTilesLen); palette_end += orangeslimePalLen/2; tiles_end += orangeslimeTilesLen/2; // enable sprites REG_DISPCNT |= OBJ_ON | OBJ_WIN_ENABLE; u16 x = 0; u16 y = 0; s8 sprite = 1; u16 status = ATTR0_NORMAL; obj_buffer[0].attr0 = (y & 0x00ff) | ATTR0_NORMAL | ATTR0_COLOR_16 | ATTR0_SQUARE; obj_buffer[0].attr1 = (x & 0x01ff) | ATTR1_SIZE_32; obj_buffer[0].attr2 = OBJ_CHAR(0); oam_copy(OAM, obj_buffer, 1); setRepeat(1,1); while (1) { // check keypad scanKeys(); u16 keystate = keysDownRepeat(); u16 keydown = keysDown(); // directional pad // move sprite if (keystate & KEY_LEFT) x -= 1; else if (keystate & KEY_RIGHT) x += 1; if (keystate & KEY_UP) y -= 1; else if (keystate & KEY_DOWN) y += 1; // A // enable/disable sprite if (keydown & KEY_A) { if (status == ATTR0_NORMAL) status = ATTR0_DISABLED; else status = ATTR0_NORMAL; } // L + R // rotate sprites if (keydown & KEY_R) { sprite++; if (sprite > 2) sprite = 0; } else if (keydown & KEY_L) { sprite--; if (sprite < 0) sprite = 2; } // set current sprite attributes obj_buffer[0].attr0 = (y & 0x00ff) | status | ATTR0_COLOR_16 | ATTR0_SQUARE; obj_buffer[0].attr1 = (x & 0x01ff) | ATTR1_SIZE_32; obj_buffer[0].attr2 = OBJ_CHAR(sprite*16) | OBJ_PALETTE(sprite); oam_copy(OAM, obj_buffer, 1); VBlankIntrWait(); } return 0; }
int main( int argc, char **argv) { // defaultExceptionHandler(); if (fatInitDefault()) { fifoWaitValue32(FIFO_USER_02); if (fifoGetValue32(FIFO_USER_01) == 0) { int size = 32; FILE* ResetData = fopen("sd:/hiya/ResetData.bin","rb"); fread((void*)0x02000300,1,size,ResetData); fclose(ResetData); fifoSendValue32(FIFO_USER_08, 1); for (int i = 0; i < 5; i++) { swiWaitForVBlank(); } } LoadSettings(); bool gotoSettings = false; if (access("sd:/hiya/settings.ini", F_OK)) { gotoSettings = true; } scanKeys(); if(keysHeld() & KEY_SELECT) gotoSettings = true; if(gotoSettings) { // Subscreen as a console videoSetMode(MODE_0_2D); vramSetBankG(VRAM_G_MAIN_BG); videoSetModeSub(MODE_0_2D); vramSetBankH(VRAM_H_SUB_BG); int pressed = 0; bool menuprinted = true; while(1) { if(menuprinted) { consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true); consoleClear(); printf("HiyaCFW v1.0 configuration\n"); printf("Press A to select, START to save"); printf("\n"); if(cursorPosition == 0) printf(">"); else printf(" "); printf("Splash: "); if(splash) printf("Off( ), On(x)"); else printf("Off(x), On( )"); printf("\n\n"); if(cursorPosition == 1) printf(">"); else printf(" "); if(dsiSplash) printf("(x)"); else printf("( )"); printf(" DSi Splash/H&S screen"); consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true); consoleClear(); if(cursorPosition == 0) { printf("Enable splash screen."); } else if(cursorPosition == 1) { printf("Enable showing the DSi Splash/\n"); printf("Health & Safety screen."); } menuprinted = false; } do { scanKeys(); pressed = keysDownRepeat(); swiWaitForVBlank(); } while (!pressed); if (pressed & KEY_A) { switch(cursorPosition){ case 0: default: splash = !splash; break; case 1: dsiSplash = !dsiSplash; break; } menuprinted = true; } if (pressed & KEY_UP) { cursorPosition -= 1; menuprinted = true; } else if (pressed & KEY_DOWN) { cursorPosition += 1; menuprinted = true; } if (cursorPosition < 0) cursorPosition = 1; if (cursorPosition > 1) cursorPosition = 0; if (pressed & KEY_START) { SaveSettings(); break; } } } if(dsiSplash) fifoSendValue32(FIFO_USER_03, 1); if(splash) { BootSplashInit(); LoadScreen(); for (int i = 0; i < 60*3; i++) { swiWaitForVBlank(); } } runNdsFile("/BOOTLOADER.NDS", 0, NULL); } else { BootSplashInit(); // Display Error Screen swiDecompressLZSSVram ((void*)topErrorTiles, (void*)CHAR_BASE_BLOCK(2), 0, &decompressBiosCallback); swiDecompressLZSSVram ((void*)subErrorTiles, (void*)CHAR_BASE_BLOCK_SUB(2), 0, &decompressBiosCallback); vramcpy_ui (&BG_PALETTE[0], topErrorPal, topErrorPalLen); vramcpy_ui (&BG_PALETTE_SUB[0], subErrorPal, subErrorPalLen); } while(1) { swiWaitForVBlank(); } }