示例#1
0
/*
-----------------------------------------------------------------------------
 Function: CAL_SetupMapFile -Setup map files for decoding.
 
 Parameters: extension -[in] file extension for map data files.
 
 Returns: Non-zero on success, zero otherwise.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupMapFile( const char *extension )
{
	FILE *handle;
	SW32 length;
	char fname[ 13 ];
	
	
//
// load maphead.xxx (offsets and tileinfo for map file)
//
	cs_strlcpy( fname, MAPHEADNAME, sizeof( fname ) );
	cs_strlcat( fname, extension, sizeof( fname ) );

	handle = fopen( cs_strupr( fname ), "rb" );
	if( handle == NULL )
	{
		handle = fopen( cs_strlwr( fname ), "rb" );
		if( handle == NULL )
		{
			printf( "Could not open file (%s) for read!\n", fname );
			return 0;
		}
	}

	length = FS_FileLength( handle );
	

	fread( &RLEWtag, 2, 1, handle );
	
	for( TotalMaps = 0 ; TotalMaps < length ; ++TotalMaps )
	{
		fread( &headeroffsets[ TotalMaps ], 4, 1, handle );		
		if( ! headeroffsets[ TotalMaps ] )
		{
			break;
		}
	}


	fclose( handle );



	cs_strlcpy( fname, MAPNAME, sizeof( fname ) );
	cs_strlcat( fname, extension, sizeof( fname ) );
	
	maphandle = fopen( cs_strupr( fname ), "rb");
	if( NULL == maphandle )
	{
		maphandle = fopen( cs_strlwr( fname ), "rb");
		if( NULL == maphandle )
		{
			return 0;
		}
	}


	return 1;
}
示例#2
0
/*
-----------------------------------------------------------------------------
 Function: CAL_SetupGrFile() -Initialize graphic files and arrays.
 
 Parameters: extension -[in] Pointer to a null-terminated string that 
                            specifies the file extension.
                            (must be in '.XXX' format).
 
 Returns: 1 on success, 0 otherwise.
 
 Notes: 
        Uses global variables grhandle and pictable.
        1. Open vgadict.XXX, read huffman dictionary data.
        2. Open vgahead.XXX, read data offsets.
        3. Open vgagraph.XXX, read pic and sprite header, expand data.
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupGrFile( const char *extension )
{
	void *compseg;
	FILE *handle;
	char filename[ 16 ];
	SW32 chunkcomplen; // chunk compressed length
	
//
// load vgadict.ext (huffman dictionary for graphics files)
//
	cs_strlcpy( filename, GFXDICTFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( handle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( handle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
	fread( grhuffman, sizeof( grhuffman ), 1, handle );
	fclose( handle );
	
//
// Open then load the data offsets from vgahead.ext
//	
	
	cs_strlcpy( filename, GFXHEADFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( (handle = fopen( cs_strupr( filename ), "rb" )) ==  NULL )
	{
		if( (handle = fopen( cs_strlwr( filename ), "rb" )) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
	
	grstarts = MM_MALLOC( (NUMCHUNKS+1) * FILEPOSSIZE );
	if( grstarts == NULL )
	{
		return 0;
	}
  
	fread( grstarts, sizeof( long ), (NUMCHUNKS+1) * FILEPOSSIZE, handle );
	
	fclose( handle );
	
//
// Open the graphics file 'vgagraph.XXX'.
//
	
	cs_strlcpy( filename, GFXFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( grhandle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( grhandle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
//
// load the pic and sprite headers into the arrays.
//
	pictable = MM_MALLOC( NUMPICS * sizeof( pictabletype ) );
	if( pictable == NULL )
	{
		return 0;
	}
  
  
	chunkcomplen = CAL_GetGrChunkLength( STRUCTPIC );  // position file pointer
	
	compseg = MM_MALLOC( chunkcomplen );
	if( compseg == NULL )
	{
		return 0;
	}
	
	fread( compseg, chunkcomplen, 1, grhandle );
	
	CAL_HuffExpand( compseg, (PW8)pictable, 
	                NUMPICS * sizeof( pictabletype ), 
                    grhuffman );

	MM_FREE( compseg ); 
 
    return 1;                 
}
示例#3
0
/*
-----------------------------------------------------------------------------
 Function: CAL_SetupAudioFile() -Setup for decoding audio data.
 
 Parameters: fextension -[in] Pointer to string with file extension.
 
 Returns: Non-zero on success, otherwise zero.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupAudioFile( const char *fextension )
{
	FILE *handle;
	SW32 length;
	W32 count;
	char fname[ 13 ];

	if( ! fextension || ! *fextension )
	{
		printf( "NULL extension passed into CAL_SetupAudioFile!\n" );
		
		return 0;	
	}

//
// load audiohed.XXX (offsets and lengths for audio file)
//
	cs_strlcpy( fname, AHEADFNAME, sizeof( fname ) );
	cs_strlcat( fname, fextension, sizeof( fname ) );
	
    handle = fopen( cs_strupr( fname ), "rb" );
	if( handle == NULL )
	{
		handle = fopen( cs_strlwr( fname ), "rb" );
		
		if( handle == NULL )
		{
			printf( "Can not open file (%s) for read!\n", fname );
			return 0;
		}
    }

	length = FS_FileLength( handle );
	if( length < 4 )
	{
		fclose( handle );
		printf( "Incorrect audio header size on file: %s\n", fname );
		return 0;
	}

	audiostarts = (PW32) MM_MALLOC( length );
	if( audiostarts == NULL )
	{
		return 0;
	}
	
	count = fread( audiostarts, sizeof( W32 ), length >> 2, handle );
	if( count != (W32)(length >> 2) )
    {
        fclose( handle );
        printf( "[Error]: Read error on file: (%s)", fname  );
		return 0;
	}
	
	
	fclose( handle );

//
// open the Audio data file
//
	cs_strlcpy( fname, AUDIOFNAME, sizeof( fname ) );
	cs_strlcat( fname, fextension, sizeof( fname ) );
	
	audiohandle = fopen( cs_strupr( fname ), "rb" );
	if( audiohandle == NULL )
	{
		audiohandle = fopen( cs_strlwr( fname ), "rb" );
		if( audiohandle == NULL )
		{
			printf( "Could not open file (%s) for read!\n", fname ); 
			return 0;
		}
    }
    
    return 1;
}