summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/info.c
blob: d0e396042493514b722d7a77dfdbd242cd7e613d (plain) (blame)
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
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
/***************************************************************************

    info.c

    Dumps the MAME internal data as an XML file.

    Copyright Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

***************************************************************************/

#include "emu.h"
#include "machine/ram.h"
#include "sound/samples.h"
#include "info.h"
#include "xmlfile.h"
#include "hash.h"
#include "config.h"

#include <ctype.h>

/* MESS/MAME configuration */
#ifdef MESS
#define XML_ROOT "mess"
#define XML_TOP "machine"
#else
#define XML_ROOT "mame"
#define XML_TOP "game"
#endif



/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

class parent_info
{
public:
	const game_driver *drv;
	machine_config mconfig;

	parent_info(const game_driver *drv, emu_options &options) : mconfig(*drv, options)
	{
		this->drv = drv;
	}
};



/***************************************************************************
    CORE IMPLEMENTATION
***************************************************************************/

/*-------------------------------------------------
    print_game_switches - print the DIP switch
    settings for a game
-------------------------------------------------*/

static void print_game_switches(FILE *out, const game_driver *game, const ioport_list &portlist)
{
	const input_port_config *port;
	const input_field_config *field;

	/* iterate looking for DIP switches */
	for (port = portlist.first(); port != NULL; port = port->next())
		for (field = port->fieldlist; field != NULL; field = field->next)
			if (field->type == IPT_DIPSWITCH)
			{
				const input_setting_config *setting;

				/* output the switch name information */
				fprintf(out, "\t\t<dipswitch name=\"%s\"", xml_normalize_string(input_field_name(field)));
				fprintf(out, " tag=\"%s\"", xml_normalize_string(field->port->tag));
				fprintf(out, " mask=\"%u\"", field->mask);
				fprintf(out, ">\n");

				/* loop over settings */
				for (setting = field->settinglist; setting != NULL; setting = setting->next)
				{
					fprintf(out, "\t\t\t<dipvalue name=\"%s\"", xml_normalize_string(setting->name));
					fprintf(out, " value=\"%u\"", setting->value);
					if (setting->value == field->defvalue)
						fprintf(out, " default=\"yes\"");
					fprintf(out, "/>\n");
				}

				/* terminate the switch entry */
				fprintf(out, "\t\t</dipswitch>\n");
			}
}

/*-------------------------------------------------
    print_game_configs - print the Configuration
    settings for a game
-------------------------------------------------*/

static void print_game_configs(FILE *out, const game_driver *game, const ioport_list &portlist)
{
	const input_port_config *port;
	const input_field_config *field;

	/* iterate looking for configurations */
	for (port = portlist.first(); port != NULL; port = port->next())
		for (field = port->fieldlist; field != NULL; field = field->next)
			if (field->type == IPT_CONFIG)
			{
				const input_setting_config *setting;

				/* output the configuration name information */
				fprintf(out, "\t\t<configuration name=\"%s\"", xml_normalize_string(input_field_name(field)));
				fprintf(out, " tag=\"%s\"", xml_normalize_string(field->port->tag));
				fprintf(out, " mask=\"%u\"", field->mask);
				fprintf(out, ">\n");

				/* loop over settings */
				for (setting = field->settinglist; setting != NULL; setting = setting->next)
				{
					fprintf(out, "\t\t\t<confsetting name=\"%s\"", xml_normalize_string(setting->name));
					fprintf(out, " value=\"%u\"", setting->value);
					if (setting->value == field->defvalue)
						fprintf(out, " default=\"yes\"");
					fprintf(out, "/>\n");
				}

				/* terminate the configuration entry */
				fprintf(out, "\t\t</configuration>\n");
			}
}

/*-------------------------------------------------
    print_game_adjusters - print the Analog
    Adjusters for a game
-------------------------------------------------*/

static void print_game_adjusters(FILE *out, const game_driver *game, const ioport_list &portlist)
{
	const input_port_config *port;
	const input_field_config *field;

	/* iterate looking for Adjusters */
	for (port = portlist.first(); port != NULL; port = port->next())
		for (field = port->fieldlist; field != NULL; field = field->next)
			if (field->type == IPT_ADJUSTER)
			{
				/* output the adjuster information */
				fprintf(out, "\t\t<adjuster name=\"%s\" default=\"%d\"/>\n", xml_normalize_string(input_field_name(field)), field->defvalue);
			}
}

/*-------------------------------------------------
    print_game_input - print a summary of a game's
    input
-------------------------------------------------*/

