void soundtest() { tte_write("#{es}"); tte_write("#{P:0,0}GBA Sound Test\n"); tte_write("A song should now be playing.\n"); tte_write("Pressing B will exit.\n"); vid_vsync(); key_poll(); mmStart( MOD_SMACHOOSEAPLAYER, MM_PLAY_LOOP ); while(key_is_up(KEY_B)){ vid_vsync(); mmFrame(); key_poll(); } mmStop(); }
int main(void) { title(); menu(); init_game(); int x=0, y=0; while(1) { key_poll(); x += key_tri_horz()*2; y += key_tri_vert()*2; vid_vsync(); //oam_copy(oam_mem, obj_buffer, 128); REG_BG1HOFS = x; REG_BG1VOFS = y; } return 0; }
/* =================================== * MAIN RUN LOOP * =================================== */ void mainRunLoop() { while(!gameover) { /* Get and process input */ key_poll(); if (key_hit(KEY_RIGHT)) keyRight(); else if (key_hit(KEY_LEFT)) keyLeft(); else if (key_hit(KEY_UP)) { droppedYet = 1; keyHardDrop(); } else if (key_hit(KEY_DOWN)) keySoftDrop(); else if (key_hit(KEY_A)) { rotatedYet = 1; keyRotateRight(); } else if (key_hit(KEY_B)) { rotatedYet = 1; keyRotateLeft(); } else if (key_hit(KEY_SELECT)) showMenu(); else if (key_hit(KEY_START)) pause(); waitForVBlank(); frame++; /* Calculate layout of next frame */ if ((frame % fallSpeed)==0) { placed = 0; clearTetrimino(keyLastR, keyLastC, keyLastT); if (checkBoundBottom(key) != 1) { key.r = key.r + 1; drawTetrimino(key); } else { placeKey(); placed = 1; } } if ((frame % inputSpeed)==0) { if (placed == 0) { clearTetrimino(keyLastR, keyLastC, keyLastT); drawTetrimino(key); } keyLastR = key.r; keyLastC = key.c; for (int i = 0; i < 16; i++) keyLastT[i] = key.t[i]; movedYet = 0; } if ((frame % rotateSpeed)==0) rotatedYet = 0; } }
int key_checkch() { int is_one_waiting = 0; key_poll(); if (key_data.keytail!=key_data.keyhead) is_one_waiting = 1; return is_one_waiting; }
/* ================================== * TITLE SCREEN * ================================== */ void titleScreen() { drawImage3(0,0,240,160,title); while(1) { key_poll(); if (key_hit(KEY_START)) break; } }
/* ================================= * GAME OVER SCREEN * ================================= */ void gameOverScreen() { drawImage3(0,0,240,160,gameoverscreen); while(1) { key_poll(); if (key_hit(KEY_START)) break; } }
int key_peekkey() { int key = 0; key_poll(); if (key_data.keytail!=key_data.keyhead) key = key_data.keybuffer[key_data.keyhead]; return key; }
unsigned int key_up_count(int scancode) { int n; key_poll(); if ((scancode<0)|| (scancode>255)) return 0; n = key_data.keys[scancode].upcount; key_data.keys[scancode].upcount = 0; return n; }
int key_inkey_time(fix * time) { int key = 0; key_poll(); if (key_data.keytail!=key_data.keyhead) { key = key_data.keybuffer[key_data.keyhead]; *time = key_data.time_pressed[key_data.keyhead]; key_data.keyhead = add_one(key_data.keyhead); } return key; }
void menu() { memcpy(vid_mem, menuBitmap, menuBitmapLen); while(~key_released(KEY_A)) { key_poll(); vid_vsync(); if(key_hit(KEY_A)) break; } }
void title() { // int* ptr; ptr = malloc(4); *ptr = 0x11223344; DEBUG_PRINTF("ptr = %#x\n", (u32)ptr); DEBUG_PRINTF("&obj_buffer = %#x\n",(u32)obj_buffer); u8 bytes[5] = { 0x11, 0x22, 0x33, 0x44, 0x55 }; u16 halfwords[5] = { 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA }; u32 words[3] = { 0x11223344, 0x55667788, 0x99AABBCC }; DEBUG_PRINTF("&bytes = %#x\n", (u32)bytes); DEBUG_PRINTF("&halfwords = %#x\n", (u32)halfwords); DEBUG_PRINTF("&words = %#x\n", (u32)words); memcpy(vid_mem, titleBitmap, titleBitmapLen); REG_DISPCNT = DCNT_MODE3 | DCNT_BG2; char* h = "PRESS A TO CONTINUE\n"; int x = 50, y = 100; int frame = 0; while(~key_hit(KEY_A)) { key_poll(); vid_vsync(); if( frame & 1 && *h != 0) { print_ch(*h, x, y, 0x0000); x += 6; h ++; frame = 0; } frame ++; if(key_hit(KEY_A)) break; } }
void Pause_Input() { //Pushing start will push the Pause state onto the stack, starting the pause. key_poll(); if(key_hit(KEY_START)) { // Pop pause state & offload Pause_Offload(); g_StateStack->states.pop(); } }
void Menu_Input() { //Pushing start will push the Game state onto the stack, starting the game. key_poll(); if(key_hit(KEY_START)) { //Push game state on after offloading this state. Menu_Offload(); State nextState; nextState.StatePointer = Game; g_StateStack->states.push(nextState); } }
int key_inkey() { int key = 0; key_poll(); if (key_data.keytail!=key_data.keyhead) { key = key_data.keybuffer[key_data.keyhead]; key_data.keyhead = add_one(key_data.keyhead); } #ifdef SUPPORTS_NICEFPS //added 9/3/98 by Matt Mueller to free cpu time instead of hogging during menus and such else d_delay(1); //end addition - Matt Mueller #endif return key; }
// Returns the number of seconds this key has been down since last call. fix key_down_time(int scancode) { fix time_down, time; if ((scancode<0)|| (scancode>255)) return 0; key_poll(); if (!keyd_pressed[scancode]) { time_down = key_data.keys[scancode].timehelddown; key_data.keys[scancode].timehelddown = 0; } else { time = timer_get_fixed_seconds(); time_down = time - key_data.keys[scancode].timewentdown; key_data.keys[scancode].timewentdown = time; } return time_down; }
void splash() { REG_DISPCTL = MODE3 | BG2_ENABLE; drawImage3(nerdbgBitmap, 0, 0, 160, 240); int rand_seed = 42; while (state == SPLASH) { rand_seed++; key_poll(); if (key_hit(BUTTON_A)) state = INSTRUCTIONS; else if (key_hit(BUTTON_B)) state = GAME; } srand(rand_seed); }
void instructions() { REG_DISPCTL = MODE3 | BG2_ENABLE; fillScreen3(COLOR(0,31,31)); drawRect3(0, 0,0,240,160); drawString(1, 1, "NERD HERDER!", COLOR(31,31,31)); drawString(21, 1, "As head TA you control the destiny of", COLOR(31,31,31)); drawString(31, 1, "scores of students. It takes dedication,", COLOR(31,31,31)); drawString(41, 1, "strength, and the ability to intimidate.", COLOR(31,31,31)); drawString(51, 1, "In this game you separate the wheat", COLOR(31,31,31)); drawString(61, 1, "from the chaff. Intimidate the nerds to", COLOR(31,31,31)); drawString(71, 1, "their dorm so they'll do their homework.", COLOR(31,31,31)); drawString(81, 1, "Send the flunkies to the M-Train so they", COLOR(31,31,31)); drawString(91, 1, "won't bother the rest of us. Also there", COLOR(31,31,31)); drawString(101, 1, "might be power ups?", COLOR(31,31,31)); drawString(121, 1, "Press A to return", COLOR(31,31,31)); while (state == INSTRUCTIONS) { key_poll(); if (key_hit(BUTTON_A)) state = SPLASH; } }
int playPuzzle(int NUR_ROWS, int NUR_COLS, int puzzle[NUR_ROWS][NUR_COLS], int puzzle_index) { int cursor_r = 0; int cursor_c = 0; // Load palette memcpy16(pal_bg_mem, SharedPal, SharedPalLen / 2); // Load tiles into CBB 0 (16x16) and 1 (8x8) // Each charblock is 0x4000, an 8x8 tile is 0x20 bytes, // so there are 512 8x8 tiles or 128 16x16 tiles in each charblock. memcpy16(tile_mem[0], tiles16Tiles, tiles16TilesLen / 2); memcpy16(tile_mem[1], tiles8Tiles, tiles8TilesLen / 2); // Load the 16x16 puzzle map into screenblocks 28-31 for (int r = 0; r < 32; r++) { for (int c = 0; c < 32; c++) { set_tile(28, r, c, OUTSIDE); } } for (int c = 0; c < NUR_COLS; c++) set_tile(28, NUR_ROWS, c, BOTTOM_EDGE); for (int r = 0; r < NUR_ROWS; r++) set_tile(28, r, NUR_COLS, RIGHT_EDGE); set_tile(28, NUR_ROWS, NUR_COLS, BOTTOM_RIGHT_CORNER); for (int r = 0; r < NUR_ROWS; r++) { for (int c = 0; c < NUR_COLS; c++) { set_tile(28, r, c, puzzle[r][c]); } } // Load the 16x16 cursor map into screenblocks 24-27 for (int r = 0; r < 32; r++) { for (int c = 0; c < 32; c++) { set_tile(24, r, c, TRANSPARENT); } } set_tile(24, cursor_r, cursor_c, CURSOR); // 8x8 tiles: // set up BG2 for a 4bpp 32x32t map, using charblock 1 and screenblock 22 (cursor) REG_BG2CNT = BG_CBB(1) | BG_SBB(22) | BG_4BPP | BG_REG_32x32; // set up BG3 for a 4bpp 32x32t map, using charblock 1 and screenblock 23 (puzzle squares) REG_BG3CNT = BG_CBB(1) | BG_SBB(23) | BG_4BPP | BG_REG_32x32; // 16x16 tiles: // set up BG0 for a 4bpp 64x64t map, using charblock 0 and screenblocks 24-27 (cursor) REG_BG0CNT = BG_CBB(0) | BG_SBB(24) | BG_4BPP | BG_REG_64x64; // set up BG1 for a 4bpp 64x64t map, using charblock 0 and screenblocks 28-31 (puzzle squares) REG_BG1CNT = BG_CBB(0) | BG_SBB(28) | BG_4BPP | BG_REG_64x64; if (small_tiles) { REG_DISPCNT = DCNT_MODE0 | DCNT_BG2 | DCNT_BG3; } else { REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1; } int max_horiz_offset_16 = NUR_COLS * 16 - 240; if (max_horiz_offset_16 < 0) max_horiz_offset_16 = 0; int max_vert_offset_16 = NUR_ROWS * 16 - 160; if (max_vert_offset_16 < 0) max_vert_offset_16 = 0; int max_horiz_offset_8 = NUR_COLS * 8 - 240; if (max_horiz_offset_8 < 0) max_horiz_offset_8 = 0; int max_vert_offset_8 = NUR_ROWS * 8 - 160; if (max_vert_offset_8 < 0) max_vert_offset_8 = 0; REG_BG0HOFS = REG_BG1HOFS = REG_BG2HOFS = REG_BG3HOFS = 0; REG_BG0VOFS = REG_BG1VOFS = REG_BG2VOFS = REG_BG3VOFS = 0; irq_init(NULL); irq_add(II_VBLANK, NULL); int key_repeat = 0; bool clearing = false; while (1) { VBlankIntrWait(); key_poll(); set_tile(24, cursor_r, cursor_c, TRANSPARENT); // remove the cursor if (key_hit(1 << KI_LEFT | 1 << KI_RIGHT | 1 << KI_UP | 1 << KI_DOWN)) { key_repeat = 0; // reset the key repeat timer } #define START_REPEAT 20 #define REPEAT_SPEED 2 if (key_is_down(1 << KI_LEFT | 1 << KI_RIGHT | 1 << KI_UP | 1 << KI_DOWN)) { if (key_repeat < START_REPEAT) key_repeat++; else key_repeat = START_REPEAT - REPEAT_SPEED; } bool virtual_left = key_hit(1 << KI_LEFT ) || (key_is_down(1 << KI_LEFT ) && key_repeat == START_REPEAT); bool virtual_right = key_hit(1 << KI_RIGHT) || (key_is_down(1 << KI_RIGHT) && key_repeat == START_REPEAT); bool virtual_up = key_hit(1 << KI_UP ) || (key_is_down(1 << KI_UP ) && key_repeat == START_REPEAT); bool virtual_down = key_hit(1 << KI_DOWN ) || (key_is_down(1 << KI_DOWN ) && key_repeat == START_REPEAT); bool moved_cursor = false; if (virtual_left && cursor_c > 0 ) { cursor_c--; REG_BG0HOFS = REG_BG1HOFS = (cursor_c * max_horiz_offset_16) / (NUR_COLS - 1); REG_BG2HOFS = REG_BG3HOFS = (cursor_c * max_horiz_offset_8 ) / (NUR_COLS - 1); moved_cursor = true; } if (virtual_right && cursor_c < NUR_COLS - 1) { cursor_c++; REG_BG0HOFS = REG_BG1HOFS = (cursor_c * max_horiz_offset_16) / (NUR_COLS - 1); REG_BG2HOFS = REG_BG3HOFS = (cursor_c * max_horiz_offset_8 ) / (NUR_COLS - 1); moved_cursor = true; } if (virtual_up && cursor_r > 0 ) { cursor_r--; REG_BG0VOFS = REG_BG1VOFS = (cursor_r * max_vert_offset_16) / (NUR_ROWS - 1); REG_BG2VOFS = REG_BG3VOFS = (cursor_r * max_vert_offset_8 ) / (NUR_ROWS - 1); moved_cursor = true; } if (virtual_down && cursor_r < NUR_ROWS - 1) { cursor_r++; REG_BG0VOFS = REG_BG1VOFS = (cursor_r * max_vert_offset_16) / (NUR_ROWS - 1); REG_BG2VOFS = REG_BG3VOFS = (cursor_r * max_vert_offset_8 ) / (NUR_ROWS - 1); moved_cursor = true; } if (key_hit(1 << KI_A)) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case BLACK: puzzle[cursor_r][cursor_c] = DOT; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = DOT; set_tile(28, cursor_r, cursor_c, DOT); clearing = false; break; case DOT: puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); clearing = true; break; default: clearing = false; break; } } else if (key_is_down(1 << KI_A) && moved_cursor) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case BLACK: case DOT: if (clearing) { puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); } else { puzzle[cursor_r][cursor_c] = DOT; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = DOT; set_tile(28, cursor_r, cursor_c, DOT); } break; } } if (key_hit(1 << KI_B)) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case DOT: puzzle[cursor_r][cursor_c] = BLACK; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = BLACK; set_tile(28, cursor_r, cursor_c, BLACK); clearing = false; break; case BLACK: puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); clearing = true; break; default: clearing = false; break; } } else if (key_is_down(1 << KI_B) && moved_cursor) { switch (puzzle[cursor_r][cursor_c]) { case WHITE: case BLACK: case DOT: if (clearing) { puzzle[cursor_r][cursor_c] = WHITE; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = WHITE; set_tile(28, cursor_r, cursor_c, WHITE); } else { puzzle[cursor_r][cursor_c] = BLACK; sram_mem[(puzzle_index + 1) * 1024 + cursor_r * NUR_COLS + cursor_c] = BLACK; set_tile(28, cursor_r, cursor_c, BLACK); } break; } } if (key_hit(1 << KI_SELECT)) { small_tiles = !small_tiles; if (small_tiles) { REG_DISPCNT = DCNT_MODE0 | DCNT_BG2 | DCNT_BG3; } else { REG_DISPCNT = DCNT_MODE0 | DCNT_BG0 | DCNT_BG1; } } if (key_hit(1 << KI_L)) { return -1; // move 1 puzzle to the left } if (key_hit(1 << KI_R)) { return 1; // move 1 puzzle to the right } set_tile(24, cursor_r, cursor_c, CURSOR); // readd the cursor } }
void buttontest() { vid_vsync(); key_poll(); while(key_is_up(KEY_B)){ vid_vsync(); key_poll(); tte_write("#{es}"); tte_write("#{P:0,0}GBA Button Test\n"); tte_write("Hold buttons to test. B will exit.\n"); if (key_held(KEY_L)){ tte_write("L\n"); } if (key_held(KEY_R)){ tte_write("R\n"); } if (key_held(KEY_UP)){ tte_write("Up\n"); } if (key_held(KEY_DOWN)){ tte_write("Down\n"); } if (key_held(KEY_LEFT)){ tte_write("Left\n"); } if (key_held(KEY_RIGHT)){ tte_write("Right\n"); } if (key_held(KEY_START)){ tte_write("Start\n"); } if (key_held(KEY_SELECT)){ tte_write("Select\n"); } if (key_held(KEY_A)){ tte_write("A\n"); } if (key_held(KEY_B)){ tte_write("B\n"); } vid_vsync(); key_poll(); } }
void pause() { REG_DISPCTL = MODE0 | BG3_ENABLE | SPRITE_ENABLE; REG_BG3CNT = CBB(0) | SBB(28) | BG_SIZE3 | COLOR256; loadPalette(stats_screenPal); DMANow(3, (unsigned int*)stats_screenTiles, &CHARBLOCKBASE[0], stats_screenTilesLen); DMANow(3, (unsigned int*)stats_screenMap, &SCREENBLOCKBASE[28], stats_screenMapLen); //sets up selector arrow shadowOAM[127].attr0 = 56 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[127].attr1 = 25 | ATTR1_SIZE8; shadowOAM[127].attr2 = 772; //sets up points remaining indicator shadowOAM[126].attr0 = 32 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[126].attr1 = 106 | ATTR1_SIZE8; shadowOAM[126].attr2 = 800; //sets up vitality points indicator shadowOAM[125].attr0 = 57 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[125].attr1 = 90 | ATTR1_SIZE8; shadowOAM[125].attr2 = 802; //sets up strength points indicator shadowOAM[124].attr0 = 73 | ATTR0_8BPP | ATTR0_SQUARE; shadowOAM[124].attr1 = 90 | ATTR1_SIZE8; shadowOAM[124].attr2 = 802; //Disable unused sprites int i; for (i=0; i<128; ++i) { OAM[i].attr0 = ATTR0_HIDE; } //This loop keeps the background from being redrawn continously int button_pushed = 0; while (!button_pushed) { OAM[127] = shadowOAM[127]; OAM[126] = shadowOAM[126]; OAM[125] = shadowOAM[125]; OAM[124] = shadowOAM[124]; shadowOAM[126].attr2 = 800 + (2 * points); key_poll(); if (key_hit(BUTTON_A) || (key_hit(BUTTON_B))) button_pushed = 1; if (key_hit(BUTTON_UP) && (selector_position > 0)) { --selector_position; shadowOAM[127].attr0 = 56 | ATTR0_8BPP | ATTR0_SQUARE; } if (key_hit(BUTTON_DOWN) && (selector_position < 1)) { ++selector_position; shadowOAM[127].attr0 = 72 | ATTR0_8BPP | ATTR0_SQUARE; } if (key_hit(BUTTON_RIGHT) && (selector_position == 0) && (points > 0)) { ++playerHealth; --points; shadowOAM[125].attr2 = 800 + (2 * playerHealth); } if (key_hit(BUTTON_LEFT) && (selector_position == 0) && (playerHealth > 1)) { --playerHealth; ++points; shadowOAM[125].attr2 = 800 + (2 * playerHealth); } if (key_hit(BUTTON_RIGHT) && (selector_position == 1) && (points > 0)) { ++player_damage; --points; shadowOAM[124].attr2 = 800 + (2 * player_damage); } if (key_hit(BUTTON_LEFT) && (selector_position == 1) && (player_damage > 1)) { --player_damage; ++points; shadowOAM[124].attr2 = 800 + (2 * player_damage); } } if (key_hit(BUTTON_A)) { int i; for (i=0; i<128; ++i) { OAM[i].attr0 = ATTR0_HIDE; } state = GAME_OVERWORLD; } }
int main() { int i; struct VEngine veng; struct World world; JoyState* joy; v_init(&veng); joy_init(); /* for a random seed, wait for user input */ i = 0; while (1) { vid_vsync(); key_poll(); v_putbgtile(5, 4, 37); v_putbgtile(6, 4, 48); v_putbgtile(7, 4, 51); v_putbgtile(8, 4, 51); v_putbgtile(9, 4, 51); if (key_hit(KEY_A) || key_hit(KEY_START)) { break; } i ++; } /* sqran(i); */ sqran(4); init_world(&world, &veng); /* obj_set_pos(dude, (16 * 7), (16 * 4)); */ v_draw_bg(world.map, &veng, world.map->dudex, world.map->dudey); while(1) { vid_vsync(); joy = joy_poll(); key_poll(); if (key_hit(KEY_A)) { /* v_draw_more_bg(world.map, veng.mapofsx, veng.mapofsy - 4, 15, 4, world.map->dudex - 6 - veng.dudeposx, world.map->dudey - 4 - 4 - veng.dudeposy); */ } if (key_hit(KEY_START)) { v_init(&veng); init_world(&world, &veng); /* obj_set_pos(veng.obj_buffer[veng.spr_dude], (16 * 7), (16 * 4)); */ v_draw_bg(world.map, &veng, world.map->dudex, world.map->dudey); } /* if (key_hit(KEY_LEFT)) { switch (r_move_left(&world)) { case 1: v_move_left(&veng); break; case 2: v_shake_dude(&veng, 1, 0); break; } } else if (key_hit(KEY_RIGHT)) { switch (r_move_right(&world)) { case 1: v_move_right(&veng); break; case 2: v_shake_dude(&veng, 1, 0); break; } } else if (key_hit(KEY_UP)) { switch (r_move_up(&world)) { case 1: v_move_up(&veng); break; case 2: v_shake_dude(&veng, 0, 1); break; } } else if (key_hit(KEY_DOWN)) { switch (r_move_down(&world)) { case 1: v_move_down(&veng); break; case 2: v_shake_dude(&veng, 0, 1); break; } } */ if (joy->moving) { switch (r_move(&world, joy->dx, joy->dy)) { case 1: v_move(&veng, joy->dx, joy->dy); break; case 2: v_shake_dude(&veng, 0, 1); break; } joy_handled(); } v_move_co(&veng); v_scroll_at_edge(&veng, &world); v_draw_dude(&veng); for (i = 0; i < world.monstercount; i ++) { v_draw_monster(&veng, &world, i); } oam_copy(oam_mem, veng.obj_buffer, 1 + world.monstercount); } return 0; }
void game_manager::title_screen_func() { curr_game_mode = gm_title_screen; irq_init(); //irqEnable(irq_vblank); bios_wait_for_vblank(); // Use video Mode 0, use 1D object mapping, enable forced blank, // and display BG 0. reg_dispcnt = dcnt_mode0 | dcnt_obj_1d | dcnt_blank_on | dcnt_bg0_on; //// Use video Mode 0, use 1D object mapping, enable forced blank, //// and display BG 0, BG 1, BG 2, and BG 3 //reg_dispcnt = dcnt_mode0 | dcnt_obj_1d | dcnt_blank_on | dcnt_bg0_on // | dcnt_bg1_on | dcnt_bg2_on | dcnt_bg3_on | dcnt_obj_on; // Use screen base block 28 for BG0's Map reg_bg0cnt = bgcnt_sbb(bg0_sbb); reg_bg1cnt = bgcnt_sbb(bg1_sbb); reg_bg2cnt = bgcnt_sbb(bg2_sbb); reg_bg3cnt = bgcnt_sbb(bg3_sbb); // Clear bgofs_mirror for ( u32 i=0; i<3; ++i ) { gfx_manager::bgofs_mirror[i].curr.x = gfx_manager::bgofs_mirror[i].prev.x = {0}; gfx_manager::bgofs_mirror[i].curr.y = gfx_manager::bgofs_mirror[i].prev.y = {0}; } gfx_manager::copy_bgofs_mirror_to_registers(); // Copy the title screen's tiles and tilemap to VRAM bios_do_lz77_uncomp_vram( title_screenTiles, bg_tile_vram ); gfx_manager::upload_bg_palettes_to_target(bg_pal_ram); // This is sort of a hack. bios_do_lz77_uncomp_wram( title_screenMap, active_level::bg0_screenblock_mirror ); active_level_manager::copy_sublevel_from_array_2d_helper_to_vram(); // Disable forced blank clear_bits( reg_dispcnt, dcnt_blank_mask ); //memcpy8( test_sram_arr, (void *)debug_arr_u32, test_sram_arr_size ); for (;;) { bios_wait_for_vblank(); key_poll(); // Start the game if the Start button is hit if ( key_hit(key_start) ) { irqSet( irq_vblank, (u32)mmVBlank ); irqEnable(irq_vblank); // Don't call mmInitDefault more than once. It uses malloc(), // and it apparently MaxMOD doesn't ever call free(). mmInitDefault( (mm_addr)practice_17_bin, 8 ); mmSetVBlankHandler(reinterpret_cast<void*>(vblank_func)); reinit_the_game(); break; } } }
int main() { // initialize IRQ (interrupts) // this must come before everything else IRQ_INIT(); // Initialize global pointers GameStateManager gameStateMan; OamManager oamMan; AudioManager audioMan; PlayState playState(&gameStateMan); TitleScreenState titleState(&gameStateMan); PauseState pauseState(&gameStateMan); GameOverState gameOverState(&gameStateMan); StoreState storeState(&gameStateMan); StageEndState stageEndState(&gameStateMan); g_gameStateMan = &gameStateMan; g_oamMan = &oamMan; g_playState = &playState; g_titleState = &titleState; g_pauseState = &pauseState; g_gameOverState = &gameOverState; g_storeState = &storeState; g_stageEndState = &stageEndState; g_audioMan = &audioMan; // create stage events StageEvent endEvent; StageEvent event1; StageEvent event2; StageEvent event3; StageEvent event4; StageEvent event5; StageEvent event6; StageEvent firePowerPowerUpEvent; StageEvent invinciblePowerUpEvent; StageEvent bombPowerUpEvent; g_endEvent = &endEvent; g_event1 = &event1; g_event2 = &event2; g_event3 = &event3; g_event4 = &event4; g_event5 = &event5; g_event6 = &event6; g_firePowerPowerUpEvent = &firePowerPowerUpEvent; g_invinciblePowerUpEvent = &invinciblePowerUpEvent; g_bombPowerUpEvent = &bombPowerUpEvent; initializeEvents(); StageEvent * stage1Events[24]; int stage1Timing[24]; int stage1yOffset[24]; fillEventsStage1(stage1Events, stage1Timing, stage1yOffset); Stage stage1(&playState, stage1Events, stage1Timing, stage1yOffset, 24); g_stage1 = &stage1; StageEvent * stage2Events[20]; int stage2Timing[20]; int stage2yOffset[20]; fillEventsStage2(stage2Events, stage2Timing, stage2yOffset); Stage stage2(&playState, stage2Events, stage2Timing, stage2yOffset, 20); g_stage2 = &stage2; StageEvent * stage3Events[20]; int stage3Timing[20]; int stage3yOffset[20]; fillEventsStage3(stage3Events, stage3Timing, stage3yOffset); Stage stage3(&playState, stage3Events, stage3Timing, stage3yOffset, 20); g_stage3 = &stage3; videoInit(); g_gameStateMan->pushState(g_titleState); #ifdef DEBUG // timers used for debug display REG_TM1D = 0x10000 - 2808; // overflow into timer 2 every 2808 cycles, approx. 1% of a screen refresh REG_TM2D = 0; REG_TM2CNT = TM_CASCADE | TM_ENABLE; REG_TM1CNT = TM_FREQ_1 | TM_ENABLE; int oldPercent, diffPercent, oldFrac, diffFrac; char buf[15]; #endif // DEBUG while(true) { // wait until next VBlank // prefer this over vid_vsync() - it's // better for power consumption VBlankIntrWait(); #ifdef DEBUG // grab current percentage oldPercent = REG_TM2D; oldFrac = REG_TM1D; #endif // DEBUG // update shadow OAM to real OAM g_oamMan->update(); // mix the next frame's audio g_audioMan->sndMix(); // poll keys - do not do this in other places key_poll(); // update the game state g_gameStateMan->update(); #ifdef DEBUG // grab current percentage, and write it out diffPercent = REG_TM2D - oldPercent; diffFrac = REG_TM1D - oldFrac; // round the percent based on the fractional amount if (diffFrac > 1404) { diffPercent++; } else if (diffFrac < -1404) { diffPercent--; } gba_itoa(diffPercent, buf); // clear out characters from the last write write(" ", Vec2(0, 0)); write(buf, Vec2(0, 0)); // reset timer 2 to 0 REG_TM2CNT = 0; // disable timer REG_TM2D = 0; // set new value to 0 REG_TM2CNT = TM_CASCADE | TM_ENABLE; // reenable timer #endif // DEBUG } }
void game_manager::vblank_func() { // If a bug was automatically detected. if ( curr_game_mode == gm_do_halt ) { // Stop the sound stuff if (mmActive()) { //mmPause(); mmSetModuleVolume(static_cast<mm_word>(0)); mmSetJingleVolume(static_cast<mm_word>(0)); mmEffectCancelAll(); mmFrame(); //mmPause(); //mmStop(); } // Enable forced blank reg_dispcnt = dcnt_blank_on; return; } gfx_manager::copy_bgofs_mirror_to_registers(); //mmFrame(); key_poll(); //pause_or_unpause_music(); if ( curr_game_mode != gm_title_screen && curr_game_mode != gm_initializing_the_game ) { mmFrame(); } switch ( curr_game_mode ) { // When on the title screen. case gm_title_screen: break; // When initializing the game case gm_initializing_the_game: break; // When loading a level. case gm_loading_level: hud_manager::hud_was_generated = false; break; // When changing from one sublevel to another. case gm_changing_sublevel: break; // When in a sublevel. case gm_in_sublevel: //gfx_manager::copy_bgofs_mirror_to_registers(); gfx_manager::upload_bg_tiles_to_vram(); copy_oam_mirror_to_oam(); active_level_manager ::copy_sublevel_from_array_2d_helper_to_vram(); sprite_manager::upload_tiles_of_active_sprites_to_vram(); hud_manager::update_hud_in_screenblock_mirror_2d(); hud_manager::copy_hud_from_array_2d_helper_to_vram(); break; // If a bug was automatically detected (this should never be the // case since gm_do_halt is handled at the start of this function). case gm_do_halt: break; default: break; } }
void MainMenu() { //This function brings up the main menu and has it do stuff. RegisterRamReset(RESET_GFX); REG_DISPCNT= DCNT_MODE0 | DCNT_BG0; tte_init_chr4c(0, // BG 0 BG_CBB(0)|BG_SBB(31), // Charblock 0; screenblock 31 0xF000, // Screen-entry offset bytes2word(1,2,0,0), // Color attributes. CLR_WHITE, // White text &verdana9Font, // Verdana 9 font NULL ); vid_vsync(); draw_main_menu(); while(1){ vid_vsync(); mmFrame(); key_poll(); //This code is still being worked on but it will handle what is selected on the menu. if (key_hit(KEY_DOWN)){ mainmenuselected++; if (mainmenuselected > 3){ mainmenuselected = 3; } draw_main_menu(); }else if (key_hit(KEY_UP)){ mainmenuselected = mainmenuselected - 1; if (mainmenuselected < 0){ mainmenuselected = 0; } draw_main_menu(); }else if (key_hit(KEY_B)){ }else if (key_hit(KEY_A)){ if (mainmenuselected == 0){ biosdump(); vid_vsync(); draw_main_menu(); }else if (mainmenuselected == 1){ buttontest(); vid_vsync(); draw_main_menu(); }else if (mainmenuselected == 2){ RTC_Main(); vid_vsync(); draw_main_menu(); }else if (mainmenuselected == 3){ soundtest(); vid_vsync(); draw_main_menu(); } } } }