home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / pslib / library.h < prev    next >
Text File  |  1998-06-08  |  6KB  |  180 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/pslib/rcs/library.h $
  15.  * $Revision: 1.12 $
  16.  * $Author: john $
  17.  * $Date: 1994/02/15 12:53:23 $
  18.  *
  19.  * PSLIB and library generation tool header file.
  20.  *
  21.  * $Log: library.h $
  22.  * Revision 1.12  1994/02/15  12:53:23  john
  23.  * Made numfiles stored in library be a short instead of char.
  24.  * 
  25.  * Revision 1.11  1993/12/08  16:07:37  yuan
  26.  * Changed MAX_FILES from 100 to 250. 
  27.  * Incorporated the constant into FileList[MAX_FILES]
  28.  * 
  29.  * Revision 1.10  1993/10/27  12:42:50  yuan
  30.  * Added prototype for ReadFileBuf.
  31.  * 
  32.  * Revision 1.9  1993/09/29  17:54:09  yuan
  33.  * ReadFileRaw, etc. prototypes imported.
  34.  * 
  35.  * Revision 1.8  1993/09/27  17:12:48  yuan
  36.  * Cleaned up... function prototypes internal to pslib.c removed.
  37.  * 
  38.  * Revision 1.7  1993/09/21  17:22:14  yuan
  39.  * *** empty log message ***
  40.  * 
  41.  * Revision 1.6  1993/09/21  17:16:50  yuan
  42.  * cleaning up
  43.  * 
  44.  * Revision 1.5  1993/09/21  17:07:11  yuan
  45.  * broken and unbroken
  46.  * 
  47.  * Revision 1.4  1993/09/14  14:19:08  yuan
  48.  * header fixed.
  49.  * 
  50.  * Revision 1.3  1993/09/14  13:16:37  yuan
  51.  * Minor function prototype modifications were made.
  52.  * 
  53.  * Revision 1.2  1993/09/09  12:39:19  yuan
  54.  * compression routine prototypes moved to pslib.h
  55.  * 
  56.  * Revision 1.1  1993/09/08  16:16:07  yuan
  57.  * Initial revision
  58.  * 
  59.  *
  60.  */
  61.  
  62. #include "cflib.h"
  63. #include "time.h"
  64. #include "types.h"
  65.  
  66. #define TICKER (*(volatile int *)0x46C)
  67. #define USECS_PER_READING( start, stop, frames ) (((stop-start)*54945)/frames)
  68. #define MSECS_TOTAL_TIME( start, stop ) ((stop - start)*55)
  69.  
  70. #define MAX_FILES 500
  71.  
  72. #define ERROR_OPENING_FILE  21
  73. #define ERROR_WRITING_FILE  22
  74. #define ERROR_READING_DATA -20
  75.  
  76. typedef struct bit_file {
  77.     ubyte *buf;
  78.     int current_byte;
  79.     ubyte mask;
  80.     int rack;
  81.     int pacifier_counter;
  82.     int length;
  83. } BIT_BUF;
  84.  
  85. typedef struct lib_header {
  86.    char id[4];      // set to 'PSLB'
  87.    short nfiles;    // how many files in this library
  88. } lib_header;
  89.  
  90. typedef struct file_header {
  91.    char name[13];       // 8 chars, dot, extension, null
  92.    byte compression;    // compression method
  93.    int offset,          // where in the lib file
  94.        length,          // how much space in lib taken by this file
  95.        original_size;   // how long the actual (uncompressed) data is
  96. //   time_t time;         // the date & time, from the time() function
  97.    ushort date;         // the date
  98.    ushort time;         // the time
  99.    short ratio;         // this makes the structure 32 bytes
  100. } file_header;
  101.  
  102. // Date and time macros
  103.  
  104. #define YEAR(t)    (((t & 0xFE00) >> 9) + 1980)
  105. #define MONTH(t)   ((t & 0x01E0) >> 5)
  106. #define DAY(t)     (t & 0x001F)
  107. #define HOUR(t)    ((t & 0xF800) >> 11)
  108. #define MINUTE(t)  ((t & 0x07E0) >> 5)
  109. #define SECOND(t)  ((t & 0x001F) << 1)
  110.  
  111. // bitio function prototypes
  112.  
  113. BIT_BUF *OpenInputBitBuf( ubyte *buffer );
  114. BIT_BUF *OpenOutputBitBuf();
  115. void OutputBit( BIT_BUF *bit_file, int bit );
  116. void OutputBits( BIT_BUF *bit_file, unsigned int code, int count );
  117. int InputBit( BIT_BUF *bit_file );
  118. unsigned int InputBits( BIT_BUF *bit_file, int bit_count );
  119. void CloseInputBitBuf( BIT_BUF *bit_file );
  120. void CloseOutputBitBuf( BIT_BUF *bit_file );
  121. void FilePrintBinary( FILE *file, unsigned int code, int bits );
  122.  
  123. #define LISTING 1       // listing the library
  124. #define BUILDING 1      // building the library
  125. #define LF_LZW 1        // this file has LZW compression
  126.  
  127. #define MAX_FILE_SIZE 1024 * 100
  128.  
  129. // pslib function prototypes
  130.  
  131. int file_size( char *name );
  132. void header_count( char *argv );
  133. int read_data( FILE *fp, struct file_header *p );
  134. void init_library( char *filename, int numfiles );
  135. void write_file_header( char *filename, file_header Header );
  136.  
  137. //void print_usage( void );
  138. //void check_list( char *argv );
  139. //void list_files( void );
  140. //void cfr_test( char *input, char *output );
  141. //void cfw_test( char *input, char *output );
  142. //void extract_test( char *extractname, char *extractout );
  143. //void lib_read_test( char *extractname, char *extractout );
  144. //void process_arg( char *argv );
  145.  
  146.  
  147. extern char *Usage;
  148. extern char *CompressionName;
  149.  
  150. extern int lib_flag;           // library flag
  151. extern int b_flag;             // building flag
  152. extern int c_flag;             // compression flag
  153. extern int l_flag;             // listing flag
  154. extern int lib_flag;           // library flag
  155. extern FILE *InputLibFile;     // file to read from
  156. extern FILE *OutputLibFile;    // file to write to
  157. extern char *lib_name;         // name of the library
  158. extern int file_count;         // number of files processed
  159. extern int headers;            // number of header spaces allocated
  160. extern file_header Header;     // Holds header info of file being processed
  161. extern char *FileList[MAX_FILES];    // Contains the list of files being processed
  162. extern file_header *LibHeaderList;
  163. extern FILE *InputLibInitFile; // file to read from
  164. extern short init_numfiles;    // number of files in the library
  165.  
  166. void *ReadFileRaw( char *filename, int *length );
  167. // ReadFileRaw reads 'filename' and returns the buffer and passes the length
  168. // in bytes.
  169.  
  170. int WriteFile( char *filename, void *data, int length );
  171. // WriteFile writes 'length' bytes of 'data' to 'filename'
  172. //  returns an error code != 0 if there is an error.
  173.  
  174. int AppendFile( char *filename, void *data, int length );
  175. // AppendFile appends 'length' bytes of 'data' to 'filename'
  176. //  returns an error code != 0 if there is an error.
  177.  
  178.  
  179. 
  180.