static void print_game_input(FILE *out, const game_driver *game, const ioport_list &portlist)
{
	/* fix me -- this needs to be cleaned up to match the core style */

enum {cjoy, cdoublejoy, cAD_stick, cdial, ctrackball, cpaddle, clightgun, cpedal, ckeypad, ckeyboard, ENDCONTROLTYPES};
	int nplayer = 0;
	int nbutton = 0;
	int ncoin = 0;
	//int controlsyes = 0;
	int analogcontrol = 0;
	int i;
	const char* service = 0;
	const char* tilt = 0;
	const char* const control_types[] = {"joy", "doublejoy", "stick", "dial", "trackball", "paddle", "lightgun", "pedal", "keypad", "keyboard"};
	static struct _input_info
	{
		const char *	type;			/* general type of input */
		const char *	Xway;			/* 2, 4, or 8 way */
		int				analog;
		int				keyb;
		int				min;			/* analog minimum value */
		int				max;			/* analog maximum value  */
		int				sensitivity;	/* default analog sensitivity */
		int				keydelta;		/* default analog keydelta */
		int				reverse;		/* default analog reverse setting */
	} control[ENDCONTROLTYPES];
	const input_port_config *port;
	const input_field_config *field;

	for (i = 0; i < ENDCONTROLTYPES; i++)
	{
		control[i].type = control_types[i];
		control[i].Xway = NULL;
		control[i].analog = 0;
		control[i].keyb = 0;
		control[i].min = 0;
		control[i].max = 0;
		control[i].sensitivity = 0;
		control[i].keydelta = 0;
		control[i].reverse = 0;
	}

	for (port = portlist.first(); port != NULL; port = port->next())
		for (field = port->fieldlist; field != NULL; field = field->next)
		{

			if (nplayer < field->player + 1)
				nplayer = field->player + 1;

			switch (field->type)
			{
				case IPT_JOYSTICK_LEFT:
				case IPT_JOYSTICK_RIGHT:

					/* if control not defined, start it off as horizontal 2-way */
					if (control[cjoy].Xway == NULL)
						control[cjoy].Xway = "joy2way";
					else if (strcmp(control[cjoy].Xway,"joy2way") == 0)
						;
					/* if already defined as vertical, make it 4 or 8 way */
					else if (strcmp(control[cjoy].Xway,"vjoy2way") == 0)
					{
						if (field->way == 4)
							control[cjoy].Xway = "joy4way";
						else
							control[cjoy].Xway = "joy8way";
					}
					//controlsyes = 1;
					break;

				case IPT_JOYSTICK_UP:
				case IPT_JOYSTICK_DOWN:

					/* if control not defined, start it off as vertical 2-way */
					if (control[cjoy].Xway == NULL)
						control[cjoy].Xway = "vjoy2way";
					else if (strcmp(control[cjoy].Xway,"vjoy2way") == 0)
						;
					/* if already defined as horiz, make it 4 or 8way */
					else if (strcmp(control[cjoy].Xway,"joy2way") == 0)
					{
						if (field->way == 4)
							control[cjoy].Xway = "joy4way";
						else
							control[cjoy].Xway = "joy8way";
					}
					//controlsyes = 1;
					break;

				case IPT_JOYSTICKRIGHT_UP:
				case IPT_JOYSTICKRIGHT_DOWN:
				case IPT_JOYSTICKLEFT_UP:
				case IPT_JOYSTICKLEFT_DOWN:

					/* if control not defined, start it off as vertical 2way */
					if (control[cdoublejoy].Xway == NULL)
						control[cdoublejoy].Xway = "vdoublejoy2way";
					else if (strcmp(control[cdoublejoy].Xway,"vdoublejoy2way") == 0)
						;
					/* if already defined as horiz, make it 4 or 8 way */
					else if (strcmp(control[cdoublejoy].Xway,"doublejoy2way") == 0)
					{
						if (field->way == 4)
							control[cdoublejoy].Xway = "doublejoy4way";
						else
							control[cdoublejoy].Xway = "doublejoy8way";
					}
					//controlsyes = 1;
					break;

				case IPT_JOYSTICKRIGHT_LEFT:
				case IPT_JOYSTICKRIGHT_RIGHT:
				case IPT_JOYSTICKLEFT_LEFT:
				case IPT_JOYSTICKLEFT_RIGHT:

					/* if control not defined, start it off as horiz 2-way */
					if (control[cdoublejoy].Xway == NULL)
						control[cdoublejoy].Xway = "doublejoy2way";
					else if (strcmp(control[cdoublejoy].Xway,"doublejoy2way") == 0)
						;
					/* if already defined as vertical, make it 4 or 8 way */
					else if (strcmp(control[cdoublejoy].Xway,"vdoublejoy2way") == 0)
					{
						if (field->way == 4)
							control[cdoublejoy].Xway = "doublejoy4way";
						else
							control[cdoublejoy].Xway = "doublejoy8way";
					}
					//controlsyes = 1;
					break;

				/* mark as an analog input, and get analog stats after switch */
				case IPT_PADDLE:
					analogcontrol = cpaddle;
					break;
				case IPT_DIAL:
					analogcontrol = cdial;
					break;
				case IPT_TRACKBALL_X:
				case IPT_TRACKBALL_Y:
					analogcontrol = ctrackball;
					break;
				case IPT_AD_STICK_X:
				case IPT_AD_STICK_Y:
					analogcontrol = cAD_stick;
					break;
				case IPT_LIGHTGUN_X:
				case IPT_LIGHTGUN_Y:
					analogcontrol = clightgun;
					break;
				case IPT_PEDAL:
				case IPT_PEDAL2:
				case IPT_PEDAL3:
					analogcontrol = cpedal;
					break;

				case IPT_BUTTON1:
				case IPT_BUTTON2:
				case IPT_BUTTON3:
				case IPT_BUTTON4:
				case IPT_BUTTON5:
				case IPT_BUTTON6:
				case IPT_BUTTON7:
				case IPT_BUTTON8:
				case IPT_BUTTON9:
				case IPT_BUTTON10:
				case IPT_BUTTON11:
				case IPT_BUTTON12:
				case IPT_BUTTON13:
				case IPT_BUTTON14:
				case IPT_BUTTON15:
				case IPT_BUTTON16:
					nbutton = MAX(nbutton, field->type - IPT_BUTTON1 + 1);
					break;

				case IPT_COIN1:
				case IPT_COIN2:
				case IPT_COIN3:
				case IPT_COIN4:
				case IPT_COIN5:
				case IPT_COIN6:
				case IPT_COIN7:
				case IPT_COIN8:
					ncoin = MAX(ncoin, field->type - IPT_COIN1 + 1);

				case IPT_SERVICE :
					service = "yes";
					break;

				case IPT_TILT :
					tilt = "yes";
					break;

				case IPT_KEYPAD:
					control[ckeypad].keyb = 1;
					break;

				case IPT_KEYBOARD:
					control[ckeyboard].keyb = 1;
					break;
			}

			/* get the analog stats */
			if (analogcontrol)
			{
				//controlsyes = 1;
				control[analogcontrol].analog = 1;

				if (field->min)
					control[analogcontrol].min = field->min;
				if (field->max)
					control[analogcontrol].max = field->max;
				if (field->sensitivity)
					control[analogcontrol].sensitivity = field->sensitivity;
				if (field->delta)
					control[analogcontrol].keydelta = field->delta;
				if (field->flags & ANALOG_FLAG_REVERSE)
					control[analogcontrol].reverse = 1;

				analogcontrol = 0;
			}
		}

	fprintf(out, "\t\t<input");
	fprintf(out, " players=\"%d\"", nplayer);
	if (nbutton != 0)
		fprintf(out, " buttons=\"%d\"", nbutton);
	if (ncoin != 0)
		fprintf(out, " coins=\"%d\"", ncoin);
	if (service != NULL)
		fprintf(out, " service=\"%s\"", xml_normalize_string(service));
	if (tilt != NULL)
		fprintf(out, " tilt=\"%s\"", xml_normalize_string(tilt));
	fprintf(out, ">\n");

	for (i = 0; i < ENDCONTROLTYPES; i++)
	{
		if (control[i].Xway != NULL)
			fprintf(out, "\t\t\t<control type=\"%s\"/>\n", xml_normalize_string(control[i].Xway));
		if (control[i].analog)
		{
			fprintf(out, "\t\t\t<control type=\"%s\"", xml_normalize_string(control_types[i]));
			if (control[i].min || control[i].max)
			{
				fprintf(out, " minimum=\"%d\"", control[i].min);
				fprintf(out, " maximum=\"%d\"", control[i].max);
			}
			if (control[i].sensitivity)
				fprintf(out, " sensitivity=\"%d\"", control[i].sensitivity);
			if (control[i].keydelta)
				fprintf(out, " keydelta=\"%d\"", control[i].keydelta);
			if (control[i].reverse)
				fprintf(out, " reverse=\"yes\"");

			fprintf(out, "/>\n");
		}
		if (control[i].keyb)
		{
			fprintf(out, "\t\t\t<control type=\"%s\"/>\n", xml_normalize_string(control_types[i]));
		}
	}
	fprintf(out, "\t\t</input>\n");
}


