/*
 *  CTM v1.0 - 26 February 1991
 *
 *  Dylan Rhodes
 *
 *  "Pretty words for pretty girls.  Who will be my queen?" - Windom Earle
 *
 *  Compiled under Turbo C++ v2.0 (with Windows support, yeah!!!)
 *
 */



#define	_cdecl

#include <typedefs.h>
#include <tiga.h>
#include <extend.h>
#include <stdio.h>


CONFIG config;

int	oldmode;

char *version = "1.0";

/*
 *	term_tiga
 *
 *	syntax void term_tiga(void)
 *
 *	See page 3-7 of the Yellow Book for details.
 *
 */

void term_tiga()
{

	set_videomode(VGA,INIT);	/* Return mode to previous state */
	tiga_set(CD_CLOSE);		/* Close the TIGA CD */


}

/*
 *	init_tiga
 *
 *	syntax		void init_tiga(load_graphics_lib)
 *			short load_graphics_lib;
 *
 */

void init_tiga(load_graphics_lib)
short load_graphics_lib;
{
short v;
long lv;

	if ( ( lv = tiga_set(CD_OPEN)) < 0L) {
		printf("TIGA CD error: %ld\n", lv);
		exit(0);
		}

	oldmode = get_videomode();

	if (!(v = set_videomode(TIGA, INIT_GLOBALS))) {
		printf("TIGA GM error: %d\n", v);
		tiga_set(CD_CLOSE);
		exit(0);
		}

	if (load_graphics_lib && (v=install_primitives()) < 0) {
		printf("Graphics Library load error: %d\n",v);
		term_tiga();
		}

}


main(argc,argv)
int argc;
char *argv[];
{
int i;

	if (argc != 2) {
		printf("Usage: %s [0-5]\n",argv[0]);
		printopts();
		exit(0);
		}

	i = atoi(argv[1]);

	if ( (i < 0) || (i > 5) ) {
		printf("Illegal argument: %s\n",argv[1]);
		printopts();
		exit(0);
		}

	init_tiga(0);



	set_config(i,1);


	term_tiga();

	exit(0);



}

printopts()
{

	printf("CTM v%s\n\n",version);

	printf("Use a numerical argument to select default TIGA resolution.\n");
	printf("The following values may be used:\n\n");

	printf("0\t640x480x8\n");
	printf("1\t640x480x16\n");
	printf("2\t800x600x8\n");
	printf("3\t1024x768\n");
	printf("4\t512x480x24\n");
	printf("5\t640x480x8 (2-page mode)\n");

	printf("\nFor mode 3, interlaced or non-interlaced mode is selected\n");
	printf("via the STATION utility.\n");


}


