#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include"C:\TTP\GUI\GLIB.CPP"

int drawSPF(int xpos, int ypos, char filen[])
{
	int x,y,xsze,ysze;
	FILE *DotSPF;
	if ((DotSPF = fopen(filen, "rb"))==NULL)
		{
		printf("\n\nCannot open the requested file.\n");
		getch();
		return 1;
		}
	xsze=getc(DotSPF);
	ysze=getc(DotSPF);
	for(y=0;y<ysze;y++)
		{
		for(x=0;x<xsze;x++)
			{
			//printf("\n%i", getc(DotSPF));
			putpixel(x+xpos,y+ypos,getc(DotSPF));
			}
		}
	//Box(xpos,xpos,xsze,ysze,15);
	fclose(DotSPF);
	return 0;
}

int drawTTPG(int xpos, int ypos, char filen[])
{
	int x,y,xsze,ysze,ncolor,frames,delayms,cnt,curpix,comp,curdat,dt,d,rlec;
	int verMaj, verMin, verRev;
	FILE *TTPG;
	if ((TTPG = fopen(filen, "rb"))==NULL)
		{
		printf("\n\nCannot open the requested file.\n");
		getch();
		return 1;
		}
	if (getc(TTPG)!='L'||getc(TTPG)!='A')
		{
		printf("Requested file is not in the TTPG File Format");
		return 1;
		}
	xsze=getc(TTPG);
	ysze=getc(TTPG);
	ncolor=getc(TTPG);
	frames=getc(TTPG);
	delayms=getc(TTPG);
	comp=getc(TTPG);
	verMaj=getc(TTPG);
	verMin=getc(TTPG);
	verRev=getc(TTPG);
	for(x=16;x<ncolor+16;x++)
		SetPal(x,getc(TTPG),getc(TTPG),getc(TTPG));
	//printf("\n\n\n\n\n\n%i", plmode);
	fseek(TTPG,-1L,SEEK_END);
	dt=getc(TTPG);
	fseek(TTPG,((frames*dt)+1)*-1,SEEK_END);
		for(cnt=0;cnt<frames;cnt++)
			{
			if(comp==0)
				{
				delay(delayms);
				for(y=ypos;y<ysze+ypos;y++)
					{
					for(x=xpos;x<xsze+xpos;x++)
						{
						curpix=getc(TTPG);
						if(curpix>-1)
							putpixel(x,y,curpix);
						}
					}
				}
			if(comp==1)
				{
				delay(delayms);
				for(d=0;d<dt;d++)
					{
					curdat=getc(TTPG);
					for(rlec=0;rlec!=curdat;rlec++)
						{
						curpix=getc(TTPG);
						if(curpix>-1)
							putpixel(x+xpos,y+ypos,curpix);
						x++;
						if(x>xsze)
							{
							x=0;
							y++;
							}
					}
				}
	//Box(xpos,ypos,xsze,ysze,15);
	//printf("\n\n\n\n\n\n\n\n\n%i-%i-%i\n",verMaj, verMin, verRev);
	fclose(TTPG);
	return 0;
}