/*-------------------------------------------------
    print_game_bios - print the BIOS set for a
    game
-------------------------------------------------*/

static void print_game_bios(FILE *out, const game_driver *game)
{
	const rom_entry *rom;

	/* skip if no ROMs */
	if (game->rom == NULL)
		return;

	/* iterate over ROM entries and look for BIOSes */
	for (rom = game->rom; !ROMENTRY_ISEND(rom); rom++)
		if (ROMENTRY_ISSYSTEM_BIOS(rom))
		{
			const char *name = ROM_GETNAME(rom);
			const char *description = ROM_GETHASHDATA(rom);

			/* output extracted name and descriptions */
			fprintf(out, "\t\t<biosset");
			fprintf(out, " name=\"%s\"", xml_normalize_string(name));
			fprintf(out, " description=\"%s\"", xml_normalize_string(description));
			if (ROM_GETBIOSFLAGS(rom) == 1)
				fprintf(out, " default=\"yes\"");
			fprintf(out, "/>\n");
		}
}

/*-------------------------------------------------
    get_merge_name - get the rom name from a
    parent set
-------------------------------------------------*/

static const char *get_merge_name(const hash_collection &romhashes, int parents, const parent_info **pinfoarray)
{
	int parent;
	const char *merge_name = NULL;

	for (parent = 0; parent < parents; ++parent)
	{
		const machine_config *pconfig = &pinfoarray[parent]->mconfig;
		const rom_source *psource;
		const rom_entry *pregion, *prom;

		/* scan the clone_of ROM for a matching ROM entry */
		for (psource = rom_first_source(*pconfig); psource != NULL; psource = rom_next_source(*psource))
			for (pregion = rom_first_region(*psource); pregion != NULL; pregion = rom_next_region(pregion))
				for (prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom))
				{
					hash_collection phashes(ROM_GETHASHDATA(prom));
					if (!phashes.flag(hash_collection::FLAG_NO_DUMP) && romhashes == phashes)
					{
						merge_name = ROM_GETNAME(prom);
						break;
					}
				}
	}

	return merge_name;
}



/*-------------------------------------------------
    print_game_rom - print the roms section of
    the XML output
-------------------------------------------------*/

