Reference Section
_crc_ccitt #define SIZE 1000
{
char buffer[SIZE];
int crc_value = 0; /* initialize CRC to zero */
...
crc_value = _crc_ccitt (buffer, SIZE, crc_value);
}
#include <inline.h>
#define SIZE 1000
{
char buffer[SIZE];
int crc_value = 0;
...
lea si,buffer /* SI=offset of buf */
mov cx,SIZE /* CX=size of buf */
mov ax,crc_value /* AX = starting CRC */
crc_value = crc_ccitt ();/* AX = new CRC */
...
}
Source file _CMCRCCI.ASM ASM equiv CRC_CCITT
{
char ss_spec = 0;/* best compression */
int inhandle, outhandle, flag = 1;
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
... /* open input and output files */
_pack_cmplinit (_getfsize_h (inhandle));
rec_mem = _pack_bufsize (ss_spec, &min_mem, &max_mem);
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _pack_start(SS_SPEC, dos_mem, rec_mem, &read_size);
if (buffer == NULL)
_put_str ("Error initializing compression system");
do {
switch (flag)
{
case 1:
read_size = _read_h (inhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error reading from input file");
return;
}
break;
case -1:
read_size = _write_h (outhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error writing to output file");
return;
}
}
flag = _pack_continue (&buffer, &read_size);
printf ("\r%d%% complete",_get_packcmpl ());
} while (flag);
printf("\nOutput file is %2.2f%% the size of the\
input file\n",(float)(_get_packratio ())/100);
}
#include <inline.h>
{
char ss_spec = 0; /* set for best compression */
int inhandle, outhandle;
unsigned int dos_mem;
... /* open input/output files */
mov bx,inhandle
getfsize_h (); /* DX;AX=infile size */
pack_cmplinit ();
mov dl,ss_spec/* DL = speedsize */
pack_bufsize ();/* BX = rec buf size */
mov ax,bx /* alloc rec memory */
dos_malloc (); /* was mem allocated? */
jc p_cont_050/* n: print err msg */
mov dos_mem,dx/* save seg of block */
mov es,dx /* ES = seg of block */
mov dl,ss_spec/* DL = speedsize */
pushds
pack_start (); /* DS:SI->input buf */
pop es /* CX=count, ES=DS */
jc p_cont_050/* if error */
p_cont_020:
mov bx,es:inhandle
read_h (); /* read successful? */
jc p_cont_050/* n: print err msg */
p_cont_030:
pushcx
printf ("\r%d%% complete", get_packcmpl ());
pop cx
pack_continue ();
ja p_cont_020/* to get more input */
je p_cont_040/* compression done */
write_h (); /* else flush output */
jncp_cont_030/* go compress more */
jmp p_cont_050/* if error occurred */
p_cont_040:
printf ("\nOutput file is %2.2f%% the size of the\
input file\n",(float)(_get_packratio ())/100);
...
p_cont_050:
_put_str ("Unable to compress data");
...
}
Source file CMPCMPL.ASM ASM equiv GET_PACKCMPL
#include <compress.h>
{
packp buffer;
_get_packprefix ((void *)buffer);
}
#include <inline.h>
#include <compress.h>
{
packp buffer;
...
lea di,buffer
pushss
pop es /* ES = SS */
get_packprefix ();
...
}
Source file _CMPRFIX.ASM ASM equiv GET_PACKPREFIX
{
char ss_spec = 0;/* best compression */
int inhandle, outhandle, flag = 1;
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
... /* open input and output files */
_pack_cmplinit (_getfsize_h (inhandle));
rec_mem = _pack_bufsize (ss_spec, &min_mem, &max_mem);
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _pack_start(ss_spec, dos_mem, rec_mem, &read_size);
if (buffer == NULL)
_put_str ("Error initializing compression system");
do {
switch (flag)
{
case 1:
read_size = _read_h (inhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error reading from input file");
return;
}
break;
case -1:
read_size = _write_h (outhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error writing to output file");
return;
}
}
flag = _pack_continue (&buffer, &read_size);
printf ("\r%d%% complete",_get_packcmpl ());
} while (flag);
printf ("\noutput file is %2.2f%% the size of the input\
file\n",(float)(_get_packratio ())/100);
}
#include <inline.h>
{
char ss_spec = 0; /* set for best compression */
int inhandle, outhandle;
unsigned int dos_mem;
... /* open input/output files */
mov bx,inhandle
getfsize_h (); /* DX;AX = input file size */
pack_cmplinit ();
mov dl,ss_spec/* DL = speedsize spec */
pack_bufsize ();/* BX = recommended buf size */
mov ax,bx /* allocate recommended memory */
dos_malloc (); /* was the memory allocated? */
jc p_cont_050/* n: print error message */
mov dos_mem,dx/* save segment of mem block */
mov es,dx /* ES = segment of mem block */
mov dl,ss_spec/* DL = speedsize spec */
pushds
pack_start (); /* DS:SI-> input buffer,
CX = count */
pop es /* ES = DS */
jc p_cont_050/* if init was unsuccessful */
p_cont_020:
mov bx,es:inhandle
read_h (); /* was the read successful? */
jc p_cont_050/* n: print error message */
p_cont_030:
pushcx
printf ("\r%d%% complete", get_packcmpl ());
pop cx
pack_continue ();
ja p_cont_020/* if more input is needed */
je p_cont_040/* if compression is finished */
write_h (); /* if output needs flushed */
jncp_cont_030/* if write was successful */
jmp p_cont_050/* if an error occurred */
p_cont_040:
printf ("\noutput file is %2.2f%% the size of the input\
file\n",(float)(_get_packratio ())/100);
...
p_cont_050:
_put_str ("Unable to compress data");
...
}
Source file CMPRAT.ASM ASM equiv GET_PACKRATIO
{
int inhandle, outhandle, flag = 1;
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
packp prefix;
.../* open input/output files */
.../* call _pack_cmplinit with
size of data before compression */
if (_read_h (inhandle, prefix, sizeof(packp)))
_put_str ("Error reading from input file");
else
rec_mem = _unpack_bufsize (prefix, &min_mem, &max_mem);
if (rec_mem == 0)
{
_put_str ("File has invalid format");
return;
}
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _unpack_start (prefix, dos_mem, rec_mem,\
&read_size);
if (buffer == NULL)
{
_put_str ("Error initializing decompression system");
} else
do {
switch (flag)
{
case 1:
read_size = _read_h (inhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error reading from input file");
return;
}
break;
case -1:
read_size = _write_h (outhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error writing to output file");
return;
}
}
flag = _unpack_continue (&buffer, &read_size);
printf ("\r%d%% complete",_get_unpackcmpl ());
} while (flag);
(C Interface Recommended)
Source file CMUCMPL.ASM ASM equiv GET_UNPACKCMPL
{
char ss_spec = 0; /* best compression */
unsigned int min_mem, max_mem, rec_mem;
rec_mem = _pack_bufsize (ss_spec, &min_mem, &max_mem);
}
#include <inline.h>
{
mov dl,0 /* setup for best compression */
pack_bufsize ();/* BX = recommended memory */
}
Source file _CMPBSZ.ASM ASM equiv PACK_BUFSIZE
{
char ss_spec = 0;/* best compression */
unsigned int min_mem, max_mem, rec_mem;
pdat settings;
...
rec_mem = _pack_bufsizec (&settings, ss_spec, &min_mem,
&max_mem);
if (rec_mem == 0)
_put_str ("Values in settings were invalid");
}
#include <inline.h>
{
pdat settings;
...
mov dl,0 /* setup for best compression */
lea si,settings/* SI = offset of pdat struct */
pack_bufsizec ();/* BX = recommended memory */
...
}
Source file _CMPBSZC.ASM ASM equiv PACK_BUFSIZEC
{
char ss_spec = 0;/* best compression */
int inhandle, outhandle, flag = 1;
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
... /* open input and output files */
_pack_cmplinit (_getfsize_h (inhandle));
rec_mem = _pack_bufsize (ss_spec, &min_mem, &max_mem);
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _pack_start (ss_spec, dos_mem, rec_mem, &read_size);
if (buffer == NULL)
_put_str ("Error initializing compression system");
do {
switch (flag)
{
case 1:
read_size = _read_h (inhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error reading from input file");
return;
}
break;
case -1:
read_size = _write_h (outhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error writing to output file");
return;
}
}
flag = _pack_continue (&buffer, &read_size);
printf ("\r%d%% complete",_get_packcmpl ());
} while (flag);
printf ("\noutput file is %2.2f%% the size of the\
input file\n",(float)(_get_packratio ())/100);
}
#include <inline.h>
{
char ss_spec = 0; /* setup for best compression */
int inhandle, outhandle;
unsigned int dos_mem;
... /* open input and output files
mov bx,inhandle
getfsize_h (); /* DX;AX = input file size */
pack_cmplinit ();
mov dl,ss_spec/* DL = speedsize spec */
pack_bufsize ();/* BX = recommended buffer size */
mov ax,bx /* allocate memory (AX) */
dos_malloc (); /* was the memory allocated? */
jc p_cont_050/* n: print error message */
mov dos_mem,dx/* save segment of mem block */
mov es,dx /* ES = segment of mem block */
mov dl,ss_spec/* DL = speedsize spec */
pushds
pack_start (); /* DS:SI->input, CX = count */
pop es /* ES = DS */
jc p_cont_050/* if init was unsuccessful */
p_cont_020:
mov bx,es:inhandle
read_h (); /* was the read successful? */
jc p_cont_050/* n: print error message */
p_cont_030:
pushcx
printf ("\r%d%% complete", get_packcmpl ());
pop cx
pack_continue ();
ja p_cont_020/* if more input is needed */
je p_cont_040/* if compression is finished */
write_h (); /* if output needs flushed */
jncp_cont_030/* if write was successful */
jmp p_cont_050/* if an error occurred */
p_cont_040:
printf ("\noutput file is %2.2f%% the size of the\
input file\n",(float)(_get_packratio ())/100);
...
p_cont_050:
_put_str ("Unable to compress data");
...
}
Source file _CMPCINT.ASM ASM equiv PACK_CMPLINIT
{
char ss_spec = 0;/* best compression */
int inhandle, outhandle, flag = 1;
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
... /* open input and output files */
_pack_cmplinit (_getfsize_h (inhandle));
rec_mem = _pack_bufsize (ss_spec, &min_mem, &max_mem);
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _pack_start (ss_spec, dos_mem, rec_mem, &read_size);
if (buffer == NULL)
_put_str ("Error initializing compression system");
do {
switch (flag)
{
case 1:
read_size = _read_h (inhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error reading from input file");
return;
}
break;
case -1:
read_size = _write_h (outhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error writing to output file");
return;
}
}
flag = _pack_continue (&buffer, &read_size);
printf ("\r%d%% complete",_get_packcmpl ());
} while (flag);
printf ("\noutput file is %2.2f%% the size of the input
file\n",(float)(_get_packratio ())/100);
}
#include <inline.h>
{
char ss_spec = 0; /* setup for best compression */
int inhandle, outhandle;
unsigned int dos_mem;
... /* open input and output files */
mov bx,inhandle
getfsize_h (); /* DX;AX = input file size */
pack_cmplinit ();
mov dl,ss_spec/* DL = speedsize spec */
pack_bufsize ();/* BX = recommended buf size */
mov ax,bx /* allocate memory (AX) */
dos_malloc (); /* was the memory allocated? */
jc p_cont_050/* n: print error message */
mov dos_mem,dx/* save segment of mem block */
mov es,dx /* ES = segment of mem block */
mov dl,ss_spec/* DL = speedsize spec */
pushds
pack_start (); /* DS:SI->input, CX = count */
pop es /* ES = DS */
jc p_cont_050/* if init was unsuccessful */
p_cont_020:
mov bx,es:inhandle
read_h (); /* was the read successful? */
jc p_cont_050/* n: print error message */
p_cont_030:
pushcx
printf ("\r%d%% complete", get_packcmpl ());
pop cx
pack_continue ();
ja p_cont_020/* if more input is needed */
je p_cont_040/* if compression is finished */
write_h (); /* if output needs flushed */
jncp_cont_030/* if write was successful */
jmp p_cont_050/* if an error occurred */
p_cont_040:
printf ("\noutput file is %2.2f%% the size of the input\
file\n",(float)(_get_packratio ())/100);
...
p_cont_050:
_put_str ("Unable to compress data");
...
}
Source file _CMPACK.ASM ASM equiv PACK_CONTINUE
{
char ss_spec = 0; /* best compression */
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
...
rec_mem = _pack_bufsize (ss_spec, &min_mem, &max_mem);
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _pack_start (ss_spec, dos_mem, rec_mem, &read_size);
if (buffer == NULL)
_put_str ("Error initializing compression system");
}
#include <inline.h>
{
unsigned int dos_mem;
void far *buffer;
...
mov dl,255 /* set for fastest compression */
pack_bufsize ();
mov ax,bx /* allocate memory (AX) */
dos_malloc (); /* was the memory allocated? */
jc p_start_050/* n: print error message */
mov dos_mem,dx/* save segment of mem block */
mov es,dx /* ES = segment of mem block */
mov dl,255 /* set for fastest compression */
pack_start (); /* DS:SI->input, CX = count */
jncp_start_100/* if init was successful */
p_start_050:
_put_str ("Error initializing compression system");
p_start_100:
...
}
Source file _CMPSTRT.ASM ASM equiv PACK_START
{
char ss_spec = 0; /* best compression */
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
pdat settings;
...
rec_mem = _pack_bufsizec(&settings, ss_spec, &min_mem,
&max_mem);
if (rec_mem == 0)
{
_put_str ("Values in settings were invalid");
return;
}
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _pack_startc (&settings, SS_SPEC, dos_mem, rec_mem,
&read_size);
if (buffer == NULL)
_put_str ("Error initializing compression system");
}
#include <inline.h>
{
unsigned int dos_mem;
pdat settings; /* make this variable a global */
...
mov dl,0 /* setup for best compression */
mov si,offset settings /* DS:SI -> settings */
pack_bufsizec ();
mov ax,bx /* allocate recommended memory */
dos_malloc (); /* was the memory allocated? */
jc p_startc_050/* n: print error message */
mov dos_mem,dx/* save segment of mem block */
mov es,dx /* ES = segment of mem block */
mov dl,0 /* setup for best compression */
pack_startc (); /* DS:SI->input, CX = count */
jncp_startc_100/* if init was successful */
p_startc_050:
_put_str ("Error initializing compression system");
p_startc_100:
...
}
Source file _CMPSTRC.ASM ASM equiv PACK_STARTC
{
unsigned int min_mem, max_mem, rec_mem;
packp prefix;
int inhandle;
.../* open the input file */
if (_read_h (inhandle, prefix, sizeof(packp)))
_put_str ("Error reading from input file");
else
rec_mem = _unpack_bufsize (prefix, &min_mem, &max_mem);
}
#include <inline.h>
{
packp prefix;
int handle, readsize = sizeof(packp);
... /* open the input file */
lea si,prefix/* SI = offset filesize */
mov bx,handle/* BX = file handle */
xor dx,dx
mov ax,readsize/* DX;AX = num bytes to read */
read_h ();
jc unpack_b_100/* if a read error occurred */
... /* open the input file */
lea si,prefix/* DS:SI -> prefix */
unpack_bufsize ();/* AX = min,
BX = recommended,
CX = max */
jnc unpack_b_100
_put_str ("File has invalid format");
unpack_b_100:
...
}
...
}
Source file _CMUBSZ.ASM ASM equiv UNPACK_BUFSIZE
{
unsigned int min_mem, max_mem, rec_mem;
udat settings;
packp prefix;
int inhandle;
... /* open the input file */
if (_read_h (inhandle, prefix, sizeof(packp)))
_put_str ("Error reading from input file");
else
rec_mem=_unpack_bufsizec(&settings,prefix,&min_mem,&max_mem);
if (rec_mem == 0)
_put_str ("File has invalid format");
}
#include <inline.h>
{
udat settings;
packp prefix;
int handle, readsize = sizeof(packp);
... /* open the input file */
lea si,prefix/* SI = offset filesize */
mov bx,handle/* BX = file handle */
xor dx,dx
mov ax,readsize/* DX;AX = num bytes to read */
read_h ();
jc unpack_bc_100/* if a read error occurred */
lea si,prefix/* DS:SI -> prefix */
lea di,settings/* ES:DI -> settings */
unpack_bufsizec ();/* AX=min,BX=recommended,CX=max */
jnc unpack_bc_100
_put_str ("File has invalid format");
unpack_bc_100:...
}
...
}
Source file _CMUBSZC.ASM ASM equiv UNPACK_BUFSIZEC
(This example assumes that the original file size is saved
in the first four bytes of the input file.)
{
long int filesize;
unsigned int handle;
...
_read_h (handle, (void *)&filesize, 4);
_unpack_cmplinit (filesize);
/* initialize for %complete calculation */
}
(This example assumes that the original file size is saved
in the first four bytes of the input file.)
#include <inline.h>
{
long int filesize;
unsigned int handle;
... /* open input file */
lea si,filesize/* SI = offset filesize */
mov bx,handle/* BX = file handle */
xor dx,dx
mov ax,4 /* DX;AX = num bytes to read */
read_h (); /* read first 4 bytes */
mov ax,word ptr filesize
mov dx,word ptr filesize+2 /* DX;AX = size of file */
unpack_cmplinit ();/* init for %complete calc */
...
}
Source file _CMPCINT.ASM ASM equiv UNPACK_CMPLINIT
{
int inhandle, outhandle, flag = 1;
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
packp prefix;
... /* open input and output files */
... /* call _pack_cmplinit with size of
data before compression */
if (_read_h (inhandle, prefix, sizeof(packp)))
{
_put_str ("Error reading from input file");
return;
} else
rec_mem = _unpack_bufsize(prefix, &min_mem, &max_mem);
if (rec_mem == 0)
{
_put_str ("File has invalid format");
return;
}
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer =_unpack_start(prefix,dos_mem,rec_mem,&read_size);
if (buffer == NULL)
_put_str ("Error initializing decompression system");
else
do {
switch (flag)
{
case 1:
read_size = _read_h (inhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error reading from input file");
return;
} break;
case -1:
read_size =_write_h(outhandle, buffer, read_size);
if (read_size == 0xffff)
{
_put_str ("Error writing to output file");
return;
}
}
flag = _unpack_continue (&buffer, &read_size);
printf ("\r%d%% complete",_get_packcmpl ());
} while (flag);
...
}
(C Interface Recommended)
Source file _CMUPACK.ASM ASM equiv UNPACK_CONTINUE
{
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
packp prefix;
int inhandle;
... /* open the input file */
if (_read_h (inhandle, prefix, sizeof(packp)))
_put_str ("Error reading from input file");
else
{
rec_mem = _unpack_bufsize (prefix, &min_mem, &max_mem);
if (rec_mem == 0)
{
_put_str ("File has invalid format");
return;
}
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer = _unpack_start(prefix, dos_mem, rec_mem, &read_size);
if (buffer == NULL)
_put_str ("Error initializing decompression system");
}
}
#include <inline.h>
{
unsigned int dos_mem;
packp prefix;
int inhandle, readsize = sizeof(packp);
... /* open the input file */
mov bx,inhandle
lea si,prefix
mov cx,readsize
read_h ();
jc ustart_050/* if an error occurred */
mov di,si
unpack_bufsize ();/* AX=min, BX=recommend, CX=max */
jc ustart_050/* if an error occurred */
mov ax,bx /* allocate recommended memory */
dos_malloc (); /* was the memory allocated? */
jc ustart_050/* n: print error message */
unpack_start ();
jncp_startc_100/* if init was successful */
ustart_050:
_put_str ("Error initializing decompression system");
ustart_100:
...
}
Source file _CMUSTRT.ASM ASM equiv UNPACK_START
{
unsigned int min_mem, max_mem, rec_mem, dos_mem, read_size;
void far *buffer;
udat settings;
packp prefix;
int inhandle;
... /* open the input file */
if (_read_h (inhandle, prefix, sizeof(packp)))
_put_str ("Error reading from input file");
else
rec_mem=_unpack_bufsizec(&settings,prefix,&min_mem,&max_mem);
if (rec_mem == 0)
{
_put_str ("File has invalid format");
return;
}
dos_mem = _dos_malloc (rec_mem);
if (dos_mem == 0)
return;
buffer=_unpack_startc(&settings,prefix,dos_mem,
rec_mem,&read_size);
if (buffer == NULL)
_put_str ("Error initializing decompression system");
}
(C Interface Recommended)
Source file _CMUSTRC.ASM ASM equiv UNPACK_STARTC