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