static void print_game_rom(FILE *out, const game_driver *game, const machine_config &config)
{
	const game_driver *clone_of = driver_get_clone(game);
	int rom_type;
	int parents = 0;
	const parent_info *pinfoarray[4];

	for (; clone_of != NULL; clone_of = driver_get_clone(clone_of))
	{
		assert_always(parents < ARRAY_LENGTH(pinfoarray), "too many parents");
		pinfoarray[parents++] = global_alloc(parent_info(clone_of, config.options()));
	}

	/* iterate over 3 different ROM "types": BIOS, ROMs, DISKs */
	for (rom_type = 0; rom_type < 3; rom_type++)
	{
		const rom_source *source;
		const rom_entry *region;

		/* iterate over ROM sources: first the game, then any devices */
		for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
			for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
			{
				int is_disk = ROMREGION_ISDISKDATA(region);
				const rom_entry *rom;

				/* disk regions only work for disks */
				if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2))
					continue;

				/* iterate through ROM entries */
				for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
				{
					int is_bios = ROM_GETBIOSFLAGS(rom);
					const char *name = ROM_GETNAME(rom);
					int offset = ROM_GETOFFSET(rom);
					const char *merge_name = NULL;
					char bios_name[100];

					/* BIOS ROMs only apply to bioses */
					if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0))
						continue;

					/* if we have a valid ROM and we are a clone, see if we can find the parent ROM */
					hash_collection hashes(ROM_GETHASHDATA(rom));
					if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && parents > 0)
					{
						merge_name = get_merge_name(hashes, parents, pinfoarray);
					}

					/* scan for a BIOS name */
					bios_name[0] = 0;
					if (!is_disk && is_bios)
					{
						const rom_entry *brom;

						/* scan backwards through the ROM entries */
						for (brom = rom - 1; brom != game->rom; brom--)
							if (ROMENTRY_ISSYSTEM_BIOS(brom))
							{
								strcpy(bios_name, ROM_GETNAME(brom));
								break;
							}
					}

					/* opening tag */
					if (!is_disk)
						fprintf(out, "\t\t<rom");
					else
						fprintf(out, "\t\t<disk");

					/* add name, merge, bios, and size tags */
					if (name != NULL && name[0] != 0)
						fprintf(out, " name=\"%s\"", xml_normalize_string(name));
					if (merge_name != NULL)
						fprintf(out, " merge=\"%s\"", xml_normalize_string(merge_name));
					if (bios_name[0] != 0)
						fprintf(out, " bios=\"%s\"", xml_normalize_string(bios_name));
					if (!is_disk)
						fprintf(out, " size=\"%d\"", rom_file_size(rom));

					/* dump checksum information only if there is a known dump */
					if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
					{
						/* iterate over hash function types and print out their values */
						astring tempstr;
						for (hash_base *hash = hashes.first(); hash != NULL; hash = hash->next())
							fprintf(out, " %s=\"%s\"", hash->name(), hash->string(tempstr));
					}

					/* append a region name */
					fprintf(out, " region=\"%s\"", ROMREGION_GETTAG(region));

					/* add nodump/baddump flags */
					if (hashes.flag(hash_collection::FLAG_NO_DUMP))
						fprintf(out, " status=\"nodump\"");
					if (hashes.flag(hash_collection::FLAG_BAD_DUMP))
						fprintf(out, " status=\"baddump\"");

					/* for non-disk entries, print offset */
					if (!is_disk)
						fprintf(out, " offset=\"%x\"", offset);
					/* for disk entries, add the disk index */
					else
						fprintf(out, " index=\"%x\"", DISK_GETINDEX(rom));

					/* add optional flag */
					if ((!is_disk && ROM_ISOPTIONAL(rom)) || (is_disk && DISK_ISOPTIONAL(rom)))
						fprintf(out, " optional=\"yes\"");

					fprintf(out, "/>\n");
				}
			}
	}

	for (; parents > 0; parents--)
		global_free(pinfoarray[parents - 1]);
}


/*-------------------------------------------------
    print_game_sampleof - print the 'sampleof'
    attribute, if appropriate
-------------------------------------------------*/

static void print_game_sampleof(FILE *out, const game_driver *game, const machine_config &config)
{
	const device_config_sound_interface *sound = NULL;

	for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound))
		if (sound->devconfig().type() == SAMPLES)
		{
			const char *const *samplenames = ((const samples_interface *)sound->devconfig().static_config())->samplenames;
			if (samplenames != NULL)
			{
				int sampnum;

				/* iterate over sample names */
				for (sampnum = 0; samplenames[sampnum] != NULL; sampnum++)
				{
					const char *cursampname = samplenames[sampnum];

					/* only output sampleof if different from the game name */
					if (cursampname[0] == '*' && strcmp(cursampname + 1, game->name) != 0)
						fprintf(out, " sampleof=\"%s\"", xml_normalize_string(cursampname + 1));

					/* must stop here, as there can only be one attribute of the same name */
					return;
				}
			}
		}
}


/*-------------------------------------------------
    print_game_sample - print a list of all
    samples referenced by a game_driver
-------------------------------------------------*/

static void print_game_sample(FILE *out, const game_driver *game, const machine_config &config)
{
	const device_config_sound_interface *sound = NULL;

	/* iterate over sound chips looking for samples */
	for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound))
		if (sound->devconfig().type() == SAMPLES)
		{
			const char *const *samplenames = ((const samples_interface *)sound->devconfig().static_config())->samplenames;
			if (samplenames != NULL)
			{
				int sampnum;

				/* iterate over sample names */
				for (sampnum = 0; samplenames[sampnum] != NULL; sampnum++)
				{
					const char *cursampname = samplenames[sampnum];
					int dupnum;

					/* ignore the special '*' samplename */
					if (sampnum == 0 && cursampname[0] == '*')
						continue;

					/* filter out duplicates */
					for (dupnum = 0; dupnum < sampnum; dupnum++)
						if (strcmp(samplenames[dupnum], cursampname) == 0)
							break;
					if (dupnum < sampnum)
						continue;

					/* output the sample name */
					fprintf(out, "\t\t<sample name=\"%s\"/>\n", xml_normalize_string(cursampname));
				}
			}
		}
}


/*-------------------------------------------------
    print_game_chips - print a list of CPU and
    sound chips used by a game
-------------------------------------------------*/

static void print_game_chips(FILE *out, const game_driver *game, const machine_config &config)
{
	/* iterate over CPUs */
	const device_config_execute_interface *exec = NULL;
	for (bool gotone = config.m_devicelist.first(exec); gotone; gotone = exec->next(exec))
	{
		fprintf(out, "\t\t<chip");
		fprintf(out, " type=\"cpu\"");
		fprintf(out, " tag=\"%s\"", xml_normalize_string(exec->devconfig().tag()));
		fprintf(out, " name=\"%s\"", xml_normalize_string(exec->devconfig().name()));
		fprintf(out, " clock=\"%d\"", exec->devconfig().clock());
		fprintf(out, "/>\n");
	}

	/* iterate over sound chips */
	const device_config_sound_interface *sound = NULL;
	for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound))
	{
		fprintf(out, "\t\t<chip");
		fprintf(out, " type=\"audio\"");
		fprintf(out, " tag=\"%s\"", xml_normalize_string(sound->devconfig().tag()));
		fprintf(out, " name=\"%s\"", xml_normalize_string(sound->devconfig().name()));
		if (sound->devconfig().clock() != 0)
			fprintf(out, " clock=\"%d\"", sound->devconfig().clock());
		fprintf(out, "/>\n");
	}
}


/*-------------------------------------------------
    print_game_display - print a list of all the
    displays
-------------------------------------------------*/

