Japanese
PROGRAMMER'S GUIDECompression/decompression library
BackForward
Compression and decompression library/1. Guide

[Compressed file format]
The diagram and table below show the run-length compressed file format.

There are two types of symbols: The two are distinguished depending on whether the run length is a positive value or a negative value.


Figure 1.3 Run-length compressed file format

Table 1.3 Run-length compressed file header


1.3 Decompression library

[overview]

The decompression library decompresses data compressed by a compression tool.
Compressed data can be stored as a separate file on a CD-ROM or in any other way. However, when decompressing, the decompression library is started by specifying input and output data buffers in memory that can be accessed directly from the main CPU.
Users of the decompression library must allocate both of these buffers and specify their addresses to library functions.
For example, when reading input data from a CD and decompressing it, it is necessary to read the input data for one decompression process to the end into memory before starting the decompression library function.
The user also informs the decompression library functions of the output data buffer size. If the decompressed data exceeds this size, the library function will not write to the position beyond the size and will interrupt processing. You can also use this function to intentionally decompress part way through the process.
However, there is no function to restart the interrupted decompression process.
The following diagram provides an overview of the decompression process.

Figure 1.4 Decompression process
in: Input buffer start address. Align to 4-byte boundaries.
out: Output buffer start address. Align to 4-byte boundaries.
bufsize: Output buffer size. An integer multiple of the number of processing unit bytes.

[Module configuration]

Functionally, the decompression library functions have a hierarchical modular structure. High-level functions are easy to use because they interpret compression algorithms and parameters and perform decompression processing, but they also have the disadvantage of being linked with extra object code.
If you want to link only the bare minimum of object code, you can use low-level functions. In this case, care must be taken to ensure that the operations do not differ from those on the compression tool side.
The following diagram shows the module structure of the decompression library.

Figure 1.5 Module configuration

[Example of use]

Here is an example of using library functions to create a program using the decompression library "CMPLIB.LIB".
When invoking the function, it is assumed that the compressed data is in memory that is directly accessible to the main CPU.

Decompression library usage example 1
The following sample shows a case where the source file contains compressed data in the form of a C language array.

sample 1
#include "cmplib.h"

/* Compress using the compressed data run-length method,
    Convert to compressed file data with binary text converter */

char comdata[] = {
	0x10, 0x01, 0x04, ・・・・・・・・・
			:
			:
			:
	}

/* Decompression data buffer (secure a size not smaller than the size before compression) */
char outputbuf[4096];
			:
			:
			:

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
main()
{
	/* Decompression data pointer */
	char *buf;

	/* Set at the beginning of the decompressed data buffer */
	bufp = outputbuf;

	/* Run-length dictionary expansion */
	CMP_DecRunlen(cmpdata, &bufp, sizeof(outputbuf));

	/* Use decompressed data */
			:
			:
			:
}

Decompression library usage example 2
The following sample shows how to read and decompress compressed data from a CD-ROM.

sample 2

#include "sega_gfs.h"
#include "cmplib.h"

/* File reading buffer */
Uint8 readbuf[READ_SIZE]
/* Decompression data buffer */
Uint8 outputbuf[4096]

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
main()
{
	GfsFid fid; /* File size identifier */
	Sint32 fsize; /* file size */
	char *bufp;
	fid = 5; /* Specify compressed data file identifier */

	/* Batch loading files */
	fsize = GFS_Load(fid, 0, readbuf,READBUF_SIZE);

	/* Set at the beginning of the decompressed data buffer */
	bufp = outputbuf;

	/* Run length extension */
	CMP_DecRanlen(readbuf, &bufp, sizeof(outoutbuf));

	/* Use decompressed data */
			:
			:
			:
}


BackForward
PROGRAMMER'S GUIDECompression/decompression library
Copyright SEGA ENTERPRISES, LTD., 1997