/*****************************************************************************
* This program builds a binary file of ZVG commands that display the
* simple ZEKTOR test screen.
*
* Author:  Zonn Moore
* Created: 11/06/02
*
* History:
*
* (c) Copyright 2002, Zektor, LLC.  All Rights Reserved.
*****************************************************************************/
#include	<stdio.h>
#include	<stdlib.h>

#include	"zstddef.h"
#include	"zvgCmds.h"
#include	"zvgEnc.h"

unsigned char	ZvgBfr[4096];			// A big buffer

// Starting with a print out of the file 64x48.txt I drew the ZEKTOR logo
// centered on the paper.  Then numbered each vector.
//
// This array is each of those numbered vectors written as: xStart,yStart,xEnd,yEnd

int zektorLogo[] =
{
	// xStart, yStart, xEnd, yEnd

	// Z

	-17,  3, -17,  5,			// 1	
	-17,  5, -13,  5,			// 2	
	-13,  5, -17, -5,			// 3	
	-17, -5, -13, -5,			// 4	
	-13, -5, -13, -3,			// 5	

	// E

	 -7,  3,  -7,  5,			// 6	
	 -7,  5, -11,  5,			// 7	
	-11,  5,  -8,  0,			// 8	
	 -8,  0, -11, -5,			// 9	
	-11, -5,  -7, -5,			// 10
	 -7, -5,  -7, -3,			// 11

	// K

	 -5, -5,  -5,  5,			// 12
	 -1,  5,  -5,  0,			// 13
	 -5,  0,  -1, -5,			// 14

	// T

	  3, -5,   3,  5,			// 15
	  1,  3,   1,  5,			// 16
	  1,  5,   5,  5,			// 17
	  5,  5,   5,  3,			// 18

	// O

	  9, -5,   7,  0,			// 19
	  7,  0,   9,  5,			// 20
	  9,  5,  11,  0,			// 21
	 11,  0,   9, -5,			// 22

	// R

	 13, -5,  13,  5,			// 23
	 13,  5,  17,  3,			// 24
	 17,  3,  13,  0,			// 25
	 13,  0,  17, -5			// 26
};

// This was an after thought, and followed the ZEKTOR logo on the same peice of paper.

int dotComLogo[] =
{
	// .

	19, -5, 19, -5,

	// C

	24, -3, 22, -5,
	22, -5, 20,  0,
	20,  0, 22,  5,
	22,  5, 24,  3,

	// O

	28, -5, 26,  0,
	26,  0, 28,  5,
	28,  5, 30,  0,
	30,  0, 28, -5,

	// M

	32, -5, 32,  3,
	32,  3, 33,  5,
	33,  5, 34,  3,
	34,  3, 35,  5,
	35,  5, 36,  3,
	36,  3, 36, -5,
	34, -5, 34,  3
};

