Example #1
0
/*
**		Regroups `block` with block->prev & block->next (if they are FREE).
*/
void		regroup_blocks(t_block **heap, t_block *block, char which)
{
  t_block	*tmp;

  if (which != NEXT && block != *heap && block->prev->state == FREE)
    {
      if (block->next)
	block->next->prev = block->prev;
      else
	(*heap)->prev = block->prev;
      block->prev->next = block->next;
      block->prev->size += (block->size + sizeof(t_block));
      tmp = block->prev;
      clear_block((char *)block, block->size + sizeof(t_block));
      block = tmp;
    }
  if (which != PREV && block->next && block->next->state == FREE)
    {
      block->size += (block->next->size + sizeof(t_block));
      if (block->next->next)
	block->next->next->prev = block;
      else
	(*heap)->prev = block;
      tmp = block->next->next;
      clear_block((char *)block->next, block->next->size + sizeof(t_block));
      block->next = tmp;
    }
}
Example #2
0
/* Scan the sparse file and create its map */
static bool
sparse_scan_file (struct tar_sparse_file *file)
{
  static char buffer[BLOCKSIZE];
  size_t count;
  size_t offset = 0;
  struct sp_array sp = {0, 0};

  if (!lseek_or_error (file, 0, SEEK_SET))
    return false;
  clear_block (buffer);

  file->stat_info->sparse_map_avail = 0;
  file->stat_info->archive_file_size = 0;

  if (!tar_sparse_scan (file, scan_begin, NULL))
    return false;

  while ((count = safe_read (file->fd, buffer, sizeof buffer)) != 0
	 && count != SAFE_READ_ERROR)
    {
      /* Analize the block */
      if (zero_block_p (buffer, count))
	{
	  if (sp.numbytes)
	    {
	      sparse_add_map (file, &sp);
	      sp.numbytes = 0;
	      if (!tar_sparse_scan (file, scan_block, NULL))
		return false;
	    }
	}
      else
	{
	  if (sp.numbytes == 0)
	    sp.offset = offset;
	  sp.numbytes += count;
	  file->stat_info->archive_file_size += count;
	  if (!tar_sparse_scan (file, scan_block, buffer))
	    return false;
	}

      offset += count;
      clear_block (buffer);
    }

  if (sp.numbytes == 0)
    sp.offset = offset;

  sparse_add_map (file, &sp);
  file->stat_info->archive_file_size += count;
  return tar_sparse_scan (file, scan_end, NULL);
}
Example #3
0
static bool
check_sparse_region (struct tar_sparse_file *file, off_t beg, off_t end)
{
  if (!lseek_or_error (file, beg, SEEK_SET))
    return false;

  while (beg < end)
    {
      size_t bytes_read;
      size_t rdsize = end - beg;

      if (rdsize > BLOCKSIZE)
	rdsize = BLOCKSIZE;
      clear_block (diff_buffer);
      bytes_read = safe_read (file->fd, diff_buffer, rdsize);
      if (bytes_read == SAFE_READ_ERROR)
	{
          read_diag_details (file->stat_info->orig_file_name,
	                     beg,
			     rdsize);
	  return false;
	}
      if (!zero_block_p (diff_buffer, bytes_read))
	{
 	  report_difference (file->stat_info,
			     _("File fragment at %lu is not a hole"), beg);
	  return false;
	}

      beg += bytes_read;
    }
  return true;
}
Example #4
0
void MenuInit(void)
{
  //int i;// yasirLiang add in20160603
  unsigned char MenuLang;

  ByteDataGet(VAL_MENU_LANG,&MenuLang);
      
  if(MenuLang!=ENGLISH)
  {
    MenuLang = CHINESE;
    ByteDataSave(VAL_MENU_LANG,MenuLang);
  }
  else
  {
    ChangeLanguage(ENGLISH);
  }
	gPresetTmnSelPro.RunFlag = 0;
	gPresetTmnSelPro.Addr = FULL_VIEW_ADDR;
	gsnCurMGrp=0;
	ByteDataInit();
#if 0
	sleep(1);
	clear_block(0,0,192,64);
  	update_disp_data(0,0,192,64);
	DisplayGroup(gsnCurMGrp);
#if 0 // yasir change in 2016-4-7
  DisplayOneState(0,PPT_MODE);
#else
  DisplayOneState(0,gByteData[VAL_DSCS_MODE]);
#endif

	sleep(1);
#endif
}
Example #5
0
void menu_first_display(void)// 必须在MenuInit函数之后调用
{
	clear_block(0,0,192,64);
	update_disp_data(0,0,192,64);
	DisplayGroup(gsnCurMGrp);
	DisplayOneState(0,gByteData[VAL_DSCS_MODE]);
}
Example #6
0
/*
**		It should free the last block of the heap partially or completely
**		according to the entire size of the heap. If the heap size is a pagesize multiple,
**		free all the block. Else, free a bit of the block so that new heap size is a pagesize multiple.
*/
void		process_free(t_block **heap, size_t pagesize)
{
  t_block	*block;
  size_t	size;
  size_t	s;

  block = (*heap)->prev;
  size = block->size + sizeof(t_block);
  if (block == *heap)
    *heap = NULL;
  else
    {
      s = get_heap_size(*heap);
      if (s % pagesize)
	{
	  block->size = (pagesize - (s + pagesize) % pagesize) - sizeof(t_block);
	  size -= (block->size + sizeof(t_block));
	  block = (void *)block + sizeof(t_block) + block->size;
	}
      else
	{
	  block->prev->next = NULL;
	  (*heap)->prev = block->prev;
	}
    }
  clear_block((char *)block, size);
  sbrk(-size);
}
Example #7
0
void for_loop_remake_zero_block(Block* forContents)
{
    Block* zero = for_loop_get_zero_block(forContents);
    clear_block(zero);

    // Clone inputs
    for (int i=0;; i++) {
        Term* placeholder = get_input_placeholder(forContents, i);
        if (placeholder == NULL)
            break;
        Term* clone = append_input_placeholder(zero);
        rename(clone, placeholder->nameSymbol);
    }

    Term* loopOutput = create_list(zero);

    // Clone outputs
    for (int i=0;; i++) {
        Term* placeholder = get_output_placeholder(forContents, i);
        if (placeholder == NULL)
            break;

        // Find the appropriate connection
        Term* result = find_local_name(zero, placeholder->name.c_str());

        if (i == 0)
            result = loopOutput;

        Term* clone = append_output_placeholder(zero, result);
        rename(clone, placeholder->nameSymbol);
    }

    block_finish_changes(zero);
}
Example #8
0
void remove_complete_lines(void) {
	char s[8];
    byte row, x, y, complete;

	for (row = curr_y - 1; row < curr_y + 3 && row < PLAYF_HEIGHT; row++) {
		complete = 1;
		for (x = 0; x < PLAYF_WIDTH && complete; x++) {
			if (!is_block_set(x, row))
				complete = 0;
		}

		if (complete) {
			for (y = row; y > 0; y--) {
				for (x = 0; x < PLAYF_WIDTH; x++) {
					if (is_block_set(x, y - 1))
						draw_block(x, y);
					else
                    	clear_block(x, y);
				}
            }
			lines++;
			buf2screen();
		}
	}

	itoa(lines, s);
	vputs(100, 80, "LINES     ");
	vputs(135, 80, s);

}
Example #9
0
void remove_nested_contents(Term* term)
{
    if (term->nestedContents == NULL)
        return;

    clear_block(term->nestedContents);

    term->nestedContents = NULL;
}
Example #10
0
LOCAL void
compress_byte (gif_dest_ptr dinfo, int c)
/* Accept and compress one 8-bit byte */
{
  register hash_int i;
  register hash_int disp;
  register hash_entry probe_value;

  if (dinfo->first_byte) {	/* need to initialize waiting_code */
    dinfo->waiting_code = c;
    dinfo->first_byte = FALSE;
    return;
  }

  /* Probe hash table to see if a symbol exists for
   * waiting_code followed by c.
   * If so, replace waiting_code by that symbol and return.
   */
  i = ((hash_int) c << (MAX_LZW_BITS-8)) + dinfo->waiting_code;
  /* i is less than twice 2**MAX_LZW_BITS, therefore less than twice HSIZE */
  if (i >= HSIZE)
    i -= HSIZE;

  probe_value = HASH_ENTRY(dinfo->waiting_code, c);
  
  if (dinfo->hash_code[i] != 0) { /* is first probed slot empty? */
    if (dinfo->hash_value[i] == probe_value) {
      dinfo->waiting_code = dinfo->hash_code[i];
      return;
    }
    if (i == 0)			/* secondary hash (after G. Knott) */
      disp = 1;
    else
      disp = HSIZE - i;
    for (;;) {
      i -= disp;
      if (i < 0)
	i += HSIZE;
      if (dinfo->hash_code[i] == 0)
	break;			/* hit empty slot */
      if (dinfo->hash_value[i] == probe_value) {
	dinfo->waiting_code = dinfo->hash_code[i];
	return;
      }
    }
  }

  /* here when hashtable[i] is an empty slot; desired symbol not in table */
  output(dinfo, dinfo->waiting_code);
  if (dinfo->free_code < LZW_TABLE_SIZE) {
    dinfo->hash_code[i] = dinfo->free_code++; /* add symbol to hashtable */
    dinfo->hash_value[i] = probe_value;
  } else
    clear_block(dinfo);
  dinfo->waiting_code = c;
}
Example #11
0
/*
 * Removes diamond when player has stepped on it.
 */
