示例#1
0
static int board_init_r(void)
{
    const unsigned int flashbase = CFG_FLASH_BASE;
    const u8 flash_esel = e500_find_tlb_idx((void *)flashbase, 1);

    checkboard();

    /* Map the whole boot flash */
    fsl_set_lbc_br(0, BR_PHYS_ADDR(CFG_FLASH_BASE_PHYS) | BR_PS_16 | BR_V);
    fsl_set_lbc_or(0, 0xff000ff7);

    /* Flush d-cache and invalidate i-cache of any FLASH data */
    flush_dcache();
    invalidate_icache();

    /* invalidate existing TLB entry for flash */
    e500_disable_tlb(flash_esel);

    /*
     * Remap Boot flash region to caching-inhibited
     * so that flash can be erased properly.
     */
    e500_set_tlb(1, flashbase, CFG_FLASH_BASE_PHYS,
                 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                 0, flash_esel, BOOKE_PAGESZ_16M, 1);

    fsl_l2_cache_init();

    return 0;
}
示例#2
0
/*
 * If the root node of the DTB has a "model" property, show it.
 * Then call checkboard().
 */
int __weak show_board_info(void)
{
#ifdef CONFIG_OF_CONTROL
	DECLARE_GLOBAL_DATA_PTR;
	const char *model;

	model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);

	if (model)
		printf("Model: %s\n", model);
#endif

	return checkboard();
}
示例#3
0
int show_board_info(void)
{
	unsigned char ethaddr[6];

	if (read_tdx_cfg_block()) {
		printf("Missing Toradex config block\n");
		checkboard();
		return 0;
	}

	/* board serial-number */
	sprintf(tdx_serial_str, "%08u", tdx_serial);
	sprintf(tdx_board_rev_str, "V%1d.%1d%c",
		tdx_hw_tag.ver_major,
		tdx_hw_tag.ver_minor,
		(char)tdx_hw_tag.ver_assembly + 'A');

	env_set("serial#", tdx_serial_str);

	/*
	 * Check if environment contains a valid MAC address,
	 * set the one from config block if not
	 */
	if (!eth_env_get_enetaddr("ethaddr", ethaddr))
		eth_env_set_enetaddr("ethaddr", (u8 *)&tdx_eth_addr);

#ifdef CONFIG_TDX_CFG_BLOCK_2ND_ETHADDR
	if (!eth_env_get_enetaddr("eth1addr", ethaddr)) {
		/*
		 * Secondary MAC address is allocated from block
		 * 0x100000 higher then the first MAC address
		 */
		memcpy(ethaddr, &tdx_eth_addr, 6);
		ethaddr[3] += 0x10;
		eth_env_set_enetaddr("eth1addr", ethaddr);
	}
#endif

	printf("Model: Toradex %s %s, Serial# %s\n",
	       toradex_modules[tdx_hw_tag.prodid],
	       tdx_board_rev_str,
	       tdx_serial_str);

	return 0;
}
示例#4
0
static int process_rqt_info(const struct rqt_box *rqt)
{
	ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
	memset(rsp, 0, sizeof(struct rsp_box));

	rsp->rsp = rqt->rqt;
	rsp->rsp_data = rqt->rqt_data;

	switch (rqt->rqt_data) {
	case RQT_INFO_VER_PROTOCOL:
		rsp->int_data[0] = VER_PROTOCOL_MAJOR;
		rsp->int_data[1] = VER_PROTOCOL_MINOR;
		break;
	case RQT_INIT_VER_HW:
		snprintf(rsp->str_data[0], sizeof(rsp->str_data[0]),
			 "%x", checkboard());
		break;
	case RQT_INIT_VER_BOOT:
		sprintf(rsp->str_data[0], "%s", U_BOOT_VERSION);
		break;
	case RQT_INIT_VER_KERNEL:
		sprintf(rsp->str_data[0], "%s", "k unknown");
		break;
	case RQT_INIT_VER_PLATFORM:
		sprintf(rsp->str_data[0], "%s", "p unknown");
		break;
	case RQT_INIT_VER_CSC:
		sprintf(rsp->str_data[0], "%s", "c unknown");
		break;
	default:
		return -EINVAL;
	}

	send_rsp(rsp);
	return true;
}
示例#5
0
文件: board.c 项目: BeanGu/U-boot
void board_init_r(gd_t *id, ulong dest_addr)
{
	ulong malloc_start;
#if !defined(CONFIG_SYS_NO_FLASH)
	ulong flash_size;
#endif

	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");

	monitor_flash_len = (ulong)&__rel_dyn_end - (ulong)_start;

	/* Enable caches */
	enable_caches();

	debug("monitor flash len: %08lX\n", monitor_flash_len);
	board_init();	/* Setup chipselects */
	/*
	 * TODO: printing of the clock inforamtion of the board is now
	 * implemented as part of bdinfo command. Currently only support for
	 * davinci SOC's is added. Remove this check once all the board
	 * implement this.
	 */
#ifdef CONFIG_CLOCKS
	set_cpu_clk_info(); /* Setup clock information */
#endif
	serial_initialize();

	debug("Now running in RAM - U-Boot at: %08lx\n", dest_addr);

#ifdef CONFIG_LOGBUFFER
	logbuff_init_ptrs();
#endif
#ifdef CONFIG_POST
	post_output_backlog();
#endif

	/* The Malloc area is immediately below the monitor copy in DRAM */
	malloc_start = dest_addr - TOTAL_MALLOC_LEN;
	mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);