/****************************************************************************
* Create a file that can be compiled into ZVG commands that write ZEKTOR
*****************************************************************************/
int main( int argc, char *argv[])
{
	FILE	*binFile;
	int	xStart, yStart, xEnd, yEnd;
	uint	zvgSize, ii;

	fputs( "\nMAKELOGO - Create the ZEKTOR test logo. Version 1.0", stdout);
	fputs( "\n(c) Copyright 2002, Zektor, LLC.  All rights reserved.\n", stdout);

	if (argc < 2)
	{	fputs( "\nUse: MAKELOGO filename\n", stdout);
		fputs( "\nWhere:", stdout);
		fputs( "\n   filename = Filename of ZVG binary command file.\n", stdout);
		exit( 0);
	}

	binFile = fopen( argv[1], "wb");

	if (binFile == NULL)
	{	fprintf( stdout, "\nError opening file: \"%s\".\n", argv[1]);
		exit( 0);
	}

	// Reset ZVG encoder to point to start of buffer

	zEncodeSetPtr( ZvgBfr);

//	// Draw a full size box, if setup properly, this will be drawn off the edges
// // of the screen.

//	zEncodeZvgNC( -600,  449,  599,  449);
//	zEncodeZvgNC(  599,  449,  599, -450);
//	zEncodeZvgNC(  599, -450, -600, -450);
//	zEncodeZvgNC( -600, -450, -600,  449);

	// Draw a box at the edges of the visible screen

	zEncodeZvgNC( -512,  383,  511,  383);
	zEncodeZvgNC(  511,  383,  511, -384);
	zEncodeZvgNC(  511, -384, -512, -384);
	zEncodeZvgNC( -512, -384, -512,  383);

	// place a "normal" size ZEKTOR logo in middle of screen

	for (ii = 0; ii < sizeof( zektorLogo) / sizeof( *zektorLogo); ii += 4)
	{
		// place logo in center of screen, 16x larger than it was drawn.

		xStart =	zektorLogo[ii] * 16;
		yStart =	zektorLogo[ii+1] * 16;
		xEnd = zektorLogo[ii+2] * 16;
		yEnd = zektorLogo[ii+3] * 16;

		// print vector

//		printf( "\nXStart=%5d, YStart=%5d, XEnd=%5d, YEnd=%5d", xStart, yStart, xEnd, yEnd);

		// encode vector into command buffer

		zEncodeZvgNC( xStart, yStart, xEnd, yEnd);
	}

	// place a smaller logo in the lower right corner followed by a .COM

	for (ii = 0; ii < sizeof( zektorLogo) / sizeof( *zektorLogo); ii += 4)
	{
		// draw logo on screen 6x size, and down 300 points and to the right 156 points

		xStart =	zektorLogo[ii] * 6 + 156;
		yStart =	zektorLogo[ii+1] * 6 - 300;
		xEnd = zektorLogo[ii+2] * 6 + 156;
		yEnd = zektorLogo[ii+3] * 6 - 300;

//		printf( "\nXStart=%5d, YStart=%5d, XEnd=%5d, YEnd=%5d", xStart, yStart, xEnd, yEnd);

		// encode vector into command buffer

		zEncodeZvgNC( xStart, yStart, xEnd, yEnd);
	}

	// Add ".com" to above logo

	for (ii = 0; ii < sizeof( dotComLogo) / sizeof( *dotComLogo); ii += 4)
	{
		// draw .com on screen 6x size, and down 300 points and to the right 156 points

		xStart =	dotComLogo[ii] * 6 + 156;
		yStart =	dotComLogo[ii+1] * 6 - 300;
		xEnd = dotComLogo[ii+2] * 6 + 156;
		yEnd = dotComLogo[ii+3] * 6 - 300;

//		printf( "\nXStart=%5d, YStart=%5d, XEnd=%5d, YEnd=%5d", xStart, yStart, xEnd, yEnd);

		// encode vector into command buffer

		zEncodeZvgNC( xStart, yStart, xEnd, yEnd);
	}

	// Draw a small logo in the upper left corner

	for (ii = 0; ii < sizeof( zektorLogo) / sizeof( *zektorLogo); ii += 4)
	{
		// draw on screen 2x size, and up 195 points and to the left 290 points

		xStart =	zektorLogo[ii] * 2 - 290;
		yStart =	zektorLogo[ii+1] * 2 + 195;
		xEnd = zektorLogo[ii+2] * 2 - 290;
		yEnd = zektorLogo[ii+3] * 2 + 195;

//		printf( "\nXStart=%5d, YStart=%5d, XEnd=%5d, YEnd=%5d", xStart, yStart, xEnd, yEnd);

		// encode vector into command buffer

		zEncodeZvgNC( xStart, yStart, xEnd, yEnd);
	}

	// Place real big logo on top of everything.  This logo should go off the edges
	// of a properly sized screen.

	for (ii = 0; ii < sizeof( zektorLogo) / sizeof( *zektorLogo); ii += 4)
	{
		// place logo in center of screen, 32x larger than it was drawn.

		xStart =	zektorLogo[ii] * 32;
		yStart =	zektorLogo[ii+1] * 32;
		xEnd = zektorLogo[ii+2] * 32;
		yEnd = zektorLogo[ii+3] * 32;

//		printf( "\nXStart=%5d, YStart=%5d, XEnd=%5d, YEnd=%5d", xStart, yStart, xEnd, yEnd);

		// encode vector into command buffer

		zEncodeZvgNC( xStart, yStart, xEnd, yEnd);
	}

	// send trace to center of screen

	zEncodeCenter();

	// get size of ZVG buffer

	zvgSize = zEncodeSize();

	// write binary file

	fwrite( ZvgBfr, 1, zvgSize, binFile);
	fclose( binFile);
	return 0;
}
