/*
    SPHINX Programming 1994
    NAME:  PCX.C--
    DESCRIPTION:  This program demonstrates some of the PCX display routines
                  currently available in C--.
    LAST MODIFIED:  22 Apr. 1994
*/


?parsecommandline  TRUE
?resize TRUE

?include "PCX.H--"

?include "VIDEO.H--"
?include "DOS.H--"
?include "KEYCODES.H--"
?include "WRITE.H--"
?include "VGA.H--"
?include "STRING.H--"


?define PALSIZE  256*3
byte palette[PALSIZE];    // palette buffer

?define BUFSEGSIZE 4095    // 4095 paragraphs == 65520 bytes

word bufseg;

PCX_HEAD pcx;


void display_info ()
{
WRITESTR("\n");
WRITESTR(PARAMSTR(0));
WRITESTR(" Loaded.\n");

WRITESTR("\nxmin = ");
WRITEWORD(pcx.PCX_xmin);
WRITESTR("    xmax = ");
WRITEWORD(pcx.PCX_xmax);

WRITESTR("\nymin = ");
WRITEWORD(pcx.PCX_ymin);
WRITESTR("    ymax = ");
WRITEWORD(pcx.PCX_ymax);

WRITESTR("\nhres = ");
WRITEWORD(pcx.PCX_hres);
WRITESTR("    vres = ");
WRITEWORD(pcx.PCX_vres);

WRITESTR("\nbits_per_pixel = ");
WRITEWORD(pcx.PCX_bits_per_pixel);

WRITESTR("\ncolor_planes = ");
WRITEWORD(pcx.PCX_color_planes);

WRITESTR("\nbytes_per_line = ");
WRITEWORD(pcx.PCX_bytes_per_line);

WRITESTR("\npalette type = ");
WRITEWORD(pcx.PCX_palette_type);

WRITESTR("\n\nPress any key to display...");
BIOSREADKEY();
}


void main ()
{
IF( PARAMCOUNT() != 1 )
    {WRITESTR("\nUSAGE:  PCX <pcx file to read>\n");
    EXIT(byte 1);
    }

bufseg = GETMEM(BUFSEGSIZE);
IF( AX == 0 )
    {WRITESTR("Unable to allocate memory.\n");
    EXIT(byte 1);
    }

IF( byte readPCX(PARAMSTR(0),bufseg,0,BUFSEGSIZE*16,#pcx,pcx_cut) != pcx_e_ok )
    {WRITESTR("Not valid PCX file.\n");
    EXIT(byte 2);
    }

IF( byte readPCXpalette(PARAMSTR(0),DS,#palette) != pcx_e_ok )
    {WRITESTR("Error reading palette.\n");
    EXIT(byte 4);
    }

display_info();

SETVIDEOMODE(vid_320x200_256);

SETVGAPALETTE( ,0,256,#palette);

$ PUSH DS
DS = bufseg;
putimage19(0,0,0);    //  put onto the screen
$ POP DS

	@BIOSREADKEY();  // wait for a key


SETVIDEOMODE(vid_text80c);
}


/* end of PCX.C-- */