#ifdef CONFIG_ARCH_EARLY_INIT_R
	arch_early_init_r();
#endif
	power_init_board();

#if !defined(CONFIG_SYS_NO_FLASH)
	puts("Flash: ");

	flash_size = flash_init();
	if (flash_size > 0) {
# ifdef CONFIG_SYS_FLASH_CHECKSUM
		print_size(flash_size, "");
		/*
		 * Compute and print flash CRC if flashchecksum is set to 'y'
		 *
		 * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
		 */
		if (getenv_yesno("flashchecksum") == 1) {
			printf("  CRC: %08X", crc32(0,
				(const unsigned char *) CONFIG_SYS_FLASH_BASE,
				flash_size));
		}
		putc('\n');
# else	/* !CONFIG_SYS_FLASH_CHECKSUM */
		print_size(flash_size, "\n");
# endif /* CONFIG_SYS_FLASH_CHECKSUM */
	} else {
		puts(failed);
		hang();
	}
#endif

#if defined(CONFIG_CMD_NAND)
	puts("NAND:  ");
	nand_init();		/* go init the NAND */
#endif

#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

#ifdef CONFIG_GENERIC_MMC
	puts("MMC:   ");
	mmc_initialize(gd->bd);
#endif

#ifdef CONFIG_CMD_SCSI
	puts("SCSI:  ");
	scsi_init();
#endif

#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

	/* initialize environment */
	if (should_load_env())
		env_relocate();
	else
		set_default_env(NULL);

#if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI)
	arm_pci_init();
#endif

	stdio_init();	/* get the devices list going. */

	jumptable_init();

#if defined(CONFIG_API)
	/* Initialize API */
	api_init();
#endif

	console_init_r();	/* fully init console as a device */

#ifdef CONFIG_DISPLAY_BOARDINFO_LATE
# ifdef CONFIG_OF_CONTROL
	/* Put this here so it appears on the LCD, now it is ready */
	display_fdt_model(gd->fdt_blob);
# else
	checkboard();
# endif
#endif

#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init();
#endif
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r();
#endif

	 /* set up exceptions */
	interrupt_init();
	/* enable exceptions */
	enable_interrupts();

	/* Initialize from environment */
	load_addr = getenv_ulong("loadaddr", 16, load_addr);

#ifdef CONFIG_BOARD_LATE_INIT
	board_late_init();
#endif

