
/*********************************************
* Benchmark utility designed mainly for PDAs
* (c)2001 Edivision LLC by Patrick Roberts
*
***********/

#include <elate/ave/ave.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>

#include "cnoise.h"

FILE *opf;

#include "tests/tests.h"

#define VERSION "1.0rc3"

ave_pix_t *splash1;
ave_screen_info_t basewin;

char *randdata;

struct AV {   
   ave_dev_t *aveinst;
   ave_app_t *app;
   ave_toolkit_t *toolkit;
   ave_win_t *win;
   ave_dialog_gadgets_t gdg;
} ctrl;


void initAVE(char *);

int main (int argc, char **argv) {


   unsigned int f;
   time_t timerS, timer1, timer2, timerA1, timerA2;
   void *tmpv;
   int numloops=100, i1, i2, i3, i4, i5, i6, tia[20];
   double d1,d2;
   char *cp1;
   unsigned char *ucp1;
   FILE *fp;
   int *ip1;

   opf=stdout;
   
   fprintf(opf,"DECbench version:" VERSION "\n");
   timerS=time(NULL);
   fprintf(opf,"timestamp: %s\n\n",ctime(&timerS));
   fprintf(opf,"System Name:\nCPU ID:\n#CPU:\nCPU Speeds (Mhz):\nGFX:\nUID:\nHost OS:\nHost OS version:\nAmigaDE version:\nComment:\n\n");
   

   fprintf(opf,"Speed Output:\n");fflush(opf);
   system("speed");
   fprintf(opf,"\n\n");

  
   fprintf(opf,"<--------------TIMER RESOLUTION AND ACCURACY----------------->\n");
   /* test timer accuracy */
   #include "tests/timer.c"
   fprintf(opf,"<------------------------------------------------------------>\n\n");

   /* test malloc */
   #include "tests/malloc.c"
   
   /* test calloc */
   #include "tests/calloc.c"
   
   /* test media->ram */
   #include "tests/media2ram.c"
      
   /* test uncompress ram->ram */
   #include "tests/zlibU_ram.c"
   
   /* test memory read/mod/write */
   #include "tests/mem_rmw.c"
   

/* AVE TESTS */
/* AVE TESTS */
/* AVE TESTS */
initAVE(argv[0]);

numloops*=10; /* fast tests ahead */

   /* test fill pixels */
   #include "tests/ave_fill.c"

   /* test plot pixels */
   #include "tests/ave_plot.c"
   
numloops*=.1; /* slower tests ahead */

   /* test draw lines */
   #include "tests/ave_lines.c"
   
   /* test draw lines */
   #include "tests/ave_gravs.c"
   
   /* test draw ellipse */
   #include "tests/ave_ellipse.c"
      
   /* test draw ellipse */
   #include "tests/ave_fellipse.c"
      
   /* test draw triangles */
   #include "tests/ave_tris.c"

   /* test draw triangles */
   #include "tests/ave_ftris.c"


   ave_avo_hide((ave_avo_t *) ctrl.win);
   ave_avo_update((ave_avo_t *) ctrl.win);
   ave_app_closeall(ctrl.app);

   ave_dev_closetoolkit(ctrl.aveinst,ctrl.toolkit);
   ave_dev_close(ctrl.aveinst,ctrl.app);

   free(randdata);
   fflush(opf);

return(0);
}


void initAVE(char *argv0) {

   /* Init the AVE */

   char *cp1, buf[64] = "/device/ave/";

   cp1=strrchr(argv0,'/');
   if(cp1==NULL)cp1=argv0;
   else cp1++;
   strcat(buf,cp1);

   kn_dev_lookup(buf,(ELATE_OO_DATA **) &ctrl.aveinst, &cp1);
   ctrl.app = ave_dev_open(ctrl.aveinst, (ELATE_OO_DATA *)cp1, 0, 0);

   sleep(1);

   ctrl.toolkit = ave_dev_opentoolkit(ctrl.aveinst,ctrl.app);

   /* Open the window */
   ctrl.win=ave_toolkit_createdialog(ctrl.toolkit, "c", NULL, 240,240,FDI_INNER|FDI_CONTENT);
   ave_app_addavo(ctrl.app, NULL, (ave_avo_t *)ctrl.win, 0);
   ctrl.gdg = ave_dialog_getgadgets(ctrl.win);
   
   splash1=ave_pix_16bit_open(NULL,240,240,480);
   ave_avo_add(ctrl.gdg.content, (ave_avo_t *)splash1, 0);
   basewin = ave_dev_getscreen(ctrl.aveinst);
   ave_avo_setpos((ave_avo_t *)splash1,0,0,1);
   ave_avo_setpos((ave_avo_t *)ctrl.win,(basewin.width-240)>>1,
       (basewin.height-240)>>1,0);
      
   ave_avo_update((ave_avo_t *)ctrl.win);
   ave_avo_update((ave_avo_t *)splash1);
   
}
