File Subsystem

The file subsystem is used to load resources from either the file system or a MIX/TLK container.
struct file_container_t      // MIX/TLK file container
{
    INT16 number_of_entries;            // Number of Entries [Read from file]
    INT32 data_segment_byte_length;     // Byte length of data segment [Read from file]
    INT32 header_segment_byte_length;   // Byte length of header segment
    INT32 ready_state;                  // This data structure: 0 = Not ready 1 = Ready
    INT32 hash_type;                    // file name hash type, 0 = MIX, 1 = TLK
    file_entry_t *entries;              // Dictionary of Entries [Read from file]
    file_handle_t *file;                // File handle data structure
    UINT32 *file_entry_offsets;         // File location offsets into MIX/TLK | Allocated as: sizeof(UINT32) * number_of_entries
    INT32 status;                       // Status of data stucture: 0 = free 1 = active
    CHAR  file_name[ 24 ];              // file name
    INT32 file_type;                    // File container type: 0 = MIX, 1 = TLK
    INT32 access_time;                  // timeGetTimeValue
};


struct file_entry_t             // MIX/TLK internal file entry
{
    INT32 id;                   // Id file name hash 
    INT32 offset;               // Byte offset in data segment   
    INT32 byte_length;          // Byte length of data
};


struct file_handle_t  // File Handle Structure
{
    FILE  *file_handle;     // File handle
    struct stat statBuffer; // Status information of file
    CHAR  file_name[ 260 ]; // Absolute path with file name
    INT32 ready_state;      // Status of data structure: 0 = Not ready 1 = Ready
};


struct file_location_t        // File Location Structure
{
    file_handle_t *file;      // File handle data structure
    INT32 file_found_system;  // Was file found in file system? Yes = 1, No = 0
    INT32 file_loaded_system; // Was file loaded from file system. Yes = 1, No = 0
    
    INT32 file_found_mix;     // Was file found in MIX/TLK container? Yes = 1, No = 0
    INT32 file_loaded_mix;    // Was file loaded from MIX/TLK container? Yes = 1, No = 0 
    
    INT32 mix_index;          // MIX/TLK Index 
    INT32 mix_entry_index;    // MIX/TLK Entry Index 
};