static void print_game_display(FILE *out, const game_driver *game, const machine_config &config)
{
	const screen_device_config *devconfig;

	/* iterate over screens */
	for (devconfig = config.first_screen(); devconfig != NULL; devconfig = devconfig->next_screen())
	{
		fprintf(out, "\t\t<display");

		switch (devconfig->screen_type())
		{
			case SCREEN_TYPE_RASTER:	fprintf(out, " type=\"raster\"");	break;
			case SCREEN_TYPE_VECTOR:	fprintf(out, " type=\"vector\"");	break;
			case SCREEN_TYPE_LCD:		fprintf(out, " type=\"lcd\"");		break;
			default:					fprintf(out, " type=\"unknown\"");	break;
		}

		/* output the orientation as a string */
		switch (game->flags & ORIENTATION_MASK)
		{
			case ORIENTATION_FLIP_X:
				fprintf(out, " rotate=\"0\" flipx=\"yes\"");
				break;
			case ORIENTATION_FLIP_Y:
				fprintf(out, " rotate=\"180\" flipx=\"yes\"");
				break;
			case ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y:
				fprintf(out, " rotate=\"180\"");
				break;
			case ORIENTATION_SWAP_XY:
				fprintf(out, " rotate=\"90\" flipx=\"yes\"");
				break;
			case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X:
				fprintf(out, " rotate=\"90\"");
				break;
			case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_Y:
				fprintf(out, " rotate=\"270\"");
				break;
			case ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y:
				fprintf(out, " rotate=\"270\" flipx=\"yes\"");
				break;
			default:
				fprintf(out, " rotate=\"0\"");
				break;
		}

		/* output width and height only for games that are not vector */
		if (devconfig->screen_type() != SCREEN_TYPE_VECTOR)
		{
			const rectangle &visarea = devconfig->visible_area();
			int dx = visarea.max_x - visarea.min_x + 1;
			int dy = visarea.max_y - visarea.min_y + 1;

			fprintf(out, " width=\"%d\"", dx);
			fprintf(out, " height=\"%d\"", dy);
		}

		/* output refresh rate */
		fprintf(out, " refresh=\"%f\"", ATTOSECONDS_TO_HZ(devconfig->refresh()));

		/* output raw video parameters only for games that are not vector */
		/* and had raw parameters specified                               */
		if (devconfig->screen_type() != SCREEN_TYPE_VECTOR && !devconfig->oldstyle_vblank_supplied())
		{
			int pixclock = devconfig->width() * devconfig->height() * ATTOSECONDS_TO_HZ(devconfig->refresh());

			fprintf(out, " pixclock=\"%d\"", pixclock);
			fprintf(out, " htotal=\"%d\"", devconfig->width());
			fprintf(out, " hbend=\"%d\"", devconfig->visible_area().min_x);
			fprintf(out, " hbstart=\"%d\"", devconfig->visible_area().max_x+1);
			fprintf(out, " vtotal=\"%d\"", devconfig->height());
			fprintf(out, " vbend=\"%d\"", devconfig->visible_area().min_y);
			fprintf(out, " vbstart=\"%d\"", devconfig->visible_area().max_y+1);
		}
		fprintf(out, " />\n");
	}
}


/*-------------------------------------------------
    print_game_sound - print a list of all the
    displays
-------------------------------------------------*/

static void print_game_sound(FILE *out, const game_driver *game, const machine_config &config)
{
	int speakers = config.m_devicelist.count(SPEAKER);

	/* if we have no sound, zero out the speaker count */
	const device_config_sound_interface *sound = NULL;
	if (!config.m_devicelist.first(sound))
		speakers = 0;

	fprintf(out, "\t\t<sound channels=\"%d\"/>\n", speakers);
}


/*-------------------------------------------------
    print_game_driver - print driver status
-------------------------------------------------*/

static void print_game_driver(FILE *out, const game_driver *game, const machine_config &config)
{
	fprintf(out, "\t\t<driver");

	/* The status entry is an hint for frontend authors */
	/* to select working and not working games without */
	/* the need to know all the other status entries. */
	/* Games marked as status=good are perfectly emulated, games */
	/* marked as status=imperfect are emulated with only */
	/* some minor issues, games marked as status=preliminary */
	/* don't work or have major emulation problems. */

	if (game->flags & (GAME_NOT_WORKING | GAME_UNEMULATED_PROTECTION | GAME_NO_SOUND | GAME_WRONG_COLORS))
		fprintf(out, " status=\"preliminary\"");
	else if (game->flags & (GAME_IMPERFECT_COLORS | GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS))
		fprintf(out, " status=\"imperfect\"");
	else
		fprintf(out, " status=\"good\"");

	if (game->flags & GAME_NOT_WORKING)
		fprintf(out, " emulation=\"preliminary\"");
	else
		fprintf(out, " emulation=\"good\"");

	if (game->flags & GAME_WRONG_COLORS)
		fprintf(out, " color=\"preliminary\"");
	else if (game->flags & GAME_IMPERFECT_COLORS)
		fprintf(out, " color=\"imperfect\"");
	else
		fprintf(out, " color=\"good\"");

	if (game->flags & GAME_NO_SOUND)
		fprintf(out, " sound=\"preliminary\"");
	else if (game->flags & GAME_IMPERFECT_SOUND)
		fprintf(out, " sound=\"imperfect\"");
	else
		fprintf(out, " sound=\"good\"");

	if (game->flags & GAME_IMPERFECT_GRAPHICS)
		fprintf(out, " graphic=\"imperfect\"");
	else
		fprintf(out, " graphic=\"good\"");

	if (game->flags & GAME_NO_COCKTAIL)
		fprintf(out, " cocktail=\"preliminary\"");

	if (game->flags & GAME_UNEMULATED_PROTECTION)
		fprintf(out, " protection=\"preliminary\"");

	if (game->flags & GAME_SUPPORTS_SAVE)
		fprintf(out, " savestate=\"supported\"");
	else
		fprintf(out, " savestate=\"unsupported\"");

	fprintf(out, " palettesize=\"%d\"", config.m_total_colors);

	fprintf(out, "/>\n");
}

