Develop and Download Open Source Software

Browse CVS Repository

Contents of /mame32jp/mame32jp/src/audit.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Wed Apr 24 03:53:20 2002 UTC (21 years, 11 months ago) by zero
Branch: MAIN
CVS Tags: ver_0_60_1, ver0_59_13, ver0_59_14, ver0_60_2, ver0_60_3, ver0_60_4, ver0_60_5, HEAD
Changes since 1.4: +0 -0 lines
File MIME type: text/x-csrc
*** empty log message ***

1 #include "driver.h"
2 #include <string.h>
3 #include "audit.h"
4
5
6 static tAuditRecord *gAudits = NULL;
7
8
9
10 /* returns 1 if rom is defined in this set */
11 int RomInSet (const struct GameDriver *gamedrv, unsigned int crc)
12 {
13 const struct RomModule *region, *rom;
14
15 for (region = rom_first_region(gamedrv); region; region = rom_next_region(region))
16 for (rom = rom_first_file(region); rom; rom = rom_next_file(rom))
17 if (ROM_GETCRC(rom) == crc)
18 return 1;
19
20 return 0;
21 }
22
23
24 /* returns nonzero if romset is missing */
25 int RomsetMissing (int game)
26 {
27 const struct GameDriver *gamedrv = drivers[game];
28
29 if (gamedrv->clone_of)
30 {
31 tAuditRecord *aud;
32 int count;
33 int i;
34
35 #if 1
36 int cloneRomsFound = 0;
37 int uniqueRomsFound = 0;
38
39 if ((count = AuditRomSet (game, &aud)) == 0)
40 return 1;
41
42 if (count == -1) return 0;
43
44 /* count number of roms found that are unique to clone */
45 for (i = 0; i < count; i++)
46 if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
47 {
48 uniqueRomsFound++;
49 if (aud[i].status != AUD_ROM_NOT_FOUND)
50 cloneRomsFound++;
51 }
52 #else
53 int cloneRomsFound = 0;
54
55 if ((count = AuditRomSet (game, &aud)) == 0)
56 return 1;
57
58 if (count == -1) return 0;
59
60 /* count number of roms found that are unique to clone */
61 for (i = 0; i < count; i++)
62 if (aud[i].status != AUD_ROM_NOT_FOUND)
63 if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
64 cloneRomsFound++;
65 #endif
66
67 return !cloneRomsFound;
68 }
69 else
70 return !osd_faccess (gamedrv->name, OSD_FILETYPE_ROM);
71 }
72
73
74 /* Fills in an audit record for each rom in the romset. Sets 'audit' to
75 point to the list of audit records. Returns total number of roms
76 in the romset (same as number of audit records), 0 if romset missing. */
77 int AuditRomSet (int game, tAuditRecord **audit)
78 {
79 const struct RomModule *region, *rom, *chunk;
80 const char *name;
81 const struct GameDriver *gamedrv;
82
83 int count = 0;
84 tAuditRecord *aud;
85 int err;
86
87 if (!gAudits)
88 gAudits = (tAuditRecord *)malloc (AUD_MAX_ROMS * sizeof (tAuditRecord));
89
90 if (gAudits)
91 *audit = aud = gAudits;
92 else
93 return 0;
94
95
96 gamedrv = drivers[game];
97
98 if (!gamedrv->rom) return -1;
99
100 /* check for existence of romset */
101 if (!osd_faccess (gamedrv->name, OSD_FILETYPE_ROM))
102 {
103 /* if the game is a clone, check for parent */
104 if (gamedrv->clone_of == 0 || (gamedrv->clone_of->flags & NOT_A_DRIVER) ||
105 !osd_faccess(gamedrv->clone_of->name,OSD_FILETYPE_ROM))
106 return 0;
107 }
108
109 for (region = rom_first_region(gamedrv); region; region = rom_next_region(region))
110 for (rom = rom_first_file(region); rom; rom = rom_next_file(rom))
111 {
112 const struct GameDriver *drv;
113
114 name = ROM_GETNAME(rom);
115 strcpy (aud->rom, name);
116 aud->explength = 0;
117 aud->length = 0;
118 aud->expchecksum = ROM_GETCRC(rom);
119 /* NS981003: support for "load by CRC" */
120 aud->checksum = ROM_GETCRC(rom);
121 count++;
122
123 /* obtain CRC-32 and length of ROM file */
124 drv = gamedrv;
125 do
126 {
127 err = osd_fchecksum (drv->name, name, &aud->length, &aud->checksum);
128 drv = drv->clone_of;
129 } while (err && drv);
130
131 /* spin through ROM_CONTINUEs, totaling length */
132 for (chunk = rom_first_chunk(rom); chunk; chunk = rom_next_chunk(chunk))
133 aud->explength += ROM_GETLENGTH(chunk);
134
135 if (err)
136 {
137 if (!aud->expchecksum)
138 /* not found but it's not good anyway */
139 aud->status = AUD_NOT_AVAILABLE;
140 else
141 /* not found */
142 aud->status = AUD_ROM_NOT_FOUND;
143 }
144 /* all cases below assume the ROM was at least found */
145 else if (aud->explength != aud->length)
146 aud->status = AUD_LENGTH_MISMATCH;
147 else if (aud->checksum != aud->expchecksum)
148 {
149 if (!aud->expchecksum)
150 aud->status = AUD_ROM_NEED_DUMP; /* new case - found but not known to be dumped */
151 else if (aud->checksum == BADCRC (aud->expchecksum))
152 aud->status = AUD_ROM_NEED_REDUMP;
153 else
154 aud->status = AUD_BAD_CHECKSUM;
155 }
156 else
157 aud->status = AUD_ROM_GOOD;
158
159 aud++;
160 }
161
162 #ifdef MESS
163 if (!count)
164 return -1;
165 else
166 #endif
167 return count;
168 }
169
170
171 /* Generic function for evaluating a romset. Some platforms may wish to
172 call AuditRomSet() instead and implement their own reporting (like MacMAME). */
173 int VerifyRomSet (int game, verify_printf_proc verify_printf)
174 {
175 tAuditRecord *aud;
176 int count;
177 int archive_status = 0;
178 const struct GameDriver *gamedrv = drivers[game];
179
180 if ((count = AuditRomSet (game, &aud)) == 0)
181 return NOTFOUND;
182
183 if (count == -1) return CORRECT;
184
185 #if 1
186 if (gamedrv->clone_of)
187 {
188 int i;
189 int cloneRomsFound = 0;
190 int uniqueRomsFound = 0;
191
192 /* count number of roms found that are unique to clone */
193 for (i = 0; i < count; i++)
194 if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
195 {
196 uniqueRomsFound++;
197 if (aud[i].status != AUD_ROM_NOT_FOUND)
198 cloneRomsFound++;
199 }
200
201 #ifndef MESS
202 /* Different MESS systems can use the same ROMs */
203 if (uniqueRomsFound && !cloneRomsFound)
204 return CLONE_NOTFOUND;
205 #endif
206 }
207 #else
208 if (gamedrv->clone_of)
209 {
210 int i;
211 int cloneRomsFound = 0;
212
213 /* count number of roms found that are unique to clone */
214 for (i = 0; i < count; i++)
215 if (aud[i].status != AUD_ROM_NOT_FOUND)
216 if (!RomInSet (gamedrv->clone_of, aud[i].expchecksum))
217 cloneRomsFound++;
218
219 #ifndef MESS
220 /* Different MESS systems can use the same ROMs */
221 if (cloneRomsFound == 0)
222 return CLONE_NOTFOUND;
223 #endif
224 }
225 #endif
226
227 while (count--)
228 {
229 archive_status |= aud->status;
230
231 #ifdef JAPANESE
232 switch (aud->status)
233 {
234 case AUD_ROM_NOT_FOUND:
235 verify_printf("%-8s: %-12s %7d�o�C�g %08x ��������������\n",
236 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum);
237 break;
238 case AUD_NOT_AVAILABLE:
239 verify_printf("%-8s: %-12s %7d�o�C�g �������������� - �_���v������������\n",
240 drivers[game]->name, aud->rom, aud->explength);
241 break;
242 case AUD_ROM_NEED_DUMP:
243 verify_printf("%-8s: %-12s %7d�o�C�g �������_���v��������������\n",
244 drivers[game]->name, aud->rom, aud->explength);
245 break;
246 case AUD_BAD_CHECKSUM:
247 verify_printf("%-8s: %-12s %7d�o�C�g %08x CRC����������: %08x\n",
248 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->checksum);
249 break;
250 case AUD_ROM_NEED_REDUMP:
251 verify_printf("%-8s: %-12s %7d�o�C�g ���_���v������������\n",
252 drivers[game]->name, aud->rom, aud->explength);
253 break;
254 case AUD_MEM_ERROR:
255 verify_printf("ROM���������������������s�������������� %s\n", aud->rom);
256 break;
257 case AUD_LENGTH_MISMATCH:
258 verify_printf("%-8s: %-12s %7d�o�C�g %08x �t�@�C���T�C�Y����������: %8d\n",
259 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->length);
260 break;
261 case AUD_ROM_GOOD:
262 #if 0
263 /* if you want a full accounting of roms */
264 verify_printf("%-8s: %-12s %7d bytes %08x ROM����������\n",
265 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum);
266 #endif
267 break;
268 }
269 #else
270 switch (aud->status)
271 {
272 case AUD_ROM_NOT_FOUND:
273 verify_printf ("%-8s: %-12s %7d bytes %08x NOT FOUND\n",
274 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum);
275 break;
276 case AUD_NOT_AVAILABLE:
277 verify_printf ("%-8s: %-12s %7d bytes NOT FOUND - NO GOOD DUMP KNOWN\n",
278 drivers[game]->name, aud->rom, aud->explength);
279 break;
280 case AUD_ROM_NEED_DUMP:
281 verify_printf ("%-8s: %-12s %7d bytes NO GOOD DUMP KNOWN\n",
282 drivers[game]->name, aud->rom, aud->explength);
283 break;
284 case AUD_BAD_CHECKSUM:
285 verify_printf ("%-8s: %-12s %7d bytes %08x INCORRECT CHECKSUM: %08x\n",
286 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->checksum);
287 break;
288 case AUD_ROM_NEED_REDUMP:
289 verify_printf ("%-8s: %-12s %7d bytes ROM NEEDS REDUMP\n",
290 drivers[game]->name, aud->rom, aud->explength);
291 break;
292 case AUD_MEM_ERROR:
293 verify_printf ("Out of memory reading ROM %s\n", aud->rom);
294 break;
295 case AUD_LENGTH_MISMATCH:
296 verify_printf ("%-8s: %-12s %7d bytes %08x INCORRECT LENGTH: %8d\n",
297 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum,aud->length);
298 break;
299 case AUD_ROM_GOOD:
300 #if 0 /* if you want a full accounting of roms */
301 verify_printf ("%-8s: %-12s %7d bytes %08x ROM GOOD\n",
302 drivers[game]->name, aud->rom, aud->explength, aud->expchecksum);
303 #endif
304 break;
305 }
306 #endif
307 aud++;
308 }
309
310 if (archive_status & (AUD_ROM_NOT_FOUND|AUD_BAD_CHECKSUM|AUD_MEM_ERROR|AUD_LENGTH_MISMATCH))
311 return INCORRECT;
312 if (archive_status & (AUD_ROM_NEED_DUMP|AUD_ROM_NEED_REDUMP|AUD_NOT_AVAILABLE))
313 return BEST_AVAILABLE;
314
315 return CORRECT;
316
317 }
318
319
320 static tMissingSample *gMissingSamples = NULL;
321
322 /* Builds a list of every missing sample. Returns total number of missing
323 samples, or -1 if no samples were found. Sets audit to point to the
324 list of missing samples. */
325 int AuditSampleSet (int game, tMissingSample **audit)
326 {
327 struct InternalMachineDriver drv;
328 int skipfirst;
329 void *f;
330 const char **samplenames, *sharedname;
331 int exist;
332 static const struct GameDriver *gamedrv;
333 int j;
334 int count = 0;
335 tMissingSample *aud;
336
337 gamedrv = drivers[game];
338 expand_machine_driver(gamedrv->drv, &drv);
339
340 samplenames = NULL;
341 #if (HAS_SAMPLES || HAS_VLM5030)
342 for( j = 0; drv.sound[j].sound_type && j < MAX_SOUND; j++ )
343 {
344 #if (HAS_SAMPLES)
345 if( drv.sound[j].sound_type == SOUND_SAMPLES )
346 samplenames = ((struct Samplesinterface *)drv.sound[j].sound_interface)->samplenames;
347 #endif
348 }
349 #endif
350 /* does the game use samples at all? */
351 if (samplenames == 0 || samplenames[0] == 0)
352 return 0;
353
354 /* take care of shared samples */
355 if (samplenames[0][0] == '*')
356 {
357 sharedname=samplenames[0]+1;
358 skipfirst = 1;
359 }
360 else
361 {
362 sharedname = NULL;
363 skipfirst = 0;
364 }
365
366 /* do we have samples for this game? */
367 exist = osd_faccess (gamedrv->name, OSD_FILETYPE_SAMPLE);
368
369 /* try shared samples */
370 if (!exist && skipfirst)
371 exist = osd_faccess (sharedname, OSD_FILETYPE_SAMPLE);
372
373 /* if still not found, we're done */
374 if (!exist)
375 return -1;
376
377 /* allocate missing samples list (if necessary) */
378 if (!gMissingSamples)
379 gMissingSamples = (tMissingSample *)malloc (AUD_MAX_SAMPLES * sizeof (tMissingSample));
380
381 if (gMissingSamples)
382 *audit = aud = gMissingSamples;
383 else
384 return 0;
385
386 for (j = skipfirst; samplenames[j] != 0; j++)
387 {
388 /* skip empty definitions */
389 if (strlen (samplenames[j]) == 0)
390 continue;
391 f = osd_fopen (gamedrv->name, samplenames[j], OSD_FILETYPE_SAMPLE, 0);
392 if (f == NULL && skipfirst)
393 f = osd_fopen (sharedname, samplenames[j], OSD_FILETYPE_SAMPLE, 0);
394
395 if (f)
396 osd_fclose(f);
397 else
398 {
399 strcpy (aud->name, samplenames[j]);
400 count++;
401 aud++;
402 }
403 }
404 return count;
405 }
406
407
408 /* Generic function for evaluating a sampleset. Some platforms may wish to
409 call AuditSampleSet() instead and implement their own reporting (like MacMAME). */
410 int VerifySampleSet (int game, verify_printf_proc verify_printf)
411 {
412 tMissingSample *aud;
413 int count;
414
415 count = AuditSampleSet (game, &aud);
416 if (count==-1)
417 return NOTFOUND;
418 else if (count==0)
419 return CORRECT;
420
421 /* list missing samples */
422 while (count--)
423 {
424 #ifdef JAPANESE
425 verify_printf ("%-8s: %s ��������������\n", drivers[game]->name, aud->name);
426 #else
427 verify_printf ("%-8s: %s NOT FOUND\n", drivers[game]->name, aud->name);
428 #endif
429 aud++;
430 }
431
432 return INCORRECT;
433 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26