Example #1
0
/*
 * Prings the welcome information when the game starts. This will have a basic
 * texted based menu system.
 */
void welcome()
{
	int i; //counter
	char c; //holds current character
	begin_welcome:
	//clear the screen
	clear_scr();
	dino_print("Windows 1.0 may have had Reversi, but dinoDOS has...\n\n\0");
	//center the next line (pad with spaces)
	for(i=0; i<34; i++) {
		dino_print(" \0");
	}
	dino_print("+-----------+\n\0");
	for(i=0; i<34; i++) {
		dino_print(" \0");
	}
	dino_print("|TIC-TAC-TOE|\n\0");
	for(i=0; i<34; i++) {
		dino_print(" \0");
	}
	dino_print("+-----------+\n\0");

	//print the menu
	dino_print("\nMain Menu:\n\0");
	dino_print("(h) - Help and Instructions\n\0");
	dino_print("(s) - Start the Game\n\0");
	dino_print("(q) - Quit\n\0");
	//wait for a correct key
	c = getchar();
	while(c != 'q' && c != 's' && c != 'h') {
		c = getchar();
	}

	//check which key was entered
	if (c == 'q') {
		//clear the screen
		clear_scr();
		//quit
		terminate();
	} else if (c == 'h') {
		//clear the screen
		clear_scr();
		//print the help screen
		printHelp();
		dino_print("\nPress any key to continue...\0");
		//wait for a key to be pressed
		getchar();
		//reprint the welcome screen
		goto begin_welcome;
	}
	//otherwise c == s so just continue onto the game!
}
Example #2
0
void draw_picture()
{
  clear_scr();
 int colors[50] = {0,0,0,0,2,2,2,2,0,0,0,1,1,1,0,0,0,0,0};
 
 
 int count =0; 
 while (count < 30)
 {
     int color = random(3);
     int i = 0;
     for (i;i < random(5);i++)
     {
       colors[i+ count] = color;
     }
     count = count + i;
 }

 for (int x = 0; x < num_panels* 16; x ++)
   {
  for (int y = 0; y < 8;y++)
  {

    picture[x][y] = colors[(x  + y+ 0) % 14] ;
 
   }
 } 
}
Example #3
0
//LCD1602初始化
void lcdInitial()
{
   writeCom(0x38);//显示模式设置
   delayms(5); 
   writeCom(0x08);//显示关闭
   clear_scr();//清屏
   writeCom(0x06); //显示光标移动设置
   delayms(5);
   writeCom(0x0C); //显示开及光标设置 
}
Example #4
0
int trm_clear(void)
{
	int err;

	err = goto_xy(0,0);
	err = err;
	clear_scr();

	return(OK);
}
Example #5
0
int main()
{
	enableInterrupts();

	while(1) {
		clear_scr();
		dino_print("Welcome to dinoDOS. Please login.\n\0");
		while(!validate()) {
			dino_print("Error: invalid credentials.\n\0");
		}
		//we do not want to logout yet
		logout = FALSE;
		clear_scr();
		//begin the shell promt
		while(!logout) {
			//holds the current input
			char curInput[MAX_INPUT];
			//used to print or not print a new line after a command
			bool addNewLine;
			//print the prompt
			dino_print(prompt);
			//wait for input
			read_input(curInput, MAX_INPUT);

			//only run on non-empty inputs
			if (strlen(curInput) > 0) {
				//return tells if a line break should be printed
				addNewLine = interpret_cmd(curInput);
			} else {
				//we want to add a new line if it was empty
				addNewLine = TRUE;
			}
			//print the new line if we want it		
			if (addNewLine) {
				dino_print("\n\0");
			}
			//let the another process continue
			yield();
			//on to the next command!
		}
	}
}
Example #6
0
void draw_picture(int move)
{
  clear_scr();
 int colors[] = {0,0,0,0,2,2,2,2,0,0,0,1,1,1,0,0,0,0,0};
 for (int x = 0; x < num_panels* 16; x ++)
   {
  for (int y = 0; y < 8;y++)
  {

    picture[x][y] = colors[(x  + y+ move) % 14] ;
 
   }
 } 
}
void vol_meter()
{

   int length = 8 * (float)num_panels * ((float)current_volume / (float)600);
clear_scr();
  for (int x = 0; x < length; x ++)
  {
    for (int y = 0; y < 8;y++)
    {
      picture[num_panels*8-x][y] = green;
      picture[num_panels*8+x][y] = green;

    }
  }
}
Example #8
0
void vol_meter()
{
  int vol = volume();
  int length = 16 * (float)num_panels * ((float)vol / (float)600);
  clear_scr();
  for (int x = 0; x < length; x ++)
   {
  for (int y = 0; y < 8;y++)
  {

    picture[x][y] = red;
 
   }
 } 
}
Example #9
0
static void		write_char(int key, t_line *line)
{
  if (key >= 256)
    {
      write_char(key % 256, line);
      write_char(key / 256, line);
    }
  else if (key != '\n')
    {
      if (line->line_len >= (BUFF_LINE * line->realloc_cpt))
	line_realloc(line);
      add_char_in_tab(key, line->line, line->pos);
      CAP("nd");
      line->pos++;
      line->line_len++;
      (line->line_len % get_cols()) == 0 ? clear_scr(line) :
	clear_and_display(line);
    }
}
Example #10
0
void mikro_disko()
{
  clear_scr();
 
  if (current_beat)
  {
    move_mikro++;
    if (random(100) > analogRead(3)/10)
    {
       stargase(); 
    }
  }
  for(int i=0;i < 48 * 8 ; i ++)
  {
    if (mikrodisko_text[i] == 1)
    {
     picture[ i % 48+ move_mikro % 2][7 - i / 48] = mikrodisko_text[i];
    }
}
  
 
}
Example #11
0
void mikro_disko()
{
  clear_scr();
 
  if (beat())
  {
    move_mikro++;
    if (random(100) > 40)
    {
       stargase(); 
    }
  }
  for(int i=0;i < 48 * 8 ; i ++)
  {
    if (mikrodisko_text[i] == 1)
    {
     picture[3* 16 - i % 48+ move_mikro % 2][i / 48] = mikrodisko_text[i];
    }
}
  
 
}
Example #12
0
File: io.c Project: weezybusy/doit
void show_opts(void)
{
        clear_scr();
        do {
                printf("available options:\n"
                                "------------------\n"
                                " a: add task\n"
                                " c: change task\n"
                                " d: delete task\n"
                                " D: delete all tasks\n"
                                " e: erase history\n"
                                " h: help\n"
                                " l: list history\n"
                                " q: quit the program\n"
                                " s: search history by date\n"
                                " u: undo task\n"
                                " U: undo all tasks\n"
                                " x: do task\n"
                                " X: do all tasks\n"
                                "------------------\n"
                                "press <Enter> to go back...");
        } while (getchar() != '\n');
}
Example #13
0
int main() {
	char chout='\n';
	int action=1;
	time_t last_time_action, current_time, last_time;
	
	if ( init_mpc () == 0) {
		printf("Error init mpc\n");
		exit (-1);
	}

	output_t * output_st = init_output_st ();

	while (init_display(output_st)) {
		printf("Error display\n");
		sleep (1);
	}

	set_cirilic ();
	clear_scr();
	
	int encoder_fd = 0;
	if (cfileexists(ENCODER_COM_PORT)) {
		encoder_fd = init_comport(ENCODER_COM_PORT, ENCODER_COM_SPEED);
	} else {
		encoder_fd = init_comport(DEFAULT_ENCODER_COM_PORT, ENCODER_COM_SPEED);
	}

	init_term();
	last_time = time(NULL); 

	int count_click = 0;
	struct timeval t_start, t_end;
	int show_time = 0;
	while (1) {
		get_all (output_st);
		int ret_read = read_com(encoder_fd, 1 , 100, &chout);
		if ((chout=='R') || (chout=='L') ||(chout=='a') || (chout=='d')) {
				action=0;
				last_time_action = time(NULL);
				set_play_list_position(tuning_movement(chout)); 
				get_cur_position (); 
				show_current_cursor_pos ();
		}
		if ((chout=='P') ||(chout=='s') ) {
			gettimeofday(&t_end, NULL);
			if(!count_click) {
				t_start = t_end;
				count_click++;
			} else {
				if (usec_used (&t_start, &t_end) <= 500000) {
					double_click_button();
					if (show_time) {
						show_time--;
					} else {
						show_time++;
					}
				} 
				count_click = 0;
			}
		}

		if (count_click) {
			gettimeofday(&t_end, NULL);
			if (usec_used (&t_start, &t_end) > 500000) 	{
				print_button_pressed();
				music_pause();
				count_click = 0;
			}
		}

		chout = '\0';
		current_time = time(NULL); 
		if (action==0) {
			if ((current_time-last_time_action)>3) {
				action++;
			}
		}
		if ((action) && ((current_time-last_time)>0)) {
			if (!show_time) {
				show_current_track(output_st);
			} else {
				show_current_time_and_date();
			}
			last_time = current_time; 
		}
	}
}
Example #14
0
int main(int argc, char *argv[]) {
	struct ap_list apl;
	struct ap_info api;
	struct iw_dev dev;
	struct pollfd pfd[2];
	struct deauth_thread_args ta;
	struct timeval tv1, tv2;
	suseconds_t msec;
	pthread_t deauth_thread;
	pthread_mutex_t chan_mutex, list_mutex, cnc_mutex;
	pthread_cond_t chan_cond;
	channelset_t chans;
	int ret, sigfd, c, n, chan;
	char *ifname, *chans_str;
	sigset_t exit_sig;
	time_t tm;

	if (argc < 2) {
		print_usage(stderr);
		return EXIT_FAILURE;
	}

	/* arguments */
	ifname = argv[argc-1];
	chans_str = NULL;

	while((c = getopt(argc, argv, "c:lh")) != -1) {
		switch (c) {
		case 'c':
			chans_str = optarg;
			break;
		case 'l':
			return print_interfaces();
		case 'h':
			print_usage(stdout);
			return EXIT_SUCCESS;
		case '?':
		default:
			return EXIT_FAILURE;
		}
	}

	if (argv[optind] != ifname) {
		print_usage(stderr);
		return EXIT_FAILURE;
	}

	if (getuid()) {
		fprintf(stderr, "Not root?\n");
		return EXIT_FAILURE;
	}

	/* init channel set */
	if (chans_str == NULL) {
		channel_zero(&chans);
		for (n=1; n<=14; n++)
			channel_set(&chans, n);
	} else {
		if (parse_chans_str(chans_str, &chans) == -1) {
			fprintf(stderr, "Can not parse the channels\n");
			return EXIT_FAILURE;
		}
	}

	/* init access point list */
	init_ap_list(&apl);

	/* init signals */
	sigemptyset(&exit_sig);
	sigaddset(&exit_sig, SIGINT);
	sigaddset(&exit_sig, SIGTERM);

	if (sigprocmask(SIG_BLOCK, &exit_sig, NULL) < 0) {
		err_msg("sigprocmask");
		return EXIT_FAILURE;
	}

	sigfd = signalfd(-1, &exit_sig, 0);
	if (sigfd < 0) {
		err_msg("signalfd");
		return EXIT_FAILURE;
	}

	pfd[0].fd = sigfd;
	pfd[0].revents = 0;
	pfd[0].events = POLLIN;

	/* init device */
	iw_init_dev(&dev);
	strncpy(dev.ifname, ifname, sizeof(dev.ifname)-1);

	if (iw_open(&dev) < 0) {
		print_error();
		goto _errout_no_thread;
	}

	pfd[1].fd = dev.fd_in;
	pfd[1].revents = 0;
	pfd[1].events = POLLIN;

	/* set channel */
	n = 0;
	chan = 0;
	do {
		chan = (chan % CHANNEL_MAX) + 1;
		if (channel_isset(&chans, chan))
			ret = iw_set_channel(&dev, chan);
		else
			ret = -1;
		/* if fails try next channel */
	} while(++n < CHANNEL_MAX && ret < 0);
	if (ret < 0) {
		print_error();
		goto _errout_no_thread;
	}

	/* start deauth thread */
	ta.stop = 0;
	ta.apl = &apl;
	ta.dev = &dev;
	pthread_mutex_init(&chan_mutex, NULL);
	ta.chan_mutex = &chan_mutex;
	pthread_cond_init(&chan_cond, NULL);
	ta.chan_cond = &chan_cond;
	pthread_mutex_init(&list_mutex, NULL);
	ta.list_mutex = &list_mutex;
	ta.chan_changed = 1;
	pthread_mutex_init(&cnc_mutex, NULL);
	ta.cnc_mutex = &cnc_mutex;
	ta.chan_need_change = 0;

	if (pthread_create(&deauth_thread, NULL, deauth_thread_func, &ta) < 0) {
		err_msg("pthread_create");
		goto _errout_no_thread;
	}

	clear_scr();
	update_scr(&apl, &dev);
	tm = time(NULL);
	gettimeofday(&tv1, NULL);

	while (!ta.stop) {
		if (poll(pfd, 2, 0) < 0) {
			err_msg("poll");
			goto _errout;
		}

		if (pfd[0].revents & POLLIN) /* got SIGTERM or SIGINT */
			break;

		if (pfd[1].revents & POLLIN) {
			ret = read_ap_info(&dev, &api);
			if (ret < 0 && ret != ERRNODATA) { /* error */
				print_error();
				goto _errout;
			} else if (ret == 0 && channel_isset(&chans, api.chan)) { /* got infos */
				pthread_mutex_lock(&list_mutex);
				if (add_or_update_ap(&apl, &api) < 0) {
					pthread_mutex_unlock(&list_mutex);
					print_error();
					goto _errout;
				}
				pthread_mutex_unlock(&list_mutex);
			}
		}

		gettimeofday(&tv2, NULL);
		if (tv2.tv_usec > tv1.tv_usec)
			msec = tv2.tv_usec - tv1.tv_usec;
		else
			msec = tv1.tv_usec - tv2.tv_usec;

		/* update screen every 0.5 second */
		if (msec >= 500000) {
			pthread_mutex_lock(&list_mutex);
			update_scr(&apl, &dev);
			pthread_mutex_unlock(&list_mutex);
			gettimeofday(&tv1, NULL);
		}

		/* change channel at least every 1 second */
		if (time(NULL) - tm >= 1) {
			if (!ta.chan_changed) {
				pthread_mutex_lock(&cnc_mutex);
				ta.chan_need_change = 0;
				pthread_mutex_unlock(&cnc_mutex);
				pthread_mutex_lock(&chan_mutex);
				n = 0;
				do {
					chan = (chan % CHANNEL_MAX) + 1;
					if (channel_isset(&chans, chan))
						ret = iw_set_channel(&dev, chan);
					else
						ret = -1;
					/* if fails try next channel */
				} while(++n < CHANNEL_MAX && ret < 0);
				/* if all channels failed */
				if (ret < 0) {
					print_error();
					goto _errout;
				}
				tm = time(NULL);
				ta.chan_changed = 1;
				pthread_cond_signal(&chan_cond);
				pthread_mutex_unlock(&chan_mutex);
			} else {
				pthread_mutex_lock(&cnc_mutex);
				ta.chan_need_change = 1;
				pthread_mutex_unlock(&cnc_mutex);
			}
		}
	}

	/* we got an error from deauth thread */
	if (ta.stop == 2)
		goto _errout;

	printf("\nExiting..\n");
	ta.stop = 1;
	pthread_mutex_unlock(&list_mutex);
	pthread_cond_broadcast(&chan_cond);
	pthread_mutex_unlock(&chan_mutex);
	pthread_join(deauth_thread, NULL);
	iw_close(&dev);
	free_ap_list(&apl);
	return EXIT_SUCCESS;
_errout:
	ta.stop = 1;
	pthread_mutex_unlock(&list_mutex);
	pthread_cond_broadcast(&chan_cond);
	pthread_mutex_unlock(&chan_mutex);
	pthread_join(deauth_thread, NULL);
_errout_no_thread:
	iw_close(&dev);
	free_ap_list(&apl);
	return EXIT_FAILURE;
}