static void move_get_diamond(struct bogoman_map *map,
                             unsigned int x, unsigned int y)
{
	clear_block(map, x, y);

	map->player_diamonds++;

	DEBUG(1, "Diamond taken, yet to collect %u\n",
	      map->diamonds_total - map->player_diamonds);
}
Example #12
0
void clear_curr_part(void) {
	byte i;
	char x, y;

	for (i = 0; i < 4; i++) {
		x = curr_part.x[i];
		y = curr_part.y[i];
		clear_block(x + curr_x, y + curr_y);
	}
}
Example #13
0
static void load(Block* block, std::string const& filename)
{
    if (filename == "") {
        clear_block(block);
        return;
    }

    load_script(block, filename.c_str());
    if (has_static_errors(block))
        print_static_errors_formatted(block, std::cout);
}
Example #14
0
void rewrite_block(Block* block, caValue* contents, caValue* reply)
{
    clear_block(block);
    parser::compile(block, parser::statement_list, as_cstring(contents));

    if (has_static_errors(block)) {
        std::stringstream errors;
        print_static_errors_formatted(block);
        set_string(reply, errors.str());
    } else {
        set_symbol(reply, sym_Success);
    }
}
Example #15
0
void test_state_type()
{
    Block block;

    block.compile("a = 1; b = 2; c = 3");
    block_update_state_type(&block);
    test_assert(block.stateType == NULL);

    clear_block(&block);
    block.compile("state a = 1; state b = 2.0");
    block_update_state_type(&block);
    test_assert(block.stateType != NULL);

    //test_equals(&block.stateType->parameter, "[[<Type int>, <Type number>], ['a', 'b']]");
    test_equals(&block.stateType->parameter, "[[<Type any>, <Type any>], ['a', 'b']]");
}
Example #16
0
void duplicate_block_nested(TermMap& newTermMap, Block* source, Block* dest)
{
    // Duplicate every term
    for (int index=0; index < source->length(); index++) {
        Term* source_term = source->get(index);

        Term* dest_term = create_duplicate(dest, source_term, &source_term->nameValue);

        newTermMap[source_term] = dest_term;

        // duplicate nested contents
        clear_block(nested_contents(dest_term));
        duplicate_block_nested(newTermMap,
                nested_contents(source_term), nested_contents(dest_term));
    }
}
Example #17
0
//显示滚动条(竖)或进度条邋(横)
void DisplaySBar(int nTotal, int nPosi, int nVert)
{
    unsigned char ucY, ucHeight;// yasirliang change in 20160603
    //unsigned char ucY,ucWidth,ucHeight;
    unsigned char MenuLang;

    ByteDataGet(VAL_MENU_LANG,&MenuLang);
    if(nVert == SB_VERT)//垂直
    {
        if(MenuLang == CHINESE)
        {
            gstDispMem.ucX1 = MI_C_LENS*8;
			gstDispMem.ucX2 = gstDispMem.ucX1+8-2;	//留1竖点画分隔线
            gstDispMem.ucY1 = 16;
            gstDispMem.ucY2 = 63;
            ucHeight = 3*16/nTotal;
            ucY = (48 - ucHeight)/(nTotal-1)*nPosi+16;
        }
        else
        {
            gstDispMem.ucX1 =  MI_E_LENS*6;
            gstDispMem.ucX2 = gstDispMem.ucX1+5;
            gstDispMem.ucY1 = 10;
            gstDispMem.ucY2 = 39;
            ucHeight = 3*10/nTotal;
            ucY = (30 - ucHeight)/(nTotal-1)*nPosi+10;
        }
		if(ucHeight<5)
			ucHeight = 5;
		clear_block(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);

		send_line_h(gstDispMem.ucX1+1,gstDispMem.ucY1,5,0);
		send_line_h(gstDispMem.ucX1+1,gstDispMem.ucY2,5,0);
		send_line_v(gstDispMem.ucX1+1,gstDispMem.ucY1,gstDispMem.ucY2-gstDispMem.ucY1,0);
		send_line_v(gstDispMem.ucX1+5,gstDispMem.ucY1,gstDispMem.ucY2-gstDispMem.ucY1,0);
		
		send_v_scrollBar(gstDispMem.ucX1+2,ucY,ucHeight);

    }
    else//水平
    {


    }
	update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);

}
Example #18
0
void clear_block(Block* block)
{
    block->names.clear();
    block->inProgress = false;

    // Iterate through the block and tear down any term references, so that we
    // don't have to worry about stale pointers later.
    for (BlockIterator it(block); it; ++it) {
        if (*it == NULL)
            continue;

        pre_erase_term(*it);
        set_inputs(*it, TermList());
        remove_from_any_user_lists(*it);
        change_function(*it, NULL);
    }

    for (int i= block->_terms.length() - 1; i >= 0; i--) {
        Term* term = block->get(i);
        if (term == NULL)
            continue;

        if (term->nestedContents)
            clear_block(term->nestedContents);
    }

    for (int i = block->_terms.length() - 1; i >= 0; i--) {
        Term* term = block->get(i);
        if (term == NULL)
            continue;

        // Delete any leftover users, mark them as repairable.
        for (int userIndex = 0; userIndex < term->users.length(); userIndex++) {
            Term* user = term->users[userIndex];
            for (int depIndex = 0; depIndex < user->numDependencies(); depIndex++) {
                if (user->dependency(depIndex) == term) {
                    // mark_repairable_link(user, term->name, depIndex);
                    user->setDependency(depIndex, NULL);
                }
            }
        }

        erase_term(term);
    }

    block->_terms.clear();
}
Example #19
0
/*
 * Moves block to empty space, only one of dx or dy can be set
 * to nonzero value and the value could only be 1 or -1.
 */
