#include <stdio.h>
#include <stdlib.h>                     // exit() atol()
#include <string.h>                     // stricmp()
#include <conio.h>                      // kbhit() getch()
#include <bios.h>
#include "..\intel\timestmp.h"
#include "..\wattcp\tcp.h"

#define BIOS_RATE 18.206482

extern longword set_timeout();

void main(int argc, char *argv[])
{
   PentiumClock now;
   double last, s, r,ts;
   long b;
   int j,k, v, n;
   Bit32 t;

   v = 18;  /* BIOS ticks */
   ts = 0;  n = 0;
   for (j = 0; j != 60; ++j) {

//      t = set_timeout(v);
      b = biostime(0, 0L);
      for (;;) {
         if (biostime(0,0L) != b) break;
         }
      now.set();
//      last = now.get_native();
      last = now;
//      while (!chk_timeout(t)) ;
      for (k = 0; k != v; ++k) {
         b = biostime(0, 0L);
         for (;;) {
            if (biostime(0,0L) != b) break;
            }
         }
      now.set();
      s = (double) now;
      r = (s-last)*BIOS_RATE/v;
      ts += r;  ++n;
      printf("   now = %f, -> %.3fE6\n", r, ts/(n*1.0E6));
      if (kbhit()) {
         getch();        /* trash the character */
         break;
         }
      }
   }
