#define __USE_SYSBASE
#include <proto/exec.h>
#include <exec/memory.h>
#include <proto/dos.h>
#include <proto/BigNum.h>
#include <proto/timer.h>
#include <devices/timer.h>
#include <string.h>

#define MEM MEMF_FAST|MEMF_CLEAR
#define TEMPLATE "Two Numbers/M"
#define TXT "Two Numbers !\n"
#define WARN "Needs BigNum.library v37 !!\n"

__saveds void maine(void)
{
 struct DosLibrary *DOSBase;
 struct ExecBase *SysBase;
 struct Library *BigNumBase;
 struct Library *TimerBase;
 struct timerequest *tr;
 struct timeval aa,bb;
 struct RDArgs *rdargs;
 long opts=0;
 PtrBigNum x,y,z;

 SysBase=*((struct ExecBase **)4);
 if(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))
 {
  if(BigNumBase=OpenLibrary("BigNum.library",37))
  {
   if(tr=(struct timerequest *)AllocVec(sizeof(struct timerequest),MEM))
   {
    if(!(OpenDevice("timer.device",UNIT_MICROHZ,(struct IORequest *)tr,0)))
    {
     TimerBase=(struct Library *)tr->tr_node.io_Device;
     if(rdargs=ReadArgs(TEMPLATE,&opts,NULL))
     {
      if(opts)
      {
       x=BigNumInit();
       y=BigNumInit();
       z=BigNumInit();
       BigNumStrToBigNum(x,((char **)opts)[0]);
       BigNumStrToBigNum(y,((char **)opts)[1]);
       GetSysTime(&aa);
       BigNumMul(x,y,z);
       GetSysTime(&bb);
       SubTime(&bb,&aa);
       BigNumPrint(z);
       Printf("\n(%ld.%05ld s)\n\n",bb.tv_secs,bb.tv_micro);
       BigNumFree(3);
      }
      else
       Printf(TXT);
      FreeArgs(rdargs);
     }
     CloseDevice((struct IORequest *)tr);
    }
    else
     PrintFault(IoErr(),NULL);
    FreeVec(tr);
   }  
   CloseLibrary(BigNumBase);
  }
  else
   Printf(WARN);
  CloseLibrary((struct Library *)DOSBase);
 }
}
