Mercurial > hg > xmms-sid
comparison src/xs_length.c @ 968:5e0a05c84694
Fix RSID MD5 hash calculation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 21 Nov 2012 00:14:52 +0200 |
parents | 3c2efa18c422 |
children | b9e6f929a617 |
comparison
equal
deleted
inserted
replaced
967:0233c5fd7d5e | 968:5e0a05c84694 |
---|---|
343 | 343 |
344 /* Compute md5hash of given SID-file | 344 /* Compute md5hash of given SID-file |
345 */ | 345 */ |
346 typedef struct | 346 typedef struct |
347 { | 347 { |
348 gchar magicID[4]; /* "PSID" / "RSID" magic identifier */ | 348 gchar magic[4]; /* "PSID" / "RSID" magic identifier */ |
349 guint16 version, /* Version number */ | 349 guint16 version, /* Version number */ |
350 dataOffset, /* Start of actual c64 data in file */ | 350 dataOffset, /* Start of actual c64 data in file */ |
351 loadAddress, /* Loading address */ | 351 loadAddress, /* Loading address */ |
352 initAddress, /* Initialization address */ | 352 initAddress, /* Initialization address */ |
353 playAddress, /* Play one frame */ | 353 playAddress, /* Play one frame */ |
375 psidv1_header_t psidH; | 375 psidv1_header_t psidH; |
376 psidv2_header_t psidH2; | 376 psidv2_header_t psidH2; |
377 guint8 *songData = NULL; | 377 guint8 *songData = NULL; |
378 guint8 ib8[2], i8; | 378 guint8 ib8[2], i8; |
379 gint index, result; | 379 gint index, result; |
380 gboolean isRSID; | |
380 | 381 |
381 /* Try to open the file */ | 382 /* Try to open the file */ |
382 if ((inFile = xs_fopen(filename, "rb")) == NULL) | 383 if ((inFile = xs_fopen(filename, "rb")) == NULL) |
383 goto error; | 384 goto error; |
384 | 385 |
385 /* Read PSID header in */ | 386 /* Read PSID header in */ |
386 if (!xs_fread_str(inFile, psidH.magicID, sizeof(psidH.magicID)) || | 387 if (!xs_fread_str(inFile, psidH.magic, sizeof(psidH.magic)) || |
387 !xs_fread_be16(inFile, &psidH.version) || | 388 !xs_fread_be16(inFile, &psidH.version) || |
388 !xs_fread_be16(inFile, &psidH.dataOffset) || | 389 !xs_fread_be16(inFile, &psidH.dataOffset) || |
389 !xs_fread_be16(inFile, &psidH.loadAddress) || | 390 !xs_fread_be16(inFile, &psidH.loadAddress) || |
390 !xs_fread_be16(inFile, &psidH.initAddress) || | 391 !xs_fread_be16(inFile, &psidH.initAddress) || |
391 !xs_fread_be16(inFile, &psidH.playAddress) || | 392 !xs_fread_be16(inFile, &psidH.playAddress) || |
402 psidH.version < 1 || psidH.version > 3) | 403 psidH.version < 1 || psidH.version > 3) |
403 { | 404 { |
404 xs_error("Not a supported PSID or RSID file '%s'\n", filename); | 405 xs_error("Not a supported PSID or RSID file '%s'\n", filename); |
405 goto error; | 406 goto error; |
406 } | 407 } |
407 | 408 |
409 isRSID = psidH.magic[0] == 'R'; | |
410 | |
408 if (!xs_fread_str(inFile, psidH.sidName, sizeof(psidH.sidName)) || | 411 if (!xs_fread_str(inFile, psidH.sidName, sizeof(psidH.sidName)) || |
409 !xs_fread_str(inFile, psidH.sidAuthor, sizeof(psidH.sidAuthor)) || | 412 !xs_fread_str(inFile, psidH.sidAuthor, sizeof(psidH.sidAuthor)) || |
410 !xs_fread_str(inFile, psidH.sidCopyright, sizeof(psidH.sidCopyright))) | 413 !xs_fread_str(inFile, psidH.sidCopyright, sizeof(psidH.sidCopyright))) |
411 { | 414 { |
412 xs_error("Error reading SID file header from '%s'\n", filename); | 415 xs_error("Error reading SID file header from '%s'\n", filename); |
469 XSADDHASH(psidH.playAddress); | 472 XSADDHASH(psidH.playAddress); |
470 XSADDHASH(psidH.nSongs); | 473 XSADDHASH(psidH.nSongs); |
471 #undef XSADDHASH | 474 #undef XSADDHASH |
472 | 475 |
473 /* Append song speed data to hash */ | 476 /* Append song speed data to hash */ |
474 i8 = 0; | 477 i8 = isRSID ? 60 : 0; |
475 for (index = 0; index < psidH.nSongs && index < 32; index++) | 478 for (index = 0; index < psidH.nSongs && index < 32; index++) |
476 { | 479 { |
477 i8 = (psidH.speed & (1 << index)) ? 60 : 0; | 480 if (isRSID) |
481 i8 = 60; | |
482 else | |
483 i8 = (psidH.speed & (1 << index)) ? 60 : 0; | |
484 | |
478 xs_md5_append(&inState, &i8, sizeof(i8)); | 485 xs_md5_append(&inState, &i8, sizeof(i8)); |
479 } | 486 } |
480 | 487 |
481 /* Rest of songs (more than 32) */ | 488 /* Rest of songs (more than 32) */ |
482 for (index = 32; index < psidH.nSongs; index++) | 489 for (index = 32; index < psidH.nSongs; index++) |