#ifdef CONFIG_FASTBOOT
	fastboot_setup();
#endif

#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
#if defined(CONFIG_CMD_NET)
	puts("Net:   ");
	eth_initialize(gd->bd);
#if defined(CONFIG_RESET_PHY_R)
	debug("Reset Ethernet PHY\n");
	reset_phy();
#endif
#endif

#ifdef CONFIG_POST
	post_run(NULL, POST_RAM | post_bootmode_get(0));
#endif

#if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
	/*
	 * Export available size of memory for Linux,
	 * taking into account the protected RAM at top of memory
	 */
	{
		ulong pram = 0;
		uchar memsz[32];

#ifdef CONFIG_PRAM
		pram = getenv_ulong("pram", 10, CONFIG_PRAM);
#endif
#ifdef CONFIG_LOGBUFFER
#ifndef CONFIG_ALT_LB_ADDR
		/* Also take the logbuffer into account (pram is in kB) */
		pram += (LOGBUFF_LEN + LOGBUFF_OVERHEAD) / 1024;
#endif
#endif
		sprintf((char *)memsz, "%ldk", (gd->ram_size / 1024) - pram);
		setenv("mem", (char *)memsz);
	}
#endif

#ifdef CONFIG_FASTBOOT
	check_fastboot();
#endif

	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		main_loop();
	}

	/* NOTREACHED - no way out of command loop except booting */
}
示例#6
0
文件: nqueens.c 项目: alecwebb/c
int main()
{
//declare function variables
int i,k,j,l;
int n=0;
int pass=0;

double numArray[];
int minout[ARRAYLEN];
int maxout[ARRAYLEN];
double meanout[ARRAYLEN];
double ntimesn[ARRAYLEN];
double nfacout[ARRAYLEN];

double mean=0;
double sizesquare=0;
double nfactorial, nsq;

//seed the generator
srandom(RNG_SEED);

//introduction message
printf("Project 1, Created by: Alec Webb, Description: Solves the nqueens problem using permutations\n");
printf("---------------------------------------------------------------\n");

for(j=4; j<=ARRAYLEN; j++){ 			//start n loop
	int solutionFound=0;	//used to determine first run or not
	int nCounter=0;			//used to count number of runs for 10 solutions
	int pncount=0;				//used to calulate current number of runs for max min functions
	int current=0;				//for max min functions
	int minimum=0;			//for max min comparisons
	int maximum=0;			//for max min comparisons

	n=j;								//set size of array
	nsq=j; 							//set size for calculations

	for(k=0; k<LOOPTIME; k++){ 								//find 10 solutions
		pass=0; 															//to continue after a first match is found
		pncount = nCounter; 										//for maxmin calc
			while(pass==0)
			{
				InitializeArray(numArray, n);						//call initialize method
				randperm(numArray, n);							//call randperm function
				pass = checkboard(numArray, n);			//check the permutation
				nCounter++;												//total# of runs
			}
		current = nCounter-pncount;  							//for max min,current run time

		if(pncount==0)													//to account for a run that has not occured
		{																		//avoids min being set to 0
			minimum = maximum = current;
		}
		else
		{
			minimum = min(minimum, current);				//compare
			maximum = max(maximum, current);				//compare
		}

		solutionFound++; 											 //indicate first solution has been found
		if(solutionFound <=1)										//handles the first and only first solution
		{
		displayboard(numArray, n);								//print the solution found

		printf("---------------------------------------------------------------\n");
		printf(" ");
		for(i=0; i<n; i++){												//print the numerical solution found
			printf("%-3.0lf", numArray[i]);
		}
		printf(": Solution for board size %d\n", n);
		printf("---------------------------------------------------------------\n");
		}
}
//calculate and store relevent values
mean = nCounter/10;											//determine mean
sizesquare = nsquared(nsq,n);								//determine n^n
nfactorial = factorial(n);											//determine n!

//stores the values for printing
minout[j-4] = minimum;
maxout[j-4] = maximum;
meanout[j-4] = mean;
ntimesn[j-4] = sizesquare;
nfacout[j-4] = nfactorial;

}//end n loop

//the following prints out the results of the 10 runs for each n
printf("size      min        max         mean     size**size      size!\n");
printf("---------------------------------------------------------------\n");
for(l=0; l<NUMBEROFBOARDS; l++)
{
	printf("%4d %8d %10d %12.1e %12.1e %12.1e\n", (l+4), minout[l], maxout[l], meanout[l], ntimesn[l], nfacout[l]);
}
return 0;
}//end main
示例#7
0
void generateallcaps(const S_BOARD *pos, S_MOVELIST *list)
{
  //printf("generate checkboard assert");
  ASSERT(checkboard(pos));

  list->count = 0;

  int pce = EMPTY;
  int side = pos->side;
  int sq = 0; int t_sq =0;
  int pceNum = 0;
  int dir =0;
  int i =0;
  int pceindex =0;

  //printf("\n\n Side: %d\n",side);

  if(side == WHITE)
  {
    for(pceNum =0; pceNum < pos->pceNum[wp];pceNum++)
    {
      sq = pos->plist[wp][pceNum];
      ASSERT(sqonboard(sq));

      if(!SQOFFBOARD(sq+9) && piececol[pos->pieces[sq+9]]==BLACK)
        addwhitepawncapmove(pos,sq,sq+9,pos->pieces[sq+9],list);
      if(!SQOFFBOARD(sq+11) && piececol[pos->pieces[sq+11]]==BLACK)
        addwhitepawncapmove(pos,sq,sq+11,pos->pieces[sq+11],list);
      //enpassnt
      if(!SQOFFBOARD(sq+9) && sq+9==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq+9,EMPTY,EMPTY,MFLAGEP),list);
      if(!SQOFFBOARD(sq+11) && sq+11==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq+11,EMPTY,EMPTY,MFLAGEP),list);
    } //for ended


  }
  else
  {
    for(pceNum =0; pceNum < pos->pceNum[bp];pceNum++)
    {
      sq = pos->plist[bp][pceNum];
      ASSERT(sqonboard(sq));

      if(!SQOFFBOARD(sq-9) && piececol[pos->pieces[sq-9]]==WHITE)
        addblackpawncapmove(pos,sq,sq-9,pos->pieces[sq-9],list);
      if(!SQOFFBOARD(sq-11) && piececol[pos->pieces[sq-11]]==WHITE)
        addblackpawncapmove(pos,sq,sq-11,pos->pieces[sq-11],list);

      //enpassnt
      if(!SQOFFBOARD(sq-9) && sq-9==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq-9,EMPTY,EMPTY,MFLAGEP),list);
      if(!SQOFFBOARD(sq-11) && sq-11==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq-11,EMPTY,EMPTY,MFLAGEP),list);
    }
  }

  /* Loop for slide pieces */  
  
  pceindex = loopslideindex[side];
  pce = loopslidepce[pceindex++];
  
  while(pce != 0)
  {
    ASSERT(piecevalid(pce));
    //printf("slider pceindex:%d pce : %d\n",pceindex,pce);
    
    for(pceNum =0; pceNum < pos->pceNum[pce];pceNum++)
    {
      sq=pos->plist[pce][pceNum];
      ASSERT(sqonboard(sq));
      //printf("Piece : %c on %s\n",pcechar[pce],prsq(sq));
      
      for(i=0;i<numdir[pce];i++)
      {
        dir = pcedir[pce][i];
        t_sq = sq +dir;
        
        while(!SQOFFBOARD(t_sq))
        {
          if(pos->pieces[t_sq] != EMPTY)
          {
            if(piececol[pos->pieces[t_sq]]== side^1)
            {//printf("\t\tCapture on %s \n", prsq(t_sq));
             addcapturemove(pos,MOVE(sq,t_sq,pos->pieces[t_sq],EMPTY,0),list);
            }
            break;
          }
          t_sq += dir;
        }
      }
    }
    pce = loopslidepce[pceindex++];
  }
  /* Loop for slide pieces */
  
  /* Loop for non slide pieces */
  
  pceindex = loopnonslideindex[side];
  pce = loopnonslidepce[pceindex++];
  
  while(pce != 0)
  {
    ASSERT(piecevalid(pce));
    //printf("non slider pceindex:%d pce : %d\n",pceindex,pce);
    
    for(pceNum =0; pceNum <pos->pceNum[pce];pceNum++)
    {
      sq=pos->plist[pce][pceNum];
      ASSERT(sqonboard(sq));
      //printf("Piece : %c on %s\n",pcechar[pce],prsq(sq));
      for(i=0;i<numdir[pce];i++)
      {
        dir = pcedir[pce][i];
        t_sq = sq +dir;

        if(SQOFFBOARD(t_sq))
          continue;
        // BLACK ^ 1 == WHITE      WHITE ^ 1 == BLACK
        if(pos->pieces[t_sq] != EMPTY)
        {
          if(piececol[pos->pieces[t_sq]] == side ^ 1)
          {//printf("\t\tCapture on %s\n",prsq(t_sq));
            addcapturemove(pos,MOVE(sq,t_sq,pos->pieces[t_sq],EMPTY,0),list);}
          continue;
        }
        //printf("\t\tNormal on %s \n",prsq(t_sq));
      }
    }
    pce = loopnonslidepce[pceindex++];
  }

  /* Loop for non slide pieces */

}
示例#8
0
void generateallmoves(const S_BOARD *pos, S_MOVELIST *list)
{
  //printf("generate checkboard assert");
  ASSERT(checkboard(pos));

  list->count = 0;

  int pce = EMPTY;
  int side = pos->side;
  int sq = 0; int t_sq =0;
  int pceNum = 0;
  int dir =0;
  int i =0;
  int pceindex =0;

  //printf("\n\n Side: %d\n",side);

  if(side == WHITE)
  {
    for(pceNum =0; pceNum < pos->pceNum[wp];pceNum++)
    {
      sq = pos->plist[wp][pceNum];
      ASSERT(sqonboard(sq));
      if(pos->pieces[sq + 10] == EMPTY)
      {
        addwhitepawnmove(pos,sq,sq+10,list);
        if(ranksbrd[sq]== RANK_2 && pos-> pieces[sq + 20]==EMPTY)
            addquietmove(pos,MOVE(sq,(sq+20),EMPTY,EMPTY,MFLAGPS),list);
      }

      if(!SQOFFBOARD(sq+9) && piececol[pos->pieces[sq+9]]==BLACK)
        addwhitepawncapmove(pos,sq,sq+9,pos->pieces[sq+9],list);
      if(!SQOFFBOARD(sq+11) && piececol[pos->pieces[sq+11]]==BLACK)
        addwhitepawncapmove(pos,sq,sq+11,pos->pieces[sq+11],list);
      //enpassnt
      if(!SQOFFBOARD(sq+9) && sq+9==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq+9,EMPTY,EMPTY,MFLAGEP),list);
      if(!SQOFFBOARD(sq+11) && sq+11==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq+11,EMPTY,EMPTY,MFLAGEP),list);
    } //for ended

    /* castle move */
    if(pos->castle & WO_O)
    {
      if(pos->pieces[F1]==EMPTY && pos->pieces[G1] == EMPTY)
        if(!sqattacked(E1,BLACK,pos) && !sqattacked(F1,BLACK,pos) && !sqattacked(G1,BLACK,pos))
        {
          //printf("WO_O MoveGen\n");
          addquietmove(pos,MOVE(E1,G1,EMPTY,EMPTY,MFLAGCA),list);
        }

    }
    if(pos->castle & WO_O_O)
    {
      if(pos->pieces[D1]==EMPTY && pos->pieces[C1] == EMPTY && pos->pieces[B1]==EMPTY)
        if(!sqattacked(E1,BLACK,pos) && !sqattacked(D1,BLACK,pos) && !sqattacked(C1,BLACK,pos))
        {
          //printf("WO_O_O MoveGen\n");
          addquietmove(pos,MOVE(E1,C1,EMPTY,EMPTY,MFLAGCA),list);
        }

    }
    /* castle move */

  }
  else
  {
    for(pceNum =0; pceNum < pos->pceNum[bp];pceNum++)
    {
      sq = pos->plist[bp][pceNum];
      ASSERT(sqonboard(sq));
      if(pos->pieces[sq - 10] == EMPTY)
      {
        addblackpawnmove(pos,sq,sq-10,list);
        if(ranksbrd[sq]== RANK_7 && pos-> pieces[sq-20]==EMPTY)
        {
            addquietmove(pos,MOVE(sq,(sq-20),EMPTY,EMPTY,MFLAGPS),list);
        }
      }

      if(!SQOFFBOARD(sq-9) && piececol[pos->pieces[sq-9]]==WHITE)
        addblackpawncapmove(pos,sq,sq-9,pos->pieces[sq-9],list);
      if(!SQOFFBOARD(sq-11) && piececol[pos->pieces[sq-11]]==WHITE)
        addblackpawncapmove(pos,sq,sq-11,pos->pieces[sq-11],list);

      //enpassnt
      if(!SQOFFBOARD(sq-9) && sq-9==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq-9,EMPTY,EMPTY,MFLAGEP),list);
      if(!SQOFFBOARD(sq-11) && sq-11==pos->enpass)
        addenpassantmove(pos,MOVE(sq,sq-11,EMPTY,EMPTY,MFLAGEP),list);
    }
    
    /* castle move */
    if(pos->castle & BO_O)
    {
      if(pos->pieces[F8]==EMPTY && pos->pieces[G8] == EMPTY)
        if(!sqattacked(E8,WHITE,pos) && !sqattacked(F8,WHITE,pos) && !sqattacked(G8,WHITE,pos))
        {
          //printf("BO_O MoveGen\n");
          addquietmove(pos,MOVE(E8,G8,EMPTY,EMPTY,MFLAGCA),list);
        }

    }
    if(pos->castle & BO_O_O)
    {
      if(pos->pieces[D8]==EMPTY && pos->pieces[C8] == EMPTY && pos->pieces[B8]==EMPTY)
        if(!sqattacked(E8,WHITE,pos) && !sqattacked(D8,WHITE,pos) && !sqattacked(C8,WHITE,pos))
        {
          //printf("BO_O_O MoveGen\n");
          addquietmove(pos,MOVE(E8,C8,EMPTY,EMPTY,MFLAGCA),list);
        }

    }
    /* castle move */


  }

  /* Loop for slide pieces */  
  
  pceindex = loopslideindex[side];
  pce = loopslidepce[pceindex++];
  
  while(pce != 0)
  {
    ASSERT(piecevalid(pce));
    //printf("slider pceindex:%d pce : %d\n",pceindex,pce);
    
    for(pceNum =0; pceNum < pos->pceNum[pce];pceNum++)
    {
      sq=pos->plist[pce][pceNum];
      ASSERT(sqonboard(sq));
      //printf("Piece : %c on %s\n",pcechar[pce],prsq(sq));
      
      for(i=0;i<numdir[pce];i++)
      {
        dir = pcedir[pce][i];
        t_sq = sq +dir;
        
        while(!SQOFFBOARD(t_sq))
        {
          if(pos->pieces[t_sq] != EMPTY)
          {
            if(piececol[pos->pieces[t_sq]]== side^1)
            {//printf("\t\tCapture on %s \n", prsq(t_sq));
             addcapturemove(pos,MOVE(sq,t_sq,pos->pieces[t_sq],EMPTY,0),list);
            }
            break;
          }
          //printf("\t\tNormal on %s\n",prsq(t_sq));
          addquietmove(pos,MOVE(sq,t_sq,EMPTY,EMPTY,0),list);
          t_sq += dir;
        }
      }
    }
    pce = loopslidepce[pceindex++];
  }
  /* Loop for slide pieces */
  
  /* Loop for non slide pieces */
  
  pceindex = loopnonslideindex[side];
  pce = loopnonslidepce[pceindex++];
  
  while(pce != 0)
  {
    ASSERT(piecevalid(pce));
    //printf("non slider pceindex:%d pce : %d\n",pceindex,pce);
    
    for(pceNum =0; pceNum <pos->pceNum[pce];pceNum++)
    {
      sq=pos->plist[pce][pceNum];
      ASSERT(sqonboard(sq));
      //printf("Piece : %c on %s\n",pcechar[pce],prsq(sq));
      for(i=0;i<numdir[pce];i++)
      {
        dir = pcedir[pce][i];
        t_sq = sq +dir;

        if(SQOFFBOARD(t_sq))
          continue;
        // BLACK ^ 1 == WHITE      WHITE ^ 1 == BLACK
        if(pos->pieces[t_sq] != EMPTY)
        {
          if(piececol[pos->pieces[t_sq]] == side ^ 1)
          {//printf("\t\tCapture on %s\n",prsq(t_sq));
            addcapturemove(pos,MOVE(sq,t_sq,pos->pieces[t_sq],EMPTY,0),list);}
          continue;
        }
        //printf("\t\tNormal on %s \n",prsq(t_sq));
        addquietmove(pos,MOVE(sq,t_sq,EMPTY,EMPTY,0),list);
      }
    }
    pce = loopnonslidepce[pceindex++];
  }

  /* Loop for non slide pieces */

}
示例#9
0
int sqattacked(const int sq, const int side, const S_BOARD *pos)
{
  int pce,i,t_sq,dir;

  ASSERT(sqonboard(sq));
  ASSERT(sidevalid(side));
  //printf("assert checkboard in sqattacked");
  ASSERT(checkboard(pos));

  //pawns
  if(side==WHITE)
  {
    if(pos->pieces[sq-11]==wp || pos->pieces[sq-9] == wp)
      return TRUE;
  }
  else
  {
    if(pos->pieces[sq+11]==bp || pos->pieces[sq+9] == bp)
      return TRUE;

  }
  
  //knights
  for(i=0;i < 8;i++)
  {
    pce=pos->pieces[sq+kndir[i]];
    if(pce != OFFBOARD && iskn(pce) && piececol[pce] == side)
      return TRUE;
  }
  
  //rooks,queens
  for(i=0;i<4;i++)
  {
    dir=rkdir[i];
    t_sq = sq + dir;
    pce = pos->pieces[t_sq];
    while(pce!=OFFBOARD)
    {
      if(pce != EMPTY)
      {
        if(isrq(pce) && piececol[pce] == side)
          return TRUE;
        break;
      }
    t_sq +=dir;
    pce = pos->pieces[t_sq];
    }
  }

 // bishop , queens
 for(i=0;i<4;i++)
 {
    dir = bidir[i];
    t_sq = sq +dir;
    pce = pos->pieces[t_sq];
    while(pce != OFFBOARD)
    {
      if(pce != EMPTY)
      {
        if(isbq(pce) && piececol[pce] == side)
          return TRUE;
        break;
      }
      t_sq += dir;
      pce = pos->pieces[t_sq];
    }
  }
  
  //kings
  for(i=0;i<8;++i)
  {
    pce=pos->pieces[sq + kidir[i]];
    if(pce != OFFBOARD && iski(pce) && piececol[pce] == side)
      return TRUE;
  }

  return FALSE;
}
示例#10
0
void board_init_r(gd_t *id, ulong dest_addr)
{

	if (id)
		gd = id;

	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */

#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif

#ifdef CONFIG_POST
	post_output_backlog();
#endif

	/* The Malloc area is at the top of simulated DRAM */
	mem_malloc_init((ulong)gd->ram_buf + gd->ram_size - TOTAL_MALLOC_LEN,
			TOTAL_MALLOC_LEN);

	/* initialize environment */
	env_relocate();

	/* IP Address */
	gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");

	stdio_init();	/* get the devices list going. */

	jumptable_init();

	console_init_r();	/* fully init console as a device */

#if defined(CONFIG_DISPLAY_BOARDINFO_LATE)
	checkboard();
#endif

#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init();
#endif
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r();
#endif

	 /* set up exceptions */
	interrupt_init();
	/* enable exceptions */
	enable_interrupts();

#ifdef CONFIG_BOARD_LATE_INIT
	board_late_init();
#endif

#ifdef CONFIG_POST
	post_run(NULL, POST_RAM | post_bootmode_get(0));
#endif

	sandbox_main_loop_init();

	/*
	 * For now, run the main loop. Later we might let this be done
	 * in the main program.
	 */
	while (1)
		main_loop();

	/* NOTREACHED - no way out of command loop except booting */
}
示例#11
0
static void game(void) {
    char c;
    int counter = sspeed, rs, a, blocks = 0, paused = 0;

    gamescreen();
    clearboard();

    nexts = rnd()%28;
    nextc = rnd()%7 + 1;
    newshape();
    score = view = 0;
    if (view) drawview(nexts, nextc);
    level = 1;
    speed = sspeed;
    printscore();
    printlevel();

    for(;;) {
        if (paused) {
            gametick();
            c = tgetchar();
            switch(c) {
            case 'q':
                goto stopgame;
            case 'p':
                paused = 0;
                moveto(68,5); setbg(black);
                printf("           ");
                normal();
                flush();
            default:
                break;
            }
            continue;
        }

        if (counter <= 0) {
            counter = 14 - speed;
            if (shapefits(current.s, current.x, current.y+1)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.y++;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                                current.y-3);
            } else {
                markboard(current.s, current.color, current.x, current.y);
                checkboard(current.y);
                incrscore(1);
                newshape();
                if (!shapefits(current.s, current.x, current.y)) goto stopgame;
                blocks++;
                if (blocks == blocksperlevel) {
                    blocks = 0;
                    incrlevel(1);
                }
                if (view) drawview(nexts, nextc);
            }
        }
        counter--;

        moveto(1,24);
        flush();
        gametick();
        c = tgetchar();
        switch(c) {
        case 'q':
            goto stopgame;
        case 'j':
            if (shapefits(current.s, current.x-1, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.x--;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case 'l':
            if (shapefits(current.s, current.x+1, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.x++;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case 'k':
            rs = (current.s & ~0x03) | ((current.s + 1) & 0x03);
            if (shapefits(rs, current.x, current.y)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.s = rs;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            break;
        case ' ':
            for (a=1; ; a++) {
                if (!shapefits(current.s, current.x, current.y+a))
                    break;
            }
            if (shapefits(current.s, current.x, current.y+a-1)) {
                drawshape(current.s, 0, 40-WIDTH-8+current.x*2, current.y-3);
                current.y += a-1;
                drawshape(current.s, current.color, 40-WIDTH-8+current.x*2,
                                                              current.y-3);
            }
            incrscore(view ? (a-1) * 3 / 4 : a-1);
            break;
        case 'n':
            view ^= 1;
            if (view) drawview(nexts, nextc);
            else clearview();
            break;
        case 'p':
            paused = 1;
            moveto(68,5); setfg(white); setbg(blue);
            printf(" PAUSED!!! ");
            moveto(1,24);
            flush();
        default:
            break;
        }
    }

stopgame:
    setbg(white);
    rect(20,8,60,12);
    setbg(red);
    frect(21,9,59,11);
    setfg(white);
    bold();
    moveto(30,10);
    printf(" G A M E    O V E R ");
    moveto(1,24);
    flush();

    for(;;) {
        c = tgetchar();
        if (c > 0) return;
    }
}