/*-------------------------------------------------
    print_game_categories - print the Categories
    settings for a system
-------------------------------------------------*/

static void print_game_categories(FILE *out, const game_driver *game, const ioport_list &portlist)
{
	const input_port_config *port;
	const input_field_config *field;

	/* iterate looking for Categories */
	for (port = portlist.first(); port != NULL; port = port->next())
		for (field = port->fieldlist; field != NULL; field = field->next)
			if (field->type == IPT_CATEGORY)
			{
				const input_setting_config *setting;

				/* output the category name information */
				fprintf(out, "\t\t<category name=\"%s\">\n", xml_normalize_string(input_field_name(field)));

				/* loop over item settings */
				for (setting = field->settinglist; setting != NULL; setting = setting->next)
				{
					fprintf(out, "\t\t\t<item name=\"%s\"", xml_normalize_string(setting->name));
					if (setting->value == field->defvalue)
						fprintf(out, " default=\"yes\"");
					fprintf(out, "/>\n");
				}

				/* terminate the category entry */
				fprintf(out, "\t\t</category>\n");
			}
}

/*-------------------------------------------------
    print_game_images - prints out all info on
    image devices
-------------------------------------------------*/

static void print_game_images(FILE *out, const game_driver *game, const machine_config &config)
{
	const device_config_image_interface *dev = NULL;
	const char *name;
	const char *shortname;

	for (bool gotone = config.m_devicelist.first(dev); gotone; gotone = dev->next(dev))
	{
		/* print out device type */
		fprintf(out, "\t\t<device type=\"%s\"", xml_normalize_string(dev->image_type_name()));

		/* does this device have a tag? */
		if (dev->devconfig().tag())
			fprintf(out, " tag=\"%s\"", xml_normalize_string(dev->devconfig().tag()));

		/* is this device mandatory? */
		if (dev->must_be_loaded())
			fprintf(out, " mandatory=\"1\"");

		if (dev->image_interface()[0] )
			fprintf(out, " interface=\"%s\"", xml_normalize_string(dev->image_interface()));

		/* close the XML tag */
		fprintf(out, ">\n");

		name = dev->instance_name();
		shortname = dev->brief_instance_name();

		fprintf(out, "\t\t\t<instance");
		fprintf(out, " name=\"%s\"", xml_normalize_string(name));
		fprintf(out, " briefname=\"%s\"", xml_normalize_string(shortname));
		fprintf(out, "/>\n");

		astring extensions(dev->file_extensions());

		char *ext = strtok((char*)extensions.cstr(),",");
		while (ext != NULL)
		{
			fprintf(out, "\t\t\t<extension");
			fprintf(out, " name=\"%s\"", xml_normalize_string(ext));
			fprintf(out, "/>\n");
			ext = strtok (NULL, ",");
		}

		fprintf(out, "\t\t</device>\n");
	}
}

/*-------------------------------------------------
    print_game_software_list - print the information
    for all known software lists for this system
-------------------------------------------------*/

static void print_game_software_list(FILE *out, const game_driver *game, const machine_config &config)
{
	for (const device_config *dev = config.m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext())
	{
		software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(dev)->inline_config();

		for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ )
		{
			if ( swlist->list_name[i] )
			{
				fprintf(out, "\t\t<softwarelist name=\"%s\" ", swlist->list_name[i] );
				fprintf(out, "status=\"%s\" />\n", (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM) ? "original" : "compatible" );
			}
		}
	}
}

/* device iteration helpers */
#define ram_first(config)				(config).m_devicelist.first(RAM)
#define ram_next(previous)				((previous)->typenext())

/*-------------------------------------------------
    print_game_ramoptions - prints out all RAM
    options for this system
-------------------------------------------------*/
static void print_game_ramoptions(FILE *out, const game_driver *game, const machine_config &config)
{
	const device_config *device;

	for (device = ram_first(config); device != NULL; device = ram_next(device))
	{
		ram_config *ram = (ram_config *)downcast<const legacy_device_config_base *>(device)->inline_config();
		fprintf(out, "\t\t<ramoption default=\"1\">%u</ramoption>\n",  ram_parse_string(ram->default_size));
		if (ram->extra_options != NULL)
		{
			int j;
			int size = strlen(ram->extra_options);
			char * const s = mame_strdup(ram->extra_options);
			char * const e = s + size;
			char *p = s;
			for (j=0;j<size;j++) {
				if (p[j]==',') p[j]=0;
			}
			/* try to parse each option */
			while(p <= e)
			{
				fprintf(out, "\t\t<ramoption>%u</ramoption>\n",  ram_parse_string(p));
				p += strlen(p);
				if (p == e)
					break;
				p += 1;
			}

			osd_free(s);
		}
	}
}

/*-------------------------------------------------
    print_game_info - print the XML information
    for one particular game driver
-------------------------------------------------*/

