void move_ship(int *y, int *x, int input) { switch (input) { case KEY_UP: if (is_out_of_bounds(*y-1, *x)) {break;} clear_tracks(*y, *x); mvprintw(--*y, *x, aircraft.ship); break; case KEY_DOWN: if (is_out_of_bounds(*y+1, *x)) {break;} clear_tracks(*y, *x); mvprintw(++*y, *x, aircraft.ship); break; case KEY_RIGHT: if (is_out_of_bounds(*y, *x+1)) {break;} clear_tracks(*y, *x); mvprintw(*y, ++*x, aircraft.ship); break; case KEY_LEFT: if ((is_out_of_bounds(*y, *x-1))) {break;} clear_tracks(*y, *x); mvprintw(*y, --*x, aircraft.ship); break; case KEY_HOME: case KEY_A1: if (is_out_of_bounds(*y-1, *x-1)) {break;} clear_tracks(*y, *x); mvprintw(--*y, --*x, aircraft.ship); break; case KEY_PPAGE: if (is_out_of_bounds(*y-1,*x+1)) {break;} clear_tracks(*y, *x); mvprintw(--*y, ++*x, aircraft.ship); break; case KEY_END: case KEY_C1: if (is_out_of_bounds(*y+1,*x-1)) {break;} clear_tracks(*y, *x); mvprintw(++*y, --*x, aircraft.ship); break; case KEY_NPAGE: if (is_out_of_bounds(*y+1, *x+1)) {break;} clear_tracks(*y, *x); mvprintw(++*y, ++*x, aircraft.ship); break; } count_moves(); }
// All square positions are calculated and playfield for whether the // calculated position is already set, or out of bounds bool Playfield::collides(const Tetromino& tetromino, const Position& pos) const { unsigned size = tetromino.get_size(); for(unsigned i = 0; i < size; i++) { for(unsigned j = 0; j < size; j++) { // check if square is filled in the tetromino if(tetromino.is_set(i, j)) { // calculate new square position Position c = pos + Position(i, j); if(is_out_of_bounds(c) || is_set(c)) { return true; } } } } return false; }
void shoot(int y, int x, int input) { int xadj = 0; int yadj = 0; switch (input) { case PROB_UP_LEFT: xadj = -1; yadj = -1; break; case PROB_UP: yadj = -1; break; case PROB_UP_RIGHT: xadj = 1; yadj = -1; break; case PROB_RIGHT: xadj = 1; break; case PROB_DOWN_RIGHT: xadj = 1; yadj = 1; break; case PROB_DOWN: yadj = 1; break; case PROB_DOWN_LEFT: xadj = -1; yadj = 1; break; case PROB_LEFT: xadj = -1; break; } if (xadj != 0 || yadj != 0) { while(!is_out_of_bounds(y + yadj, x + xadj)) { y += yadj; x += xadj; mvprintw(y, x, fire.probe); aftershot(y, x); if (check_if_wormhole_is_hit(y, x)) {break; } } } }
bool Playfield::lock(Tetromino_p tetromino, const Position& pos) { unsigned size = tetromino->get_size(); for(unsigned i = 0; i < size; i++) { for(unsigned j = 0; j < size; j++) { // check if square is filled in the tetromino if(tetromino->is_set(i, j)) { Position c = pos + Position(i, j); assert(!is_out_of_bounds(c)); if(is_set(c)) { // Game over! return false; } // move square ownership to matrix matrix[c.get_x()][c.get_y()] = std::move(tetromino->release(i, j)); } } } return true; }
/**************************************************************************** * * lcd_dev_dirty_rect * * Marks the indicated rows as dirty and arranges for them to be transferred * to the LCD. * ***************************************************************************/ static void lcd_dev_dirty_rect(LCD_dev_info_t * dev, LCD_DirtyRect_t * dirtyRect) { CSL_LCD_RES_T ret; int i; int err = -EINVAL; OSDAL_Dma_Buffer_List *buffer_list, *temp_list; if (unlikely(ap_crashed)) { return; } if(!dev) { pr_info("dev pointer is NULL\n"); return; } if(!dirtyRect) { pr_info("dirtyRect pointer is NULL\n"); return; } if ((dirtyRect->top > dirtyRect->bottom) || ((dirtyRect->bottom - dirtyRect->top) >= dev->height) || (dirtyRect->left > dirtyRect->right) || ((dirtyRect->right - dirtyRect->left) >= dev->width)) { LCD_DEBUG("invalid dirty-rows params - ignoring\n"); LCD_DEBUG("top = %u, bottom = %u, left = %u, right = %u\n", dirtyRect->top, dirtyRect->bottom, dirtyRect->left, dirtyRect->right); return; } down_interruptible(&gDmaSema); #ifdef CONFIG_HAS_WAKELOCK wake_lock(&glcdfb_wake_lock); #endif dev->dirty_rect = *dirtyRect; dev->row_start = dev->dirty_rect.top % dev->height; dev->row_end = dev->dirty_rect.bottom % dev->height; /*If start address is aligned to odd boundary */ if (is_unaligned(dev)) { dev->col_start = dev->dirty_rect.left; dev->col_end = dev->dirty_rect.left; lcd_setup_for_data(dev); lcd_update_column(dev, dev->dirty_rect.left); dev->dirty_rect.left += 1; } /*If length is odd multiple */ if (is_odd_stride(dev) || ((dev->bits_per_pixel == 32) && is_odd_total(dev))) { dev->col_start = dev->dirty_rect.right; dev->col_end = dev->dirty_rect.right; lcd_setup_for_data(dev); lcd_update_column(dev, dev->dirty_rect.right); dev->dirty_rect.right -= 1; } if (is_out_of_bounds(dev) || ((32 != dev->bits_per_pixel) && is_tx_done_16(dev)) || ((32 == dev->bits_per_pixel) && is_tx_done_32(dev))) { /* Dirty columns have been transferred. No further processing required.*/ goto done; } buffer_list = kzalloc((dev->dirty_rect.bottom - dev->dirty_rect.top + 1) * sizeof(OSDAL_Dma_Buffer_List), GFP_KERNEL); if (!buffer_list) { pr_info("Couldn't allocate memory for dma buffer list\n"); goto done; } temp_list = buffer_list; for (i = dev->dirty_rect.top; i <= dev->dirty_rect.bottom; i++) { temp_list->buffers[0].srcAddr = (UInt32)dev->frame_buffer.physPtr + (i * dev->width + dev->dirty_rect.left) * dev->bits_per_pixel / 8; temp_list->buffers[0].destAddr = REG_LCDC_DATR_PADDR; temp_list->buffers[0].length = (dev->dirty_rect.right - dev->dirty_rect.left + 1) * dev->bits_per_pixel / 8; temp_list->buffers[0].bRepeat = 0; temp_list++; } temp_list--; /* Go back to the last list item to set interrupt = 1 */ temp_list->buffers[0].interrupt = 1; req.buff = (void *)buffer_list; req.buffBpp = dev->bits_per_pixel; req.lineLenP = dev->dirty_rect.right - dev->dirty_rect.left + 1; req.lineCount = dev->dirty_rect.bottom - dev->dirty_rect.top + 1; req.timeOut_ms = 100; req.cslLcdCb = lcd_csl_cb; req.cslLcdCbRef = NULL; req.multiLLI = true; dev->col_start = dev->dirty_rect.left; dev->col_end = dev->dirty_rect.right; lcd_setup_for_data(dev); // if(hsm_supported && window_hsm_compatible(dev->dirty_rect)) // CSL_LCDC_PAR_SetSpeed(handle, &timingMem_hs); // else CSL_LCDC_PAR_SetSpeed(handle, &timingMem); /*CP processor is setting IOCR6[19], which it shouldn't be doing. Remove this once the CP team fixes it.*/ if (dev->te_supported) { board_sysconfig(SYSCFG_LCD, SYSCFG_ENABLE); } ret = CSL_LCDC_Update(handle, &req); if (CSL_LCD_OK != ret) { pr_info("CSL_LCDC_Update failed error: %d", ret); goto fail; } err = 0; fail: kfree(buffer_list); done: #ifdef CONFIG_HAS_WAKELOCK wake_unlock(&glcdfb_wake_lock); #endif if (err < 0) up(&gDmaSema); }
//***************************************************************************** // // Function Name: dsic_dirty_rect_update // // Description: DMA/OS Update using INT frame buffer // //***************************************************************************** Int32 dsic_dirty_rect_update ( DISPDRV_HANDLE_T drvH, lcd_drv_rect_t * dirtyRect, DISPDRV_CB_T apiCb ) { dsic_panel_t *pPanel = (dsic_panel_t *)drvH; CSL_LCD_UPD_REQ_T req; Int32 res = 0; Int32 i; Int32 err = -EINVAL; OSDAL_Dma_Buffer_List *buffer_list, *temp_list; //LCD_DBG ( LCD_DBG_ID, "[DISPDRV] +%s\r\n", __FUNCTION__ ); if ( pPanel->pwrState != DISP_PWR_SLEEP_OFF ) { LCD_DBG ( LCD_DBG_ERR_ID, "[DISPDRV] +%s: Skip Due To Power State\r\n", __FUNCTION__ ); return ( -1 ); } if(!dirtyRect) { pr_info("dirtyRect pointer is NULL\n"); return -1; } if ((dirtyRect->top > dirtyRect->bottom) || ((dirtyRect->bottom - dirtyRect->top) >= DSI_Display_Info.height) || (dirtyRect->left > dirtyRect->right) || ((dirtyRect->right - dirtyRect->left) >= DSI_Display_Info.width)) { LCD_DBG("invalid dirty-rows params - ignoring\n"); LCD_DBG("top = %u, bottom = %u, left = %u, right = %u\n", dirtyRect->top, dirtyRect->bottom, dirtyRect->left, dirtyRect->right); return -1; } pPanel->win = *dirtyRect; pPanel->row_start = pPanel->win.top % DSI_Display_Info.height; pPanel->row_end = pPanel->win.bottom % DSI_Display_Info.height; pPanel->win.width = DSI_Display_Info.width; pPanel->win.height = DSI_Display_Info.height; /*If start address is aligned to odd boundary */ if (is_unaligned(pPanel)) { pPanel->col_start = pPanel->win.left; pPanel->col_end = pPanel->win.left; dsi_setwindow(drvH); dsi_update_column(pPanel, pPanel->win.left,NULL); pPanel->win.left += 1; } /*If length is odd multiple */ if (is_odd_stride(pPanel) || (is_odd_total(pPanel))) { pPanel->col_start = pPanel->win.right; pPanel->col_end = pPanel->win.right; dsi_setwindow(drvH); dsi_update_column(pPanel, pPanel->win.right,NULL); pPanel->win.right -= 1; } if (is_out_of_bounds(pPanel) || (is_tx_done_16(pPanel)) || (is_tx_done_32(pPanel))) { /* Dirty columns have been transferred. No further processing required.*/ goto done; } buffer_list = kzalloc((pPanel->win.bottom - pPanel->win.top + 1) * sizeof(OSDAL_Dma_Buffer_List), GFP_KERNEL); if (!buffer_list) { pr_info("Couldn't allocate memory for dma buffer list\n"); goto done; } temp_list = buffer_list; for (i = pPanel->win.top; i <= pPanel->win.bottom; i++) { temp_list->buffers[0].srcAddr = (UInt32)pPanel->pFbA + (i * DSI_Display_Info.width + pPanel->win.left) * INPUT_BPP; temp_list->buffers[0].destAddr = 0x084a0140; temp_list->buffers[0].length = (pPanel->win.right - pPanel->win.left +1) * INPUT_BPP; temp_list->buffers[0].bRepeat = 0; temp_list++; } temp_list--; /* Go back to the last list item to set interrupt = 1 */ temp_list->buffers[0].interrupt = 1; req.buff = (void *)buffer_list; req.buffBpp = INPUT_BPP; req.lineLenP = pPanel->win.right - pPanel->win.left + 1; req.lineCount = pPanel->win.bottom - pPanel->win.top + 1; req.timeOut_ms = 100; req.multiLLI = true; req.cslLcdCbRef = NULL; dispdrv_cb = apiCb; if( apiCb != NULL ) req.cslLcdCb = dsi_cb; else req.cslLcdCb = NULL; pPanel->col_start = pPanel->win.left; pPanel->col_end = pPanel->win.right; dsi_setwindow(drvH); if ( CSL_DSI_UpdateCmVc ( pPanel->dsiCmVcHandle, &req ) != CSL_LCD_OK ) { LCD_DBG ( LCD_DBG_ERR_ID, "[DISPDRV] %s: ERROR ret by " "CSL_DSI_UpdateCmVc\n\r", __FUNCTION__ ); res = -1; } done: //LCD_DBG ( LCD_DBG_ID, "[DISPDRV] -%s\r\n", __FUNCTION__ ); kfree(buffer_list); return ( res ); }