home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / lib / library.h < prev    next >
C/C++ Source or Header  |  1998-06-08  |  6KB  |  174 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.9 $
  16.  * $Author: yuan $
  17.  * $Date: 1993/09/29 17:54:09 $
  18.  *
  19.  * PSLIB and library generation tool header file.
  20.  *
  21.  * $Log: library.h $
  22.  * Revision 1.9  1993/09/29  17:54:09  yuan
  23.  * ReadFileRaw, etc. prototypes imported.
  24.  * 
  25.  * Revision 1.8  1993/09/27  17:12:48  yuan
  26.  * Cleaned up... function prototypes internal to pslib.c removed.
  27.  * 
  28.  * Revision 1.7  1993/09/21  17:22:14  yuan
  29.  * *** empty log message ***
  30.  * 
  31.  * Revision 1.6  1993/09/21  17:16:50  yuan
  32.  * cleaning up
  33.  * 
  34.  * Revision 1.5  1993/09/21  17:07:11  yuan
  35.  * broken and unbroken
  36.  * 
  37.  * Revision 1.4  1993/09/14  14:19:08  yuan
  38.  * header fixed.
  39.  * 
  40.  * Revision 1.3  1993/09/14  13:16:37  yuan
  41.  * Minor function prototype modifications were made.
  42.  * 
  43.  * Revision 1.2  1993/09/09  12:39:19  yuan
  44.  * compression routine prototypes moved to pslib.h
  45.  * 
  46.  * Revision 1.1  1993/09/08  16:16:07  yuan
  47.  * Initial revision
  48.  * 
  49.  *
  50.  */
  51.  
  52. #include "cflib.h"
  53. #include "time.h"
  54. #include "types.h"
  55.  
  56. #define TICKER (*(volatile int *)0x46C)
  57. #define USECS_PER_READING( start, stop, frames ) (((stop-start)*54945)/frames)
  58. #define MSECS_TOTAL_TIME( start, stop ) ((stop - start)*55)
  59.  
  60. #define MAX_FILES 100
  61.  
  62. #define ERROR_OPENING_FILE  21
  63. #define ERROR_WRITING_FILE  22
  64. #define ERROR_READING_DATA -20
  65.  
  66. typedef struct bit_file {
  67.     ubyte *buf;
  68.     int current_byte;
  69.     ubyte mask;
  70.     int rack;
  71.     int pacifier_counter;
  72.     int length;
  73. } BIT_BUF;
  74.  
  75. typedef struct lib_header {
  76.    char id[4];      // set to 'PSLB'
  77.    short nfiles;    // how many files in this library
  78. } lib_header;
  79.  
  80. typedef struct file_header {
  81.    char name[13];       // 8 chars, dot, extension, null
  82.    byte compression;    // compression method
  83.    int offset,          // where in the lib file
  84.        length,          // how much space in lib taken by this file
  85.        original_size;   // how long the actual (uncompressed) data is
  86. //   time_t time;         // the date & time, from the time() function
  87.    ushort date;         // the date
  88.    ushort time;         // the time
  89.    short ratio;         // this makes the structure 32 bytes
  90. } file_header;
  91.  
  92. // Date and time macros
  93.  
  94. #define YEAR(t)    (((t & 0xFE00) >> 9) + 1980)
  95. #define MONTH(t)   ((t & 0x01E0) >> 5)
  96. #define DAY(t)     (t & 0x001F)
  97. #define HOUR(t)    ((t & 0xF800) >> 11)
  98. #define MINUTE(t)  ((t & 0x07E0) >> 5)
  99. #define SECOND(t)  ((t & 0x001F) << 1)
  100.  
  101. // bitio function prototypes
  102.  
  103. BIT_BUF *OpenInputBitBuf( ubyte *buffer );
  104. BIT_BUF *OpenOutputBitBuf();
  105. void OutputBit( BIT_BUF *bit_file, int bit );
  106. void OutputBits( BIT_BUF *bit_file, unsigned int code, int count );
  107. int InputBit( BIT_BUF *bit_file );
  108. unsigned int InputBits( BIT_BUF *bit_file, int bit_count );
  109. void CloseInputBitBuf( BIT_BUF *bit_file );
  110. void CloseOutputBitBuf( BIT_BUF *bit_file );
  111. void FilePrintBinary( FILE *file, unsigned int code, int bits );
  112.  
  113. #define LISTING 1       // listing the library
  114. #define BUILDING 1      // building the library
  115. #define LF_LZW 1        // this file has LZW compression
  116.  
  117. #define MAX_FILE_SIZE 1024 * 100
  118.  
  119. // pslib function prototypes
  120.  
  121. int file_size( char *name );
  122. void header_count( char *argv );
  123. int read_data( FILE *fp, struct file_header *p );
  124. void init_library( char *filename, int numfiles );
  125. void write_file_header( char *filename, file_header Header );
  126.  
  127. //void print_usage( void );
  128. //void check_list( char *argv );
  129. //void list_files( void );
  130. //void cfr_test( char *input, char *output );
  131. //void cfw_test( char *input, char *output );
  132. //void extract_test( char *extractname, char *extractout );
  133. //void lib_read_test( char *extractname, char *extractout );
  134. //void process_arg( char *argv );
  135.  
  136.  
  137. extern char *Usage;
  138. extern char *CompressionName;
  139.  
  140. extern int lib_flag;           // library flag
  141. extern int b_flag;             // building flag
  142. extern int c_flag;             // compression flag
  143. extern int l_flag;             // listing flag
  144. extern int lib_flag;           // library flag
  145. extern FILE *InputLibFile;     // file to read from
  146. extern FILE *OutputLibFile;    // file to write to
  147. extern char *lib_name;         // name of the library
  148. extern int file_count;         // number of files processed
  149. extern int headers;            // number of header spaces allocated
  150. extern file_header Header;     // Holds header info of file being processed
  151. extern char *FileList[100];    // Contains the list of files being processed
  152. extern file_header *LibHeaderList;
  153. extern FILE *InputLibInitFile; // file to read from
  154. extern short init_numfiles;    // number of files in the library
  155.  
  156. void *ReadFileRaw( char *filename, int *length );
  157. // ReadFileRaw reads 'filename' and returns the buffer and passes the length
  158. // in bytes.
  159.  
  160. int WriteFile( char *filename, void *data, int length );
  161. // WriteFile writes 'length' bytes of 'data' to 'filename'
  162. //  returns an error code != 0 if there is an error.
  163.  
  164. int AppendFile( char *filename, void *data, int length );
  165. // AppendFile appends 'length' bytes of 'data' to 'filename'
  166. //  returns an error code != 0 if there is an error.
  167.  
  168. int ReadFileBuf( char *filename, byte *buf, int bufsize );
  169. // ReadFileBuf reads bufize bytes of 'filename' into the address of 'buf'
  170. //  returns an error code < 0 if there is an error.
  171.  
  172.  
  173.  
  174.