/**
 **
 **  Ultima 5 Tools by Otmar Lendl (lendl@cosy.sbg.ac.at)
 **
 **	Use and redistribution of this program is free.
 **	Please send any modifications to me.
 **
 **		Share and Enjoy !
 **
 **/

#include <dos.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include <graphics.h>


#define ESC	0x1b			/* Define the escape key	*/
#define TRUE	1			/* Define some handy constants	*/
#define FALSE	0			/* Define some handy constants	*/
#define PI	3.14159 		/* Define a value for PI	*/
#define ON	1			/* Define some handy constants	*/
#define OFF	0			/* Define some handy constants	*/

int    GraphDriver;		/* The Graphics device driver		*/
int    GraphMode;		/* The Graphics mode value		*/
double AspectRatio;		/* Aspect ratio of a pixel on the screen*/
int    MaxX, MaxY;		/* The maximum resolution of the screen */
int    MaxColors;		/* The maximum # of colors available	*/
int    ErrorCode;		/* Reports any graphics errors		*/
struct palettetype palette;		/* Used to read palette info	*/


void Initialize(void)
{
  int xasp, yasp;			/* Used to read the aspect ratio*/

  GraphDriver = DETECT; 		/* Request auto-detection	*/
  initgraph( &GraphDriver, &GraphMode, "" );
  ErrorCode = graphresult();		/* Read result of initialization*/
  if( ErrorCode != grOk ){		/* Error occured during init	*/
    printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
    exit( 1 );
  }

  getpalette( &palette );		/* Read the palette from board	*/
  MaxColors = getmaxcolor() + 1;	/* Read maximum number of colors*/

  MaxX = getmaxx();
  MaxY = getmaxy();			/* Read size of screen		*/

  getaspectratio( &xasp, &yasp );	/* read the hardware aspect	*/
  AspectRatio = (double)xasp / (double)yasp; /* Get correction factor	*/

}

#define BPROW  (256*16)    /* Bytes pro 16 Linien */


main()
{
 char filen[50]="mybrit.DAT";
 int sy,x,y,i;
 long foffset;
 unsigned char n1,n2;
 unsigned char block[16][16][16];
 FILE *fh;

 fh = fopen(filen,"rb");
 if ( fh==NULL) exit(10);

 puts("\n Ultima V Landscape-viewer (c) Anduril 1990 !\n");
 Initialize();
 for(y=0;y<16;y++)		/* Schleife ueber die y ! */
	{
	if (fread(block,1,BPROW,fh) != BPROW )
		{
		getch();
		puts("\nFile error !!!! \n");
		exit(20);
		}
	for(sy=0;sy<16;sy++)
		{
		for(x=0;x<256;x++)
			{
			i = block[x>>4][sy][x&15];
			putpixel(x,y*16+sy,i&15);
			}
		}
	}
 fclose(fh);
 fh = fopen("under.dat","rb");
 if ( fh==NULL) exit(10);

 for(y=0;y<16;y++)		/* Schleife ueber die y ! */
	{
	if (fread(block,1,BPROW,fh) != BPROW )
		{
		getch();
		puts("\nFile error !!!! \n");
		exit(20);
		}
	for(sy=0;sy<16;sy++)
		{
		for(x=0;x<256;x++)
			{
			i = block[x>>4][sy][x&15];
			putpixel(300+x,y*16+sy,i&15);
			}
		}
	}
fclose(fh);
getch();
closegraph();
}


