void bootmgr_setup_touch() { if(!settings.touch_ui) return; bootmgr_set_touches_count(0); switch(bootmgr_phase) { case BOOTMGR_MAIN: bootmgr_add_touch(40, 125, 160, 245, bootmgr_touch_int, 1); bootmgr_add_touch(160, 125, 280, 245, bootmgr_touch_sd, 2); bootmgr_add_touch(40, 245, 160, 365, bootmgr_touch_ums, 3); bootmgr_add_touch(160, 245, 280, 365, bootmgr_touch_tetris, 4); break; case BOOTMGR_UMS: bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_ums, 1); bootmgr_print_fill(80, 370, 160, 40, WHITE, 24); bootmgr_printf(-1, 24, BLACK, "Exit"); break; case BOOTMGR_SD_SEL: { bootmgr_add_touch(0, 430, 78, 480, bootmgr_touch_sd_up, 1); bootmgr_add_touch(80, 430, 158, 480, bootmgr_touch_sd_down, 2); bootmgr_add_touch(160, 430, 238, 480, bootmgr_touch_sd_select, 3); bootmgr_add_touch(240, 430, 320, 480, bootmgr_touch_sd_exit, 4); bootmgr_printf(31, 28, BLACK, "Up Down Select Exit"); bootmgr_print_fill(0, 430, 78, 49, WHITE, 28); bootmgr_print_fill(80, 430, 78, 49, WHITE, 29); bootmgr_print_fill(160, 430, 78, 49, WHITE, 30); bootmgr_print_fill(240, 430, 78, 49, WHITE, 31); break; } } }
void tetris_init() { tetris_set_defaults(); pieces = (tetris_piece***)malloc(sizeof(tetris_piece*)*TETRIS_W); uint16_t y, z; for(y = 0; y < TETRIS_W; ++y) { pieces[y] = (tetris_piece**)malloc(sizeof(tetris_piece*)*TETRIS_H); for(z = 0; z < TETRIS_H; ++z) pieces[y][z] = NULL; } pthread_mutex_init(tetris_draw_mutex, NULL); t_tetris = (pthread_t*)malloc(sizeof(pthread_t)); pthread_create(t_tetris, NULL, tetris_thread, NULL); bootmgr_display->bg_img = 0; bootmgr_set_lines_count(0); bootmgr_set_fills_count(0); bootmgr_print_fill(9, 29, TETRIS_W*BLOCK_SIZE+1, 1, WHITE, TETRIS_BORDER_TOP); bootmgr_print_fill(9, 29, 1, TETRIS_H*BLOCK_SIZE+1, WHITE, TETRIS_BORDER_LEFT); bootmgr_print_fill(TETRIS_W*BLOCK_SIZE+10, 29, 1, TETRIS_H*BLOCK_SIZE+1, WHITE, TETRIS_BORDER_RIGHT); bootmgr_print_fill(9, 470, TETRIS_W*BLOCK_SIZE+1, 1, WHITE, TETRIS_BORDER_BOTTOM); tetris_print_score(); tetris_print_batt(); bootmgr_printf(243, 1, WHITE, "Next"); bootmgr_printf(243, 2, WHITE, "piece:"); bootmgr_printf(10+((220 - 21*8)/2), 15, WHITE, "Press \"Home\" to start"); bootmgr_draw(); }
void bootmgr_setup_touch(void) { if(!settings.touch_ui) return; bootmgr_set_touches_count(0); switch(bootmgr_phase) { case BOOTMGR_MAIN: bootmgr_add_touch(40, 125, 160, 245, bootmgr_touch_int, 1); bootmgr_add_touch(160, 125, 280, 245, bootmgr_touch_sd, 2); bootmgr_add_touch(40, 245, 160, 365, bootmgr_touch_ums, 3); bootmgr_add_touch(160, 245, 280, 365, bootmgr_touch_misc, 4); break; case BOOTMGR_UMS: bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_ums, 1); bootmgr_print_fill(80, 370, 160, 40, WHITE, 24); bootmgr_printf(-1, 24, BLACK, "Exit"); break; case BOOTMGR_SD_SEL: { bootmgr_add_touch(0, 430, 78, 480, bootmgr_touch_sd_up, 1); bootmgr_add_touch(80, 430, 158, 480, bootmgr_touch_sd_down, 2); bootmgr_add_touch(160, 430, 238, 480, bootmgr_touch_sd_select, 3); bootmgr_add_touch(240, 430, 320, 480, bootmgr_touch_sd_exit, 4); bootmgr_printf(31, 28, BLACK, "Up Down Select Exit"); bootmgr_print_fill(0, 430, 78, 49, WHITE, 28); bootmgr_print_fill(80, 430, 78, 49, WHITE, 29); bootmgr_print_fill(160, 430, 78, 49, WHITE, 30); bootmgr_print_fill(240, 430, 78, 49, WHITE, 31); break; } case BOOTMGR_CHARGER: { bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_charger, 1); bootmgr_print_fill(80, 370, 160, 40, WHITE, 24); bootmgr_printf(-1, 24, BLACK, "Back to main menu"); break; } case BOOTMGR_MISC: { int itr = 0; for(; misc_callbacks[itr] != NULL; ++itr) bootmgr_add_touch(0, itr*ISO_CHAR_HEIGHT*3, BOOTMGR_DIS_W, (itr+1)*ISO_CHAR_HEIGHT*3, misc_callbacks[itr], itr); bootmgr_add_touch(80, 370, 240, 410, bootmgr_touch_exit_misc, itr); bootmgr_print_fill(80, 370, 160, 40, WHITE, 24); bootmgr_printf(-1, 24, BLACK, "Back to main menu"); break; } } }
void bootmgr_select(int8_t line) { bootmgr_line *ln = NULL; if(selected != -1 && (ln = _bootmgr_get_line(selected))) ln->color = WHITE; ln = _bootmgr_get_line(line); if(ln) ln->color = BLACK; if(line == -1) bootmgr_erase_fill(BOOTMGR_FILL_SELECT); else bootmgr_print_fill(0, line*ISO_CHAR_HEIGHT, BOOTMGR_DIS_W, ISO_CHAR_HEIGHT, WHITE, BOOTMGR_FILL_SELECT); selected = line; }
void tetris_draw(uint8_t move) { if(move && current) { pthread_mutex_lock(tetris_draw_mutex); if(!tetris_can_move_piece(TETRIS_DOWN)) { if(!current->moved) { uint8_t lines = 2; if(settings.tetris_max_score < score) { ++lines; settings.tetris_max_score = score; bootmgr_save_settings(); bootmgr_printf(10+((220 - 15*8)/2), 16, WHITE, "New high score!"); } bootmgr_print_fill(11, 14*ISO_CHAR_HEIGHT, 219, lines*ISO_CHAR_HEIGHT, BLACK, 1); bootmgr_printf(10+((220 - 9*8)/2), 14, WHITE, "Game over"); bootmgr_printf(10+((220 - 23*8)/2), 15, WHITE, "Press \"Home\" to restart"); bootmgr_draw_fills(); bootmgr_draw_text(); fb_update(&fb); state = TETRIS_FINISHED; pthread_mutex_unlock(tetris_draw_mutex); return; } uint8_t x,y; for(x = 0; x < 5; ++x) for(y = current->y < 2 ? current->y : 0; y < 5; ++y) if(p_shape[current->type][current->rotation][y][x]) pieces[current->x+(x-2)][current->y+(y-2)] = current; tetris_check_line(); tetris_spawn_new(); } else tetris_move_piece(TETRIS_DOWN); pthread_mutex_unlock(tetris_draw_mutex); } android_memset16(fb.bits, BLACK, BOOTMGR_DIS_W*BOOTMGR_DIS_H*2); tetris_print_batt(); bootmgr_draw_fills(); bootmgr_draw_text(); tetris_piece *itr = current; uint8_t i = 0; uint16_t *bits; uint8_t y, x; do { for(y = 0; y < 5; ++y) { uint8_t len = 0; int8_t st = -1; for(x = 0; x < (i ? 4 : 5); ++x) { if(p_shape[itr->type][itr->rotation][y][x]) { if(st == -1) st = x; ++len; } } if(st == -1) continue; bits = fb.bits; bits += BOOTMGR_DIS_W*(30+((itr->y-(2-y))*BLOCK_SIZE)) + 10 + (itr->x-(2-st))*BLOCK_SIZE; for(x = 0; x < BLOCK_SIZE; ++x) { android_memset16(bits, tetris_get_color_for_type(itr->type), len*BLOCK_SIZE*2); bits += BOOTMGR_DIS_W; } } itr = preview; ++i; } while(i < 2); for(x = 0; x < TETRIS_W; ++x) { for(y = 0; y < TETRIS_H; ++y) { if(!pieces[x][y]) continue; bits = fb.bits; bits += BOOTMGR_DIS_W*(30+(y*BLOCK_SIZE)) + 10 + x*BLOCK_SIZE; for(i = 0; i < BLOCK_SIZE; ++i) { android_memset16(bits, tetris_get_color_for_type(pieces[x][y]->type), BLOCK_SIZE*2); bits += BOOTMGR_DIS_W; } } } fb_update(&fb); }
void tetris_key(int key) { switch(key) { case KEY_VOLUMEDOWN: { if(state & TETRIS_PAUSED) { bootmgr_erase_text(14); bootmgr_erase_text(15); bootmgr_erase_fill(1); state &= ~(TETRIS_PAUSED); state |= TETRIS_STARTED; } else if(state & TETRIS_STARTED) { bootmgr_print_fill(11, 14*ISO_CHAR_HEIGHT, 219, 32, BLACK, 1); bootmgr_printf(10+((220 - 6*8)/2), 14, WHITE, "Paused"); bootmgr_printf(10+((220 - 25*8)/2), 15, WHITE, "Press \"VolDown\" to resume"); bootmgr_draw_fills(); bootmgr_draw_text(); fb_update(&fb); state &= ~(TETRIS_STARTED); state |= TETRIS_PAUSED; } break; } case KEY_VOLUMEUP: tetris_exit(); bootmgr_set_time_thread(1); break; case KEY_HOME: { if(!(state & TETRIS_STARTED)) { if(state & TETRIS_FINISHED) { tetris_clear(0); tetris_set_defaults(); bootmgr_erase_text(14); bootmgr_erase_fill(1); tetris_print_score(); } bootmgr_erase_text(15); state = (TETRIS_STARTED | TETRIS_SPAWN_NEW); } else { pthread_mutex_lock(tetris_draw_mutex); tetris_move_piece(TETRIS_DOWN_FAST); tetris_draw(0); pthread_mutex_unlock(tetris_draw_mutex); } break; } case KEY_BACK: { if(state & TETRIS_STARTED) { pthread_mutex_lock(tetris_draw_mutex); tetris_rotate_piece(); tetris_draw(0); pthread_mutex_unlock(tetris_draw_mutex); } break; } case KEY_MENU: case KEY_SEARCH: { if(state & TETRIS_STARTED) { pthread_mutex_lock(tetris_draw_mutex); if(tetris_can_move_piece(key == KEY_MENU ? TETRIS_LEFT : TETRIS_RIGHT)) tetris_move_piece(key == KEY_MENU ? TETRIS_LEFT : TETRIS_RIGHT); tetris_draw(0); pthread_mutex_unlock(tetris_draw_mutex); } break; } } }