|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Config file handling
5: * This still needs some thought before it's complete...
6: *
7: * Copyright 1998 Brian King, Bernd Schmidt
8: */
9:
10: #include "sysconfig.h"
11: #include "sysdeps.h"
12:
13: #include <ctype.h>
14:
15: #include "config.h"
16: #include "options.h"
1.1.1.10 root 17: #include "threaddep/thread.h"
1.1 root 18: #include "uae.h"
19: #include "autoconf.h"
1.1.1.8 root 20: #include "events.h"
1.1.1.3 root 21: #include "custom.h"
1.1 root 22:
23: /* @@@ need to get rid of this... just cut part of the manual and print that
24: * as a help text. */
25: struct cfg_lines
26: {
27: const char *config_label, *config_help;
28: };
29:
30: static struct cfg_lines opttable[] =
31: {
32: {"help", "Prints this help" },
33: {"config_description", "" },
34: {"use_gui", "Enable the GUI? If no, then goes straight to emulator" },
35: {"use_debugger", "Enable the debugger?" },
36: {"cpu_speed", "can be max, real, or a number between 1 and 20" },
37: {"cpu_type", "Can be 68000, 68010, 68020, 68020/68881" },
38: {"cpu_compatible", "yes enables compatibility-mode" },
39: {"cpu_24bit_addressing", "must be set to 'no' in order for Z3mem or P96mem to work" },
40: {"autoconfig", "yes = add filesystems and extra ram" },
41: {"accuracy", "emulation accuracy, default is 2" },
42: {"log_illegal_mem", "print illegal memory access by Amiga software?" },
43: {"fastmem_size", "Size in megabytes of fast-memory" },
44: {"chipmem_size", "Size in megabytes of chip-memory" },
45: {"bogomem_size", "Size in megabytes of bogo-memory at 0xC00000" },
46: {"a3000mem_size", "Size in megabytes of A3000 memory" },
47: {"gfxcard_size", "Size in megabytes of Picasso96 graphics-card memory" },
48: {"z3mem_size", "Size in megabytes of Zorro-III expansion memory" },
49: {"gfx_test_speed", "Test graphics speed?" },
50: {"framerate", "Print every nth frame" },
51: {"gfx_width", "Screen width" },
52: {"gfx_height", "Screen height" },
53: {"gfx_lores", "Treat display as lo-res?" },
54: {"gfx_linemode", "Can be none, double, or scanlines" },
55: {"gfx_fullscreen_amiga", "Amiga screens are fullscreen?" },
56: {"gfx_fullscreen_picasso", "Picasso screens are fullscreen?" },
57: {"gfx_correct_aspect", "Correct aspect ratio?" },
58: {"gfx_center_horizontal", "Center display horizontally?" },
59: {"gfx_center_vertical", "Center display vertically?" },
60: {"gfx_colour_mode", "" },
61: {"32bit_blits", "Enable 32 bit blitter emulation" },
62: {"immediate_blits", "Perform blits immediately" },
1.1.1.15! root 63: {"show_leds", "LED display" },
1.1 root 64: {"gfxlib_replacement", "Use graphics.library replacement?" },
65: {"sound_output", "" },
66: {"sound_frequency", "" },
67: {"sound_bits", "" },
68: {"sound_channels", "" },
69: {"sound_min_buff", "" },
70: {"sound_max_buff", "" },
71: {"parallel_on_demand", "" },
72: {"serial_on_demand", "" },
73: {"joyport0", "" },
74: {"joyport1", "" },
75: {"kickstart_rom_file", "Kickstart ROM image, (C) Copyright Amiga, Inc." },
1.1.1.12 root 76: {"kickstart_ext_rom_file", "Extended Kickstart ROM image, (C) Copyright Amiga, Inc." },
1.1 root 77: {"kickstart_key_file", "Key-file for encrypted ROM images (from Cloanto's Amiga Forever)" },
78: {"floppy0", "Diskfile for drive 0" },
79: {"floppy1", "Diskfile for drive 1" },
80: {"floppy2", "Diskfile for drive 2" },
81: {"floppy3", "Diskfile for drive 3" },
82: {"hardfile", "access,sectors, surfaces, reserved, blocksize, path format" },
83: {"filesystem", "access,'Amiga volume-name':'host directory path' - where 'access' can be 'read-only' or 'read-write'" }
84: };
85:
1.1.1.10 root 86: static const char *guimode1[] = { "no", "yes", "nowait", 0 };
87: static const char *guimode2[] = { "false", "true", "nowait", 0 };
88: static const char *guimode3[] = { "0", "1", "nowait", 0 };
89: static const char *csmode[] = { "ocs", "ecs_agnus", "ecs_denise", "ecs", "aga", 0 };
1.1 root 90: static const char *linemode1[] = { "none", "double", "scanlines", 0 };
91: static const char *linemode2[] = { "n", "d", "s", 0 };
92: static const char *speedmode[] = { "max", "real", 0 };
1.1.1.7 root 93: static const char *cpumode[] = {
94: "68000", "68000", "68010", "68010", "68ec020", "68020", "68ec020/68881", "68020/68881",
1.1.1.9 root 95: "68040", "68040", 0
1.1.1.7 root 96: };
1.1 root 97: static const char *portmode[] = { "joy0", "joy1", "mouse", "kbd1", "kbd2", "kbd3", 0 };
98: static const char *colormode1[] = { "8bit", "15bit", "16bit", "8bit_dither", "4bit_dither", "32bit", 0 };
99: static const char *colormode2[] = { "8", "15", "16", "8d", "4d", "32", 0 };
100: static const char *soundmode[] = { "none", "interrupts", "normal", "exact", 0 };
1.1.1.2 root 101: static const char *centermode1[] = { "none", "simple", "smart", 0 };
102: static const char *centermode2[] = { "false", "true", "smart", 0 };
1.1.1.8 root 103: static const char *stereomode1[] = { "mono", "stereo", "mixed", 0 };
104: static const char *stereomode2[] = { "m", "s", "x", 0 };
105: static const char *stereomode3[] = { "1", "2", "3", 0 };
1.1.1.4 root 106: static const char *interpolmode[] = { "none", "rh", "crux", 0 };
1.1.1.9 root 107: static const char *collmode[] = { "none", "sprites", "playfields", "full", 0 };
1.1 root 108:
109: #define UNEXPANDED "$(FILE_PATH)"
110:
111: static int match_string (const char *table[], const char *str)
112: {
113: int i;
114: for (i = 0; table[i] != 0; i++)
115: if (strcasecmp (table[i], str) == 0)
116: return i;
117: return -1;
118: }
119:
120: char *cfgfile_subst_path (const char *path, const char *subst, const char *file)
121: {
122: /* @@@ use strcasecmp for some targets. */
123: if (strlen (path) > 0 && strncmp (file, path, strlen (path)) == 0) {
124: int l;
125: char *p = xmalloc (strlen (file) + strlen (subst) + 2);
126: strcpy (p, subst);
127: l = strlen (p);
128: while (l > 0 && p[l - 1] == '/')
129: p[--l] = '\0';
130: l = strlen (path);
131: while (file[l] == '/')
132: l++;
133: strcat (p, "/"); strcat (p, file + l);
134: return p;
135: }
136: return my_strdup (file);
137: }
138:
139: void save_options (FILE *f, struct uae_prefs *p)
140: {
141: struct strlist *sl;
142: char *str;
143: int i;
144:
145: fprintf (f, "config_description=%s\n", p->description);
146:
147: for (sl = p->unknown_lines; sl; sl = sl->next)
148: fprintf (f, "%s\n", sl->str);
149:
150: fprintf (f, "%s.rom_path=%s\n", TARGET_NAME, p->path_rom);
151: fprintf (f, "%s.floppy_path=%s\n", TARGET_NAME, p->path_floppy);
152: fprintf (f, "%s.hardfile_path=%s\n", TARGET_NAME, p->path_hardfile);
153:
1.1.1.2 root 154: target_save_options (f, p);
155:
1.1.1.10 root 156: fprintf (f, "use_gui=%s\n", guimode1[p->start_gui]);
1.1 root 157: fprintf (f, "use_debugger=%s\n", p->start_debugger ? "true" : "false");
158: str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->romfile);
159: fprintf (f, "kickstart_rom_file=%s\n", str);
160: free (str);
1.1.1.12 root 161: str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->romextfile);
162: fprintf (f, "kickstart_ext_rom_file=%s\n", str);
163: free (str);
1.1 root 164: str = cfgfile_subst_path (p->path_rom, UNEXPANDED, p->keyfile);
165: fprintf (f, "kickstart_key_file=%s\n", str);
166: free (str);
1.1.1.11 root 167: fprintf (f, "kickshifter=%s\n", p->kickshifter ? "true" : "false");
1.1 root 168:
169: for (i = 0; i < 4; i++) {
170: str = cfgfile_subst_path (p->path_floppy, UNEXPANDED, p->df[i]);
171: fprintf (f, "floppy%d=%s\n", i, str);
172: free (str);
173: }
1.1.1.6 root 174: fprintf (f, "nr_floppies=%d\n", p->nr_floppies);
1.1 root 175: fprintf (f, "parallel_on_demand=%s\n", p->parallel_demand ? "true" : "false");
176: fprintf (f, "serial_on_demand=%s\n", p->serial_demand ? "true" : "false");
177:
178: fprintf (f, "sound_output=%s\n", soundmode[p->produce_sound]);
1.1.1.14 root 179: fprintf (f, "sound_channels=%s\n", stereomode1[p->sound_stereo + p->mixed_stereo]);
1.1 root 180: fprintf (f, "sound_bits=%d\n", p->sound_bits);
181: fprintf (f, "sound_min_buff=%d\n", p->sound_minbsiz);
182: fprintf (f, "sound_max_buff=%d\n", p->sound_maxbsiz);
183: fprintf (f, "sound_frequency=%d\n", p->sound_freq);
1.1.1.4 root 184: fprintf (f, "sound_interpol=%s\n", interpolmode[p->sound_interpol]);
1.1 root 185:
186: fprintf (f, "sound_pri_time=%d\n", p->sound_pri_time);
187: fprintf (f, "sound_pri_cutoff=%d\n", p->sound_pri_cutoff);
188:
189: fprintf (f, "joyport0=%s\n", portmode[p->jport0]);
190: fprintf (f, "joyport1=%s\n", portmode[p->jport1]);
191:
1.1.1.3 root 192: fprintf (f, "bsdsocket_emu=%s\n", p->socket_emu ? "true" : "false");
1.1 root 193:
1.1.1.3 root 194: fprintf (f, "gfx_framerate=%d\n", p->gfx_framerate);
1.1 root 195: fprintf (f, "gfx_width=%d\n", p->gfx_width);
196: fprintf (f, "gfx_height=%d\n", p->gfx_height);
197: fprintf (f, "gfx_lores=%s\n", p->gfx_lores ? "true" : "false");
198: fprintf (f, "gfx_linemode=%s\n", linemode1[p->gfx_linedbl]);
199: fprintf (f, "gfx_correct_aspect=%s\n", p->gfx_correct_aspect ? "true" : "false");
200: fprintf (f, "gfx_fullscreen_amiga=%s\n", p->gfx_afullscreen ? "true" : "false");
201: fprintf (f, "gfx_fullscreen_picasso=%s\n", p->gfx_pfullscreen ? "true" : "false");
1.1.1.2 root 202: fprintf (f, "gfx_center_horizontal=%s\n", centermode1[p->gfx_xcenter]);
203: fprintf (f, "gfx_center_vertical=%s\n", centermode1[p->gfx_ycenter]);
1.1 root 204: fprintf (f, "gfx_colour_mode=%s\n", colormode1[p->color_mode]);
205:
206: fprintf (f, "immediate_blits=%s\n", p->immediate_blits ? "true" : "false");
1.1.1.3 root 207: fprintf (f, "ntsc=%s\n", p->ntscmode ? "true" : "false");
1.1.1.15! root 208: fprintf (f, "show_leds=%s\n", p->leds_on_screen ? "true" : "false");
1.1.1.3 root 209: if (p->chipset_mask & CSMASK_AGA)
210: fprintf (f, "chipset=aga\n");
211: else if ((p->chipset_mask & CSMASK_ECS_AGNUS) && (p->chipset_mask & CSMASK_ECS_AGNUS))
212: fprintf (f, "chipset=ecs\n");
213: else if (p->chipset_mask & CSMASK_ECS_AGNUS)
214: fprintf (f, "chipset=ecs_agnus\n");
215: else if (p->chipset_mask & CSMASK_ECS_DENISE)
216: fprintf (f, "chipset=ecs_denise\n");
217: else
218: fprintf (f, "chipset=ocs\n");
1.1.1.8 root 219: fprintf (f, "collision_level=%s\n", collmode[p->collision_level]);
1.1 root 220:
221: fprintf (f, "fastmem_size=%d\n", p->fastmem_size / 0x100000);
222: fprintf (f, "a3000mem_size=%d\n", p->a3000mem_size / 0x100000);
223: fprintf (f, "z3mem_size=%d\n", p->z3fastmem_size / 0x100000);
224: fprintf (f, "bogomem_size=%d\n", p->bogomem_size / 0x40000);
225: fprintf (f, "gfxcard_size=%d\n", p->gfxmem_size / 0x100000);
226: fprintf (f, "chipmem_size=%d\n", p->chipmem_size / 0x80000);
227:
1.1.1.3 root 228: if (p->m68k_speed > 0)
1.1.1.8 root 229: fprintf (f, "finegrain_cpu_speed=%d\n", p->m68k_speed);
1.1 root 230: else
1.1.1.11 root 231: fprintf (f, "cpu_speed=%s\n", p->m68k_speed == -1 ? "max" : "real");
1.1 root 232:
233: fprintf (f, "cpu_type=%s\n", cpumode[p->cpu_level * 2 + !p->address_space_24]);
234: fprintf (f, "cpu_compatible=%s\n", p->cpu_compatible ? "true" : "false");
235:
236: fprintf (f, "accuracy=%d\n", p->emul_accuracy);
237: fprintf (f, "log_illegal_mem=%s\n", p->illegal_mem ? "true" : "false");
238:
239: fprintf (f, "kbd_lang=%s\n", (p->keyboard_lang == KBD_LANG_DE ? "de"
1.1.1.9 root 240: : p->keyboard_lang == KBD_LANG_DK ? "dk"
1.1 root 241: : p->keyboard_lang == KBD_LANG_ES ? "es"
242: : p->keyboard_lang == KBD_LANG_US ? "us"
243: : p->keyboard_lang == KBD_LANG_SE ? "se"
244: : p->keyboard_lang == KBD_LANG_FR ? "fr"
245: : p->keyboard_lang == KBD_LANG_IT ? "it"
246: : "FOO"));
247:
248: write_filesys_config (p->mountinfo, UNEXPANDED, p->path_hardfile, f);
249:
250: /* Don't write gfxlib/gfx_test_speed options. */
251: }
252:
253: int cfgfile_yesno (char *option, char *value, char *name, int *location)
254: {
255: if (strcmp (option, name) != 0)
256: return 0;
257: if (strcasecmp (value, "yes") == 0 || strcasecmp (value, "y") == 0
258: || strcasecmp (value, "true") == 0 || strcasecmp (value, "t") == 0)
259: *location = 1;
260: else if (strcasecmp (value, "no") == 0 || strcasecmp (value, "n") == 0
261: || strcasecmp (value, "false") == 0 || strcasecmp (value, "f") == 0)
262: *location = 0;
263: else
264: write_log ("Option `%s' requires a value of either `yes' or `no'.\n", option);
265: return 1;
266: }
267:
268: int cfgfile_intval (char *option, char *value, char *name, int *location, int scale)
269: {
270: int base = 10;
271: char *endptr;
272: if (strcmp (option, name) != 0)
273: return 0;
274: /* I guess octal isn't popular enough to worry about here... */
275: if (value[0] == '0' && value[1] == 'x')
276: value += 2, base = 16;
277: *location = strtol (value, &endptr, base) * scale;
278:
279: if (*endptr != '\0' || *value == '\0')
280: write_log ("Option `%s' requires a numeric argument.\n", option);
281: return 1;
282: }
283:
284: int cfgfile_strval (char *option, char *value, char *name, int *location, const char *table[], int more)
285: {
286: int val;
287: if (strcmp (option, name) != 0)
288: return 0;
289: val = match_string (table, value);
290: if (val == -1) {
1.1.1.6 root 291: if (more)
292: return 0;
293:
294: write_log ("Unknown value for option `%s'.\n", option);
1.1 root 295: return 1;
296: }
297: *location = val;
298: return 1;
299: }
300:
301: int cfgfile_string (char *option, char *value, char *name, char *location, int maxsz)
302: {
303: if (strcmp (option, name) != 0)
304: return 0;
305: strncpy (location, value, maxsz - 1);
306: location[maxsz - 1] = '\0';
307: return 1;
308: }
309:
310: static int getintval (char **p, int *result, int delim)
311: {
312: char *value = *p;
313: int base = 10;
314: char *endptr;
315: char *p2 = strchr (*p, delim);
316:
317: if (p2 == 0)
318: return 0;
319:
320: *p2++ = '\0';
321:
322: if (value[0] == '0' && value[1] == 'x')
323: value += 2, base = 16;
324: *result = strtol (value, &endptr, base);
325: *p = p2;
326:
327: if (*endptr != '\0' || *value == '\0')
328: return 0;
329:
330: return 1;
331: }
332:
1.1.1.8 root 333: static void set_chipset_mask (struct uae_prefs *p, int val)
1.1.1.5 root 334: {
335: p->chipset_mask = (val == 0 ? 0
336: : val == 1 ? CSMASK_ECS_AGNUS
337: : val == 2 ? CSMASK_ECS_DENISE
338: : val == 3 ? CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS
339: : CSMASK_AGA | CSMASK_ECS_DENISE | CSMASK_ECS_AGNUS);
340: }
341:
1.1.1.2 root 342: int cfgfile_parse_option (struct uae_prefs *p, char *option, char *value)
1.1 root 343: {
1.1.1.3 root 344: int tmpval;
1.1.1.9 root 345: int dummy;
1.1 root 346: char *section = 0;
347: char *tmpp;
1.1.1.3 root 348:
1.1 root 349: for (tmpp = option; *tmpp != '\0'; tmpp++)
350: if (isupper (*tmpp))
351: *tmpp = tolower (*tmpp);
352: tmpp = strchr (option, '.');
353: if (tmpp) {
354: section = option;
355: option = tmpp + 1;
356: *tmpp = '\0';
357: if (strcmp (section, TARGET_NAME) == 0) {
358: /* We special case the various path options here. */
359: if (cfgfile_string (option, value, "rom_path", p->path_rom, 256)
360: || cfgfile_string (option, value, "floppy_path", p->path_floppy, 256)
361: || cfgfile_string (option, value, "hardfile_path", p->path_hardfile, 256))
362: return 1;
363: return target_parse_option (p, option, value);
364: }
365: return 0;
366: }
367: if (cfgfile_yesno (option, value, "use_debugger", &p->start_debugger)
1.1.1.3 root 368: || cfgfile_yesno (option, value, "bsdsocket_emu", &p->socket_emu)
1.1 root 369: || cfgfile_yesno (option, value, "immediate_blits", &p->immediate_blits)
1.1.1.11 root 370: || cfgfile_yesno (option, value, "kickshifter", &p->kickshifter)
1.1 root 371: || cfgfile_yesno (option, value, "gfx_lores", &p->gfx_lores)
372: || cfgfile_yesno (option, value, "gfx_correct_aspect", &p->gfx_correct_aspect)
373: || cfgfile_yesno (option, value, "gfx_fullscreen_amiga", &p->gfx_afullscreen)
374: || cfgfile_yesno (option, value, "gfx_fullscreen_picasso", &p->gfx_pfullscreen)
1.1.1.3 root 375: || cfgfile_yesno (option, value, "ntsc", &p->ntscmode)
1.1 root 376: || cfgfile_yesno (option, value, "cpu_compatible", &p->cpu_compatible)
377: || cfgfile_yesno (option, value, "cpu_24bit_addressing", &p->address_space_24)
1.1.1.9 root 378: /* For backward compatibility. */
379: || cfgfile_yesno (option, value, "autoconfig", &dummy)
1.1 root 380: || cfgfile_yesno (option, value, "parallel_on_demand", &p->parallel_demand)
381: || cfgfile_yesno (option, value, "serial_on_demand", &p->serial_demand)
382: || cfgfile_yesno (option, value, "log_illegal_mem", &p->illegal_mem))
383: return 1;
384: if (cfgfile_intval (option, value, "accuracy", &p->emul_accuracy, 1)
385: || cfgfile_intval (option, value, "sound_min_buff", &p->sound_minbsiz, 1)
386: || cfgfile_intval (option, value, "sound_max_buff", &p->sound_maxbsiz, 1)
387: || cfgfile_intval (option, value, "sound_frequency", &p->sound_freq, 1)
388: || cfgfile_intval (option, value, "sound_bits", &p->sound_bits, 1)
389: || cfgfile_intval (option, value, "sound_pri_cutoff", &p->sound_pri_cutoff, 1)
390: || cfgfile_intval (option, value, "sound_pri_time", &p->sound_pri_time, 1)
1.1.1.3 root 391: || cfgfile_intval (option, value, "gfx_framerate", &p->gfx_framerate, 1)
1.1 root 392: || cfgfile_intval (option, value, "gfx_width", &p->gfx_width, 1)
393: || cfgfile_intval (option, value, "gfx_height", &p->gfx_height, 1)
394: || cfgfile_intval (option, value, "fastmem_size", &p->fastmem_size, 0x100000)
395: || cfgfile_intval (option, value, "a3000mem_size", &p->a3000mem_size, 0x100000)
396: || cfgfile_intval (option, value, "z3mem_size", &p->z3fastmem_size, 0x100000)
397: || cfgfile_intval (option, value, "bogomem_size", &p->bogomem_size, 0x40000)
398: || cfgfile_intval (option, value, "gfxcard_size", &p->gfxmem_size, 0x100000)
1.1.1.6 root 399: || cfgfile_intval (option, value, "chipmem_size", &p->chipmem_size, 0x80000)
400: || cfgfile_intval (option, value, "nr_floppies", &p->nr_floppies, 1))
1.1 root 401: return 1;
402: if (cfgfile_strval (option, value, "sound_output", &p->produce_sound, soundmode, 0)
1.1.1.4 root 403: || cfgfile_strval (option, value, "sound_interpol", &p->sound_interpol, interpolmode, 0)
1.1 root 404: || cfgfile_strval (option, value, "joyport0", &p->jport0, portmode, 0)
405: || cfgfile_strval (option, value, "joyport1", &p->jport1, portmode, 0)
1.1.1.10 root 406: || cfgfile_strval (option, value, "use_gui", &p->start_gui, guimode1, 1)
407: || cfgfile_strval (option, value, "use_gui", &p->start_gui, guimode2, 1)
408: || cfgfile_strval (option, value, "use_gui", &p->start_gui, guimode3, 0)
1.1.1.8 root 409: || cfgfile_strval (option, value, "collision_level", &p->collision_level, collmode, 0)
1.1 root 410: || cfgfile_strval (option, value, "gfx_linemode", &p->gfx_linedbl, linemode1, 1)
411: || cfgfile_strval (option, value, "gfx_linemode", &p->gfx_linedbl, linemode2, 0)
1.1.1.2 root 412: || cfgfile_strval (option, value, "gfx_center_horizontal", &p->gfx_xcenter, centermode1, 1)
413: || cfgfile_strval (option, value, "gfx_center_vertical", &p->gfx_ycenter, centermode1, 1)
414: || cfgfile_strval (option, value, "gfx_center_horizontal", &p->gfx_xcenter, centermode2, 0)
415: || cfgfile_strval (option, value, "gfx_center_vertical", &p->gfx_ycenter, centermode2, 0)
1.1 root 416: || cfgfile_strval (option, value, "gfx_colour_mode", &p->color_mode, colormode1, 1)
417: || cfgfile_strval (option, value, "gfx_colour_mode", &p->color_mode, colormode2, 0)
418: || cfgfile_strval (option, value, "gfx_color_mode", &p->color_mode, colormode1, 1)
419: || cfgfile_strval (option, value, "gfx_color_mode", &p->color_mode, colormode2, 0))
420: return 1;
421: if (cfgfile_string (option, value, "floppy0", p->df[0], 256)
422: || cfgfile_string (option, value, "floppy1", p->df[1], 256)
423: || cfgfile_string (option, value, "floppy2", p->df[2], 256)
424: || cfgfile_string (option, value, "floppy3", p->df[3], 256)
425: || cfgfile_string (option, value, "kickstart_rom_file", p->romfile, 256)
1.1.1.12 root 426: || cfgfile_string (option, value, "kickstart_ext_rom_file", p->romextfile, 256)
1.1 root 427: || cfgfile_string (option, value, "kickstart_key_file", p->keyfile, 256)
1.1.1.2 root 428: || cfgfile_string (option, value, "config_description", p->description, 256))
1.1 root 429: return 1;
430:
431: /* Tricky ones... */
1.1.1.3 root 432: if (cfgfile_strval (option, value, "chipset", &tmpval, csmode, 0)) {
1.1.1.5 root 433: set_chipset_mask (p, tmpval);
1.1.1.3 root 434: return 1;
435: }
1.1.1.7 root 436:
1.1.1.14 root 437: if (cfgfile_strval (option, value, "sound_channels", &p->sound_stereo, stereomode1, 1)
438: || cfgfile_strval (option, value, "sound_channels", &p->sound_stereo, stereomode2, 1)
439: || cfgfile_strval (option, value, "sound_channels", &p->sound_stereo, stereomode3, 0))
1.1.1.8 root 440: {
441: p->mixed_stereo = 0;
1.1.1.14 root 442: if (p->sound_stereo == 2) {
443: p->sound_stereo = 1;
1.1.1.8 root 444: p->mixed_stereo = 1;
445: }
1.1.1.13 root 446: return 1;
1.1.1.8 root 447: }
448:
1.1 root 449: if (cfgfile_strval (option, value, "cpu_type", &p->cpu_level, cpumode, 0)) {
1.1.1.7 root 450: p->address_space_24 = p->cpu_level < 8 && !(p->cpu_level & 1);
1.1 root 451: p->cpu_level >>= 1;
452: return 1;
453: }
1.1.1.11 root 454: if (cfgfile_strval (option, value, "cpu_speed", &p->m68k_speed, speedmode, 1)
455: /* Broken earlier versions used to write this out as a string. */
456: || cfgfile_strval (option, value, "finegraincpu_speed", &p->m68k_speed, speedmode, 1))
457: {
1.1 root 458: p->m68k_speed--;
459: return 1;
460: }
1.1.1.8 root 461: if (cfgfile_intval (option, value, "cpu_speed", &p->m68k_speed, 1)) {
462: p->m68k_speed *= CYCLE_UNIT;
463: return 1;
464: }
1.1.1.9 root 465: if (cfgfile_intval (option, value, "finegrain_cpu_speed", &p->m68k_speed, 1)) {
466: if (OFFICIAL_CYCLE_UNIT > CYCLE_UNIT) {
467: int factor = OFFICIAL_CYCLE_UNIT / CYCLE_UNIT;
468: p->m68k_speed = (p->m68k_speed + factor - 1) / factor;
469: }
1.1 root 470: return 1;
1.1.1.9 root 471: }
1.1 root 472:
473: if (strcmp (option, "kbd_lang") == 0) {
474: KbdLang l;
475: if ((l = KBD_LANG_DE, strcasecmp (value, "de") == 0)
1.1.1.9 root 476: || (l = KBD_LANG_DK, strcasecmp (value, "dk") == 0)
1.1 root 477: || (l = KBD_LANG_SE, strcasecmp (value, "se") == 0)
478: || (l = KBD_LANG_US, strcasecmp (value, "us") == 0)
479: || (l = KBD_LANG_FR, strcasecmp (value, "fr") == 0)
480: || (l = KBD_LANG_IT, strcasecmp (value, "it") == 0)
481: || (l = KBD_LANG_ES, strcasecmp (value, "es") == 0))
482: p->keyboard_lang = l;
483: else
484: write_log ("Unknown keyboard language\n");
485: return 1;
486: }
487:
488: if (strcmp (option, "filesystem") == 0
489: || strcmp (option, "hardfile") == 0)
490: {
1.1.1.2 root 491: int secs, heads, reserved, bs, ro;
492: char *aname, *root;
1.1 root 493: char *tmpp = strchr (value, ',');
1.1.1.2 root 494: char *str;
1.1 root 495: if (tmpp == 0)
496: goto invalid_fs;
497:
498: *tmpp++ = '\0';
499: if (strcmp (value, "0") == 0 || strcasecmp (value, "ro") == 0
500: || strcasecmp (value, "readonly") == 0
501: || strcasecmp (value, "read-only") == 0)
1.1.1.2 root 502: ro = 1;
1.1 root 503: else if (strcmp (value, "1") == 0 || strcasecmp (value, "rw") == 0
504: || strcasecmp (value, "readwrite") == 0
505: || strcasecmp (value, "read-write") == 0)
1.1.1.2 root 506: ro = 0;
1.1 root 507: else
508: goto invalid_fs;
1.1.1.2 root 509: secs = 0; heads = 0; reserved = 0; bs = 0;
1.1 root 510:
511: value = tmpp;
512: if (strcmp (option, "filesystem") == 0) {
513: tmpp = strchr (value, ':');
514: if (tmpp == 0)
515: goto invalid_fs;
516: *tmpp++ = '\0';
1.1.1.2 root 517: aname = value;
518: root = tmpp;
1.1 root 519: } else {
1.1.1.2 root 520: if (! getintval (&value, &secs, ',')
521: || ! getintval (&value, &heads, ',')
522: || ! getintval (&value, &reserved, ',')
523: || ! getintval (&value, &bs, ','))
1.1 root 524: goto invalid_fs;
1.1.1.2 root 525: root = value;
526: aname = 0;
1.1 root 527: }
1.1.1.2 root 528: str = cfgfile_subst_path (UNEXPANDED, p->path_hardfile, root);
529: tmpp = add_filesys_unit (p->mountinfo, aname, str, ro, secs,
530: heads, reserved, bs);
531: free (str);
532: if (tmpp)
533: write_log ("Error: %s\n", tmpp);
1.1 root 534: return 1;
535:
536: invalid_fs:
537: write_log ("Invalid filesystem/hardfile specification.\n");
538: return 1;
539: }
540:
541: return 0;
542: }
543:
1.1.1.2 root 544: void cfgfile_parse_line (struct uae_prefs *p, char *line)
1.1 root 545: {
546: int i;
547: char *orig_line = my_strdup (line);
548: char *line1, *line2;
549:
550: line1 = line;
551: line2 = strchr (line, '=');
552: if (! line2) {
553: write_log ("CFGFILE: line was incomplete with only %s\n", line1);
554: return;
555: }
556:
557: *line2++ = '\0';
558:
559: /* Get rid of whitespace. */
1.1.1.2 root 560: i = strlen (line2);
561: while (i > 0 && (line2[i - 1] == '\t' || line2[i - 1] == ' '
562: || line2[i - 1] == '\r' || line2[i - 1] == '\n'))
563: line2[--i] = '\0';
1.1 root 564: line2 += strspn (line2, "\t \r\n");
1.1.1.2 root 565: i = strlen (line);
566: while (i > 0 && (line[i - 1] == '\t' || line[i - 1] == ' '
567: || line[i - 1] == '\r' || line[i - 1] == '\n'))
568: line[--i] = '\0';
1.1 root 569: line += strspn (line, "\t \r\n");
570:
1.1.1.2 root 571: if (! cfgfile_parse_option (p, line, line2)) {
1.1 root 572: struct strlist *u = xmalloc (sizeof (struct strlist));
573: u->str = orig_line;
574: u->next = p->unknown_lines;
575: p->unknown_lines = u;
576: } else
577: free (orig_line);
578: }
579:
580: static void subst (char *p, char *f, int n)
581: {
582: char *str = cfgfile_subst_path (UNEXPANDED, p, f);
583: strncpy (f, str, n - 1);
584: f[n - 1] = '\0';
585: free (str);
586: }
587:
588: int cfgfile_load (struct uae_prefs *p, const char *filename)
589: {
590: int i;
591:
592: FILE *fh;
593: char line[256];
594:
1.1.1.4 root 595: fh = fopen (filename, "r");
1.1 root 596: if (! fh)
597: return 0;
598:
599: while (fgets (line, 256, fh) != 0) {
1.1.1.13 root 600: int len = strlen (line);
601: /* Delete trailing whitespace. */
602: while (len > 0 && strcspn (line + len - 1, "\t \r\n") == 0) {
603: line[--len] = '\0';
604: }
1.1 root 605: if (strlen (line) > 0)
1.1.1.2 root 606: cfgfile_parse_line (p, line);
1.1 root 607: }
608: fclose (fh);
609:
610: for (i = 0; i < 4; i++)
611: subst (p->path_floppy, p->df[i], sizeof p->df[i]);
612: subst (p->path_rom, p->romfile, sizeof p->romfile);
1.1.1.12 root 613: subst (p->path_rom, p->romextfile, sizeof p->romextfile);
1.1 root 614: subst (p->path_rom, p->keyfile, sizeof p->keyfile);
615:
616: return 1;
617: }
618:
619: int cfgfile_save (struct uae_prefs *p, const char *filename)
620: {
621: FILE *fh = fopen (filename, "w");
622: if (! fh)
623: return 0;
624:
625: save_options (fh, p);
626: fclose (fh);
627: return 1;
628: }
629:
630: int cfgfile_get_description (const char *filename, char *description)
631: {
632: int result = 0;
633: struct uae_prefs p;
634: default_prefs (&p);
635: strcpy (p.description, "");
1.1.1.12 root 636: if (cfgfile_load (&p, filename)) {
1.1 root 637: result = 1;
638: strcpy (description, p.description);
639: }
640: discard_prefs (&p);
641: return result;
642: }
643:
644: void cfgfile_show_usage (void)
645: {
646: int i;
647: fprintf (stderr, "UAE Configuration Help:\n" \
648: "=======================\n");
649: for (i = 0; i < sizeof opttable / sizeof *opttable; i++)
650: fprintf (stderr, "%s: %s\n", opttable[i].config_label, opttable[i].config_help);
651: }
1.1.1.4 root 652:
653: /* This implements the old commandline option parsing. I've re-added this
654: because the new way of doing things is painful for me (it requires me
655: to type a couple hundred characters when invoking UAE). The following
656: is far less annoying to use. */
657: static void parse_gfx_specs (char *spec)
658: {
659: char *x0 = my_strdup (spec);
660: char *x1, *x2;
661:
662: x1 = strchr (x0, ':');
663: if (x1 == 0)
664: goto argh;
665: x2 = strchr (x1+1, ':');
666: if (x2 == 0)
667: goto argh;
668: *x1++ = 0; *x2++ = 0;
669:
670: currprefs.gfx_width = atoi (x0);
671: currprefs.gfx_height = atoi (x1);
672: currprefs.gfx_lores = strchr (x2, 'l') != 0;
673: currprefs.gfx_xcenter = strchr (x2, 'x') != 0 ? 1 : strchr (x2, 'X') != 0 ? 2 : 0;
674: currprefs.gfx_ycenter = strchr (x2, 'y') != 0 ? 1 : strchr (x2, 'Y') != 0 ? 2 : 0;
675: currprefs.gfx_linedbl = strchr (x2, 'd') != 0;
676: currprefs.gfx_linedbl += 2 * (strchr (x2, 'D') != 0);
677: currprefs.gfx_afullscreen = strchr (x2, 'a') != 0;
678: currprefs.gfx_pfullscreen = strchr (x2, 'p') != 0;
679: currprefs.gfx_correct_aspect = strchr (x2, 'c') != 0;
680:
681: if (currprefs.gfx_linedbl == 3) {
682: fprintf (stderr, "You can't use both 'd' and 'D' modifiers in the display mode specification.\n");
683: }
684:
685: free (x0);
686: return;
687:
688: argh:
689: fprintf (stderr, "Bad display mode specification.\n");
690: fprintf (stderr, "The format to use is: \"width:height:modifiers\"\n");
691: fprintf (stderr, "Type \"uae -h\" for detailed help.\n");
692: free (x0);
693: }
694:
695: static void parse_sound_spec (char *spec)
696: {
697: char *x0 = my_strdup (spec);
698: char *x1, *x2 = NULL, *x3 = NULL, *x4 = NULL, *x5 = NULL;
699:
700: x1 = strchr (x0, ':');
701: if (x1 != NULL) {
702: *x1++ = '\0';
703: x2 = strchr (x1 + 1, ':');
704: if (x2 != NULL) {
705: *x2++ = '\0';
706: x3 = strchr (x2 + 1, ':');
707: if (x3 != NULL) {
708: *x3++ = '\0';
709: x4 = strchr (x3 + 1, ':');
710: if (x4 != NULL) {
711: *x4++ = '\0';
712: x5 = strchr (x4 + 1, ':');
713: }
714: }
715: }
716: }
717: currprefs.produce_sound = atoi (x0);
718: if (x1) {
1.1.1.8 root 719: currprefs.mixed_stereo = 0;
720: if (*x1 == 'S')
1.1.1.14 root 721: currprefs.sound_stereo = currprefs.mixed_stereo = 1;
1.1.1.8 root 722: else if (*x1 == 's')
1.1.1.14 root 723: currprefs.sound_stereo = 1;
1.1.1.4 root 724: else
1.1.1.14 root 725: currprefs.sound_stereo = 0;
1.1.1.4 root 726: }
727: if (x2)
728: currprefs.sound_bits = atoi (x2);
729: if (x3)
730: currprefs.sound_freq = atoi (x3);
731: if (x4)
732: currprefs.sound_maxbsiz = currprefs.sound_minbsiz = atoi (x4);
733: if (x5)
734: currprefs.sound_minbsiz = atoi (x5);
735: free (x0);
736: return;
737: }
738:
739:
740: static void parse_joy_spec (char *spec)
741: {
742: int v0 = 2, v1 = 0;
743: if (strlen(spec) != 2)
744: goto bad;
745:
746: switch (spec[0]) {
747: case '0': v0 = 0; break;
748: case '1': v0 = 1; break;
749: case 'M': case 'm': v0 = 2; break;
750: case 'A': case 'a': v0 = 3; break;
751: case 'B': case 'b': v0 = 4; break;
752: case 'C': case 'c': v0 = 5; break;
753: default: goto bad;
754: }
755:
756: switch (spec[1]) {
757: case '0': v1 = 0; break;
758: case '1': v1 = 1; break;
759: case 'M': case 'm': v1 = 2; break;
760: case 'A': case 'a': v1 = 3; break;
761: case 'B': case 'b': v1 = 4; break;
762: case 'C': case 'c': v1 = 5; break;
763: default: goto bad;
764: }
765: if (v0 == v1)
766: goto bad;
767: /* Let's scare Pascal programmers */
768: if (0)
769: bad:
770: fprintf (stderr, "Bad joystick mode specification. Use -J xy, where x and y\n"
771: "can be 0 for joystick 0, 1 for joystick 1, M for mouse, and\n"
772: "a, b or c for different keyboard settings.\n");
773:
774: currprefs.jport0 = v0;
775: currprefs.jport1 = v1;
776: }
777:
778: static void parse_filesys_spec (int readonly, char *spec)
779: {
780: char buf[256];
781: char *s2;
782:
783: strncpy (buf, spec, 255); buf[255] = 0;
784: s2 = strchr (buf, ':');
785: if (s2) {
786: *s2++ = '\0';
787: #ifdef __DOS__
788: {
789: char *tmp;
790:
791: while ((tmp = strchr (s2, '\\')))
792: *tmp = '/';
793: }
794: #endif
795: s2 = add_filesys_unit (currprefs.mountinfo, buf, s2, readonly, 0, 0, 0, 0);
796: if (s2)
797: fprintf (stderr, "%s\n", s2);
798: } else {
799: fprintf (stderr, "Usage: [-m | -M] VOLNAME:mount_point\n");
800: }
801: }
802:
803: static void parse_hardfile_spec (char *spec)
804: {
805: char *x0 = my_strdup (spec);
806: char *x1, *x2, *x3, *x4;
807:
808: x1 = strchr (x0, ':');
809: if (x1 == NULL)
810: goto argh;
811: *x1++ = '\0';
812: x2 = strchr (x1 + 1, ':');
813: if (x2 == NULL)
814: goto argh;
815: *x2++ = '\0';
816: x3 = strchr (x2 + 1, ':');
817: if (x3 == NULL)
818: goto argh;
819: *x3++ = '\0';
820: x4 = strchr (x3 + 1, ':');
821: if (x4 == NULL)
822: goto argh;
823: *x4++ = '\0';
824: x4 = add_filesys_unit (currprefs.mountinfo, 0, x4, 0, atoi (x0), atoi (x1), atoi (x2), atoi (x3));
825: if (x4)
826: fprintf (stderr, "%s\n", x4);
827:
828: free (x0);
829: return;
830:
831: argh:
832: free (x0);
833: fprintf (stderr, "Bad hardfile parameter specified - type \"uae -h\" for help.\n");
834: return;
835: }
836:
837: static void parse_cpu_specs (char *spec)
838: {
1.1.1.7 root 839: if (*spec < '0' || *spec > '4') {
840: fprintf (stderr, "CPU parameter string must begin with '0', '1', '2', '3' or '4'.\n");
1.1.1.4 root 841: return;
842: }
843:
844: currprefs.cpu_level = *spec++ - '0';
845: currprefs.address_space_24 = currprefs.cpu_level < 2;
846: currprefs.cpu_compatible = 0;
847: while (*spec != '\0') {
848: switch (*spec) {
849: case 'a':
850: if (currprefs.cpu_level < 2)
851: fprintf (stderr, "In 68000/68010 emulation, the address space is always 24 bit.\n");
1.1.1.7 root 852: else if (currprefs.cpu_level >= 4)
853: fprintf (stderr, "In 68040 emulation, the address space is always 32 bit.\n");
1.1.1.4 root 854: else
855: currprefs.address_space_24 = 1;
856: break;
857: case 'c':
858: if (currprefs.cpu_level != 0)
859: fprintf (stderr, "The more compatible CPU emulation is only available for 68000\n"
860: "emulation, not for 68010 upwards.\n");
861: else
862: currprefs.cpu_compatible = 1;
863: break;
864: default:
865: fprintf (stderr, "Bad CPU parameter specified - type \"uae -h\" for help.\n");
866: break;
867: }
868: spec++;
869: }
870: }
871:
872: /* Returns the number of args used up (0 or 1). */
873: int parse_cmdline_option (char c, char *arg)
874: {
1.1.1.5 root 875: const char arg_required[] = "0123rKpImWSAJwNCZUFcblOdHRv";
1.1.1.4 root 876:
877: if (strchr (arg_required, c) && ! arg) {
878: fprintf (stderr, "Missing argument for option `-%c'!\n", c);
879: return 0;
880: }
881:
882: switch (c) {
1.1.1.5 root 883: case 'h': usage (); exit (0);
1.1.1.4 root 884:
1.1.1.5 root 885: case '0': strncpy (currprefs.df[0], arg, 255); currprefs.df[0][255] = 0; break;
886: case '1': strncpy (currprefs.df[1], arg, 255); currprefs.df[1][255] = 0; break;
887: case '2': strncpy (currprefs.df[2], arg, 255); currprefs.df[2][255] = 0; break;
888: case '3': strncpy (currprefs.df[3], arg, 255); currprefs.df[3][255] = 0; break;
889: case 'r': strncpy (currprefs.romfile, arg, 255); currprefs.romfile[255] = 0; break;
890: case 'K': strncpy (currprefs.keyfile, arg, 255); currprefs.keyfile[255] = 0; break;
891: case 'p': strncpy (currprefs.prtname, arg, 255); currprefs.prtname[255] = 0; break;
1.1.1.4 root 892: /* case 'I': strncpy (currprefs.sername, arg, 255); currprefs.sername[255] = 0; currprefs.use_serial = 1; break; */
1.1.1.5 root 893: case 'm': case 'M': parse_filesys_spec (c == 'M', arg); break;
894: case 'W': parse_hardfile_spec (arg); break;
895: case 'S': parse_sound_spec (arg); break;
896: case 'R': currprefs.gfx_framerate = atoi (arg); break;
897: case 'A': currprefs.emul_accuracy = atoi (arg); break;
898: case 'x': currprefs.no_xhair = 1; break;
899: case 'i': currprefs.illegal_mem = 1; break;
900: case 'J': parse_joy_spec (arg); break;
901:
902: case 't': currprefs.test_drawing_speed = 1; break;
903: case 'L': currprefs.x11_use_low_bandwidth = 1; break;
904: case 'T': currprefs.x11_use_mitshm = 1; break;
905: case 'w': currprefs.m68k_speed = atoi (arg); break;
1.1.1.4 root 906:
907: /* case 'g': currprefs.use_gfxlib = 1; break; */
1.1.1.5 root 908: case 'G': currprefs.start_gui = 0; break;
909: case 'D': currprefs.start_debugger = 1; break;
1.1.1.4 root 910:
1.1.1.5 root 911: case 'n':
1.1.1.4 root 912: if (strchr (arg, '3') != 0)
913: currprefs.blits_32bit_enabled = 1;
914: if (strchr (arg, 'i') != 0)
915: currprefs.immediate_blits = 1;
916: break;
917:
1.1.1.5 root 918: case 'v':
919: set_chipset_mask (&currprefs, atoi (arg));
920: break;
921:
922: case 'C':
1.1.1.4 root 923: parse_cpu_specs (arg);
924: break;
925:
1.1.1.5 root 926: case 'Z':
1.1.1.4 root 927: currprefs.z3fastmem_size = atoi (arg) * 0x100000;
928: break;
929:
1.1.1.5 root 930: case 'U':
1.1.1.4 root 931: currprefs.gfxmem_size = atoi (arg) * 0x100000;
932: break;
933:
1.1.1.5 root 934: case 'F':
1.1.1.4 root 935: currprefs.fastmem_size = atoi (arg) * 0x100000;
936: break;
937:
1.1.1.5 root 938: case 'b':
1.1.1.4 root 939: currprefs.bogomem_size = atoi (arg) * 0x40000;
940: break;
941:
1.1.1.5 root 942: case 'c':
1.1.1.4 root 943: currprefs.chipmem_size = atoi (arg) * 0x80000;
944: break;
945:
1.1.1.5 root 946: case 'l':
1.1.1.4 root 947: if (0 == strcasecmp(arg, "de"))
948: currprefs.keyboard_lang = KBD_LANG_DE;
1.1.1.9 root 949: else if (0 == strcasecmp(arg, "dk"))
950: currprefs.keyboard_lang = KBD_LANG_DK;
1.1.1.4 root 951: else if (0 == strcasecmp(arg, "us"))
952: currprefs.keyboard_lang = KBD_LANG_US;
953: else if (0 == strcasecmp(arg, "se"))
954: currprefs.keyboard_lang = KBD_LANG_SE;
955: else if (0 == strcasecmp(arg, "fr"))
956: currprefs.keyboard_lang = KBD_LANG_FR;
957: else if (0 == strcasecmp(arg, "it"))
958: currprefs.keyboard_lang = KBD_LANG_IT;
959: else if (0 == strcasecmp(arg, "es"))
960: currprefs.keyboard_lang = KBD_LANG_ES;
961: break;
962:
1.1.1.5 root 963: case 'O': parse_gfx_specs (arg); break;
964: case 'd':
1.1.1.4 root 965: if (strchr (arg, 'S') != NULL || strchr (arg, 's')) {
966: write_log (" Serial on demand.\n");
967: currprefs.serial_demand = 1;
968: }
969: if (strchr (arg, 'P') != NULL || strchr (arg, 'p')) {
970: write_log (" Parallel on demand.\n");
971: currprefs.parallel_demand = 1;
972: }
973:
974: break;
975:
1.1.1.5 root 976: case 'H':
1.1.1.4 root 977: currprefs.color_mode = atoi (arg);
978: if (currprefs.color_mode < 0) {
979: fprintf (stderr, "Bad color mode selected. Using default.\n");
980: currprefs.color_mode = 0;
981: }
982: break;
1.1.1.5 root 983: default:
1.1.1.4 root 984: fprintf (stderr, "Unknown option `-%c'!\n", c);
985: break;
986: }
987: return !! strchr (arg_required, c);
988: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.