1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
|
// For licensing and usage information, read docs/winui_license.txt
//****************************************************************************
// MASTER
/****************************************************************************
* datafile.c
* History database engine
*
* Token parsing by Neil Bradley
* Modifications and higher-level functions by John Butler
****************************************************************************/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// MAME/MAMEUI headers
#include "emu.h"
#include "datafile.h"
#include "mui_opts.h"
#include "mui_util.h"
#include "sound/samples.h"
#include "drivenum.h" // MESSUI only
#define MAX_TOKEN_LENGTH 256
#define DATAFILE_TAG '$'
/****************************************************************************
* datafile constants
****************************************************************************/
static const char *DATAFILE_TAG_KEY = "$info";
static const char *DATAFILE_TAG_BIO = "$bio";
static const char *DATAFILE_TAG_MAME = "$mame";
static const char *DATAFILE_TAG_DRIV = "$drv";
static const char *DATAFILE_TAG_CMD = "$cmd";
static const char *DATAFILE_TAG_SCORE = "$story";
static const char *DATAFILE_TAG_END = "$end";
/****************************************************************************
* private data for parsing functions
****************************************************************************/
static FILE *fp = nullptr; /* Our file pointer */
static UINT64 dwFilePos = 0; /* file position */
static char filename[MAX_PATH]; /* datafile name */
struct tDatafileIndex
{
long offset;
const game_driver *driver;
};
static struct tDatafileIndex *gameinit_idx = nullptr;
static struct tDatafileIndex *hist_idx = nullptr;
static struct tDatafileIndex *mame_idx = nullptr;
static struct tDatafileIndex *driv_idx = nullptr;
static struct tDatafileIndex *sysinfo_idx = nullptr;
static struct tDatafileIndex *mess_idx = nullptr;
static struct tDatafileIndex *messdriv_idx = nullptr;
static struct tDatafileIndex *cmd_idx = nullptr;
static struct tDatafileIndex *score_idx = nullptr;
/****************************************************************************
* Create an array with sorted sourcedrivers for the function
* index_datafile_drivinfo to speed up the datafile access
****************************************************************************/
typedef struct
{
const char *srcdriver;
int index;
} srcdriver_data_type;
static srcdriver_data_type *sorted_srcdrivers = nullptr;
static int SrcDriverDataCompareFunc(const void *arg1, const void *arg2)
{
return strcmp(((srcdriver_data_type *)arg1)->srcdriver, ((srcdriver_data_type *)arg2)->srcdriver);
}
static int GetSrcDriverIndex(const char *srcdriver)
{
srcdriver_data_type *srcdriver_index_info;
srcdriver_data_type key;
key.srcdriver = srcdriver;
int num_games = driver_list::total();
if (sorted_srcdrivers == NULL)
{
/* initialize array of game names/indices */
sorted_srcdrivers = (srcdriver_data_type *)malloc(sizeof(srcdriver_data_type) * num_games);
for (int i = 0; i < num_games; i++)
{
sorted_srcdrivers[i].srcdriver = driver_list::driver(i).source_file+32;
sorted_srcdrivers[i].index = i;
}
qsort(sorted_srcdrivers,num_games,sizeof(srcdriver_data_type),SrcDriverDataCompareFunc);
}
srcdriver_index_info = (srcdriver_data_type *)bsearch(&key, sorted_srcdrivers, num_games, sizeof(srcdriver_data_type), SrcDriverDataCompareFunc);
if (srcdriver_index_info)
return srcdriver_index_info->index;
else
return -1;
}
/****************************************************************************
* ParseClose - Closes the existing opened file (if any)
****************************************************************************/
static void ParseClose(void)
{
/* If the file is open, time for fclose. */
if (fp)
fclose(fp);
}
/****************************************************************************
* ParseOpen - Open up file for reading
****************************************************************************/
static BOOL ParseOpen(const char *pszFilename)
{
/* MAME core file parsing functions fail in recognizing UNICODE chars in UTF-8 without BOM,
so it's better and faster use standard C fileio functions */
fp = fopen(pszFilename, "r");
if (fp == NULL)
return FALSE;
/* Otherwise, prepare! */
dwFilePos = 0;
/* identify text file type first */
fgetc(fp);
fseek(fp, dwFilePos, SEEK_SET);
return TRUE;
}
/****************************************************************************
* ParseSeek - Move the file position indicator
****************************************************************************/
static UINT8 ParseSeek(UINT64 offset, int whence)
{
int result = fseek(fp, offset, whence);
if (result == 0)
dwFilePos = ftell(fp);
return (UINT8)result;
}
/**************************************************************************
**************************************************************************
*
* Datafile functions
*
**************************************************************************
**************************************************************************/
/**************************************************************************
* index_datafile
* Create an index for the records in the currently open datafile.
*
* Returns 0 on error, or the number of index entries created.
**************************************************************************/
static int index_datafile(struct tDatafileIndex **_index, int source)
{
struct tDatafileIndex *idx;
int count = 0;
char readbuf[512];
char name[40];
int num_games = driver_list::total();
/* rewind file */
if (ParseSeek (0L, SEEK_SET))
return 0;
/* allocate index */
idx = *_index = global_alloc_array(tDatafileIndex, (num_games + 1) * sizeof (struct tDatafileIndex));
if (!idx)
return 0;
while (fgets(readbuf, 512, fp))
{
/* DATAFILE_TAG_KEY identifies the driver */
if (!core_strnicmp(DATAFILE_TAG_KEY, readbuf, strlen(DATAFILE_TAG_KEY)))
{
int game_index = 0;
char *curpoint = &readbuf[strlen(DATAFILE_TAG_KEY) + 1];
char *pch = NULL;
char *ends = &readbuf[strlen(readbuf) - 1];
while (curpoint < ends)
{
// search for comma
pch = strpbrk(curpoint, ",");
// found it
if (pch)
{
// copy data and validate driver
int len = pch - curpoint;
strncpy(name, curpoint, len);
name[len] = '\0';
if (!source)
game_index = GetGameNameIndex(name);
else
game_index = GetSrcDriverIndex(name);
if (game_index >= 0)
{
idx->driver = &driver_list::driver(game_index);
idx->offset = ftell(fp);
idx++;
count++;
}
// update current point
curpoint = pch + 1;
}
// if comma not found, copy data while until reach the end of string
else if (!pch && curpoint < ends)
{
int len = ends - curpoint;
strncpy(name, curpoint, len);
name[len] = '\0';
if (!source)
game_index = GetGameNameIndex(name);
else
game_index = GetSrcDriverIndex(name);
if (game_index >= 0)
{
idx->driver = &driver_list::driver(game_index);
idx->offset = ftell(fp);
idx++;
count++;
}
// update current point
curpoint = ends;
}
}
}
}
/* mark end of index */
idx->offset = 0L;
idx->driver = 0;
return count;
}
/**************************************************************************
* load_datafile_text
*
* Loads text field for a driver into the buffer specified. Specify the
* driver, a pointer to the buffer, the buffer size, the index created by
* index_datafile(), and the desired text field (e.g., DATAFILE_TAG_BIO).
*
* Returns 0 if successful.
**************************************************************************/
static int load_datafile_text(const game_driver *drv, char *buffer, int bufsize, struct tDatafileIndex *idx, const char *tag, int source_file, int mameinfo)
{
char readbuf[16384];
*buffer = '\0';
if (!source_file)
{
/* find driver in datafile index */
while (idx->driver)
{
if (idx->driver == drv)
break;
idx++;
}
}
else
{
/* find source file in datafile index */
while (idx->driver)
{
if (idx->driver->source_file == drv->source_file)
break;
idx++;
}
}
if (idx->driver == 0)
return 1; /* driver not found in index */
/* seek to correct point in datafile */
if (ParseSeek (idx->offset, SEEK_SET))
return 1;
/* read text until buffer is full or end of entry is encountered */
while (fgets(readbuf, 16384, fp))
{
if (!core_strnicmp(DATAFILE_TAG_END, readbuf, strlen(DATAFILE_TAG_END)))
break;
if (!core_strnicmp(tag, readbuf, strlen(tag)))
continue;
if (strlen(buffer) + strlen(readbuf) > bufsize)
break;
if (mameinfo)
{
char *temp = strtok(readbuf, "\r\n\r\n");
if (temp != nullptr)
strcat(buffer, temp);
else
strcat(buffer, readbuf);
}
else
strcat(buffer, readbuf);
}
return 0;
}
/**************************************************************************
* load_driver_history
* Load history text for the specified driver into the specified buffer.
* Combines $bio field of HISTORY.DAT with $mame field of MAMEINFO.DAT.
*
* Returns 0 if successful.
*
* NOTE: For efficiency the indices are never freed (intentional leak).
**************************************************************************/
int load_driver_history(const game_driver *drv, char *buffer, int bufsize, int filenum)
{
int history = 0;
*buffer = 0;
if (filenum)
snprintf(filename, ARRAY_LENGTH(filename), "%s\\sysinfo.dat", GetDatsDir());
else
snprintf(filename, ARRAY_LENGTH(filename), "%s\\history.dat", GetDatsDir());
/* try to open history datafile */
if (filenum)
{
if (ParseOpen(filename))
{
/* create index if necessary */
if (sysinfo_idx)
history = 1;
else
history = (index_datafile (&sysinfo_idx, 0) != 0);
/* load history text (append)*/
if (sysinfo_idx)
{
strcat(buffer, "\n**** SYSINFO: ****\n\n");
int len = strlen(buffer);
int err = 0;
const game_driver *gdrv;
gdrv = drv;
do
{
err = load_datafile_text(gdrv, buffer + len, bufsize - len, sysinfo_idx, DATAFILE_TAG_BIO, 0, 0);
int g = driver_list::clone(*gdrv);
if (g!=-1)
gdrv = &driver_list::driver(g);
else
gdrv = NULL;
} while (err && gdrv);
if (err)
history = 0;
}
ParseClose();
}
}
else
{
if (ParseOpen(filename))
{
/* create index if necessary */
if (hist_idx)
history = 1;
else
history = (index_datafile (&hist_idx, 0) != 0);
/* load history text (append)*/
if (hist_idx)
{
strcat(buffer, "\n**** HISTORY: ****\n\n");
int len = strlen(buffer);
int err = 0;
const game_driver *gdrv;
gdrv = drv;
do
{
err = load_datafile_text(gdrv, buffer + len, bufsize - len, hist_idx, DATAFILE_TAG_BIO, 0, 0);
int g = driver_list::clone(*gdrv);
if (g!=-1)
gdrv = &driver_list::driver(g);
else
gdrv = NULL;
} while (err && gdrv);
if (err)
history = 0;
}
ParseClose();
}
}
strcat(buffer, "\n");
return (history == 0);
}
int load_driver_mameinfo(const game_driver *drv, char *buffer, int bufsize, int filenum)
{
machine_config config(*drv, MameUIGlobal());
const game_driver *parent = NULL;
char name[512];
int mameinfo = 0;
int is_bios = 0;
*buffer = 0;
switch (filenum)
{
case 0:
snprintf(filename, ARRAY_LENGTH(filename), "%s\\mameinfo.dat", GetDatsDir());
strcat(buffer, "\n**** MAMEINFO: ****\n\n");
break;
case 1:
snprintf(filename, ARRAY_LENGTH(filename), "%s\\messinfo.dat", GetDatsDir());
strcat(buffer, "\n**** MESSINFO: ****\n\n");
break;
case 2:
snprintf(filename, ARRAY_LENGTH(filename), "%s\\gameinit.dat", GetDatsDir());
strcat(buffer, "\n**** GAMEINIT: ****\n\n");
break;
default:
break;
}
if (filenum < 2)
{
/* List the game info 'flags' */
if (drv->flags & MACHINE_NOT_WORKING)
strcat(buffer, "THIS GAME DOESN'T WORK PROPERLY\n");
if (drv->flags & MACHINE_UNEMULATED_PROTECTION)
strcat(buffer, "The game has protection which isn't fully emulated.\n");
if (drv->flags & MACHINE_IMPERFECT_GRAPHICS)
strcat(buffer, "The video emulation isn't 100% accurate.\n");
if (drv->flags & MACHINE_WRONG_COLORS)
strcat(buffer, "The colors are completely wrong.\n");
if (drv->flags & MACHINE_IMPERFECT_COLORS)
strcat(buffer, "The colors aren't 100% accurate.\n");
if (drv->flags & MACHINE_NO_SOUND)
strcat(buffer, "The game lacks sound.\n");
if (drv->flags & MACHINE_IMPERFECT_SOUND)
strcat(buffer, "The sound emulation isn't 100% accurate.\n");
if (drv->flags & MACHINE_SUPPORTS_SAVE)
strcat(buffer, "Save state support.\n");
if (drv->flags & MACHINE_MECHANICAL)
strcat(buffer, "The game contains mechanical parts.\n");
strcat(buffer, "\n");
if (drv->flags & MACHINE_IS_BIOS_ROOT)
is_bios = 1;
}
/* try to open mameinfo datafile */
if (ParseOpen(filename))
{
if (filenum == 2)
{
/* create index if necessary */
if (gameinit_idx)
mameinfo = 1;
else
mameinfo = (index_datafile (&gameinit_idx, 0) != 0);
/* load informational text (append) */
if (gameinit_idx)
{
int len = strlen(buffer);
int err = 0;
const game_driver *gdrv;
gdrv = drv;
do
{
err = load_datafile_text(gdrv, buffer + len, bufsize - len, gameinit_idx, DATAFILE_TAG_MAME, 0, 1);
int g = driver_list::clone(*gdrv);
if (g!=-1)
gdrv = &driver_list::driver(g);
else
gdrv = NULL;
} while (err && gdrv);
if (err)
mameinfo = 0;
}
}
else
if (filenum == 1)
{
/* create index if necessary */
if (mess_idx)
mameinfo = 1;
else
mameinfo = (index_datafile (&mess_idx, 0) != 0);
/* load informational text (append) */
if (mess_idx)
{
int len = strlen(buffer);
int err = 0;
const game_driver *gdrv;
gdrv = drv;
do
{
err = load_datafile_text(gdrv, buffer + len, bufsize - len, mess_idx, DATAFILE_TAG_MAME, 0, 1);
int g = driver_list::clone(*gdrv);
if (g!=-1)
gdrv = &driver_list::driver(g);
else
gdrv = NULL;
} while (err && gdrv);
if (err)
mameinfo = 0;
}
}
else
if (filenum == 0)
{
/* create index if necessary */
if (mame_idx)
mameinfo = 1;
else
mameinfo = (index_datafile (&mame_idx, 0) != 0);
/* load informational text (append) */
if (mame_idx)
{
int len = strlen(buffer);
int err = 0;
const game_driver *gdrv;
gdrv = drv;
do
{
err = load_datafile_text(gdrv, buffer + len, bufsize - len, mame_idx, DATAFILE_TAG_MAME, 0, 1);
int g = driver_list::clone(*gdrv);
if (g!=-1)
gdrv = &driver_list::driver(g);
else
gdrv = NULL;
} while (err && gdrv);
if (err)
mameinfo = 0;
}
}
ParseClose();
}
if (filenum > 1)
return (mameinfo == 0);
/* GAME INFORMATIONS */
snprintf(name, ARRAY_LENGTH(name), "\nGAME: %s\n", drv->name);
strcat(buffer, name);
snprintf(name, ARRAY_LENGTH(name), "%s", drv->description);
strcat(buffer, name);
snprintf(name, ARRAY_LENGTH(name), " (%s %s)\n\nCPU:\n", drv->manufacturer, drv->year);
strcat(buffer, name);
/* iterate over CPUs */
for (device_execute_interface &cpu : execute_interface_iterator(config.root_device()))
{
if (cpu.device().clock() >= 1000000)
snprintf(name, ARRAY_LENGTH(name), "%s %d.%06d MHz\n", cpu.device().name(), cpu.device().clock() / 1000000, cpu.device().clock() % 1000000);
else
snprintf(name, ARRAY_LENGTH(name), "%s %d.%03d kHz\n", cpu.device().name(), cpu.device().clock() / 1000, cpu.device().clock() % 1000);
strcat(buffer, name);
}
strcat(buffer, "\nSOUND:\n");
int has_sound = 0;
/* iterate over sound chips */
for (device_sound_interface &sound : sound_interface_iterator(config.root_device()))
{
char tmpname[1024];
snprintf(tmpname, ARRAY_LENGTH(tmpname), "%s", sound.device().name());
int clock = sound.device().clock();
has_sound = 1;
strcat(buffer, tmpname);
if (clock)
{
if (clock >= 1000000)
snprintf(name, ARRAY_LENGTH(name), " %d.%06d MHz", clock / 1000000, clock % 1000000);
else
snprintf(name, ARRAY_LENGTH(name), " %d.%03d kHz", clock / 1000, clock % 1000);
strcat(buffer, name);
}
strcat(buffer, "\n");
}
if (has_sound)
{
speaker_device_iterator iter(config.root_device());
int channels = iter.count();
if(channels == 1)
snprintf(name, ARRAY_LENGTH(name), "%d Channel\n",channels);
else
snprintf(name, ARRAY_LENGTH(name), "%dx Channels\n",channels);
strcat(buffer, name);
}
strcat(buffer, "\nVIDEO:\n");
screen_device_iterator screeniter(config.root_device());
const screen_device *screen1 = screeniter.first();
if (screen1 == nullptr)
strcat(buffer, "Screenless\n");
else if (screen1->screen_type() == SCREEN_TYPE_VECTOR)
strcat(buffer,"Vector\n");
else
{
for (screen_device &screen : screen_device_iterator(config.root_device()))
{
if (drv->flags & ORIENTATION_SWAP_XY)
snprintf(name, ARRAY_LENGTH(name), "%d x %d (V)", screen.visible_area().height(), screen.visible_area().width());
else
snprintf(name, ARRAY_LENGTH(name), "%d x %d (H)", screen.visible_area().width(), screen.visible_area().height());
strcat(buffer, name);
snprintf(name, ARRAY_LENGTH(name), " %f Hz", ATTOSECONDS_TO_HZ(screen.refresh_attoseconds()));
strcat(buffer, name);
strcat(buffer, "\n");
}
}
strcat(buffer, "\nROM REGION:\n");
int g = driver_list::clone(*drv);
if (g != -1)
parent = &driver_list::driver(g);
for (device_t &device : device_iterator(config.root_device()))
{
for (const rom_entry *region = rom_first_region(device); region; region = rom_next_region(region))
{
for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
{
util::hash_collection hashes(ROM_GETHASHDATA(rom));
if (g != -1)
{
machine_config pconfig(*parent, MameUIGlobal());
device_iterator deviter(pconfig.root_device());
for (device_t &device : device_iterator(pconfig.root_device()))
for (const rom_entry *pregion = rom_first_region(device); pregion; pregion = rom_next_region(pregion))
for (const rom_entry *prom = rom_first_file(pregion); prom; prom = rom_next_file(prom))
{
util::hash_collection phashes(ROM_GETHASHDATA(prom));
if (hashes == phashes)
break;
}
}
snprintf(name, ARRAY_LENGTH(name), "%-16s \t", ROM_GETNAME(rom));
strcat(buffer, name);
snprintf(name, ARRAY_LENGTH(name), "%09d \t", rom_file_size(rom));
strcat(buffer, name);
snprintf(name, ARRAY_LENGTH(name), "%-10s", ROMREGION_GETTAG(region));
strcat(buffer, name);
strcat(buffer, "\n");
}
}
}
for (samples_device &device : samples_device_iterator(config.root_device()))
{
samples_iterator sampiter(device);
if (sampiter.altbasename() )
{
snprintf(name, ARRAY_LENGTH(name), "\nSAMPLES (%s):\n", sampiter.altbasename());
strcat(buffer, name);
}
std::unordered_set<std::string> already_printed;
for (const char *samplename = sampiter.first(); samplename; samplename = sampiter.next())
{
// filter out duplicates
if (!already_printed.insert(samplename).second)
continue;
// output the sample name
snprintf(name, ARRAY_LENGTH(name), "%s.wav\n", samplename);
strcat(buffer, name);
}
}
if (!is_bios)
{
int g = driver_list::clone(*drv);
if (g != -1)
drv = &driver_list::driver(g);
strcat(buffer, "\nORIGINAL:\n");
strcat(buffer, drv->description);
strcat(buffer, "\n\nCLONES:\n");
for (int i = 0; i < driver_list::total(); i++)
{
if (!strcmp (drv->name, driver_list::driver(i).parent))
{
strcat(buffer, driver_list::driver(i).description);
strcat(buffer, "\n");
}
}
}
strcat(buffer, "\n");
return (mameinfo == 0);
}
int load_driver_driverinfo(const game_driver *drv, char *buffer, int bufsize, int filenum)
{
int drivinfo = 0;
char source_file[40];
char tmp[100];
std::string temp = core_filename_extract_base(drv->source_file);
strcpy(source_file, temp.c_str());
*buffer = 0;
if (filenum)
snprintf(filename, ARRAY_LENGTH(filename), "%s\\messinfo.dat", GetDatsDir());
else
snprintf(filename, ARRAY_LENGTH(filename), "%s\\mameinfo.dat", GetDatsDir());
/* Print source code file */
snprintf(tmp, ARRAY_LENGTH(tmp), "\n\nSOURCE: %s\n\n", source_file);
strcat(buffer, tmp);
/* Try to open mameinfo datafile - driver section*/
if (ParseOpen(filename))
{
if (filenum)
{
/* create index if necessary */
if (messdriv_idx)
drivinfo = 1;
else
drivinfo = (index_datafile (&messdriv_idx, 1) != 0);
/* load informational text (append) */
if (messdriv_idx)
{
int len = strlen(buffer);
int err = load_datafile_text(drv, buffer + len, bufsize - len, messdriv_idx, DATAFILE_TAG_DRIV, 1, 1);
if (err)
drivinfo = 0;
}
}
else
{
/* create index if necessary */
if (driv_idx)
drivinfo = 1;
else
drivinfo = (index_datafile (&driv_idx, 1) != 0);
/* load informational text (append) */
if (driv_idx)
{
int len = strlen(buffer);
int err = load_datafile_text(drv, buffer + len, bufsize - len, driv_idx, DATAFILE_TAG_DRIV, 1, 1);
if (err)
drivinfo = 0;
}
}
ParseClose();
}
strcat(buffer, "\nGAMES SUPPORTED:\n");
for (int i = 0; i < driver_list::total(); i++)
{
if (!strcmp(source_file, GetDriverFilename(i)) && !(DriverIsBios(i)))
{
strcat(buffer, driver_list::driver(i).description);
strcat(buffer,"\n");
}
}
strcat(buffer, "\n\n");
return (drivinfo == 0);
}
int load_driver_command(const game_driver *drv, char *buffer, int bufsize)
{
int command = 0;
*buffer = 0;
snprintf(filename, ARRAY_LENGTH(filename), "%s\\command.dat", GetDatsDir());
strcat(buffer, "\n**** COMMAND: ****\n\n");
/* try to open command datafile */
if (ParseOpen(filename))
{
/* create index if necessary */
if (cmd_idx)
command = 1;
else
command = (index_datafile (&cmd_idx, 0) != 0);
/* load informational text (append) */
if (cmd_idx)
{
int len = strlen(buffer);
int err = 0;
const game_driver *gdrv;
gdrv = drv;
do
{
err = load_datafile_text(gdrv, buffer + len, bufsize - len, cmd_idx, DATAFILE_TAG_CMD, 0, 0);
int g = driver_list::clone(*gdrv);
if (g!=-1)
gdrv = &driver_list::driver(g);
else
gdrv = NULL;
} while (err && gdrv);
if (err)
command = 0;
}
ParseClose();
}
strcat(buffer, "\n\n");
return (command == 0);
}
int load_driver_scoreinfo(const game_driver *drv, char *buffer, int bufsize)
{
int scoreinfo = 0;
*buffer = 0;
snprintf(filename, ARRAY_LENGTH(filename), "%s\\story.dat", GetDatsDir());
/* try to open story datafile */
if (ParseOpen(filename))
{
/* create index if necessary */
if (score_idx)
scoreinfo = 1;
else
scoreinfo = (index_datafile (&score_idx, 0) != 0);
/* load informational text (append) */
if (score_idx)
{
int len = strlen(buffer);
int err = 0;
const game_driver *gdrv;
gdrv = drv;
do
{
err = load_datafile_text(gdrv, buffer + len, bufsize - len, score_idx, DATAFILE_TAG_SCORE, 0, 0);
int g = driver_list::clone(*gdrv);
if (g!=-1)
gdrv = &driver_list::driver(g);
else
gdrv = NULL;
} while (err && gdrv);
if (err)
scoreinfo = 0;
}
ParseClose();
}
return (scoreinfo == 0);
}
|