#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>

//#LIB## "VGA.LIB"

#include ".\..\SOURCE\VGA\VGA.HPP"

void extern libb(void);
void extern newattribution(void);
void extern deleteattribution(void);
void extern mode_13h(void);
void extern mode_text(void);
void extern nosound(void);
/*
void libmain(void)
{
   void extern libb();
   return 0;
};
*/
void extern libb(void)
{
   //unsigned char *screen[10];
   /*
   printf("\nVGA PROGRAM STARTED V0.3\n");
   printf("\nMOUSE TO ROTATE, ESC TO QUIT.\n");
   printf("\nPRESS ANY KEY TO CONTINUE.\n");

   getch();
   */

   //set_mousex_minmax(1,319);
   //set_mousey_minmax(1,199);
   //set_mouse_cursor_xy(160,100);

   cycle=0;

   for (int a=0;a<255;a++)
   {
      key[a]=0;
   }

   for (int i=0;i<10;i++)
   {
      object[i]=new vector[10];
   }

   object[0][0].x=-50;
   object[0][0].y=50;
   object[0][0].z=-50;

   object[0][1].x=50;
   object[0][1].y=50;
   object[0][1].z=-50;

   object[0][2].x=50;
   object[0][2].y=-50;
   object[0][2].z=-50;

   object[0][3].x=-50;
   object[0][3].y=-50;
   object[0][3].z=-50;


   object[0][4].x=-50;
   object[0][4].y=50;
   object[0][4].z=50;

   object[0][5].x=50;
   object[0][5].y=50;
   object[0][5].z=50;

   object[0][6].x=50;
   object[0][6].y=-50;
   object[0][6].z=50;

   object[0][7].x=-50;
   object[0][7].y=-50;
   object[0][7].z=50;

   object[1][0].x=-5;
   object[1][0].y=-5;
   object[1][0].z=-5;

   object[1][1].x=+5;
   object[1][1].y=-5;
   object[1][1].z=-5;

   object[1][2].x=+5;
   object[1][2].y=-5;
   object[1][2].z=+5;

   object[1][3].x=-5;
   object[1][3].y=-5;
   object[1][3].z=+5;

   xan=0;
   yan=0;
   zan=0;
   zadd=0;

   hx=160;
   hy=100;




//   while(key[1]!=1)
   {
//      readkey();

//      cycle++;
      //if (cycle%100==1) mode_13h();
//      if (cycle>10000) cycle=0;

      int i;

      for(i=0;i<8;i++)
      {
	 rotate(object[0][i].x,object[0][i].y,object[0][i].z,xan,yan,zan);
	 object[0][i].rx=x_t;
	 object[0][i].ry=y_t;
	 object[0][i].rz=z_t;
      }

      for(i=0;i<8;i++)
      {
	 project(0,i);
      }

      hx=160;//+mousex()/2;
      hy=100;//+mousey()/2;

      xan=360-mousex()/2;
      yan=360-mousey()/2;

      line(hx+object[0][0].sx,hy+object[0][0].sy,hx+object[0][1].sx,hy+object[0][1].sy,1,1);
      line(hx+object[0][1].sx,hy+object[0][1].sy,hx+object[0][2].sx,hy+object[0][2].sy,1,1);
      line(hx+object[0][2].sx,hy+object[0][2].sy,hx+object[0][3].sx,hy+object[0][3].sy,1,1);
      line(hx+object[0][3].sx,hy+object[0][3].sy,hx+object[0][0].sx,hy+object[0][0].sy,1,1);

      line(hx+object[0][4].sx,hy+object[0][4].sy,hx+object[0][5].sx,hy+object[0][5].sy,1,1);
      line(hx+object[0][5].sx,hy+object[0][5].sy,hx+object[0][6].sx,hy+object[0][6].sy,1,1);
      line(hx+object[0][6].sx,hy+object[0][6].sy,hx+object[0][7].sx,hy+object[0][7].sy,1,1);
      line(hx+object[0][7].sx,hy+object[0][7].sy,hx+object[0][4].sx,hy+object[0][4].sy,1,1);

      line(hx+object[0][0].sx,hy+object[0][0].sy,hx+object[0][4].sx,hy+object[0][4].sy,1,1);
      line(hx+object[0][1].sx,hy+object[0][1].sy,hx+object[0][5].sx,hy+object[0][5].sy,1,1);
      line(hx+object[0][2].sx,hy+object[0][2].sy,hx+object[0][6].sx,hy+object[0][6].sy,1,1);
      line(hx+object[0][3].sx,hy+object[0][3].sy,hx+object[0][7].sx,hy+object[0][7].sy,1,1);

      for(i=0;i<4;i++)
      {
	 rotate(object[1][i].x,object[1][i].y,object[1][i].z,xan,yan,zan);
	 object[1][i].rx=x_t;
	 object[1][i].ry=y_t;
	 object[1][i].rz=z_t;
      }

      for(i=0;i<4;i++)
      {
	 project(1,i);
      }

      hx=160;//+mousex()/2;
      hy=100;//+mousey()/2;
      /*
      line(hx+object[1][0].sx,hy+object[1][0].sy,hx+object[1][1].sx,hy+object[1][1].sy,1);
      line(hx+object[1][1].sx,hy+object[1][1].sy,hx+object[1][2].sx,hy+object[1][2].sy,1);
      line(hx+object[1][2].sx,hy+object[1][2].sy,hx+object[1][3].sx,hy+object[1][3].sy,1);
      line(hx+object[1][3].sx,hy+object[1][3].sy,hx+object[1][0].sx,hy+object[1][0].sy,1);
      */
/*      for (int y=0;y<10;y++)
      {
	 for (int x=0;x<10;x++)
	 {
	    object[1][0].x=-5;
	    object[1][0].y=-5;
	    object[1][0].z=-5;

	    object[1][1].x=+5;
	    object[1][1].y=-5;
	    object[1][1].z=-5;

	    object[1][2].x=+5;
	    object[1][2].y=-5;
	    object[1][2].z=+5;

	    object[1][3].x=-5;
	    object[1][3].y=-5;
	    object[1][3].z=+5;
	 }
      }

      if (key[73]==1)
      {
	 zan=zan-0.1f;
	 if (zan<0) zan=360+zan;
      }
      if (key[81]==1)
      {
	 zan=zan+0.1f;
	 if (zan>359) zan=zan-359;
      }

      if (key[72]==1)
      {
	 yan=yan-0.1f;
	 if (yan<0) yan=360+yan;
      }
      if (key[80]==1)
      {
	 yan=yan+0.1f;
	 if (yan>359) yan=yan-359;
      }

      if (key[75]==1)
      {
	 xan=xan-0.1f;
	 if (xan<0) xan=360+xan;
      }
      if (key[77]==1)
      {
	 xan=xan+0.1f;
	 if (xan>359) xan=xan-359;
      }


      if (key[74]==1)
      {
	 zadd=zadd-1;
      }
      if (key[78]==1)
      {
	 zadd=zadd+1;
      }
      */
   }

   mode_text();

   printf("\nARTENIS\n");

}
