annotate sidinfo.c @ 1:25a3a142e909

Moar work.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 24 Sep 2014 22:15:55 +0300
parents 8e7e08bf7b9e
children ffb795582a91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "th_args.h"
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "th_endian.h"
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "th_crypto.h"
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
5 #define PSID_BUFFER_SIZE (1024 * 16)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
6
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 typedef struct
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 char magic[4]; // "PSID" / "RSID" magic identifier
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 uint16_t version, // Version number
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 dataOffset, // Start of actual c64 data in file
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 loadAddress, // Loading address
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 initAddress, // Initialization address
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 playAddress, // Play one frame
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 nSongs, // Number of subsongs
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 startSong; // Default starting song
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 uint32_t speed; // Speed
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 char sidName[32]; // Descriptive text-fields, ASCIIZ
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 char sidAuthor[32];
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 char sidCopyright[32];
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 // PSIDv2 data
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 uint16_t flags; // Flags
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 uint8_t startPage, pageLength;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 uint16_t reserved;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
28 // Extra data
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 BOOL isRSID;
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
30 size_t dataSize; // Total size of data - header
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
31 th_md5hash_t hash; // Songlength database hash
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 } PSIDHeader;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
36 int si_read_sid_file(FILE *inFile, PSIDHeader *psid)
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
38 th_md5state_t state;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
39 uint8_t tmp8, *fileData = NULL;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
40 int index, ret = -1;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
41 size_t read;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
42 BOOL first;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 memset(psid, 0, sizeof(*psid));
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
46 if ((fileData = (uint8_t *) th_malloc(PSID_BUFFER_SIZE)) == NULL)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
48 THERR("Error allocating temporary data buffer of %d bytes.\n", PSID_BUFFER_SIZE);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
49 goto error;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
50 }
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 // Read PSID header in
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
53 if (!th_fread_str(inFile, (uint8_t *) psid->magic, sizeof(psid->magic)) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
54 !th_fread_be16(inFile, &psid->version) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
55 !th_fread_be16(inFile, &psid->dataOffset) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
56 !th_fread_be16(inFile, &psid->loadAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
57 !th_fread_be16(inFile, &psid->initAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
58 !th_fread_be16(inFile, &psid->playAddress) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
59 !th_fread_be16(inFile, &psid->nSongs) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
60 !th_fread_be16(inFile, &psid->startSong) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
61 !th_fread_be32(inFile, &psid->speed))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
63 THERR("Could not read PSID/RSID header.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 if ((psid->magic[0] != 'R' && psid->magic[0] != 'P') ||
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 psid->magic[1] != 'S' || psid->magic[2] != 'I' || psid->magic[3] != 'D' ||
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 psid->version < 1 || psid->version > 3)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
71 THERR("Not a supported PSID or RSID file.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
75 psid->isRSID = psid->magic[0] == 'R';
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
77 if (!th_fread_str(inFile, (uint8_t *)psid->sidName, sizeof(psid->sidName)) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
78 !th_fread_str(inFile, (uint8_t *)psid->sidAuthor, sizeof(psid->sidAuthor)) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
79 !th_fread_str(inFile, (uint8_t *)psid->sidCopyright, sizeof(psid->sidCopyright)))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
81 THERR("Error reading SID file header.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 // Check if we need to load PSIDv2NG header ...
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 if (psid->version >= 2)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 // Yes, we need to
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
89 if (!th_fread_be16(inFile, &psid->flags) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
90 !th_fread_byte(inFile, &psid->startPage) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
91 !th_fread_byte(inFile, &psid->pageLength) ||
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
92 !th_fread_be16(inFile, &psid->reserved))
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
94 THERR("Error reading PSID/RSID v2+ extra header data.\n");
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 goto error;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
99 // Initialize MD5-hash calculation
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
100 th_md5_init(&state);
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
102 // Process actual data
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
103 psid->dataSize = 0;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
104 first = TRUE;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
105 do {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
106 read = fread(fileData, sizeof(uint8_t), PSID_BUFFER_SIZE, inFile);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
107 psid->dataSize += read;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
108 if (read < 16)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
109 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
110 THERR("Error reading song data, unexpectedly small file.\n");
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
111 goto error;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
112 }
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
114 if (first && psid->loadAddress == 0)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
115 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
116 // Strip load address (2 first bytes)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
117 th_md5_append(&state, &fileData[2], read - 2);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
118 first = FALSE;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
119 }
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
120 else
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
121 {
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
122 // Append "as is"
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
123 th_md5_append(&state, fileData, read);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
124 }
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
125 } while (read > 0 && !feof(inFile));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
127 // Append header data to hash
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 #define THADDHASH(QDATAB) do { \
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 uint8_t ib8[2]; \
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 ib8[0] = (QDATAB & 0xff); \
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 ib8[1] = (QDATAB >> 8); \
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
132 th_md5_append(&state, (uint8_t *) &ib8, sizeof(ib8)); \
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 } while (0)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 THADDHASH(psid->initAddress);
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 THADDHASH(psid->playAddress);
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 THADDHASH(psid->nSongs);
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 #undef THADDHASH
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 // Append song speed data to hash
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
141 tmp8 = psid->isRSID ? 60 : 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 for (index = 0; index < psid->nSongs && index < 32; index++)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 {
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
144 if (psid->isRSID)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
145 tmp8 = 60;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 else
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
147 tmp8 = (psid->speed & (1 << index)) ? 60 : 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
149 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 // Rest of songs (more than 32)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 for (index = 32; index < psid->nSongs; index++)
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
154 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 // PSIDv2NG specific
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 if (psid->version >= 2)
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 // REFER TO SIDPLAY HEADERS FOR MORE INFORMATION
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
160 tmp8 = (psid->flags >> 2) & 3;
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
161 if (tmp8 == 2)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
162 th_md5_append(&state, &tmp8, sizeof(tmp8));
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 // Calculate the hash
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
166 th_md5_finish(&state, psid->hash);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
167 ret = 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
169 error:
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 // Free buffer
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
171 th_free(fileData);
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
172 return ret;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 }
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 int main(int argc, char *argv[])
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 {
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 // Initialize
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 th_init("SIDInfo", "PSID/RSID information displayer", "0.1", NULL, NULL);
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 th_verbosityLevel = 0;
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 // Try to open the file
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
184 // if ((inFile = fopen(inFilename, "rb")) == NULL)
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
185 // goto error;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186
1
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
187
25a3a142e909 Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
188 return 0;
0
8e7e08bf7b9e Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 }