Category : Assembly Language Source Code
Archive   : DEFEND.ZIP
Filename : EGATOOLS.C

 
Output of file : EGATOOLS.C contained in archive : DEFEND.ZIP
/*******************************
* egatools.c *
* video stuff for EGA mode 13 *
*******************************/

#include
#include "egatools.h"

/******************
* set video mode *
******************/
void set_mode(int mode)
{
union REGS inregs;

inregs.x.ax = mode;
int86( 0x10, &inregs, &inregs);
}

/**********************************
* decode color info in .LBM file *
* and set the color palette *
**********************************/
void set_palette(unsigned char *fp)
{
union REGS inregs;
struct SREGS segs;

int z;
unsigned char *pt;
unsigned char c1;
unsigned char pal_tbl[17];

pt = pal_tbl;
fp += 4;

for(z=16; z>0; --z)
{
c1 = (*fp++ & 18) << 1;
c1 |= *fp++ & 18;
c1 |= (*fp++ & 18) >> 1;
if(c1 == 0x14)
c1 = 6;
*pt++ = c1;
}
*pt = 0;

pt = pal_tbl;
inregs.h.ah = 0x10;
inregs.h.al = 0x02;
inregs.x.dx = FP_OFF(pt);
segs.es = FP_SEG(pt);

int86x( 0x10, &inregs, &inregs, &segs);
}

/***************************
* test for a string match *
***************************/
char *match_code(char *s, char *d, int count)
{
int c;
for(c=0; c if(*s++ != *d++)
return(0);
return(s);
}

/******************************
* scan the .LBM file header *
* for the info necessary for *
* drawing the image. *
******************************/
char *find_body(char *fp, char *fe, int *backg)
{
int t;
char *temp;

if (!(fp=match_code(fp,"FORM",4)))
return(0);

fp+=4; /* skip count */

if (!(fp=match_code(fp,"ILBM",4)))
return(0);

while(!(temp=match_code(fp,"BMHD",4)))
if((fp = skip(fp+4)) >= fe)
return(0);

if (temp[12] != 4) /* check for planar data */
return(0);

*backg = temp[17];

fp = skip(temp);

while(!(temp=match_code(fp,"CMAP",4)))
if((fp = skip(fp+4)) >= fe)
return(0);

set_palette(temp); /* decode & set color info */

do /* find "BODY" or error out */
{
fp += 4;
fp = skip(fp);

if (fp >= fe)
return(0);
}
while(!(temp=match_code(fp,"BODY",4)));

return(temp+4);
}

/**********************************
* count literal data for packing *
**********************************/
static int count_lit(char *s, unsigned int *sc)
{
int c,z;

c = 1;
z = 126;

do
{
if(!(--(*sc)))
break;
++s;
if(s[0] == s[1])
break;
++c;
}
while(z--);
return (c);
}

/*********************************
* count repeat data for packing *
*********************************/
static int count_same(char *s, unsigned int *sc)
{
int c,z;
unsigned char k;

k = *s;
c = 0;
z = 126;

do
{
++c;
++s;
if(!(--(*sc)))
break;
if(k != *s)
break;
}
while(z--);
return (c);
}

/**********************************
* pack the data in an RLE format *
**********************************/
int pack(unsigned char *s, unsigned char *d, int count)
{
unsigned int screen_count;
int out_count, c;
unsigned char *t;
unsigned char k;

screen_count = count;
out_count = 0;

while(screen_count)
{
if(s[0] != s[1]) /* pack literal */
{
c = count_lit(s, &screen_count);
*d++ = (unsigned char) c;
out_count += (c+1);
for( ; c>0; *d++ = *s++, --c);
}
else /* pack same */
{
c = count_same(s, &screen_count);
*d++ = (unsigned char) (c | 0x80);
*d++ = *s;
s += c;
out_count += 2;
}
}
*d = 0;
++out_count;
return(out_count);
}

/*************** end of EGATOOLS.C *****************/



  3 Responses to “Category : Assembly Language Source Code
Archive   : DEFEND.ZIP
Filename : EGATOOLS.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. 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/