static int try_move_block(struct bogoman_map *map,
                           int x, int y, int dx, int dy)
{
	int new_x = (int)x + dx;
	int new_y = (int)y + dy;

	if (bogoman_coord_in_map(map, new_x, new_y)) {

		if (!bogoman_is_empty(map, new_x, new_y))
			return 0;

		copy_block(map, new_x, new_y, x, y);
	} else {
		DEBUG(1, "Block moved out of screen %ux%u -> %ix%i",
		      x, y, new_x, new_y);
	}

	clear_block(map, x, y);
	return 1;
}
Example #20
0
//改变显示语言
void ChangeLanguage(int nLang)
{
    int i;
    unsigned char Mode;

    ByteDataSave(VAL_MENU_LANG,(unsigned char)nLang);
    if(nLang == CHINESE)
    {
		MI_LENS = MI_C_LENS;
        for(i=0; i<MGS_NUM; i++)
            gMG[i].pTitle = (char *)gMGTitle[i];

        gMG[0].FirstItem = (TMenu*)gMMain;
        gMG[1].FirstItem = (TMenu*)gM11;
        gMG[2].FirstItem = (TMenu*)gM12;
        gMG[3].FirstItem = (TMenu*)gM13;
        gMG[4].FirstItem = (TMenu*)gM21;


    }
    else
    {
		MI_LENS = MI_E_LENS;
        for(i=0; i<MGS_NUM_E; i++)
            gMG[i].pTitle = (char *)gMGTitle_E[i];

        gMG[0].FirstItem = (TMenu*)gMMain_E;
        gMG[1].FirstItem = (TMenu*)gM11_E;
        gMG[2].FirstItem = (TMenu*)gM12_E;
        gMG[3].FirstItem = (TMenu*)gM13_E;
        gMG[4].FirstItem = (TMenu*)gM21_E;

    }
    
    //清空显示区域
    clear_block(0,0,191,63);
    update_disp_data(0,0,191,63);
    ByteDataGet(VAL_DSCS_MODE,&Mode);
    ChangeMenu((int)Mode);
    //显示主菜单
}
Example #21
0
void ItemSelected(short snMGSeq)
{
    TMenu *pMenu;
    short usNew;
    //unsigned char Index;// yasirliang change in 20160603
   // int i; // yasirliang change in 20160603
    unsigned char MenuLang;

    
    ByteDataGet(VAL_MENU_LANG,&MenuLang);
    usNew = snMGSeq;
	  if(gMG[snMGSeq].Type==ST_CMN)	//普通菜单项
    {
        pMenu = gMG[snMGSeq].FirstItem + gMG[snMGSeq].Position;
        if(pMenu->Type == MT_MENU)
        {
          if(pMenu->Link!=MGS_NONE)
          {
            usNew = pMenu->Link;
            if(gMG[snMGSeq].Level > gMG[usNew].Level)
                gMG[snMGSeq].Position = 0;

          }
          if(pMenu->fpMenuDo != NULL)
              pMenu->fpMenuDo(0);
	      //pMenu->fpMenuDo(NULL);
        }
        else if(pMenu->Type == MT_SWITCH)	//语言切换
        {
          if(MenuLang == CHINESE)
              ChangeLanguage(ENGLISH);
          else
              ChangeLanguage(CHINESE);

          usNew = 0;
          gMG[usNew].Position = 0;
			
        }
        else	if((pMenu->Type==MT_YESNO)||(pMenu->Type==MT_ONOFF)) //不跳转,直接改变值
        {
          gMG[snMGSeq].ss.BitState ^= (1<<gMG[snMGSeq].Position);
          if(pMenu->fpMenuDo != NULL)
              pMenu->fpMenuDo(gMG[snMGSeq].ss.BitState&(1<<gMG[snMGSeq].Position));
          DisplayMItem(gMG+snMGSeq,gMG[snMGSeq].Position%3,gMG[snMGSeq].Position,MD_REVERSE);
            
            return;
        }
        else
        {
          // 记录当前页
          if((gsnCurMGrp==0)&&(pMenu->Link!=0))
          {
            UseDisSet(CPT_USE,BOOL_TRUE);
          }
          gsnCurMGrp = pMenu->Link;
					//DEBUG_INFO("gsnCurMGrp=%d,gMG[gsnCurMGrp].Position=%d\n",gsnCurMGrp,gMG[gsnCurMGrp].Position);
          DisplayMItem(gMG+gsnCurMGrp,-1,gMG[gsnCurMGrp].Position,MD_NORMAL);
          if(ENGLISH==MenuLang)
          {
            clear_block(0,10,191,39);
            update_disp_data(0,10,191,39);
          }
          else
          {
            clear_block(0,16,118,63);
            update_disp_data(0,16,118,63);
          }
          RenewMenuValue(pMenu->Link,0);
          MenuScroll(pMenu->Link,0);
          return;
        }
        
    }
    else
    {
      usNew = gMG[snMGSeq].Count;
			//DEBUG_INFO("snMGSeq=%d,usNew=%d\n",snMGSeq,usNew);
      if(gMG[snMGSeq].Type==ST_VALUE)
      {
        SendMainState(0,NULL,0);
      }
      else if(gMG[snMGSeq].Type==ST_MODE)
      {
        pMenu = gMG[usNew].FirstItem + gMG[usNew].Position;
        if(pMenu->fpMenuDo!=NULL)
        {
          pMenu->fpMenuDo(gMG[snMGSeq].Position);
        }    
        DisplayOneState(0,gMG[snMGSeq].Position);
        SendMainState(0,NULL,0);
      }
    }
    DisplayGroup(usNew);


    // 显示当前页
//    DisplayGroup(usNew);

    // 记录当前页
    if((usNew==0)&&(gsnCurMGrp>0))
    {
      UseDisSet(CPT_USE,BOOL_FALSE);
    }
    else if((gsnCurMGrp==0)&&(usNew>0))
    {
      UseDisSet(CPT_USE,BOOL_TRUE);
    }
    gsnCurMGrp = usNew;
}
Example #22
0
int alloc_disk_blockno(INODE *pinode, uint32_t file_blockst, uint32_t nr_block)
{
	int i, count = 0;
	int level[128] = {0};
	uint32_t addr[128] = {0}, stno[128] = {0};
	uint32_t p = 0, q = 0;
	uint32_t ll[4] = {L1_ST, L2_ST, L3_ST, L4_ST};
	uint32_t lp[4] = {1, L2_ST - L1_ST, L3_ST - L2_ST, L4_ST - L3_ST};
	uint32_t tbuf[BLOCKSZ / sizeof(uint32_t)];

	if(nr_block > 64)
		return 0;

	for(i = 0; i < 10; i++)
		if(i >= file_blockst && i < file_blockst + nr_block)
		{
			level[q] = 0;
			stno[q] = i;
			if(pinode->nr_block[i] == INVALID_BLOCKNO)
				pinode->nr_block[i] = apply_block();
			addr[q++] = pinode->nr_block[i];
		}

	for(i = 0; i < 3; i++)
		if(max(ll[i], file_blockst) < min(ll[i + 1], file_blockst + nr_block))
		{
			level[q] = i + 1;
			stno[q] = ll[i];
			if(pinode->nr_block[10 + i] == INVALID_BLOCKNO)
			{
				pinode->nr_block[10 + i] = apply_block();
				clear_block(pinode->nr_block[10 + i]);
			}
			addr[q++] = pinode->nr_block[10 + i];
		}
	

	if(q == 0)
		return 0;

	while(p < q)
	{
		if(level[p] > 0)
		{
			uint32_t disk_off = FILE_ST + addr[p] * BLOCKSZ;
			read_disk(tbuf, disk_off, sizeof(tbuf));
			for(i = 0; i < sizeof(tbuf)/sizeof(uint32_t); i++)
			{
				level[q] = level[p] - 1;
				stno[q] = stno[p] + i * lp[level[q]];
				stno[q + 1] = stno[p] + (i + 1) * lp[level[q]];
	
				if(max(stno[q], file_blockst) < min(stno[q + 1], file_blockst + nr_block))
				{
					if(tbuf[i] == INVALID_BLOCKNO)
					{
						tbuf[i] = apply_block();
						if(level[q] > 0)
							clear_block(tbuf[i]);
					}
					addr[q] = tbuf[i];
					q++;
				}
			}
			p ++;
			write_disk(tbuf, disk_off, sizeof(tbuf));
			assert(p < 128 && q < 128);
		}
		else
		{
			assert(p < 128 && q < 128);
			count ++;
			if(count >= nr_block)
			{
				return count;
			}
			p++;
		}
	}
	printk("%d, %d, %d\n", file_blockst, nr_block, count);
	return count;
}
Example #23
0
Block::~Block()
{
    clear_block(this);
}
Example #24
0
void main()
{
	int driver=0,mode=VESA_1024x768x8bit,paused=0;
	char *p;
	block bl;
	int key,n=1;
	long t0;
	initgraph(&driver,&mode,"");
	randomize();
	memset(map_check,0,sizeof(map_check));
	draw_map();
	t0=time(NULL);
	init_block(&bl);
	itoa(score,ss,10);
	outtextxy(X0+470,Y0+320,ss);
	outtextxy(X0+397,Y0+220,"Press spacebar to pause");
	outtextxy(X0+397,Y0+270,"Press spacebar agian to continue");
	while(!stop)
	{
		show_block(bl);
		if(check_xy(bl)==3)
		{
			bl.y--;
			init_block(&bl);
			check_gameover();
			show_block(bl);
		}
		while(((long)time(NULL)-t0)<=n*dtime)
		{
			if(bioskey(1)!=0)
			{
				key=bioskey(0);
				clear_block(bl);
				switch(key)
				{
					case UP:bl.rotate++;break;
					case LEFT:bl.x--;break;
					case RIGHT:bl.x++;break;
					case DOWN:bl.y++;break;
					case ESC:stop=1;break;
					case SPACE:show_block(bl);paused=1;break;
					default:break;
				}
				while(paused){
					if(bioskey(1)!=0)
					{
						if(bioskey(0)==SPACE)
						{
							clear_block(bl);
							paused=0;
						    break;
						}
					}
				}
				if(bl.rotate>3 || bl.rotate<0)
					bl.rotate=0;
				if(check_xy(bl)==1)
					bl.x++;
				if(check_xy(bl)==2)
					bl.x--;
				if(check_xy(bl)==3)
				{
					bl.y--;
					check_gameover();
					show_block(bl);
					while(cover())
					{
						delete_last(cover());
						score+=100;
						setfillstyle(SOLID_FILL,BLACK);
						bar(X0+460,Y0+300,X0+520,Y0+340);
						itoa(score,ss,10);
						setcolor(WHITE);
						outtextxy(X0+470,Y0+320,ss);
					}
					init_block(&bl);
					check_gameover();
				}
				if(check_collision(bl))
				{
					if(key==UP)
						bl.rotate--;
					if(key==LEFT)
						bl.x++;
					if(key==RIGHT)
						bl.x--;
					if(key==DOWN)
					{
						bl.y--;
						check_gameover();
						show_block(bl);
						while(cover())
						{
							delete_last(cover());
							score+=100;
							setfillstyle(SOLID_FILL,BLACK);
							bar(X0+460,Y0+300,X0+520,Y0+340);
							itoa(score,ss,10);
							setcolor(WHITE);
							outtextxy(X0+470,Y0+320,ss);
						}
						init_block(&bl);
						check_gameover();
					}
				}
				check_gameover();
				show_block(bl);
			}
		}
		clear_block(bl);
		bl.y++;
		if(check_xy(bl)==3 || check_collision(bl))
		{
			bl.y--;
			check_gameover();
			show_block(bl);
			while(cover())
			{
				delete_last(cover());
				score+=100;
				setfillstyle(SOLID_FILL,BLACK);
				bar(X0+460,Y0+300,X0+520,Y0+340);
				itoa(score,ss,10);
				setcolor(WHITE);
				outtextxy(X0+470,Y0+320,ss);
			}
			init_block(&bl);
			check_gameover();
		}
		n++;
	}
	getchar();
	closegraph();
}
Example #25
0
void
Block::clear()
{
    clear_block(this);
}
Example #26
0
uint64_t read_file(file_descriptor* fd, void* buf, uint64_t length)
{
  // Store number of bytes read.
  uint64_t read = 0;
  int read_error;

  // Pull inode.
  inode_t* inode = &table[fd->inode];

  // Allocate room for a block size in memory.
  void* block = (void*)malloc(BLOCK_SZ);

  // Read from block at RW pointer until length is complete.
  int starting_block_index = fd->rwptr / BLOCK_SZ;
  int current_block_count = starting_block_index;
  while (length) {
    // Get block index.
    int block_index = get_block_at(inode, current_block_count, false);
    if (block_index < 0) {
      perror("read_file()");
      break;
    }

    // Read from block.
    clear_block(block, 0, BLOCK_SZ);
    read_error = read_blocks(block_index, 1, block);
    if (read_error < 0) {
      perror("read_file(): read chunk from block");
      break;
    }

    // Modify block in memory.
    for (int j = fd->rwptr % BLOCK_SZ; j < BLOCK_SZ; j++) {
      // Check if EOF.
      if (fd->rwptr == inode->size) {
        // Reached end of file. Done.
        break;
      }

      // Copy current byte into buffer.
      memcpy(buf, block + j, 1);

      // Increment pointers.
      fd->rwptr += 1;
      buf += 1;

      // Increment number of bytes read.
      read += 1;

      // Decrement length.
      length -= 1;
      if (length == 0) {
        // Done in the middle of a block.
        break;
      }
    }

    // Increment block.
    current_block_count += 1;
  }

  // Free memory buffer.
  free(block);

  // Return bytes read.
  return read;
}
Example #27
0
//显示进度、值
void DisplayVal(short snMGSeq, int nTotal, int nPosi, int nVert)
{
    unsigned char ucAscii[3];
    char ucNumTab[]="0123456789";
    unsigned char x,y;
    unsigned char MenuLang;

    ByteDataGet(VAL_MENU_LANG,&MenuLang);
    if(ENGLISH==MenuLang)
    {
      clear_block(0,10,191,39);
      send_h_StepBar(0,24,191*nPosi/nTotal,191);
    }
    else
    {
      clear_block(0,16,119,63);
      send_h_StepBar(0,32,112*nPosi/nTotal,112);
    }

    if(ENGLISH==MenuLang)
    {
      x=0;
      y=16;
    }
    else
    {
      x=0;
      y=24;
    }
    ucAscii[0] = ucNumTab[gMG[snMGSeq].ss.mm.Min/100];
    ucAscii[1] = ucNumTab[gMG[snMGSeq].ss.mm.Min/10%10];
    ucAscii[2] = ucNumTab[gMG[snMGSeq].ss.mm.Min%10];
    if(gMG[snMGSeq].ss.mm.Min <= 9)
        send_zf5x8(x,y,ucAscii+2,1,0);
    else if(gMG[snMGSeq].ss.mm.Min <= 99)
        send_zf5x8(x,y,ucAscii+1,2,0);
    else
        send_zf5x8(x,y,ucAscii,3,0);

    if(ENGLISH==MenuLang)
    {
      x=176;
      y=16;
    }
    else
    {
      x=97;
      y=24;
    }
    ucAscii[0] = ucNumTab[nTotal/100];
    ucAscii[1] = ucNumTab[nTotal/10%10];
    ucAscii[2] = ucNumTab[nTotal%10];
    if(nTotal <= 9)
        send_zf5x8(x+10,y,ucAscii+2,1,0);
    else if(nTotal <= 99)
        send_zf5x8(x+5,y,ucAscii+1,2,0);
    else
        send_zf5x8(x,y,ucAscii,3,0);

    if(ENGLISH==MenuLang)
    {
      x=95;
      y=32;
    }
    else
    {
      x=48;
      y=48;
    }
    ucAscii[0] = ucNumTab[nPosi/100];
    ucAscii[1] = ucNumTab[nPosi/10%10];
    ucAscii[2] = ucNumTab[nPosi%10];
    if(nPosi <= 9)
        send_zf5x8(x+5,y,ucAscii+2,1,0);
    else if(nPosi <= 99)
        send_zf5x8(x+3,y,ucAscii+1,2,0);
    else
        send_zf5x8(x,y,ucAscii,3,0);


     if(ENGLISH==MenuLang)
    {
      gstDispMem.ucX1 = 0;
      gstDispMem.ucX2 = 191;
      gstDispMem.ucY1 = 10;
      gstDispMem.ucY2 = 39;
    }
    else
    {
      gstDispMem.ucX1 = 0;
      gstDispMem.ucX2 = 118;
      gstDispMem.ucY1 = 16;
      gstDispMem.ucY2 = 63;
    }
    update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);

}
Example #28
0
uint64_t write_file(file_descriptor* fd, void* buf, uint64_t length)
{
  // Store number of bytes written.
  uint64_t written = 0;
  int read_error, write_error;

  // Pull inode.
  inode_t* inode = &table[fd->inode];

  // Allocate room for a block size in memory.
  void* block = (void*)malloc(BLOCK_SZ);

  // Write from block at RW pointer until length is complete.
  int starting_block_index = fd->rwptr / BLOCK_SZ;
  int current_block_count = starting_block_index;
  while (length) {
    // Get block index.
    int block_index = get_block_at(inode, current_block_count, true);
    if (block_index < 0) {
      perror("write_file()");
      break;
    }

    // Read from block.
    clear_block(block, 0, BLOCK_SZ);
    read_error = read_blocks(block_index, 1, block);
    if (read_error < 0) {
      perror("write_file(): read chunk from block");
      break;
    }

    // Modify block in memory.
    for (int j = fd->rwptr % BLOCK_SZ; j < BLOCK_SZ; j++) {
      // Copy current byte into buffer.
      memcpy(block + j, buf, 1);

      // Increment pointers.
      fd->rwptr += 1;
      buf += 1;

      // Increment number written.
      written += 1;

      // Decrement length.
      length -= 1;
      if (length == 0) {
        // Done in the middle of a block.
        break;
      }
    }

    // Write block.
    write_error = write_blocks(block_index, 1, block);
    if (write_error < 0) {
      perror("write_file(): write chunk to block");
      break;
    }

    // Increment block.
    current_block_count += 1;
  }

  // Free block.
  free(block);

  // Update inode size.
  if (fd->rwptr > inode->size) {
    inode->size = fd->rwptr;
  }

  // Write inodes and free blocks.
  write_inode_table();
  write_free_blocks();

  // Return number of bytes written.
  return written;
}
Example #29
0
int get_block_at(inode_t* inode, int i, bool create)
{
  int block_index = -1;

  // Get direct block.
  if (i < NUM_DIRECT_BLOCKS) {
    if (inode->direct_blocks[i]) {
      // It exists.
      return inode->direct_blocks[i];
    } else if (create) {
      // Yield free block.
      block_index = yield_block();
      if (block_index < 0) {
        errno = ENOSPC;
        return block_index;
      }

      // Add to inode.
      inode->direct_blocks[i] = block_index;
      write_inode_table();

      return block_index;
    }
  }

  // Not enough blocks.
  if (i >= MAX_BLOCKS_PER_INODE) {
    // File too big.
    errno = EFBIG;
    return block_index;
  }

  // Otherwise, get indirect block.
  if (i >= NUM_DIRECT_BLOCKS) {
    uint64_t* block;
    if (inode->indirect_block || create) {
      // Create buffer in memory.
      block = (uint64_t*)malloc(BLOCK_SZ);
      clear_block(block, 0, BLOCK_SZ);

      if (create && inode->indirect_block == 0) {
        // Create if needed.
        int indirect_block_index = yield_block();
        if (indirect_block_index < 0) {
          free(block);
          errno = ENOSPC;
          return indirect_block_index;
        }

        // Write to inode.
        inode->indirect_block = indirect_block_index;
        write_inode_table();
      }

      uint64_t indirect_block_ptr = i - NUM_DIRECT_BLOCKS;
      read_blocks(inode->indirect_block, 1, block);
      if (block[indirect_block_ptr] > 0) {
        block_index = block[indirect_block_ptr];
      } else if (create) {
        // Create if needed.
        block_index = yield_block();
        if (block_index > 0) {
          // Succeeded, so write to disk.
          block[indirect_block_ptr] = block_index;
          write_blocks(inode->indirect_block, 1, block);
        }
      }

      // Free memory.
      free(block);
    }
  }

  if (block_index < 0) {
    errno = EFAULT;
  }
  return block_index;
}
Example #30
0
// 显示当前设置状态
//	中文:
//  	第一行:单元 xxx
//	  	第二行:会讨模式
//	 	第三行:上限 xxx
//	  	第四行:(签到/表决 xxx)摄像头 x
//	英文:
//
//	
//	显示当前状态
//	参数
//		nStateBit: bit0~4分别代表第一到第四个状态信息
//		nStNum[]:  分别对应各个状态的当前量或对应下标
//void DisplayOneState(TMGrpData *pMGrp, int nSeq)
//void DisplayOneState(TMGrpData *pMGrp, int nSeq ,int nLine,int nNum)
void DisplayAllState(int nStateBit,int nStNum[])
{
    unsigned char caItem[16];		//中文时需要8个字符,英文时需要16
    int Temp;
    //TMenu *pMenu;// yasirliang change in 20160603
   // int nState;
    //unsigned char ucLine,ucMode;// yasirliang change in 20160603
    unsigned char Len;

	int i;
	
  unsigned char MenuLang;

  ByteDataGet(VAL_MENU_LANG,&MenuLang);

//     pMenu = pMGrp->FirstItem+nSeq;
//     nState = pMGrp->ss.BitState & (1<<nSeq);
//
//     switch(pMenu->Type)
//     {
//         case MT_YESNO:
//             if(gsnCurMGrp == 1)
//             {
//                 ucLine = 0;
//                 memcpy(caItem,pMenu->Text,strlen(pMenu->Text));
//             }
//             else if(gsnCurMGrp == 4)
//             {
//                 ucLine = 4;
//                 memcpy(caItem,pMenu->Text,strlen(pMenu->Text));
//             }
//             break;
//         case MT_ONOFF:
//             if(gsnCurMGrp == 1)
//             {
//                 ucLine = 2;
//                 memcpy(caItem,pMenu->Text,strlen(pMenu->Text));
//             }
//             break;
//         default:
//           break;
// 	}
    ChangeMenu(nStNum[0]);

    // 更新显示数据
    if(MenuLang == CHINESE)
    {
        gstDispMem.ucX1 = 128;
        gstDispMem.ucX2 = 191;
 		for(i=0;i<4;i++)
		{
			gstDispMem.ucY1 = i*8*2;
			gstDispMem.ucY2 = (i+1)*8*2-1;
			switch(nStateBit & (1<<i))
			{
			case STD_MODE:
        Len=GetDiscussModeText(nStNum[0],caItem,MenuLang);
			  send_hz16x16(gstDispMem.ucX1,i*2*8,caItem, Len/2, 0);
        update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
				break;
      case STD_CAM:
				if(GetCmrTrack())
				{
					disp_ico(gstDispMem.ucX1,i*2*8,16,16,ico_data[ICO_CMR],0);
				}
				else
				{
        	disp_ico(gstDispMem.ucX1,i*2*8,16,16,ico_data[ICO_CMR_LOCK],0);
				}
				if(nStNum[1]>0)
				{
					Temp=IntToRightStr(caItem,nStNum[1],7);
					send_zf8x16(gstDispMem.ucX1+8*Temp+8,i*2*8,caItem+Temp+1, 7-Temp, 0);
				}
        update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
				break;
			case STD_LIMIT:
        disp_ico(gstDispMem.ucX1,i*2*8,16,16,ico_data[ICO_SPKER_LIMIT],0);
        if((FIFO_MODE==nStNum[0])||(LIMIT_MODE==nStNum[0]))
        {
  				if(nStNum[2]>0)
  				{
  					Temp=IntToRightStr(caItem,nStNum[2],7);
  					send_zf8x16(gstDispMem.ucX1+8*Temp+8,i*2*8,caItem+Temp+1, 7-Temp, 0);
  				}
        }
        else
        {
          disp_ico(gstDispMem.ucX1+6*8,i*2*8,16,16,ico_data[ICO_PROHIBIT],0);
        }
        update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
        break;
			case STD_APPLY:
        disp_ico(gstDispMem.ucX1,i*2*8,16,16,ico_data[ICO_APPLY_LIMIT],0);
        if((APPLY_MODE==nStNum[0])||(LIMIT_MODE==nStNum[0]))
        {
  				if(nStNum[3]>0)
  				{
  					Temp=IntToRightStr(caItem,nStNum[3],7);
  					send_zf8x16(gstDispMem.ucX1+8*Temp+8,i*2*8,caItem+Temp+1, 7-Temp, 0);
  				}
        }
        else
        {
          disp_ico(gstDispMem.ucX1+6*8,i*2*8,16,16,ico_data[ICO_PROHIBIT],0);
        }
        update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);        
        break;
			}		
			
			
			
		}

    }
    else		//English
    {
 		for(i=0;i<4;i++)
		{
			memset(caItem,' ',16);
			
			gstDispMem.ucX1 = (i%2)*96;
			gstDispMem.ucX2 = gstDispMem.ucX1+96-1;
			gstDispMem.ucY1 = (i/2)*10+44;
			gstDispMem.ucY2 =gstDispMem.ucY1+10-1;
			switch(nStateBit & (1<<i))
			{
			case STD_MODE:
        Len=GetDiscussModeText(nStNum[0],caItem,MenuLang);
			  send_zf6x10(gstDispMem.ucX1,gstDispMem.ucY1,(unsigned char *)caItem, Len, 0);
        update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
				break;
      case STD_CAM:
				memcpy(caItem,"Curr Cam:",9);
				if(nStNum[1]>0)
				{
					Temp=IntToRightStr(caItem,nStNum[1],12);
//					send_zf6x10(gstDispMem.ucX1+8*Temp+8,i*2*8,caItem+Temp+1, 12-Temp, 0);
				}
        send_zf6x10(gstDispMem.ucX1,gstDispMem.ucY1,(unsigned char *)caItem, 16, 0);
			  update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
				break;
			case STD_LIMIT:
        if((FIFO_MODE==nStNum[0])||(LIMIT_MODE==nStNum[0]))
        {
  				memcpy(caItem,"MaxSpeakers:",13);
  				if(nStNum[2]>0)
  				{
  					Temp=IntToRightStr(caItem,nStNum[2],12);
  				}
          send_zf6x10(gstDispMem.ucX1,gstDispMem.ucY1,(unsigned char *)caItem, 16, 0);
        }
         else
        {
          clear_block(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
        }
        update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
        break;
			case STD_APPLY:
        if((APPLY_MODE==nStNum[0])||(LIMIT_MODE==nStNum[0]))
        {
  				memcpy(caItem,"MaxApplicants:",13);
  				if(nStNum[3]>0)
  				{
  					Temp=IntToRightStr(caItem,nStNum[3],12);
  				}
          send_zf6x10(gstDispMem.ucX1,gstDispMem.ucY1,(unsigned char *)caItem, 16, 0);
  			  
        }
        else
        {
          clear_block(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
        }
        update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
        break;
			}			
 		}
    }

//		update_disp_data(gstDispMem.ucX1,gstDispMem.ucY1,gstDispMem.ucX2,gstDispMem.ucY2);
}