예제 #1
0
파일: L17-1.CPP 프로젝트: CHMyFork/GPBB
void main()
{
   unsigned int init_length, x, y, seed;
   unsigned long generation = 0;
   char gen_text[80];
   long bios_time, start_bios_time;

   cellmap current_map(cellmap_height, cellmap_width);
   cellmap next_map(cellmap_height, cellmap_width);

   // Get the seed; seed randomly if 0 entered
   cout << "Seed (0 for random seed): ";
   cin >> seed;
   if (seed == 0) seed = (unsigned) time(NULL);

   // Randomly initialize the initial cell map
   cout << "Initializing...";
   srand(seed);
   init_length = (cellmap_height * cellmap_width) / 2;
   do {
      x = random(cellmap_width);
      y = random(cellmap_height);
      next_map.set_cell(x, y);
   } while (--init_length);
   current_map.copy_cells(next_map); // put init map in current_map

   enter_display_mode();

   // Keep recalculating and redisplaying generations until a key
   // is pressed
   show_text(0, MSG_LINE, "Generation: ");
   start_bios_time = _bios_timeofday(_TIME_GETCLOCK, &bios_time);
   do {
      generation++;
      sprintf(gen_text, "%10lu", generation);
      show_text(1, GENERATION_LINE, gen_text);
      // Recalculate and draw the next generation
      current_map.next_generation(next_map);
      // Make current_map current again
      current_map.copy_cells(next_map);
#if LIMIT_18_HZ
      // Limit to a maximum of 18.2 frames per second, for visibility
      do {
         _bios_timeofday(_TIME_GETCLOCK, &bios_time);
      } while (start_bios_time == bios_time);
      start_bios_time = bios_time;
#endif
   } while (!kbhit());
   getch();    // clear keypress
   exit_display_mode();
   cout << "Total generations: " << generation << "\nSeed: " <<
         seed << "\n";
}
예제 #2
0
void LogPacket(struct ax25_level1 *p, int dir)
{
    struct packet_log   *pl;

    /* log full? */
    if(nlogs >= LOGSIZE)
        return;

    /* allocate a structure */
    pl = malloc(sizeof(struct packet_log) + sizeof(struct ax25_level1) + p->len);
    if(pl == NULL) {
        fprintf(stderr,"--- Out of memory in LogPacket\n");
        return;
    }

    /* set up the log packet */
    pl->time = _bios_timeofday(_TIME_GETCLOCK,&clock_count);
    pl->dir = dir;
    memcpy(&pl->p,p,sizeof(struct ax25_level1) + p->len);

    /* insert into log */
    log[nlogs++] = pl;
}
예제 #3
0
unsigned long biostime(unsigned cmd, unsigned long lon)
{
    long tval = (long)lon;
    _bios_timeofday(cmd, &tval);
    return (unsigned long)tval;
}
예제 #4
0
long _RTL_FUNC     biostime(int __cmd, long __newtime)
{
   _bios_timeofday(__cmd, &__newtime) ;
   return __newtime ;
}