Category : Printer + Display Graphics
Archive   : PCX1.ZIP
Filename : PCX1.C
Output of file : PCX1.C contained in archive : PCX1.ZIP
#include
#include
#include
#include
#include
#include
#include
char filename[40]; /* Global variables */
unsigned char far *ScreenMemory;
int *mode = 0;
void main(void) /* Program starts */
{
SetVid();
GetDir();
GetName();
LoadPCX( filename );
getch();
AnotherPic();
setvmode(DEFAULTMODE);
exit(0);
}
GetDir()
{
void listfile(struct ffblk *filedata);
struct ffblk filedata;
if(findfirst("*.pcx", &filedata, FA_NORMAL) == 0){
printf("Choose a PCX file to view\n\n");
listfile(&filedata);
while(findnext(&filedata) == 0)
listfile(&filedata);
}
}
listfile(struct ffblk *filedata)
{
printf("%-16s", (filedata -> ff_name));
}
SetVid()
{
char ch = 0;
setvmode(3);
clrscrn2(0x1e);
printf("Card type (must have EGA or VGA, otherwise (q)uit)\n\n");
printf(" (E)GA\n");
printf(" (V)GA\n");
printf(" (Q)uit\n");
ch = getch();
if(isupper(ch)) ch = tolower(ch);
switch(ch){
case 'e' : mode = 16;
break;
case 'v' : mode = 18;
break;
case 'q' : exit(0);
break;
default: main();
}
}
char GetName() /* Get a file name & path */
{
printf("\n\n\n\n\n");
printf("Hit any key to quit current PCX showing\n");
printf("Enter file name (path if needed) with .PCX extension:");
scanf("%s", &filename);
setvmode(mode);
}
AnotherPic()
{
char c = 0;
printf("Would you like to view another PCX file? Y/N \n");
c = getch();
if( c == 'y' || c == 'Y' )
main();
else if( c == 'n' || c == 'N' )
goto end;
else
main();
end:
}
void LoadPCX( char *filename )
{
unsigned char Buffer[768];
FILE *fp;
unsigned int *numrows = 0;
unsigned int y = 0;
unsigned int linebytes;
unsigned int currentbyte = 0;
unsigned char data;
unsigned char reps;
unsigned char count;
fp = fopen( filename, "rb" ); /* Open the file */
if(fp == NULL ) main(); /**end if no fp**/
fread( Buffer, 128, 1, fp ); /**read pcxheader into buffer**/
/* VGA 640x480x16 or EGA 640x350x16 */
numrows = mode == 16 ? 350 : 480;
ScreenMemory = ( unsigned char far * ) 0xa0000000; /* Define seg */
linebytes = 320; /* Bytes per line in modes 16 & 18 */
outport( 0x3ce, 3 );
outport( 0x3ce, 5 );
outport( 0x3ce, 7 );
outport( 0x3ce, 0xff08 );
while( y < numrows ){
fread( &data, 1, 1, fp ); /**send one byte to &data**/
if(( data & 0xc0 ) == 0xc0){ /** flag set or goto else**/
reps = data & 0x3f; /**if not set it, bitmask rep**/
fread( &data, 1, 1, fp ); /**read &data again**/
for( count = 0; count < reps; count++ ){ /**???**/
Buffer[currentbyte++] = data;
if( currentbyte == linebytes ){ /**as line fills**/
PutLine( y, Buffer ); /**put it on the screen**/
currentbyte = 0; /**prepare for next line**/
y++; /**start next line**/
}
}
}
else Buffer[currentbyte++] = data;
if(currentbyte == linebytes ) /**as line fills**/
{
PutLine( y, Buffer ); /**put it on the screen**/
currentbyte = 0; /**prepare for next line**/
y++; /**start next line**/
}
}
outport( 0x3c4, 0x0f02 ); /* Reset VGA card defaults */
outport( 0x3ce, 0x0f07 );
fclose( fp );
return;
}
void PutLine( int y, unsigned char *Buffer ) /* One line of data on screen */
{
register int i,j;
unsigned int vgaregs;
vgaregs = 0x0102;
for( i = 0; i < 4; i++ ) /* 4 bit planes */
{
outport( 0x3c4, vgaregs );
for( j = 0; j < 80; j++ )
*ScreenMemory++ = Buffer[j+i*80];
vgaregs = (vgaregs & 0x00ff)|((vgaregs & 0xff00) << 1 );
ScreenMemory -= 80;
}
ScreenMemory += 80;
return;
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/