示例#1
0
/*
 * We can determine if a clause is true by
 * running through each of the values in it and checking
 * if any of them are true (as a clause is a set of ORs)
 */
inline uint8_t is_clause_true(uint64_t i) {
	list_t * clause = clauses[i];

	foreach(node, clause) {
		intptr_t var = (intptr_t)node->value;
		if (var < 0) {
			if (!checkbit(-var - 1)) return 1;
		} else {
			if (checkbit(var - 1)) return 1;
		}
	}
示例#2
0
void main()
{
	int n,set,clr,tog,res,check;
	printf("Enter the number:\n");
	scanf("%d",&n);
	printf("Position to set:\n");
	scanf("%d",&set);
	printf("Position to clear:\n");
	scanf("%d",&clr);
	printf("Position to toggle:\n");
	scanf("%d",&tog);
	printf("Position to check:\n");
	scanf("%d",&check);
	res=setbit(n,set);
	printf("Result after set is :%d \n",res);
	res=clearbit(n,clr);
	printf("Result after clear is :%d \n",res);
	res=togglebit(n,tog);
	printf("Result after toggle is :%d \n",res);
	res=checkbit(n,check);
	if(res)
		printf("The %d th bit in %d is  set\n",check,n);
	else
		printf("The %d th bit in %d is  not set\n",check,n);
}
int allocDataBlock()
{
	char byte;
	int i,j;
	int freeFound=0;//flag to check if free block found
	int freeBlock;
	//Find free block
	for(i=0; i<MAXDATABLOCKS; i=i+8)
	{
		lseek(fdImage,BYOFF_BIT(i),SEEK_SET);//get the byte for that block in the bitmap
		read(fdImage,&byte,sizeof(char));
		for(j=0; j<8; j++)
		{
			if(checkbit(j,byte)==0)//if unused bit found
			{
				freeBlock= i + j;
				freeFound=1;
				setbit(j,&byte);//set that bit to used
				//write back the byte
				lseek(fdImage,BYOFF_BIT(i),SEEK_SET);
				write(fdImage,&byte,sizeof(char));
				break;
			}
		}
		if(freeFound)
			break;
	}

	if(!freeFound)
		return -1;//No free block to write on, should not happen
	else
	{

		//update superblock total and data block
		super.nblocks++;
		super.size++;
		lseek(fdImage, BYOFF_SUPER, SEEK_SET);
		write(fdImage, &super, sizeof(superblock_t));
		return freeBlock;
	}

}
示例#4
0
void turnleft(void)
{

    motorALL_ON();
   motor2_Forward(); 
motor1_OFF();
if ((checkbit(PINF,6)!=0 && checkbit(PINF,7)!=0 && checkbit(PINF,5)!=0)||(checkbit(PINF,6)!=0 && checkbit(PINF,7)==0 && checkbit(PINF,5)!=0))  //THE CROSSOVER DETECTED
                {
					
				               
                              
								j++;
							  
								/*lcd_gotoxy2(5);
								lcd_showvalue(j);*/
								PORTC=~j;
								_delay_ms(500);	
								
				}
//PORTC=0x02;
if((checkbit(PINF,6)==0) && (checkbit(PINF,7)==0) && (checkbit(PINF,5)==0)||(checkbit(PINF,6)!=0) && (checkbit(PINF,7)!=0) && (checkbit(PINF,5)!=0)) 
turnleft();
}
int main(void)
{
	// test checkbit()

	int value, position, ch;

	printf("Enter an integer: ");
	while (scanf("%d", &value) == 1)
	{
		printf("Enter a position: ");
		while (scanf("%d", &position) == 1)
		{
			printf("Position %d of %d is %d\n", position, value,
				   checkbit(value, position));
			printf("Enter a position: ");
		}
		CLEARINPUT;
		printf("\nEnter an integer: ");
	}

	puts("Bye.");
	return 0;
}
示例#6
0
/* sdr navigation data function ------------------------------------------------
* decide navigation bit and decode navigation data
* args   : sdrch_t *sdr     I/O sdr channel struct
*          uint64_t buffloc I   buffer location
*          uint64_t cnt     I   counter of sdr channel thread
* return : none
*-----------------------------------------------------------------------------*/
extern void sdrnavigation(sdrch_t *sdr, uint64_t buffloc, uint64_t cnt)
{
    int sfn;

    sdr->nav.biti=cnt%sdr->nav.rate; /* current bit location for bit sync */
    sdr->nav.ocodei=(sdr->nav.biti-sdr->nav.synci-1); /* overlay code index */
    if (sdr->nav.ocodei<0) sdr->nav.ocodei+=sdr->nav.rate;

    /* navigation bit synchronization */
    /* if synchronization does not need (NH20 case) */
    if (sdr->nav.rate==1&&cnt>2000/(sdr->ctime*1000)) {
        sdr->nav.synci=0;
        sdr->nav.flagsync=ON;
    }
    /* check bit synchronization */
    if (!sdr->nav.flagsync&&cnt>2000/(sdr->ctime*1000))
        sdr->nav.flagsync=checksync(sdr->trk.II[0],sdr->trk.oldI[0],&sdr->nav);
    
    if (sdr->nav.flagsync) {
        /* navigation bit determination */
        if (checkbit(sdr->trk.II[0],sdr->trk.loopms,&sdr->nav)==OFF) {
            //SDRPRINTF("%s nav sync error!!\n",sdr->satstr);
        }

        /* check navigation frame synchronization */
        if (sdr->nav.swsync) {
            /* FEC (foward error correction) decoding */
            if (!sdr->nav.flagtow) predecodefec(&sdr->nav);

            /* frame synchronization (preamble search) */
            if (!sdr->nav.flagtow) sdr->nav.flagsyncf=findpreamble(&sdr->nav);

            /* preamble is found */
            if (sdr->nav.flagsyncf&&!sdr->nav.flagtow) {
                /* set reference sample data */
                sdr->nav.firstsf=buffloc;
                sdr->nav.firstsfcnt=cnt;
                SDRPRINTF("*** find preamble! %s %d %d ***\n",
                    sdr->satstr,(int)cnt,sdr->nav.polarity);
                sdr->nav.flagtow=ON;
            }
        }
        /* decoding navigation data */
        if (sdr->nav.flagtow&&sdr->nav.swsync) {
            /* if frame bits are stored */
            if ((int)(cnt-sdr->nav.firstsfcnt)%sdr->nav.update==0) {
                predecodefec(&sdr->nav); /* FEC decoding */
                sfn=decodenav(&sdr->nav); /* navigation message decoding */
                
                SDRPRINTF("%s ID=%d tow:%.1f week=%d cnt=%d\n",
                    sdr->satstr,sfn,sdr->nav.sdreph.tow_gpst,
                    sdr->nav.sdreph.week_gpst,(int)cnt);

                /* set reference tow data */
                if (sdr->nav.sdreph.tow_gpst==0) {
                    /* reset if tow does not decoded */
                    sdr->nav.flagsyncf=OFF;
                    sdr->nav.flagtow=OFF;
                } else if (cnt-sdr->nav.firstsfcnt==0) {
                    sdr->nav.flagdec=ON;
                    sdr->nav.sdreph.eph.sat=sdr->sat; /* satellite number */
                    sdr->nav.firstsftow=sdr->nav.sdreph.tow_gpst; /* tow */

                    if (sdr->nav.ctype==CTYPE_G1)
                        sdr->prn=sdr->nav.sdreph.prn;
                }
            }
        }
    }
}
示例#7
0
void main()
{

DDRA=0XFF;
DDRC=0xFF;
//PORTC=0XFF;           //led 
                    // PORT F Initialization
DDRF=0x00;
PORTF=0xFF;            //SENSOR


DDRB=0XF0;


DDRE=0x0F;  //motor enable
int i=PINF;
    
while(1)
   { 
 
 if(checkbit(i,4)==0)
  {
  PORTA=0X00;
   
   if(( checkbit(i,6)==0 && checkbit(i,7)!=0 && checkbit(i,5)!=0) || (checkbit(i,6)==0 && checkbit(i,7)==0 && checkbit(i,5)!=0))
		turnright();
  
	else if(( checkbit(i,6)!=0 && checkbit(i,7)!=0 && checkbit(i,5)==0) || (checkbit(i,6)!=0 && checkbit(i,7)==0 && checkbit(i,5)==0))

          turnleft();
		  
  else if(checkbit(i,5)==0 && checkbit(i,7)!=0 && checkbit(i,6)==0)                               
	{
		motorALL_ON();
		motor2_Forward();   
	   motor1_Forward();
		//PORTC=0x00;
		
			 if ((checkbit(i,6)!=0 && checkbit(i,7)!=0 && checkbit(i,5)!=0)||(checkbit(i,6)!=0 && checkbit(i,7)==0 && checkbit(i,5)!=0))  //THE CROSSOVER DETECTED
                {
					
				               
                              motorALL_ON();
                               motor2_Forward();   
							   motor1_Forward();
								j++;
							  
								/*lcd_gotoxy2(5);
								lcd_showvalue(j);*/
								PORTC=~j;
								_delay_ms(500);	
								
				}
	}
}						
	else
	 {
	    PORTA=0X0A;
        //_delay_ms(500);
        //PORTA=0X00; 
        motor2_OFF();
		motor1_OFF();
		motorALL_OFF();
		
		}

     }
  
}
示例#8
0
void lcd_int(void)
// Прерывание каждую миллисекунду
// Опрос клавиатуры и регенерация дисплея
{
    unsigned char disp_temp; /* Временный рабочий регистр */
    unsigned char kbd;
// TCNT0 = 0xAF; /* Перезагрузить таймер */

    if(!--sec_recount)
    {
        SET_SECONDS; /* Установить флаг "Очередная секунда" */
        sec_recount = 1000;
//  sec_recount = 540;
    }
    if(!--blink_count)
    {
        TOGGLE_BLINK;
        blink_count = 300;
//  if(ALARM) /* Проверить флаг "Тревога" */
//   BELL_TOGGLE;
    }
    if(START_DELAY) /* Проверить флаг разрешения начала выдержки */
    {
        if(!--repeat_count) /* Если обратный отсчет закончен */
        {
            SET_STOP_DELAY; /* Установить флаг окончания выдержки */
            RESET_START_DELAY; /* Сбросить флаг начала выдержки */
        }
    }
    if(START_BEEP) /* Проверить флаг начала выдержки звукового сигнала */
    {
        BELL_TOGGLE;
        if(!--beep_count) /* Если обратный отсчет закончен */
        {
            BELL_OFF; /* Выключить звуковой сигнал */
            RESET_START_BEEP; /* Сбросить флаг начала выдержки звукового сигнала */
        }
    }
//KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
    kbd = (PING & 0x0F) ; //
// kbd >>= 4;

    if(!(kbd & kbd_shift)) /* Считать состояние клавиатуры по текущему биту порта PA */
    {   /* Текущая кнопка нажата */
        if(!(keyboard & kbd_shift)) /* Если кнопка не была удержана */
        {
            if(!SCAN_READY) /* Если предыдущий скан-код обработан */
            {
                scan_code = 4-kbd_count; /* Взять скан-код кнопки */
                SET_SCAN_READY; /* Установить флаг готовности скан-кода */
            }
            BELL_ON; /* Звуковой сигнал нажатия кнопки */
            SET_START_BEEP; /* Установить флаг начала выдержки звукового сигнала */
            beep_count = DELAY_BEEP;  /* Длительности в мс звукового сигнала */
            SET_START_DELAY; /* Установить флаг начала выдержки перед автоповтором */
            repeat_count = DELAY_REPEAT; /* Выдержка в мс перед автоповтором */
        }
        else /* Если кнопка была удержана */
        {
            if(STOP_DELAY) /* Проверить окончание выдержки перед автоповтором */
            {
                SET_KEYB_REPEAT; /* Установить флаг признака действия автоповтора */
                if(!SCAN_READY && AUTO_REPEAT) /* Если предыдущий скан-код обработан и разрешен автоповтор */
                {
                    scan_code = 4-kbd_count; /* Взять скан-код кнопки */
                    SET_SCAN_READY; /* Установить флаг готовности скан-кода */
                }
                RESET_STOP_DELAY; /* Сбросить флаг окончания выдержки */
                SET_START_DELAY; /* Установить флаг начала выдержки периода автоповтора */
                repeat_count = TIME_REPEAT; /* Период автоповтора */
            }
        }
        keyboard |= kbd_shift; /* Установить соответствующий бит нажатой кнопки */
    }
    else /* Текущая кнопка отжата */
    {
        if(keyboard & kbd_shift) /* Если кнопка была удержана и отпущена */
        {
            RESET_START_DELAY; /* Сбросить флаг начала выдержки */
            RESET_STOP_DELAY; /* Сбросить флаг окончания выдержки */
            RESET_KEYB_REPEAT; /* Сбросить флаг признака действия автоповтора */
        }
        keyboard &= ~kbd_shift; /* Сбросить соответствующий бит отжатой кнопки */
    }

    kbd_count++;
    kbd_shift <<= 1;    /* Сдвинуть на следующую позицию */

    if(kbd_count == 4) /* Проверить счетчик кнопок на последний разряд */
    {
        kbd_count = 0;    /* Счетчик указатель скан-кода */
        kbd_shift = 0x01; /* Указатель на битовую позицию кнопки */
    }


    if(disp_count == 32) /* Проверить счетчик на последний разряд */
    {
        disp_count = 0;       /* Сбросить счетчик */
        LCD_CONTROL;          /* Выбрать регистр управления */
        PORT_LCD &= 0xF0;  /* Обнулить младшую тетраду */
        PORT_LCD |= 0x08;  /* Установить адрес первого символа первой строки */
        LOAD_LCD;             /* Загрузить старшую тетраду в индикатор */
        PORT_LCD &= 0xF0;  /* Обнулить младшую тетраду */
        LOAD_LCD;             /* Загрузить младшую тетраду в индикатор */
        RESET_TWO_LINE;       /* Сбросить флаг второй строки */
        return;
    }
    if(disp_count == 16 && !TWO_LINE)
    {
        LCD_CONTROL;          /* Выбрать регистр управления */
        PORT_LCD &= 0xF0;  /* Обнулить младшую тетраду */
        PORT_LCD |= 0x0C;  /* Установить адрес первого символа второй строки */
        LOAD_LCD;             /* Загрузить старшую тетраду в индикатор */
        PORT_LCD &= 0xF0;  /* Обнулить младшую тетраду */
        LOAD_LCD;             /* Загрузить младшую тетраду в индикатор */
        SET_TWO_LINE;         /* Установить флаг перехода на вторую строку */
        return;
    }
    LCD_DATA; /* Выбрать регистр данных */
    disp_temp = display[disp_count];
    if(disp_temp>0x7f)
        disp_temp = TableDecode[display[disp_count] - 0x80];


    if(TWO_LINE)   // Определить выводимую строку
    {   // Мигание на 2 строке
        if(checkbit(blinc_line2,disp_count-16) && BLINK) // Проверить разряд на мигание
            disp_temp = 0x20; // Код пробела //
    }
    else
    {   // Мигание на 1 строке
        if(checkbit(blinc_line1,disp_count) && BLINK) // Проверить разряд на мигание
            disp_temp = 0x20; // Код пробела
    }


    PORT_LCD &= 0xF0; /* Обнулить младшую тетраду */
    PORT_LCD |= disp_temp >> 4; /* Записать старшую тетраду в регистр индикатора/клавиатуры */
    LOAD_LCD;              /* Загрузить данные в LCD индикатор */
    PORT_LCD &= 0xF0; /* Обнулить младшую тетраду */
    PORT_LCD |= (disp_temp & 0x0F); /* Записать младшую тетраду в регистр индикатора/клавиатуры */
    LOAD_LCD;              /* Загрузить данные в LCD индикатор */
    disp_count ++;
}
void NavigationSystem::DrawSystem()
{
    UniverseUtil::PythonUnitIter bleh = UniverseUtil::getUnitList();
    if ( !(*bleh) )
        return;
//string mystr ("3d "+XMLSupport::tostring (system_view));
//UniverseUtil::IOmessage (0,"game","all",mystr);

    //what's my name
    //***************************
    TextPlane systemname;       //will be used to display shits names
    int faction = FactionUtil::GetFactionIndex( UniverseUtil::GetGalaxyFaction( _Universe->activeStarSystem()->getFileName() ) );
    //GFXColor factioncolor = factioncolours[faction];
    string    systemnamestring = "#ff0000Sector: #ffff00"+getStarSystemSector( _Universe->activeStarSystem()->getFileName() )
                                 +"  #ff0000Current System: #ffff00"+_Universe->activeStarSystem()->getName()+" ("
                                 +FactionUtil::GetFactionName( faction )
                                 +"#ffff00)";
    //int length = systemnamestring.size();
    //float offset = (float(length)*0.001);
    //systemname.SetPos( (((screenskipby4[0]+screenskipby4[1])/2)-offset) , screenskipby4[3]); // middle position
    systemname.SetPos( screenskipby4[0]+0.03, screenskipby4[3]+0.02 );     //left position
    systemname.col = GFXColor( 1, 1, .7, 1 );
    systemname.SetText( systemnamestring );
//systemname.SetCharSize(1, 1);
    static float background_alpha =
        XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
    GFXColor     tpbg = systemname.bgcol;
    bool automatte    = (0 == tpbg.a);
    if (automatte) systemname.bgcol = GFXColor( 0, 0, 0, background_alpha );
    systemname.Draw( systemnamestring, 0, true, false, automatte );
    systemname.bgcol = tpbg;
    //***************************

//navdrawlist mainlist(0, screenoccupation, factioncolours);		//	lists of items to draw
//mainlist.unselectedalpha = unselectedalpha;
    navdrawlist mouselist( 1, screenoccupation, factioncolours );       //lists of items to draw that are in mouse range

    QVector     pos;    //item position
    QVector     pos_flat;       //item position flat on plane

    float zdistance = 0.0;
    float zscale    = 0.0;

    Adjust3dTransformation( system_view == VIEW_3D, 1 );
    //Set up first item to compare to + centres
    //**********************************
    while ( (*bleh) && ( _Universe->AccessCockpit()->GetParent() != (*bleh) )
           && ( UnitUtil::isSun( *bleh ) || !UnitUtil::isSignificant( *bleh ) ) )                                                                       //no sun's in initial setup
        ++bleh;
    if ( !(*bleh) )      //nothing there that's significant, just do it all
        bleh = UniverseUtil::getUnitList();
    //GET THE POSITION
    //*************************
    pos = (*bleh)->Position();
    ReplaceAxes( pos );
    //*************************

    //Modify by old rotation amount
    //*************************
//if(system_view==VIEW_3D)
//{
//pos = dxyz(pos, 0, ry_s, 0);
//pos = dxyz(pos, rx_s, 0, 0);
//}
    //*************************

    float max_x = (float) pos.i;
    float min_x = (float) pos.i;
    float max_y = (float) pos.j;
    float min_y = (float) pos.j;
    float max_z = (float) pos.k;
    float min_z = (float) pos.k;

//float themaxvalue = fabs(pos.i);
    themaxvalue = 0.0;

    float center_nav_x = ( (screenskipby4[0]+screenskipby4[1])/2 );
    float center_nav_y = ( (screenskipby4[2]+screenskipby4[3])/2 );
    //**********************************
    //Retrieve unit data min/max
    //**********************************
    while (*bleh) {
        //this goes through one time to get the major components locations, and scales its output appropriately
        if ( UnitUtil::isSun( *bleh ) ) {
            ++bleh;
            continue;
        }
        string temp = (*bleh)->name;
        pos = (*bleh)->Position();
        ReplaceAxes( pos );
        //Modify by old rotation amount
        //*************************
//if(system_view==VIEW_3D)
//{
//pos = dxyz(pos, 0, ry_s, 0);
//pos = dxyz(pos, rx_s, 0, 0);
//}
        //*************************
        //*************************
        if ( ( UnitUtil::isSignificant( *bleh ) ) || ( _Universe->AccessCockpit()->GetParent() == (*bleh) ) )
            RecordMinAndMax( pos, min_x, max_x, min_y, max_y, min_z, max_z, themaxvalue );
        ++bleh;
    }
    //**********************************

    //Find Centers
    //**********************************
    center_x     = (min_x+max_x)/2;
    center_y     = (min_y+max_y)/2;
    center_z     = (min_z+max_z)/2;
    //**********************************

    max_x        = 2*max_x-center_x;
    max_y        = 2*max_y-center_y;
    max_z        = 2*max_z-center_z;
    min_x        = 2*min_x-center_x;
    min_y        = 2*min_y-center_y;
    min_z        = 2*min_z-center_z;

    themaxvalue *= 2;

//#define SQRT3 1.7320508
//themaxvalue = sqrt(themaxvalue*themaxvalue + themaxvalue*themaxvalue + themaxvalue*themaxvalue);
//themaxvalue = SQRT3*themaxvalue;

    //Set Camera Distance
    //**********************************
//{
    float half_x = (max_x-min_x);
    float half_y = (max_y-min_y);
    float half_z = (max_z-min_z);

    camera_z = sqrt( (half_x*half_x)+(half_y*half_y)+(half_z*half_z) );

//float halfmax = 0.5*themaxvalue;
//camera_z = sqrt( (halfmax*halfmax) + (halfmax*halfmax) + (halfmax*halfmax) );
//camera_z = 4.0*themaxvalue;
//}

    //**********************************

    DrawOriginOrientationTri( center_nav_x, center_nav_y, 1 );

/*
 *       string mystr ("max x "+XMLSupport::tostring (max_x));
 *       UniverseUtil::IOmessage (0,"game","all",mystr);
 *
 *       string mystr2 ("min x "+XMLSupport::tostring (min_x));
 *       UniverseUtil::IOmessage (0,"game","all",mystr2);
 *
 *       string mystr3 ("max y "+XMLSupport::tostring (max_y));
 *       UniverseUtil::IOmessage (0,"game","all",mystr3);
 *
 *       string mystr4 ("min y "+XMLSupport::tostring (min_y));
 *       UniverseUtil::IOmessage (0,"game","all",mystr4);
 *
 *       string mystrcx ("center x "+XMLSupport::tostring (center_x));
 *       UniverseUtil::IOmessage (0,"game","all",mystrcx);
 *
 *       string mystrcy ("center y "+XMLSupport::tostring (center_y));
 *       UniverseUtil::IOmessage (0,"game","all",mystrcy);
 */

    Unit *ThePlayer = ( UniverseUtil::getPlayerX( UniverseUtil::getCurrentPlayer() ) );

    //Enlist the items and attributes
    //**********************************
    un_iter blah = UniverseUtil::getUnitList();
    while (*blah) {
        //this draws the points

        //Retrieve unit data
        //**********************************
        string temp = (*blah)->name;

        pos = (*blah)->Position();
        ReplaceAxes( pos );

        float the_x, the_y, the_x_flat, the_y_flat, system_item_scale_temp;
        TranslateCoordinates( pos,
                              pos_flat,
                              center_nav_x,
                              center_nav_y,
                              themaxvalue,
                              zscale,
                              zdistance,
                              the_x,
                              the_y,
                              the_x_flat,
                              the_y_flat,
                              system_item_scale_temp,
                              1 );
        //IGNORE OFF SCREEN
        //**********************************
        if ( !TestIfInRange( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], the_x, the_y ) ) {
            ++blah;
            continue;
        }
        //**********************************

        //Now starts the test that determines the type of things and inserts
        //|
        //|
        //\/

        float insert_size = 0.0;
        int   insert_type = navambiguous;
        if ( (*blah)->isUnit() == UNITPTR ) {
            //unit
            /*if(UnitUtil::isPlayerStarship(*blah) > -1)	//	is a PLAYER SHIP
             *  {
             *       if (UnitUtil::isPlayerStarship (*blah)==UniverseUtil::getCurrentPlayer()) //	is THE PLAYER
             *       {
             *               insert_type = navcurrentplayer;
             *               insert_size = navcurrentplayersize;
             *       }
             *       else	//	is A PLAYER
             *       {
             *               insert_type = navplayer;
             *               insert_size = navplayersize;
             *       }
             *  }
             *  else	//	is a non player ship
             *  {*/
            if ( UnitUtil::isSignificant( *blah ) ) {
                //capship or station
                if ( (*blah)->GetComputerData().max_speed() == 0 ) {
                    //is this item STATIONARY?
                    insert_type = navstation;
                    insert_size = navstationsize;
                } else {
                    //it moves = capship
                    if ( ThePlayer->InRange( (*blah), false, false ) ) {
                        //only insert if in range
                        insert_type = navcapship;
                        insert_size = navcapshipsize;
                    } else {
                        //skip unit completely if not in range
                        ++blah;
                        continue;
                    }
                }
            } else {
                //fighter
                /*if(ThePlayer->InRange((*blah),false,false))	//	only insert if in range
                 *  {
                 *       insert_type = navfighter;
                 *       insert_size = navfightersize;
                 *  }
                 *  else	// skip unit completely if not in range
                 *  {
                 * ++blah;
                 *       continue;
                 *  }*/
                if (UnitUtil::isPlayerStarship( *blah ) > -1) {
                    //is THE PLAYER
                    insert_type = navfighter;
                    insert_size = navfightersize;
                } else {
                    //skip unit completely if not in range
                    ++blah;
                    continue;
                }
            }
            //}
        } else if ( (*blah)->isUnit() == PLANETPTR ) {
            //is it a PLANET?
            if ( UnitUtil::isSun( *blah ) ) {
                //is this a SUN?
                insert_type = navsun;
                insert_size = navsunsize;
            } else if ( !( (*blah)->GetDestinations().empty() ) ) {
                //is a jump point (has destinations)
                insert_type = navjump;
                insert_size = navjumpsize;
            } else {
                //its a planet
                insert_type = navplanet;
                insert_size = navplanetsize;
            }
        } else if ( (*blah)->isUnit() == MISSILEPTR ) {
            //a missile
            insert_type = navmissile;
            insert_size = navmissilesize;
        } else if ( (*blah)->isUnit() == ASTEROIDPTR ) {
            //an asteroid
            insert_type = navasteroid;
            insert_size = navasteroidsize;
        } else if ( (*blah)->isUnit() == NEBULAPTR ) {
            //a nebula
            insert_type = navnebula;
            insert_size = navnebulasize;
        } else {
            //undefined non unit
            insert_type = navambiguous;
            insert_size = navambiguoussize;
        }
        if ( system_item_scale_temp > (system_item_scale*3) )
            system_item_scale_temp = (system_item_scale*3);
        insert_size *= system_item_scale_temp;
        if ( _Universe->AccessCockpit()->GetParent()->Target() == (*blah) ) {
            //Get a color from the config
            static GFXColor col = vs_config->getColor( "nav", "targetted_unit", GFXColor(1, 0.3, 0.3, 0.8) );
            DrawTargetCorners( the_x, the_y, insert_size, col );
            }
        bool tests_in_range = 0;
        if (insert_type == navstation)
            tests_in_range = TestIfInRangeBlk( the_x, the_y, insert_size, mouse_x_current, mouse_y_current );
        else
            tests_in_range = TestIfInRangeRad( the_x, the_y, insert_size, mouse_x_current, mouse_y_current );
        Unit *myunit = (*blah);

        ++blah;
        DisplayOrientationLines( the_x, the_y, the_x_flat, the_y_flat, 1 );
        if (tests_in_range) {
            mouselist.insert( insert_type, insert_size, the_x, the_y, myunit );
        } else {
            drawlistitem( insert_type,
                          insert_size,
                          the_x,
                          the_y,
                          myunit,
                          screenoccupation,
                          false,
                          (*blah) ? true : false,
                          unselectedalpha,
                          factioncolours );
        }
    }
    //**********************************	//	done enlisting items and attributes
    //Adjust mouse list for 'n' kliks
    //**********************************
    //STANDARD	: (1 3 2) ~ [0] [2] [1]
    //VS			: (1 2 3) ~ [0] [1] [2]	<-- use this
    if (mouselist.get_n_contents() > 0) {
        //mouse is over a target when this is > 0
        if (mouse_wentdown[2] == 1)             //mouse button went down for mouse button 2(standard)
            rotations += 1;
    }
    if ( rotations >= mouselist.get_n_contents() )      //dont rotate more than there is
        rotations = 0;
    int r = 0;
    while (r < rotations) {
        //rotate whatver rotations, leaving n rotated items, tail on top
        mouselist.rotate();
        r += 1;
    }
    //**********************************
    //Draw the damn shit
    //**********************************
//mainlist.draw();	//	draw the items
//mainlist.wipe();	//	whipe the list
    //**********************************
    //Check for selection query
    //give back the selected tail IF there is one
    //IF given back, undo the selection state
    //**********************************
    if ( 1 || checkbit( buttonstates, 1 ) ) {
        //button #2 is down, wanting a (selection)
        if (mouselist.get_n_contents() > 0) {
            //mouse is over a target when this is > 0
            if (mouse_wentdown[0] == 1) {
                //mouse button went down for mouse button 1
                currentselection = mouselist.gettailunit();
                unsetbit( buttonstates, 1 );
                //JUST FOR NOW, target == current selection. later it'll be used for other shit, that will then set target.
                if ( currentselection.GetUnit() ) {
                    ( UniverseUtil::getPlayerX( UniverseUtil::getCurrentPlayer() ) )->Target( currentselection.GetUnit() );
                    ( UniverseUtil::getPlayerX( UniverseUtil::getCurrentPlayer() ) )->LockTarget( currentselection.GetUnit() );
                }
            }
        }
    }
    //**********************************

    //Clear the lists
    //**********************************
    mouselist.draw();           //draw mouse over'd items
    mouselist.wipe();           //whipe mouse over'd list
    //**********************************
}