98 char * entireFile = NULL;
100 FILE * fhandle = fopen( _filename,
"rb" );
107 memset( result, 0,
sizeof(
SIDFILE ) );
109 fseek( fhandle, 0, SEEK_END );
110 int fileSize = ftell( fhandle );
111 fseek( fhandle, 0, SEEK_SET );
113 entireFile =
malloc( fileSize );
114 memset( entireFile, 0, fileSize );
116 (void)!fread( entireFile, fileSize, 1, fhandle );
118 if ( _reloc_address ) {
120 char * relocatedFile =
malloc( fileSize );
121 memset( relocatedFile, 0, fileSize );
143 entireFile = relocatedFile;
150 memcpy( signature, entireFile, 4 );
158 if ( memcmp( signature,
"RSID", 4 ) && memcmp( signature,
"PSID", 4 ) ) {
159 sprintf( lastErrorString,
"Unable to load sid file, wrong signature: %2.2x%2.2x%2.2x%2.2x", signature[0], signature[1], signature[2], signature[3] );
193 switch ( header->
version[1] ) {
195 if ( dataOffset != 0x76 ) {
196 sprintf( lastErrorString,
"Unable to load sid, wrong offset for v1: %4.4x", dataOffset );
203 if ( dataOffset != 0x7c ) {
204 sprintf( lastErrorString,
"Unable to load sid, wrong offset for v%d: %4.4x", header->
version[1], dataOffset );
209 sprintf( lastErrorString,
"Unknown version (%d)", header->
version[1] );
229 memcpy( &header->
loadAddress[0], &entireFile[dataOffset], 2 );
266 if ( memcmp( signature,
"RSID", 4 ) == 0 ) {
268 sprintf( lastErrorString,
"Unable to load sid, RSID on ROM: %4.4x", result->
initAddress );
272 sprintf( lastErrorString,
"Unable to load sid, RSID on ZERO PAGE: %4.4x\n", result->
initAddress );
330 fileSize -= dataOffset;
332 memset( result->
data, 0, fileSize );
333 memcpy( result->
data, &entireFile[dataOffset], fileSize );
334 result->
size = fileSize;