static void print_game_info(FILE *out, const game_driver *game, emu_options &options)
{
	const game_driver *clone_of;
	machine_config config(*game, options);
	ioport_list portlist;
	const char *start;

	/* no action if not a game */
	if (game->flags & GAME_NO_STANDALONE)
		return;

	/* start tracking resources and allocate the machine and input configs */
	input_port_list_init(portlist, game->ipt, NULL, 0, FALSE, NULL);
	for (device_config *cfg = config.m_devicelist.first(); cfg != NULL; cfg = cfg->next())
	{
		if (cfg->input_ports() != NULL)
			input_port_list_init(portlist, cfg->input_ports(), NULL, 0, FALSE, cfg);
	}

	/* print the header and the game name */
	fprintf(out, "\t<" XML_TOP);
	fprintf(out, " name=\"%s\"", xml_normalize_string(game->name) );

	/* strip away any path information from the source_file and output it */
	start = strrchr(game->source_file, '/');
	if (start == NULL)
		start = strrchr(game->source_file, '\\');
	if (start == NULL)
		start = game->source_file - 1;
	fprintf(out, " sourcefile=\"%s\"", xml_normalize_string(start + 1));

	/* append bios and runnable flags */
	if (game->flags & GAME_IS_BIOS_ROOT)
		fprintf(out, " isbios=\"yes\"");
	if (game->flags & GAME_NO_STANDALONE)
		fprintf(out, " runnable=\"no\"");
	if (game->flags & GAME_MECHANICAL)
		fprintf(out, " ismechanical=\"yes\"");

	/* display clone information */
	clone_of = driver_get_clone(game);
	if (clone_of != NULL && !(clone_of->flags & GAME_IS_BIOS_ROOT))
		fprintf(out, " cloneof=\"%s\"", xml_normalize_string(clone_of->name));
	if (clone_of != NULL)
		fprintf(out, " romof=\"%s\"", xml_normalize_string(clone_of->name));

	/* display sample information and close the game tag */
	print_game_sampleof(out, game, config);
	fprintf(out, ">\n");

	/* output game description */
	if (game->description != NULL)
		fprintf(out, "\t\t<description>%s</description>\n", xml_normalize_string(game->description));

	/* print the year only if is a number or another allowed character (? or +) */
	if (game->year != NULL && strspn(game->year, "0123456789?+") == strlen(game->year))
		fprintf(out, "\t\t<year>%s</year>\n", xml_normalize_string(game->year));

	/* print the manufacturer information */
	if (game->manufacturer != NULL)
		fprintf(out, "\t\t<manufacturer>%s</manufacturer>\n", xml_normalize_string(game->manufacturer));

	/* now print various additional information */
	print_game_bios(out, game);
	print_game_rom(out, game, config);
	print_game_sample(out, game, config);
	print_game_chips(out, game, config);
	print_game_display(out, game, config);
	print_game_sound(out, game, config);
	print_game_input(out, game, portlist);
	print_game_switches(out, game, portlist);
	print_game_configs(out, game, portlist);
	print_game_categories(out, game, portlist);
	print_game_adjusters(out, game, portlist);
	print_game_driver(out, game, config);
	print_game_images( out, game, config );
	print_game_software_list( out, game, config );
	print_game_ramoptions( out, game, config );
	/* close the topmost tag */
	fprintf(out, "\t</" XML_TOP ">\n");
}


/*-------------------------------------------------
    print_mame_xml - print the XML information
    for all known games
-------------------------------------------------*/

