// Filename : PCFILE.C // Coded by : Scott Evans (MMV4 team) // Description : PC file functions // // History : 23/11/98 Created #include "pcfile.h" // Function : InitPCFile() // Coded by : Scott Evans (MMV4 team) // Created/Modified : 23/11/98 // // Description : Initialises the PC file system // // Parameters : None // // Returns : 0 if no problems with initialisation // // Notes : None long InitPCFile(void) { long r; r=PCinit(); #ifdef DEBUG_INFO if(r!=0) PrintFM("Failed\n"); else PrintFM("Completed\n"); #endif return(r); } // Function : ClosePCFile() // Coded by : Scott Evans (MMV4 team) // Created/Modified : 23/11/98 // // Description : Close PC file system // // Parameters : None // // Returns : None // // Notes : None void ClosePCFile(void) { PCinit(); } // Function : GetFileSize() // Coded by : Scott Evans (MMV4 team) // Created/Modified : 23/11/98 // // Description : Find the size of a file (in bytes) // // Parameters : fh - handle of open file // // Returns : Size of file // // Notes : None u_long GetFileSize(u_long fh) { long size; // Find size of file size=PClseek(fh,0,2); // Return pointer back to start of file PClseek(fh,0,0); // Return the file size return(size); } // Function : LoadPCFile() // Coded by : Scott Evans (MMV4 team) // Created/Modified : 23/11/98 // // Description : Load a file // // Parameters : fname - name of file // buffer - where to load file // // Returns : Bytes read, 0 for error // // Notes : None long LoadPCFile(u_byte *fname,u_byte *buffer) { long fh,size,count; // Open the file if((fh=PCopen(fname,0,0))>=0) { // Read in the file size=GetFileSize(fh); count=PCread(fh,buffer,size); // Close the file PCclose(fh); // Did we get it all if(count==size) { #ifdef DEBUG_INFO sprintf(fm_string,"%s %d bytes (%x)\n",fname,size,buffer); PrintFM(fm_string); #endif return(size); } } #ifdef DEBUG_INFO sprintf(fm_string,"Failed (%s)\n",fname); PrintFM(fm_string); #endif return(0); } // Function : SavePCFile() // Coded by : Scott Evans (MMV4 team) // Created/Modified : 23/11/98 // // Description : Save a file // // Parameters : fname - name of file // buffer - data to save // size - number of bytes to write // // Returns : Size of file, 0 for error // // Notes : None long SavePCFile(u_byte *fname,u_byte *buffer,u_long size) { long fh,count; // Open the file if((fh=PCcreat(fname,0))>=0) { // Write data to the file count=PCwrite(fh,buffer,size); // Close the file PCclose(fh); // Did we get it all if(count==size) { #ifdef DEBUG_INFO sprintf(fm_string,"%s %d bytes\n",fname,size); PrintFM(fm_string); #endif return(size); } } #ifdef DEBUG_INFO sprintf(fm_string,"Failed (%s)\n",fname); PrintFM(fm_string); #endif return(0); } // Function : GetFileSize2() // Coded by : Scott Evans (MMV4 team) // Created/Modified : 23/11/98 // // Description : Find the size of a file (in bytes) // // Parameters : fname - name of file // // Returns : Size of file // // Notes : None u_long GetFileSize2(u_byte *fname) { long fh,size; if((fh=PCopen(fname,0,0))>=0) { // Find size of file size=PClseek(fh,0,2); // Return pointer back to start of file PClseek(fh,0,0); // Return the file size return(size); } return(0); }