Exemple #1
0
// ------------------------------------------------------
// Load a reverb file
void Load_Midi_Cfg(char *FileName)
{
    FILE *in;
    in = fopen(FileName, "rb");

    if(in != NULL)
    {
        // Reading and checking extension...
        char extension[10];
        fread(extension, sizeof(char), 9, in);

        if(strcmp(extension, "PROTMID1") == 0)
        {
            // Ok, extension matched!
            Status_Box("Loading midi config data...");

            Read_Data(Midi_Name, sizeof(char), 20, in);
            Load_Midi_Cfg_Data(Read_Data, Read_Data_Swap, in);
            Actualize_Midi_Ed(0);

            Status_Box("Midi config data loaded ok.");
        }
        else
        {
            Status_Box("That file is not a "TITLE" midi config file...");
        }
        fclose(in);
    }
    else
    {
        Status_Box("Midi config data loading failed. (Possible cause: file not found)");
    }
}
Exemple #2
0
//**************读取Y坐标
unsigned char ADC_Y(void)
{
    unsigned char temp;
	Write_Command(0x73);//TPYH	  Y_coordinate high byte
    //Chk_Busy();
	temp=Read_Data();
	return temp;
}
Exemple #3
0
//**************读取XY坐标(高位坐标值)
unsigned char ADC_XY(void)
{	
    unsigned char temp;
 	Write_Command(0x74);//TPXYL	  bit[3:2] Y_coordinate low byte  bit[1:0] X_coordinate low byte 
	//Chk_Busy();
	temp=Read_Data();
	return temp;
}   
Exemple #4
0
void Layer1_Visible(void)
{
    unsigned char temp;
    Write_Command(0x52);//LTPR0
    temp = Read_Data();
    temp&=0xf8;
    Write_Data(temp);  
}
Exemple #5
0
void Chk_DMA_Busy(void)
{
	unsigned char temp; 	
	do
	{
	Write_Command(0xBF);
	temp =Read_Data();
	}while((temp&0x01)==0x01);   
}
Exemple #6
0
/*
名称: uint8_t HT1261B_ReadData(uint8_t MAddr)
功能: 向HT1261B发送数据
形参: MAddr 内存地址, 连续读2个地址上的数据, MAddr, MAddr+1
返回: 读取到的数据
*/
uint8_t HT1261B_ReadData(uint8_t MAddr)
{
  uint8_t data;
  CS_OUT;
  WR_OUT;
  RD_OUT;
  DATA_OUT;
  
  CS_0;
  WR_1;
  Write_ID(READ_CMD);
  Write_MemoryAddr(MAddr);
  data = Read_Data() << 4;
  data |= Read_Data();
  CS_1;
  
  return data;
}
Exemple #7
0
unsigned char Chk_INT(void)
{
    unsigned char temp; 	
    temp=Read_Data();
    if ((temp&0x20)==0x20)
        return 1;
    else 
        return 0;	   
}
Exemple #8
0
//****************触摸中断判断
unsigned char Touch_Status(void)
{	
    unsigned char temp;
    Write_Command(0xF1);//INTC	
    temp =Read_Data();
    if ((temp&0x04)==0x04)
        return 1;
    else 
        return 0;
}
Exemple #9
0
unsigned char Chk_INT2(void)
{
    unsigned char temp; 	
    Write_Command(0x74);//INTC
    temp =Read_Data();
    if ((temp&0x80)==0x80)
        return 1;
    else 
        return 0;	   
}
Exemple #10
0
struct group_block get_group_block(struct super_block sb,long index)
{
	struct group_block data;
	long blockSize=1024 << sb.block_Size;
	long startp=blockSize*(sb.No_0_Block+1);
	startp+=index*32;
	unsigned char *t_data;
	t_data=Read_Data(startp,32);
	memcpy(&data,t_data,sizeof(data));
	return data;
}
Exemple #11
0
void Layers_Progressive(void)
{
    unsigned char temp;
    Write_Command(0x52);//LTPR0
    temp = Read_Data();
    temp&=0xf8;
    temp|=0x02;
    Write_Data(temp);  
    Write_Command(0x53);//LTPR1
    for(temp=0;temp<9;temp++)
    {
        Write_Data(temp);  
        Delay10ms(100);
    }
}	
Exemple #12
0
/* judge the extX filesystem */
int is_ext_fs(char *File)
{
	strcpy(Read_File,File);
	struct super_block superblock;
	unsigned char *t_data;
	t_data=Read_Data(1024,1024);
	memcpy(&superblock,t_data,sizeof(superblock));
	if ( superblock.signature_Logo == 0xEF53 )
	{
		return true;
	}
	else
	{
		return false;
	}
}
Exemple #13
0
void main()
{
	Output_File=fopen("output.txt","w");
    Read_Data();
    Form_Y();
    for(index=1;Current_Accuracy>=Calculation_Accuracy;index++)
    {
		Calculate_Unblanced_Value();
        Form_Jacobi_Matric();
        Solve_Equations(Jacobi_Matric,Delta_PQ,Delta_fe);
        Calculate_Fixed_Value();
    }
    Powerflow_Results();
	fclose(Output_File);
	printf("潮流计算结束\n");
}
Exemple #14
0
// ------------------------------------------------------
// Load a pattern file
void Load_Pattern(char *FileName)
{
    FILE *in;
    int version = 0;

    if(!is_editing)
    {
        Status_Box("Edit mode isn't turned on.");
        return;
    }

    in = fopen(FileName, "rb");

    if(in != NULL)
    {
        // Reading and checking extension...
        char extension[10];
        fread(extension, sizeof(char), 9, in);

#ifndef __LITE__
        if(strcmp(extension, "TWNNBLK1") == 0) version = 1;
        if(strcmp(extension, "PROTBLK2") == 0) version = 2;
#else
        if(strcmp(extension, "PTKLBLK3") == 0) version = 2;
#endif
        if(version)
        {
            // Ok, extension matched!
            Status_Box("Loading Pattern data...");

            Read_Data(Selection_Name, sizeof(char), 20, in);
            Load_Pattern_Data(Read_Data, Read_Data_Swap, in, version);
            Actupated(0);

            Status_Box("Pattern data loaded ok.");
        }
        else
        {
            Status_Box("That file is not a "TITLE" Pattern file...");
        }
        fclose(in);
    }
    else
    {
        Status_Box("Pattern data loading failed. (Possible cause: file not found)");
    }
}
Exemple #15
0
/* print the extX file system infomation */
void print_extx_info()
{
		struct super_block superblock;
		struct group_block groupblock;
		unsigned char *t_data;
		t_data=Read_Data(1024,1024);
		memcpy(&superblock,t_data,sizeof(superblock));
		print_super_block(superblock);
		
		int i,groupCount=superblock.total_Blocks / superblock.block_Group_Blocks+1;
		for (i=0;i<groupCount;i++)
		{
			printf("BlockGroup=%01d\n",i);
			groupblock=get_group_block(superblock,i);
			print_group_block(groupblock);
		}
}
Exemple #16
0
/*
	函数名: void USART3_DW(void)
	描述:	 串口3接收完一帧数据处理
*/
void USART3_DW(void)
{
	
	if(Serial3.RxFlag & RECEIVE_OVER)
	{
		u8 i=0;
		if(Serial3.RxFlag & RECEIVE_SUCCESS)	
		{//接收成功
			switch(Serial3.RxBuffer[0])
			{
				case 'R':;
				case 'r':
				{
					i=(Serial3.RxBuffer[1]-0x30)*100 + (Serial3.RxBuffer[2]-0x30)*10 + 
							Serial3.RxBuffer[3]-0x30;
					Read_Data(i);
					break;
				}
				case 'W':;
				case 'w':
				{
					break;
				}
				case 'S':;
				case 's':
				{
					break;
				}
				default: ;
			}
		}
		else if(Serial3.RxFlag & RECEIVE_WRONG)
		{//接收错误
			printf("接收错误完毕!\r\n");
		}
		Serial3.RxFlag =0;		//清接收标志位
		Serial3.RxCount=0;		//清计数器
		for(i=0;i<RXBF_LEN;i++) Serial3.RxBuffer[i]=0;
		USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);		//打开中断
	}
}
int main()
{
#if DEBUG
    freopen("E:\\zoj_1721.txt", "r", stdin);
    freopen("E:\\zoj_1721_ans.txt", "w", stdout);
#endif
    
    while (~scanf("%d", &N), N!=-1)
    {
        memset(px, 0, sizeof(px));
        memset(py, 0, sizeof(py));
        memset(p, 0, sizeof(p));
        memset(edge, 0, sizeof(edge));

        Read_Data();
        Bellman_Ford( 0 );
        
        printf("%.2lf\n", dist[pSizes-1]);
    }// End of while
    
    return 0;
}
Exemple #18
0
void main()
{
    Read_Data();
    Form_Y();
    Calculate_Unblanced_Value();
}
Exemple #19
0
void Sound::Init(string source)
{
    string delimiter = ":";
    m_read_file.open(source);
    if(m_read_file.is_open())
    {
        m_sound_type = Read_Data(delimiter, "type");
        if(m_sound_type=="music")
        {
            m_source_music1 = Read_Data(delimiter, "file1");
            m_source_music2 = Read_Data(delimiter, "file2");
            m_source_music3 = Read_Data(delimiter, "file3");
            m_repeat_music = Read_Data(delimiter, "repeat");
            cout<<m_source_music1<<endl;
            cout<<m_source_music2<<endl;
            cout<<m_source_music3<<endl;
            Mix_Music * tmp_music = Mix_LoadMUS( m_source_music1.c_str() );
            if( tmp_music == NULL )
            {
                printf( "Failed to load  music! SDL_mixer Error: %s\n", Mix_GetError() );
            }
            else
                {
                    m_music.push_back(tmp_music);
                    tmp_music=NULL;
                    cout<<"first_song"<<endl;
                }

            tmp_music = Mix_LoadMUS( m_source_music2.c_str() );
            if( tmp_music == NULL )
            {
                printf( "Failed to load  music! SDL_mixer Error: %s\n", Mix_GetError() );
            }
            else
                {
                    m_music.push_back(tmp_music);
                    tmp_music=NULL;
                    cout<<"first_song"<<endl;
                }



            tmp_music = Mix_LoadMUS( m_source_music3.c_str() );
            if( tmp_music == NULL )
            {
                printf( "Failed to load  music! SDL_mixer Error: %s\n", Mix_GetError() );
            }
            else
                {
                    m_music.push_back(tmp_music);
                    tmp_music=NULL;
                    cout<<"first_song"<<endl;
                }
            Mix_FreeMusic(tmp_music);
            if(m_repeat_music=="repeat")
            {
                m_repeat_index=-1;
            }
            else
                if(m_repeat_music=="ones")
                {
                    m_repeat_index=0;
                }
            m_vector_size=int(m_music.size());
        }
        else
            if((m_sound_type=="sound effect")||(m_sound_type=="engine sound"))
            {
                cout<<"read sound effect"<<endl;
                m_sound_animation = Read_Data(delimiter, "sound for animation");
                m_source_chunk_first = Read_Data(delimiter, "file1");
                m_source_chunk_second = Read_Data(delimiter, "file2");
                m_source_chunk_third = Read_Data(delimiter, "file3");

                Mix_Chunk * tmp_sound_effect = Mix_LoadWAV(m_source_chunk_first.c_str());
                if( tmp_sound_effect == NULL )
                {
                    printf( "Failed to load sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
                }
                else
                {
                    m_sound_effect.push_back(tmp_sound_effect);
                    tmp_sound_effect=NULL;
                }

                tmp_sound_effect = Mix_LoadWAV(m_source_chunk_second.c_str());
                if( tmp_sound_effect == NULL )
                {
                    printf( "Failed to load sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
                }
                else
                    {
                    m_sound_effect.push_back(tmp_sound_effect);
                    tmp_sound_effect=NULL;
                    }

                tmp_sound_effect = Mix_LoadWAV(m_source_chunk_third.c_str());
                if( tmp_sound_effect == NULL )
                {
                    printf( "Failed to load sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
                }
                else{
                    m_sound_effect.push_back(tmp_sound_effect);
                    tmp_sound_effect=NULL;
                    }
                Mix_FreeChunk( tmp_sound_effect );
                cout<<"end reading sound effect"<<endl;
            }
            m_vector_size=int(m_sound_effect.size());
    }
    else
        {
            printf( "ERROR reading file \n");
        }

   // m_backup_music = Mix_LoadMUS( "media/The Legion - allegro + reprise.wav" );
    //m_backup_sound=Mix_LoadWAV("media/backup_sound");
    m_vector_size=3;
    m_read_file.close();
    srand (time(NULL));
    m_vector_index=rand() % m_vector_size;
    m_prev_sound=m_vector_index;

    cout<<"vector size"<<m_vector_size<<endl;
    cout<<m_vector_index<<endl;
    printf( "opened Music");
}
Exemple #20
0
// ------------------------------------------------------
// Load the configuration file
void LoadConfig(void)
{
    FILE *in;
    int i;
    int Real_Palette_Idx;
    char FileName[MAX_PATH];
    char KeyboardName[MAX_PATH];
    signed char phony = -1;
    char Win_Coords[64];
    SDL_Surface *Desktop = NULL;

#ifdef __linux__
    sprintf(FileName, "%s/.ptk.cfg", getenv("HOME"));
#else
    sprintf(FileName, "%s"SLASH"ptk.cfg", ExePath);
#endif

    memset(KeyboardName, 0, sizeof(KeyboardName));

    in = fopen(FileName, "rb");
    if(in != NULL)
    {
        // Reading and checking extension...
        char extension[10];

        Read_Data(extension, sizeof(char), 9, in);
        if(strcmp(extension, "PROTCFGF") == 0)
        {
            Read_Data_Swap(&Current_Edit_Steps, sizeof(Current_Edit_Steps), 1, in);
            Read_Data_Swap(&patt_highlight, sizeof(patt_highlight), 1, in);
            Read_Data_Swap(&AUDIO_Milliseconds, sizeof(AUDIO_Milliseconds), 1, in);

#if defined(__NO_MIDI__)
            Read_Data(&phony, sizeof(phony), 1, in);
#else
            Read_Data(&c_midiin, sizeof(c_midiin), 1, in);
#endif

#if defined(__NO_MIDI__)
            Read_Data(&phony, sizeof(phony), 1, in);
#else
            Read_Data(&c_midiout, sizeof(c_midiout), 1, in);
#endif

            Read_Data_Swap(&MouseWheel_Multiplier, sizeof(MouseWheel_Multiplier), 1, in);
            Read_Data(&Rows_Decimal, sizeof(Rows_Decimal), 1, in);
            Read_Data(&FullScreen, sizeof(FullScreen), 1, in);

            for(i = 0; i < NUMBER_COLORS; i++)
            {
                Real_Palette_Idx = Idx_Palette[i];
                Read_Data(&Ptk_Palette[Real_Palette_Idx].r, sizeof(char), 1, in);
                Read_Data(&Ptk_Palette[Real_Palette_Idx].g, sizeof(char), 1, in);
                Read_Data(&Ptk_Palette[Real_Palette_Idx].b, sizeof(char), 1, in);
                Ptk_Palette[Real_Palette_Idx].unused = 0;
            }
            Read_Data(&See_Prev_Next_Pattern, sizeof(See_Prev_Next_Pattern), 1, in);
            Read_Data_Swap(&Beveled, sizeof(Beveled), 1, in);
            Read_Data_Swap(&Continuous_Scroll, sizeof(Continuous_Scroll), 1, in);
            Read_Data(&AutoSave, sizeof(AutoSave), 1, in);
            Read_Data(&AutoBackup, sizeof(AutoBackup), 1, in);
            Read_Data(&Dir_Mods, sizeof(Dir_Mods), 1, in);
            Read_Data(&Dir_Instrs, sizeof(Dir_Instrs), 1, in);
            Read_Data(&Dir_Presets, sizeof(Dir_Presets), 1, in);
            Read_Data(&Dir_Reverbs, sizeof(Dir_Reverbs), 1, in);
            Read_Data(&Dir_MidiCfg, sizeof(Dir_MidiCfg), 1, in);
            Read_Data(&Dir_Patterns, sizeof(Dir_Patterns), 1, in);
            Read_Data(&Dir_Samples, sizeof(Dir_Samples), 1, in);
            Read_Data(KeyboardName, MAX_PATH, 1, in);

            Read_Data(&rawrender_32float, sizeof(char), 1, in);
            Read_Data(&rawrender_multi, sizeof(char), 1, in);
            Read_Data(&rawrender_target, sizeof(char), 1, in);
            Read_Data(&Large_Patterns, sizeof(char), 1, in);
            Read_Data(&Scopish_LeftRight, sizeof(char), 1, in);

            Read_Data(&Paste_Across, sizeof(char), 1, in);
            Read_Data(&Jazz_Edit, sizeof(char), 1, in);
            Read_Data(&Accidental, sizeof(char), 1, in);

            Read_Data(&Use_Shadows, sizeof(char), 1, in);
            Read_Data(&Global_Patterns_Font, sizeof(char), 1, in);

            Read_Data(&metronome_magnify, sizeof(int), 1, in);

            if(Large_Patterns)
            {
                Set_Pattern_Size();
                userscreen = USER_SCREEN_LARGE_PATTERN;
                curr_tab_highlight = USER_SCREEN_DISKIO_EDIT;
            }
            else
            {
                Set_Pattern_Size();
                userscreen = USER_SCREEN_DISKIO_EDIT;
                curr_tab_highlight = USER_SCREEN_DISKIO_EDIT;
            }

            // Reload the compelte midi automation config
            Load_MidiCfg_Data(Read_Data, Read_Data_Swap, in);

            Read_Data_Swap(&Cur_Width, sizeof(int), 1, in);
            Read_Data_Swap(&Cur_Height, sizeof(int), 1, in);

            Read_Data_Swap(&Cur_Left, sizeof(int), 1, in);
            Read_Data_Swap(&Cur_Top, sizeof(int), 1, in);
            Desktop = SDL_SetVideoMode(0, 0, 0, 0);
            // Check if the coords are too big
            if(Cur_Width > SDL_GetVideoSurface()->w)
            {
                Cur_Left = 0;
                Cur_Width = SDL_GetVideoSurface()->w;
            }
            if(Cur_Height > SDL_GetVideoSurface()->h)
            {
                Cur_Top = 0;
                Cur_Height = SDL_GetVideoSurface()->h;
            }
            if(Cur_Left == -1 ||
               Cur_Top == -1)
            {
                Cur_Left = SDL_GetVideoSurface()->w;
                Cur_Top = SDL_GetVideoSurface()->h;
                Cur_Left = (Cur_Left - Cur_Width) / 2;
                Cur_Top = (Cur_Top - Cur_Height) / 2;
            }
            SDL_FreeSurface(Desktop);

            sprintf(Win_Coords,
                    "SDL_VIDEO_WINDOW_POS=%d,%d",
                    Cur_Left,
                    Cur_Top);
            SDL_putenv(Win_Coords);
        }
        fclose(in);
    }
    sprintf(Keyboard_Name, "%s", KeyboardName);

    // Set default dirs if nothing
    if(!strlen(Dir_Mods))
    {
        GETCWD(Dir_Mods, MAX_PATH);

#if defined(__WIN32__)
        strcat(Dir_Mods, "\\modules");
#else
        strcat(Dir_Mods, "/modules");
#endif

    }
    if(!strlen(Dir_Instrs))
    {
        GETCWD(Dir_Instrs, MAX_PATH);

#if defined(__WIN32__)
        strcat(Dir_Instrs, "\\instruments");
#else
        strcat(Dir_Instrs, "/instruments");
#endif

    }
    if(!strlen(Dir_Presets))
    {
        GETCWD(Dir_Presets, MAX_PATH);

#if defined(__WIN32__)
        strcat(Dir_Presets, "\\presets");
#else
        strcat(Dir_Presets, "/presets");
#endif

    }

    if(!strlen(Dir_Reverbs))
    {
        GETCWD(Dir_Reverbs, MAX_PATH);

#if defined(__WIN32__)
        strcat(Dir_Reverbs, "\\reverbs");
#else
        strcat(Dir_Reverbs, "/reverbs");
#endif

    }

    if(!strlen(Dir_MidiCfg))
    {
        GETCWD(Dir_MidiCfg, MAX_PATH);

#if defined(__WIN32__)
        strcat(Dir_MidiCfg, "\\midicfgs");
#else
        strcat(Dir_MidiCfg, "/midicfgs");
#endif

    }

    if(!strlen(Dir_Patterns))
    {
        GETCWD(Dir_Patterns, MAX_PATH);

#if defined(__WIN32__)
        strcat(Dir_Patterns, "\\patterns");
#else
        strcat(Dir_Patterns, "/patterns");
#endif

    }

    if(!strlen(Dir_Samples))
    {
        GETCWD(Dir_Samples, MAX_PATH);

#if defined(__WIN32__)
        strcat(Dir_Samples, "\\samples");
#else
        strcat(Dir_Samples, "/samples");
#endif

    }

    cur_dir = Dir_Mods;
}
Exemple #21
0
int main(int argc,char *argv[]){
  
  if(argc != 3){
    std::cout << "Usage: " << argv[0] << " [input file] [output file]" << std::endl;
    exit(1);
  }
  
  std::cout << "This is the LiSA open shop branch and bound module." << std::endl;
  std::cout << "PID= " << getpid() << std::endl;
  
  G_ExceptionList.set_output_to_cout();
    
  struct BranchList  *DeleteBranch;
    
  Initialize();
    
  Read_Data(argv[1]);
  
  run_start();
  if ( Compute_Head_Tail() ){
    Heuristic_Schedule();
    if ((SonNode->lower_bound = Additional_Arcs()) < UpperBound){
      Compute_Blocks();
      Compute_BranchList();   
      ActualNode = SonNode;
      Push();
      if ( (SonNode = new struct NodeType) == NIL ) {
        G_ExceptionList.lthrow("main,SonNode: kein Speicherplatz",
                               Lisa_ExceptionList::NO_MORE_MEMORY);
        exit(1);
      } 
      SonNode->blocks = NIL; 
      SonNode->order = NIL;
    }
  }
  
  while (FirstOfStack != NIL && !abort_algorithm){
    
    Pop();
    Update_Arcs();
    while (ActualNode->order != NIL && ActualNode->lower_bound < UpperBound){
      
      Fix_Arcs(ActualNode->order->branch_op,
      ActualNode->order->before_or_after,
      ActualNode->order->kind_of_block);
      DeleteBranch = ActualNode->order;
      ActualNode->order = ActualNode->order->next;
      delete DeleteBranch;
      if ( Compute_Head_Tail() && 
        Compute_LowerBound() < UpperBound && 
        (SonNode->lower_bound = Additional_Arcs()) < UpperBound){
          
          Heuristic_Schedule();
          
          if ( SonNode->lower_bound < UpperBound ){
            Compute_Blocks();
            Compute_BranchList();
            SearchTreeNodes++;
            Push();                 
            ActualNode = SonNode;  
            if ( (SonNode = new struct NodeType)== NIL ){
              G_ExceptionList.lthrow("main,SonNode: kein Speicherplatz",
                                     Lisa_ExceptionList::NO_MORE_MEMORY);
              exit(1);
            }
            SonNode->blocks = NIL; 
            SonNode->order = NIL;
          }else{ 
            Update_Arcs();     
          }
        }else{ 
          Update_Arcs();                 
        }
    }
  }
  run_stop();
  
  Write_Solution(argv[2]);
    
  return(0); 
}
Exemple #22
0
/**
 * 6 Buttons are available to press
 *  - Ignite    -> Starts the timer and ignition of the detonators
 *  - Slave_Up  -> Increases the currently selected slave, 3 available
 *  - Port_Up   -> Increases the currently selected port, 10 available
 *  - Time_Up   -> Increases the time for the selected port on the
 *                  selected slave
 *  - Time_Down -> Decreases the time for the selected port on the
 *                  selected slave
 *  - Time_Upup -> Increases the time for the selected port on the
 *                  selected slave by 10
 * 
 * Functions accessed by combinations
 *  - Connection-test
 *      Port_Up + Slave_Up
 *      -> Tests if a connection to the detonators is available and
 *          displays the result on the LED matrix
 *  - Clear Storage
 *      TimeUp + TimeDown
 *      -> Clears the whole EEPROM register by wirting 0 to all
 *          accessed addresses
 */
void Check_Buttons(void) {
    if(Ignite == 1) {
        Delay_Routine(3);
        if(Ignite == 1) {
            NOP();
            ignite_ready = 1;
            Start_Timer();
            NOP();
            return;             //End of Subroutine! No further actions
                                // need to be possible and ignition is
                                // prioritized
        }
    } else if(Time_Up == 1) {
        Delay_Routine(3);
        if(Time_Up == 1) {
            NOP();
            if(Time_Down == 1) {
                Delay_Routine(3);
                if(Time_Down == 1) {
                    Del_Data();
                    return;             // End of function due to other
                                        // desired operation
                }
            }
            pin[pin_selected].time++;
            if(pin[pin_selected].time > 999) {
                pin[pin_selected].time = 0;
            }
            NOP();
            Set_Display('7', '-', pin[pin_selected].time);
            NOP();
        }
    } else if(Time_Down == 1) {
        Delay_Routine(3);
        if(Time_Down == 1) {
            NOP();
            if(Time_Up == 1) {
                Delay_Routine(3);
                if(Time_Up == 1) {
                    Del_Data();
                    return;             // End of function due to other
                                        // desired operation
                }
            }
            pin[pin_selected].time--;
            if(pin[pin_selected].time < 0) {
                pin[pin_selected].time = 999;
            }
            NOP();
            Set_Display('7', '-', pin[pin_selected].time);
            NOP();
        }
    } else if(Time_Upup == 1) {
        Delay_Routine(3);
        if(Time_Upup == 1) {
            NOP();
            pin[pin_selected].time += 10;
            if(pin[pin_selected].time > 999) {
                pin[pin_selected].time = 0;
            }
            NOP();
            Set_Display('7', '-', pin[pin_selected].time);
            NOP();
        }
    } else if(Port_Up == 1) {
        Delay_Routine(3);
        if(Port_Up == 1) {
            NOP();
            if(Slave_Up == 1) {
                Delay_Routine(3);
                if(Slave_Up == 1) {
                    testflag = 1;
                    Set_Display('7', 'T',0);
                    Delay_Routine(30);
                    Check_Detonators();
                    return;             // End of function due to other
                                        // desired operation
                }
            }
            Save_Data(pin[pin_selected].time, pin[pin_selected].address);
            pin_selected++;
            switch (slave_selected) {
                case 0:
                    if(pin_selected > 9) {
                        pin_selected = 0;
                    }
                    break;
                case 1:
                    if(pin_selected > 19) {
                        pin_selected = 10;
                    }
                    break;
                case 2:
                    if(pin_selected > 29) {
                        pin_selected = 20;
                    }
                    break;
            }
            pin[pin_selected].time = Read_Data(pin[pin_selected].address);
            NOP();
            Set_Display('7', 'A', pin[pin_selected].output);
            Delay_Routine(30);
            Set_Display('7', '-', pin[pin_selected].time);
            Delay_Routine(30);
            NOP();
        }
    } else if(Slave_Up == 1) {
        Delay_Routine(3);
        if(Slave_Up == 1) {
            NOP();
            if(Port_Up == 1) {
                Delay_Routine(3);
                if(Port_Up == 1) {
                    testflag = 1;
                    Set_Display('7', 'T',0);
                    Delay_Routine(30);
                    Check_Detonators();
                    return;             // End of function due to other
                                        // desired operation
                }
            }
            Save_Data(pin[pin_selected].time, pin[pin_selected].address);
            slave_selected++;
            if(slave_selected > 2) {
                slave_selected = 0;
            }
            pin_selected = slave_selected * 10;
            pin[pin_selected].time = Read_Data(pin[pin_selected].address);
            NOP();
            Set_Display('7', 'E', pin[pin_selected].slave);
            //Displays 'E' = Empfänger and selected receiver
            Delay_Routine(30);
            Set_Display('7', 'A', pin[pin_selected].output);
            Delay_Routine(30);
            Set_Display('7', '-', pin[pin_selected].time);
            Delay_Routine(30);
            NOP();
        }
    } else {
        NOP();
    }
}
void Animation::Init(SDL_Renderer* render, string source)
{
    string delimiter = ":";
    m_read_file.open(source);
    if(m_read_file.is_open())
    {
        m_source = Read_Data(delimiter, "file");
        m_frames_x = To_int(Read_Data(delimiter, "frames x"));
        m_frames_y = To_int(Read_Data(delimiter, "frames y"));
        m_frame_duration = To_int(Read_Data(delimiter, "frame duration"));
        m_animation_type = Read_Data(delimiter, "animation type");
        m_flip_type=Read_Data(delimiter, "flip");
        m_img_width=To_int(Read_Data(delimiter, "width"));
        m_img_height=To_int(Read_Data(delimiter, "height"));

        if((m_animation_type=="hpship")||(m_animation_type=="hpbarbody"))
        {
            m_position=To_int(Read_Data(delimiter, "position"));
        }
        else
        {
            m_position=0;
        }
        if(m_animation_type=="repeat middle")
        {
            m_repeat_from_index=To_int(Read_Data(delimiter, "repeat from"));
        }
        else
        {
            m_repeat_from_index=int(m_frames_x/2);
        }
        m_read_file.close();
    }
    else
    {
        m_source="media/Magenta.png";
        m_frames_x=1;
        m_frames_y=1;
        m_frame_duration=0;
        m_animation_type="";
        m_flip_type="none";
    }

    if("horizontal"==m_flip_type)
        {
            m_flip=SDL_FLIP_HORIZONTAL;
        }
        else
            if("vertical"==m_flip_type)
            {
                m_flip=SDL_FLIP_VERTICAL;
            }
            else
                m_flip=SDL_FLIP_NONE;

    if(m_animation_type=="rand")
        {
            srand (time(NULL));
        }

    m_file = IMG_Load(m_source.c_str());

    if(m_sprite != NULL)
    {
        SDL_DestroyTexture(m_sprite);
    }
        if(m_file == NULL)
        {
            printf("ERROR opening image : %s , SDL_Eror: %s\n",(char*)m_source.c_str(),SDL_GetError());
        }
        else
        {
            m_sprite = SDL_CreateTextureFromSurface(render,m_file);
            if(m_sprite == NULL)
            {
                printf("ERROR Creating Texture from : %s , SDL_Eror: %s\n",(char*)m_source.c_str(),SDL_GetError());
            }
            else
            {
                m_width = m_file->w;
                m_height = m_file->h;
            }
            SDL_FreeSurface(m_file);
        }

        SDL_Rect Frames;
        Frames.x=0;
        Frames.y=0;
        Frames.w=int(m_width/m_frames_x);
        Frames.h=int(m_height/m_frames_y);

        m_percentage_height=Frames.h;

        m_prev_percentage=100;
        m_vector_index=0;
        m_more=true;
        m_startTime=SDL_GetTicks();

        for(Frames.y =0; Frames.y<m_height; Frames.y=Frames.y+m_height/m_frames_y)
        {
            for(Frames.x=0; Frames.x<m_width; Frames.x=Frames.x+m_width/m_frames_x)
            {
                m_vector_frames.push_back(Frames);
            }
        }
}
int main() {
   int Sample,Samples;
   char answer;
   char ResultsName[40];
	char DataName[40];
   char BacktrackName[40];
   int i,k;
   Vector Labels,LabelsB;
   Vector Sol;
	int Num_Comp,Num_Blocks;
   int Num_Sol;
   int value;
   double AvgValue;
	clock_t u1, u2;
	double u;
	Adj_item *a;

   do{
      for (i=1;i<25;i++) printf("\n");
		// clrscr();
      //textmode(_ORIGMODE);
   	printf("DEMO? \n");
   	printf("(1) : YES \n");
		printf("(0) : NO \n");
      printf("\n-> TYPE YOUR CHOICE: ");
      scanf("%d",&Demo);
      printf("\n");
      while ((Demo!=1)&&(Demo!=0)) {
      	for (i=1;i<25;i++) printf("\n");
      	//clrscr();
      	printf("!!! WRONG ANSWER !!! Demo: %d\n",Demo);
			printf("YOU MUST TYPE 1 OR 0!!! PLEASE, TRY AGAIN.");
      	printf("\n\n\n\n\nPress a key to continue ...");
			getch();
			for (i=1;i<25;i++) printf("\n");
			// clrscr();
      	printf(" Demo? \n");
   		printf(" (1) : YES \n");
			printf(" (0) : NO \n");
         printf("\n-> TYPE YOUR CHOICE: ");
   		scanf("%d",&Demo);
         printf("\n");
   	}
      printf("Data File Name: ");
		scanf("%s",DataName);
      Data_File=fopen(DataName,"rt");
		while (Data_File==NULL) {
      	for (i=1;i<25;i++) printf("\n");
			//clrscr();
      	printf("!!! DANGER !!! CANNOT OPEN FILE: %s\n",DataName);
			printf("THE FILE DOESN'T EXIST! PLEASE, TRY AGAIN.");
      	printf("\n\n\n\n\nPress a key to continue ...");
			getch();
			for (i=1;i<25;i++) printf("\n");
			// clrscr();
      	printf("Data File Name: ");
			scanf("%s",DataName);
      	Data_File=fopen(DataName,"rt");
   	}
      printf("Number of Samples: ");
   	scanf("%d",&Samples);
      n=ReadNumber(Data_File);
   	if (n>Size){
   		      for (i=1;i<25;i++) printf("\n");
			//clrscr();
      	printf("!!! DANGER !!! CANNOT OPEN FILE: %s\n",DataName);
			printf("THE TOTAL NUMBER OF VERTICES IS %d AND IT EXCEEDS THE MAXIMUM LIMIT OF %d!\n",n,Size);
      	printf("\n\n\n\n\nPress a key to continue ...");
			getch();
      	fclose(Data_File);
			      for (i=1;i<25;i++) printf("\n");
			//clrscr();
      	return 0;
   	}
		c=ReadNumber(Data_File);
   	if (c>Size){
   		      for (i=1;i<25;i++) printf("\n");
			// clrscr();
      	printf("!!! DANGER !!! CANNOT OPEN FILE: %s\n",DataName);
			printf("THE TOTAL NUMBER OF COLOURS IS %d AND IT EXCEEDS THE MAXIMUM LIMIT OF %d!\n",c,Size);
      	printf("\n\n\n\n\nPress a key to continue ...");
			getch();
      	fclose(Data_File);
			      for (i=1;i<25;i++) printf("\n");
			//clrscr();
      	return 0;
   	}
      printf("\nNumber of nodes (n)= %d;\nNumber of colours (c)= %d;\n",n,c);
      getch();
      printf("\n==================================== RESULTS ==================================\n\n");
   	printf("\n");
      if (Demo==1){
         sprintf(ResultsName,"%c%c_DEMObacktracking_%d_%d.txt",DataName[0],DataName[1],n,c);
      }
      else{
      	sprintf(ResultsName,"%c%c_BACKTRACKING_%d_%d.txt",DataName[0],DataName[1],n,c);

      }
   	Results_File=fopen(ResultsName,"wt");
   	if (Results_File==NULL) {
   		printf("CANNOT OPEN FILE: %s\n",ResultsName);
      	printf("\n\n\n\nPress a key to continue ...");
			getch();
			      for (i=1;i<25;i++) printf("\n");
			//clrscr();
			return 0;
		}
   	fprintf(Results_File,"%d %d\n\n",n,c);
      sprintf(BacktrackName,"back%d%c%c%d.txt",n,DataName[0],DataName[1],c);
      Backtrack_File=fopen(BacktrackName,"wt");
      value=0;
		u=0.000;
      for (Sample=0; Sample<Samples; Sample++){
         printf("\t\t\t\t\n  ----------------   SAMPLE %d :\n",Sample+1);
         system("PAUSE");
      	u1=clock();
         Read_Data();
         List_Colors();
         call=0;
         Num_Comp=n;
         Num_Blocks = n;
         Num_Sol=0;
         Best_call=0;
         Best_Num_Sol=0;	//Best_Num_Sol=c+1;  //if you want not use the initial MVCA you have to put this instruction and delete Best_Num_Sol=0; and initial_MVCA();
         initial_MVCA(Demo);

         for (k=0; k<c; k++){ // lui 1 to c
         	if (Demo==1)	printf("\n - - - - - - - - - - - - WE START WITH A NEW COLOR: %d \n",k);
            if ((Num_Sol==Best_Num_Sol-2)&&(Freq[k]<(Num_Comp-1)))	break;
            for (i=0; i<n; i++)	Labels[i]=i;
            for (i=0; i<n; i++)	LabelsB[i]=i;
            // Delete Adj 
            if (Demo==1) printf("\n Deleting Adj for all colors");
   			for (int i=0; i<n; i++)
      			while(Adj[i]!=NULL){
         			a = Adj[i];
						Adj[i] = Adj[i]->next;
         			delete[] a;
					}
	
            Try(k,Labels,Num_Comp,LabelsB,Num_Blocks,Sol,Num_Sol);
         }
         u2=clock();
         value=value+Best_Num_Sol;
			//u = u+ (double(u2 - u1)/1000); seconds
         u = u+ (double(u2 - u1));  // milliseconds
         if (Demo==1)	printf(" \nEND\n ") ;
         if(Best_call==0){
         	printf(" \n NOT FOUND A SOLUTION BETTER THAN THE MVCA ONE S[%d]: ",Best_Num_Sol);
   			for (i=0; i<Best_Num_Sol; i++)	// := 1 to Best_Num_Sol
   				printf("%d ",MVCA_Sol[i]);
         	printf(" \n with %d total calls.\n",call);
         	fprintf(Results_File," Sample %d:",Sample) ;
   			fprintf(Results_File," -MVCA-Sol[%d] :",Best_Num_Sol);
   			for (k=0; k<Best_Num_Sol; k++){	// k := 1 to Best_Num_Sol
   				fprintf(Results_File,"%d ",MVCA_Sol[k]);
         	}
   			fprintf(Results_File," with %d total calls.\n",call);
         }
         else{
         	printf(" \n FOUND SOLUTION S[%d]: ",Best_Num_Sol);
   			for (i=0; i<Best_Num_Sol; i++)	// := 1 to Best_Num_Sol
   				printf("%d ",Best_Sol[i]);
         	printf(" \n Calls:%d",Best_call);
   			printf(" with %d total calls.\n",call);
         	fprintf(Results_File," Sample %d:",Sample) ;
   			fprintf(Results_File," FOUND Sol[%d] :",Best_Num_Sol);
   			for (k=0; k<Best_Num_Sol; k++){	// k := 1 to Best_Num_Sol
   				fprintf(Results_File,"%d ",Best_Sol[k]);
         	}
   			fprintf(Results_File," Calls:%d",Best_call);
         	fprintf(Results_File," with %d total calls.\n",call);
         }
         fprintf(Backtrack_File,"%d\n",Best_Num_Sol);
      } //(* End Sample *)

      AvgValue=(value+0.0)/Samples;
   	printf("\n************************ SPERIMENTALS EXECUTING VALUES: ************************\n\n");
   	printf("\t\t\t   Average Value: %f\n",AvgValue);
		printf("\t\t\t   Average Time (msec): %f\n",(double(u/Samples)));
   	printf("\n\t\tResults saved in the file: \\%s\n",ResultsName);
   	fprintf(Results_File,"\n************************ SPERIMENTALS EXECUTING VALUES: ************************\n\n");
   	fprintf(Results_File,"\t\t\t   Average Value: %f\n",AvgValue);
		fprintf(Results_File,"\t\t\t   Average Time (msec): %f\n",(double(u/Samples)));
   	fclose(Data_File) ;
		fclose(Results_File);
      fclose(Backtrack_File);
      printf("\n\n\n\n\n\n\t\t\t   ANOTHER SIMULATION? (y/n): ");
      answer=getch();
      //textmode(C80);
			for (i=1;i<25;i++) printf("\n");
		//clrscr();
   }while (answer=='y'||answer=='Y');
}