void print_mame_xml(FILE *out, const game_driver *const games[], const char *gamename, emu_options &options)
{
	int drvnum;

	fprintf(out,
		"<?xml version=\"1.0\"?>\n"
		"<!DOCTYPE " XML_ROOT " [\n"
		"<!ELEMENT " XML_ROOT " (" XML_TOP "+)>\n"
		"\t<!ATTLIST " XML_ROOT " build CDATA #IMPLIED>\n"
		"\t<!ATTLIST " XML_ROOT " debug (yes|no) \"no\">\n"
		"\t<!ATTLIST " XML_ROOT " mameconfig CDATA #REQUIRED>\n"
		"\t<!ELEMENT " XML_TOP " (description, year?, manufacturer, biosset*, rom*, disk*, sample*, chip*, display*, sound?, input?, dipswitch*, configuration*, category*, adjuster*, driver?, device*, softwarelist*, ramoption*)>\n"
		"\t\t<!ATTLIST " XML_TOP " name CDATA #REQUIRED>\n"
		"\t\t<!ATTLIST " XML_TOP " sourcefile CDATA #IMPLIED>\n"
		"\t\t<!ATTLIST " XML_TOP " isbios (yes|no) \"no\">\n"
		"\t\t<!ATTLIST " XML_TOP " ismechanical (yes|no) \"no\">\n"
		"\t\t<!ATTLIST " XML_TOP " runnable (yes|no) \"yes\">\n"
		"\t\t<!ATTLIST " XML_TOP " cloneof CDATA #IMPLIED>\n"
		"\t\t<!ATTLIST " XML_TOP " romof CDATA #IMPLIED>\n"
		"\t\t<!ATTLIST " XML_TOP " sampleof CDATA #IMPLIED>\n"
		"\t\t<!ELEMENT description (#PCDATA)>\n"
		"\t\t<!ELEMENT year (#PCDATA)>\n"
		"\t\t<!ELEMENT manufacturer (#PCDATA)>\n"
		"\t\t<!ELEMENT biosset EMPTY>\n"
		"\t\t\t<!ATTLIST biosset name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST biosset description CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST biosset default (yes|no) \"no\">\n"
		"\t\t<!ELEMENT rom EMPTY>\n"
		"\t\t\t<!ATTLIST rom name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST rom bios CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST rom size CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST rom crc CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST rom md5 CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST rom sha1 CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST rom merge CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST rom region CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST rom offset CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST rom status (baddump|nodump|good) \"good\">\n"
		"\t\t\t<!ATTLIST rom optional (yes|no) \"no\">\n"
		"\t\t<!ELEMENT disk EMPTY>\n"
		"\t\t\t<!ATTLIST disk name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST disk md5 CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST disk sha1 CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST disk merge CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST disk region CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST disk index CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST disk status (baddump|nodump|good) \"good\">\n"
		"\t\t\t<!ATTLIST disk optional (yes|no) \"no\">\n"
		"\t\t<!ELEMENT sample EMPTY>\n"
		"\t\t\t<!ATTLIST sample name CDATA #REQUIRED>\n"
		"\t\t<!ELEMENT chip EMPTY>\n"
		"\t\t\t<!ATTLIST chip name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST chip tag CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST chip type (cpu|audio) #REQUIRED>\n"
		"\t\t\t<!ATTLIST chip clock CDATA #IMPLIED>\n"
		"\t\t<!ELEMENT display EMPTY>\n"
		"\t\t\t<!ATTLIST display type (raster|vector|lcd|unknown) #REQUIRED>\n"
		"\t\t\t<!ATTLIST display rotate (0|90|180|270) #REQUIRED>\n"
		"\t\t\t<!ATTLIST display flipx (yes|no) \"no\">\n"
		"\t\t\t<!ATTLIST display width CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display height CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display refresh CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST display pixclock CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display htotal CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display hbend CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display hbstart CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display vtotal CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display vbend CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST display vbstart CDATA #IMPLIED>\n"
		"\t\t<!ELEMENT sound EMPTY>\n"
		"\t\t\t<!ATTLIST sound channels CDATA #REQUIRED>\n"
		"\t\t<!ELEMENT input (control*)>\n"
		"\t\t\t<!ATTLIST input service (yes|no) \"no\">\n"
		"\t\t\t<!ATTLIST input tilt (yes|no) \"no\">\n"
		"\t\t\t<!ATTLIST input players CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST input buttons CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST input coins CDATA #IMPLIED>\n"
		"\t\t\t<!ELEMENT control EMPTY>\n"
		"\t\t\t\t<!ATTLIST control type CDATA #REQUIRED>\n"
		"\t\t\t\t<!ATTLIST control minimum CDATA #IMPLIED>\n"
		"\t\t\t\t<!ATTLIST control maximum CDATA #IMPLIED>\n"
		"\t\t\t\t<!ATTLIST control sensitivity CDATA #IMPLIED>\n"
		"\t\t\t\t<!ATTLIST control keydelta CDATA #IMPLIED>\n"
		"\t\t\t\t<!ATTLIST control reverse (yes|no) \"no\">\n"
		"\t\t<!ELEMENT dipswitch (dipvalue*)>\n"
		"\t\t\t<!ATTLIST dipswitch name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST dipswitch tag CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST dipswitch mask CDATA #REQUIRED>\n"
		"\t\t\t<!ELEMENT dipvalue EMPTY>\n"
		"\t\t\t\t<!ATTLIST dipvalue name CDATA #REQUIRED>\n"
		"\t\t\t\t<!ATTLIST dipvalue value CDATA #REQUIRED>\n"
		"\t\t\t\t<!ATTLIST dipvalue default (yes|no) \"no\">\n"
		"\t\t<!ELEMENT configuration (confsetting*)>\n"
		"\t\t\t<!ATTLIST configuration name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST configuration tag CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST configuration mask CDATA #REQUIRED>\n"
		"\t\t\t<!ELEMENT confsetting EMPTY>\n"
		"\t\t\t\t<!ATTLIST confsetting name CDATA #REQUIRED>\n"
		"\t\t\t\t<!ATTLIST confsetting value CDATA #REQUIRED>\n"
		"\t\t\t\t<!ATTLIST confsetting default (yes|no) \"no\">\n"
		"\t\t<!ELEMENT category (item*)>\n"
		"\t\t\t<!ATTLIST category name CDATA #REQUIRED>\n"
		"\t\t\t<!ELEMENT item EMPTY>\n"
		"\t\t\t\t<!ATTLIST item name CDATA #REQUIRED>\n"
		"\t\t\t\t<!ATTLIST item default (yes|no) \"no\">\n"
		"\t\t<!ELEMENT adjuster EMPTY>\n"
		"\t\t\t<!ATTLIST adjuster name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST adjuster default CDATA #REQUIRED>\n"
		"\t\t<!ELEMENT driver EMPTY>\n"
		"\t\t\t<!ATTLIST driver status (good|imperfect|preliminary) #REQUIRED>\n"
		"\t\t\t<!ATTLIST driver emulation (good|imperfect|preliminary) #REQUIRED>\n"
		"\t\t\t<!ATTLIST driver color (good|imperfect|preliminary) #REQUIRED>\n"
		"\t\t\t<!ATTLIST driver sound (good|imperfect|preliminary) #REQUIRED>\n"
		"\t\t\t<!ATTLIST driver graphic (good|imperfect|preliminary) #REQUIRED>\n"
		"\t\t\t<!ATTLIST driver cocktail (good|imperfect|preliminary) #IMPLIED>\n"
		"\t\t\t<!ATTLIST driver protection (good|imperfect|preliminary) #IMPLIED>\n"
		"\t\t\t<!ATTLIST driver savestate (supported|unsupported) #REQUIRED>\n"
		"\t\t\t<!ATTLIST driver palettesize CDATA #REQUIRED>\n"
		"\t\t<!ELEMENT device (instance*, extension*)>\n"
		"\t\t\t<!ATTLIST device type CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST device tag CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST device mandatory CDATA #IMPLIED>\n"
		"\t\t\t<!ATTLIST device interface CDATA #IMPLIED>\n"
		"\t\t\t<!ELEMENT instance EMPTY>\n"
		"\t\t\t\t<!ATTLIST instance name CDATA #REQUIRED>\n"
		"\t\t\t\t<!ATTLIST instance briefname CDATA #REQUIRED>\n"
		"\t\t\t<!ELEMENT extension EMPTY>\n"
		"\t\t\t\t<!ATTLIST extension name CDATA #REQUIRED>\n"
		"\t\t<!ELEMENT softwarelist EMPTY>\n"
		"\t\t\t<!ATTLIST softwarelist name CDATA #REQUIRED>\n"
		"\t\t\t<!ATTLIST softwarelist status (original|compatible) #REQUIRED>\n"
		"\t\t<!ELEMENT ramoption (#PCDATA)>\n"
		"\t\t\t<!ATTLIST ramoption default CDATA #IMPLIED>\n"
		"]>\n\n"
		"<" XML_ROOT " build=\"%s\" debug=\""
#ifdef MAME_DEBUG
		"yes"
#else
		"no"
#endif
		"\" mameconfig=\"%d\">\n",
		xml_normalize_string(build_version),
		CONFIG_VERSION
	);

	for (drvnum = 0; games[drvnum] != NULL; drvnum++)
		if (mame_strwildcmp(gamename, games[drvnum]->name) == 0)
			print_game_info(out, games[drvnum], options);

	fprintf(out, "</" XML_ROOT ">\n");
}