|
|
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: }
444: }
445:
1.1 root 446: if (cfgfile_strval (option, value, "cpu_type", &p->cpu_level, cpumode, 0)) {
1.1.1.7 root 447: p->address_space_24 = p->cpu_level < 8 && !(p->cpu_level & 1);
1.1 root 448: p->cpu_level >>= 1;
449: return 1;
450: }
1.1.1.11 root 451: if (cfgfile_strval (option, value, "cpu_speed", &p->m68k_speed, speedmode, 1)
452: /* Broken earlier versions used to write this out as a string. */
453: || cfgfile_strval (option, value, "finegraincpu_speed", &p->m68k_speed, speedmode, 1))
454: {
1.1 root 455: p->m68k_speed--;
456: return 1;
457: }
1.1.1.8 root 458: if (cfgfile_intval (option, value, "cpu_speed", &p->m68k_speed, 1)) {
459: p->m68k_speed *= CYCLE_UNIT;
460: return 1;
461: }
1.1.1.9 root 462: if (cfgfile_intval (option, value, "finegrain_cpu_speed", &p->m68k_speed, 1)) {
463: if (OFFICIAL_CYCLE_UNIT > CYCLE_UNIT) {
464: int factor = OFFICIAL_CYCLE_UNIT / CYCLE_UNIT;
465: p->m68k_speed = (p->m68k_speed + factor - 1) / factor;
466: }
1.1 root 467: return 1;
1.1.1.9 root 468: }
1.1 root 469:
470: if (strcmp (option, "kbd_lang") == 0) {
471: KbdLang l;
472: if ((l = KBD_LANG_DE, strcasecmp (value, "de") == 0)
1.1.1.9 root 473: || (l = KBD_LANG_DK, strcasecmp (value, "dk") == 0)
1.1 root 474: || (l = KBD_LANG_SE, strcasecmp (value, "se") == 0)
475: || (l = KBD_LANG_US, strcasecmp (value, "us") == 0)
476: || (l = KBD_LANG_FR, strcasecmp (value, "fr") == 0)
477: || (l = KBD_LANG_IT, strcasecmp (value, "it") == 0)
478: || (l = KBD_LANG_ES, strcasecmp (value, "es") == 0))
479: p->keyboard_lang = l;
480: else
481: write_log ("Unknown keyboard language\n");
482: return 1;
483: }
484:
485: if (strcmp (option, "filesystem") == 0
486: || strcmp (option, "hardfile") == 0)
487: {
1.1.1.2 root 488: int secs, heads, reserved, bs, ro;
489: char *aname, *root;
1.1 root 490: char *tmpp = strchr (value, ',');
1.1.1.2 root 491: char *str;
1.1 root 492: if (tmpp == 0)
493: goto invalid_fs;
494:
495: *tmpp++ = '\0';
496: if (strcmp (value, "0") == 0 || strcasecmp (value, "ro") == 0
497: || strcasecmp (value, "readonly") == 0
498: || strcasecmp (value, "read-only") == 0)
1.1.1.2 root 499: ro = 1;
1.1 root 500: else if (strcmp (value, "1") == 0 || strcasecmp (value, "rw") == 0
501: || strcasecmp (value, "readwrite") == 0
502: || strcasecmp (value, "read-write") == 0)
1.1.1.2 root 503: ro = 0;
1.1 root 504: else
505: goto invalid_fs;
1.1.1.2 root 506: secs = 0; heads = 0; reserved = 0; bs = 0;
1.1 root 507:
508: value = tmpp;
509: if (strcmp (option, "filesystem") == 0) {
510: tmpp = strchr (value, ':');
511: if (tmpp == 0)
512: goto invalid_fs;
513: *tmpp++ = '\0';
1.1.1.2 root 514: aname = value;
515: root = tmpp;
1.1 root 516: } else {
1.1.1.2 root 517: if (! getintval (&value, &secs, ',')
518: || ! getintval (&value, &heads, ',')
519: || ! getintval (&value, &reserved, ',')
520: || ! getintval (&value, &bs, ','))
1.1 root 521: goto invalid_fs;
1.1.1.2 root 522: root = value;
523: aname = 0;
1.1 root 524: }
1.1.1.2 root 525: str = cfgfile_subst_path (UNEXPANDED, p->path_hardfile, root);
526: tmpp = add_filesys_unit (p->mountinfo, aname, str, ro, secs,
527: heads, reserved, bs);
528: free (str);
529: if (tmpp)
530: write_log ("Error: %s\n", tmpp);
1.1 root 531: return 1;
532:
533: invalid_fs:
534: write_log ("Invalid filesystem/hardfile specification.\n");
535: return 1;
536: }
537:
538: return 0;
539: }
540:
1.1.1.2 root 541: void cfgfile_parse_line (struct uae_prefs *p, char *line)
1.1 root 542: {
543: int i;
544: char *orig_line = my_strdup (line);
545: char *line1, *line2;
546:
547: line1 = line;
548: line2 = strchr (line, '=');
549: if (! line2) {
550: write_log ("CFGFILE: line was incomplete with only %s\n", line1);
551: return;
552: }
553:
554: *line2++ = '\0';
555:
556: /* Get rid of whitespace. */
1.1.1.2 root 557: i = strlen (line2);
558: while (i > 0 && (line2[i - 1] == '\t' || line2[i - 1] == ' '
559: || line2[i - 1] == '\r' || line2[i - 1] == '\n'))
560: line2[--i] = '\0';
1.1 root 561: line2 += strspn (line2, "\t \r\n");
1.1.1.2 root 562: i = strlen (line);
563: while (i > 0 && (line[i - 1] == '\t' || line[i - 1] == ' '
564: || line[i - 1] == '\r' || line[i - 1] == '\n'))
565: line[--i] = '\0';
1.1 root 566: line += strspn (line, "\t \r\n");
567:
1.1.1.2 root 568: if (! cfgfile_parse_option (p, line, line2)) {
1.1 root 569: struct strlist *u = xmalloc (sizeof (struct strlist));
570: u->str = orig_line;
571: u->next = p->unknown_lines;
572: p->unknown_lines = u;
573: } else
574: free (orig_line);
575: }
576:
577: static void subst (char *p, char *f, int n)
578: {
579: char *str = cfgfile_subst_path (UNEXPANDED, p, f);
580: strncpy (f, str, n - 1);
581: f[n - 1] = '\0';
582: free (str);
583: }
584:
585: int cfgfile_load (struct uae_prefs *p, const char *filename)
586: {
587: int i;
588:
589: FILE *fh;
590: char line[256];
591:
1.1.1.4 root 592: fh = fopen (filename, "r");
1.1 root 593: if (! fh)
594: return 0;
595:
596: while (fgets (line, 256, fh) != 0) {
597: line[strcspn (line, "\t \r\n")] = '\0';
598: if (strlen (line) > 0)
1.1.1.2 root 599: cfgfile_parse_line (p, line);
1.1 root 600: }
601: fclose (fh);
602:
603: for (i = 0; i < 4; i++)
604: subst (p->path_floppy, p->df[i], sizeof p->df[i]);
605: subst (p->path_rom, p->romfile, sizeof p->romfile);
1.1.1.12! root 606: subst (p->path_rom, p->romextfile, sizeof p->romextfile);
1.1 root 607: subst (p->path_rom, p->keyfile, sizeof p->keyfile);
608:
609: return 1;
610: }
611:
612: int cfgfile_save (struct uae_prefs *p, const char *filename)
613: {
614: FILE *fh = fopen (filename, "w");
615: if (! fh)
616: return 0;
617:
618: save_options (fh, p);
619: fclose (fh);
620: return 1;
621: }
622:
623: int cfgfile_get_description (const char *filename, char *description)
624: {
625: int result = 0;
626: struct uae_prefs p;
627: default_prefs (&p);
628: strcpy (p.description, "");
1.1.1.12! root 629: if (cfgfile_load (&p, filename)) {
1.1 root 630: result = 1;
631: strcpy (description, p.description);
632: }
633: discard_prefs (&p);
634: return result;
635: }
636:
637: void cfgfile_show_usage (void)
638: {
639: int i;
640: fprintf (stderr, "UAE Configuration Help:\n" \
641: "=======================\n");
642: for (i = 0; i < sizeof opttable / sizeof *opttable; i++)
643: fprintf (stderr, "%s: %s\n", opttable[i].config_label, opttable[i].config_help);
644: }
1.1.1.4 root 645:
646: /* This implements the old commandline option parsing. I've re-added this
647: because the new way of doing things is painful for me (it requires me
648: to type a couple hundred characters when invoking UAE). The following
649: is far less annoying to use. */
650: static void parse_gfx_specs (char *spec)
651: {
652: char *x0 = my_strdup (spec);
653: char *x1, *x2;
654:
655: x1 = strchr (x0, ':');
656: if (x1 == 0)
657: goto argh;
658: x2 = strchr (x1+1, ':');
659: if (x2 == 0)
660: goto argh;
661: *x1++ = 0; *x2++ = 0;
662:
663: currprefs.gfx_width = atoi (x0);
664: currprefs.gfx_height = atoi (x1);
665: currprefs.gfx_lores = strchr (x2, 'l') != 0;
666: currprefs.gfx_xcenter = strchr (x2, 'x') != 0 ? 1 : strchr (x2, 'X') != 0 ? 2 : 0;
667: currprefs.gfx_ycenter = strchr (x2, 'y') != 0 ? 1 : strchr (x2, 'Y') != 0 ? 2 : 0;
668: currprefs.gfx_linedbl = strchr (x2, 'd') != 0;
669: currprefs.gfx_linedbl += 2 * (strchr (x2, 'D') != 0);
670: currprefs.gfx_afullscreen = strchr (x2, 'a') != 0;
671: currprefs.gfx_pfullscreen = strchr (x2, 'p') != 0;
672: currprefs.gfx_correct_aspect = strchr (x2, 'c') != 0;
673:
674: if (currprefs.gfx_linedbl == 3) {
675: fprintf (stderr, "You can't use both 'd' and 'D' modifiers in the display mode specification.\n");
676: }
677:
678: free (x0);
679: return;
680:
681: argh:
682: fprintf (stderr, "Bad display mode specification.\n");
683: fprintf (stderr, "The format to use is: \"width:height:modifiers\"\n");
684: fprintf (stderr, "Type \"uae -h\" for detailed help.\n");
685: free (x0);
686: }
687:
688: static void parse_sound_spec (char *spec)
689: {
690: char *x0 = my_strdup (spec);
691: char *x1, *x2 = NULL, *x3 = NULL, *x4 = NULL, *x5 = NULL;
692:
693: x1 = strchr (x0, ':');
694: if (x1 != NULL) {
695: *x1++ = '\0';
696: x2 = strchr (x1 + 1, ':');
697: if (x2 != NULL) {
698: *x2++ = '\0';
699: x3 = strchr (x2 + 1, ':');
700: if (x3 != NULL) {
701: *x3++ = '\0';
702: x4 = strchr (x3 + 1, ':');
703: if (x4 != NULL) {
704: *x4++ = '\0';
705: x5 = strchr (x4 + 1, ':');
706: }
707: }
708: }
709: }
710: currprefs.produce_sound = atoi (x0);
711: if (x1) {
1.1.1.8 root 712: currprefs.mixed_stereo = 0;
713: if (*x1 == 'S')
714: currprefs.stereo = currprefs.mixed_stereo = 1;
715: else if (*x1 == 's')
1.1.1.4 root 716: currprefs.stereo = 1;
717: else
718: currprefs.stereo = 0;
719: }
720: if (x2)
721: currprefs.sound_bits = atoi (x2);
722: if (x3)
723: currprefs.sound_freq = atoi (x3);
724: if (x4)
725: currprefs.sound_maxbsiz = currprefs.sound_minbsiz = atoi (x4);
726: if (x5)
727: currprefs.sound_minbsiz = atoi (x5);
728: free (x0);
729: return;
730: }
731:
732:
733: static void parse_joy_spec (char *spec)
734: {
735: int v0 = 2, v1 = 0;
736: if (strlen(spec) != 2)
737: goto bad;
738:
739: switch (spec[0]) {
740: case '0': v0 = 0; break;
741: case '1': v0 = 1; break;
742: case 'M': case 'm': v0 = 2; break;
743: case 'A': case 'a': v0 = 3; break;
744: case 'B': case 'b': v0 = 4; break;
745: case 'C': case 'c': v0 = 5; break;
746: default: goto bad;
747: }
748:
749: switch (spec[1]) {
750: case '0': v1 = 0; break;
751: case '1': v1 = 1; break;
752: case 'M': case 'm': v1 = 2; break;
753: case 'A': case 'a': v1 = 3; break;
754: case 'B': case 'b': v1 = 4; break;
755: case 'C': case 'c': v1 = 5; break;
756: default: goto bad;
757: }
758: if (v0 == v1)
759: goto bad;
760: /* Let's scare Pascal programmers */
761: if (0)
762: bad:
763: fprintf (stderr, "Bad joystick mode specification. Use -J xy, where x and y\n"
764: "can be 0 for joystick 0, 1 for joystick 1, M for mouse, and\n"
765: "a, b or c for different keyboard settings.\n");
766:
767: currprefs.jport0 = v0;
768: currprefs.jport1 = v1;
769: }
770:
771: static void parse_filesys_spec (int readonly, char *spec)
772: {
773: char buf[256];
774: char *s2;
775:
776: strncpy (buf, spec, 255); buf[255] = 0;
777: s2 = strchr (buf, ':');
778: if (s2) {
779: *s2++ = '\0';
780: #ifdef __DOS__
781: {
782: char *tmp;
783:
784: while ((tmp = strchr (s2, '\\')))
785: *tmp = '/';
786: }
787: #endif
788: s2 = add_filesys_unit (currprefs.mountinfo, buf, s2, readonly, 0, 0, 0, 0);
789: if (s2)
790: fprintf (stderr, "%s\n", s2);
791: } else {
792: fprintf (stderr, "Usage: [-m | -M] VOLNAME:mount_point\n");
793: }
794: }
795:
796: static void parse_hardfile_spec (char *spec)
797: {
798: char *x0 = my_strdup (spec);
799: char *x1, *x2, *x3, *x4;
800:
801: x1 = strchr (x0, ':');
802: if (x1 == NULL)
803: goto argh;
804: *x1++ = '\0';
805: x2 = strchr (x1 + 1, ':');
806: if (x2 == NULL)
807: goto argh;
808: *x2++ = '\0';
809: x3 = strchr (x2 + 1, ':');
810: if (x3 == NULL)
811: goto argh;
812: *x3++ = '\0';
813: x4 = strchr (x3 + 1, ':');
814: if (x4 == NULL)
815: goto argh;
816: *x4++ = '\0';
817: x4 = add_filesys_unit (currprefs.mountinfo, 0, x4, 0, atoi (x0), atoi (x1), atoi (x2), atoi (x3));
818: if (x4)
819: fprintf (stderr, "%s\n", x4);
820:
821: free (x0);
822: return;
823:
824: argh:
825: free (x0);
826: fprintf (stderr, "Bad hardfile parameter specified - type \"uae -h\" for help.\n");
827: return;
828: }
829:
830: static void parse_cpu_specs (char *spec)
831: {
1.1.1.7 root 832: if (*spec < '0' || *spec > '4') {
833: fprintf (stderr, "CPU parameter string must begin with '0', '1', '2', '3' or '4'.\n");
1.1.1.4 root 834: return;
835: }
836:
837: currprefs.cpu_level = *spec++ - '0';
838: currprefs.address_space_24 = currprefs.cpu_level < 2;
839: currprefs.cpu_compatible = 0;
840: while (*spec != '\0') {
841: switch (*spec) {
842: case 'a':
843: if (currprefs.cpu_level < 2)
844: fprintf (stderr, "In 68000/68010 emulation, the address space is always 24 bit.\n");
1.1.1.7 root 845: else if (currprefs.cpu_level >= 4)
846: fprintf (stderr, "In 68040 emulation, the address space is always 32 bit.\n");
1.1.1.4 root 847: else
848: currprefs.address_space_24 = 1;
849: break;
850: case 'c':
851: if (currprefs.cpu_level != 0)
852: fprintf (stderr, "The more compatible CPU emulation is only available for 68000\n"
853: "emulation, not for 68010 upwards.\n");
854: else
855: currprefs.cpu_compatible = 1;
856: break;
857: default:
858: fprintf (stderr, "Bad CPU parameter specified - type \"uae -h\" for help.\n");
859: break;
860: }
861: spec++;
862: }
863: }
864:
865: /* Returns the number of args used up (0 or 1). */
866: int parse_cmdline_option (char c, char *arg)
867: {
1.1.1.5 root 868: const char arg_required[] = "0123rKpImWSAJwNCZUFcblOdHRv";
1.1.1.4 root 869:
870: if (strchr (arg_required, c) && ! arg) {
871: fprintf (stderr, "Missing argument for option `-%c'!\n", c);
872: return 0;
873: }
874:
875: switch (c) {
1.1.1.5 root 876: case 'h': usage (); exit (0);
1.1.1.4 root 877:
1.1.1.5 root 878: case '0': strncpy (currprefs.df[0], arg, 255); currprefs.df[0][255] = 0; break;
879: case '1': strncpy (currprefs.df[1], arg, 255); currprefs.df[1][255] = 0; break;
880: case '2': strncpy (currprefs.df[2], arg, 255); currprefs.df[2][255] = 0; break;
881: case '3': strncpy (currprefs.df[3], arg, 255); currprefs.df[3][255] = 0; break;
882: case 'r': strncpy (currprefs.romfile, arg, 255); currprefs.romfile[255] = 0; break;
883: case 'K': strncpy (currprefs.keyfile, arg, 255); currprefs.keyfile[255] = 0; break;
884: case 'p': strncpy (currprefs.prtname, arg, 255); currprefs.prtname[255] = 0; break;
1.1.1.4 root 885: /* case 'I': strncpy (currprefs.sername, arg, 255); currprefs.sername[255] = 0; currprefs.use_serial = 1; break; */
1.1.1.5 root 886: case 'm': case 'M': parse_filesys_spec (c == 'M', arg); break;
887: case 'W': parse_hardfile_spec (arg); break;
888: case 'S': parse_sound_spec (arg); break;
889: case 'R': currprefs.gfx_framerate = atoi (arg); break;
890: case 'A': currprefs.emul_accuracy = atoi (arg); break;
891: case 'x': currprefs.no_xhair = 1; break;
892: case 'i': currprefs.illegal_mem = 1; break;
893: case 'J': parse_joy_spec (arg); break;
894:
895: case 't': currprefs.test_drawing_speed = 1; break;
896: case 'L': currprefs.x11_use_low_bandwidth = 1; break;
897: case 'T': currprefs.x11_use_mitshm = 1; break;
898: case 'w': currprefs.m68k_speed = atoi (arg); break;
1.1.1.4 root 899:
900: /* case 'g': currprefs.use_gfxlib = 1; break; */
1.1.1.5 root 901: case 'G': currprefs.start_gui = 0; break;
902: case 'D': currprefs.start_debugger = 1; break;
1.1.1.4 root 903:
1.1.1.5 root 904: case 'n':
1.1.1.4 root 905: if (strchr (arg, '3') != 0)
906: currprefs.blits_32bit_enabled = 1;
907: if (strchr (arg, 'i') != 0)
908: currprefs.immediate_blits = 1;
909: break;
910:
1.1.1.5 root 911: case 'v':
912: set_chipset_mask (&currprefs, atoi (arg));
913: break;
914:
915: case 'C':
1.1.1.4 root 916: parse_cpu_specs (arg);
917: break;
918:
1.1.1.5 root 919: case 'Z':
1.1.1.4 root 920: currprefs.z3fastmem_size = atoi (arg) * 0x100000;
921: break;
922:
1.1.1.5 root 923: case 'U':
1.1.1.4 root 924: currprefs.gfxmem_size = atoi (arg) * 0x100000;
925: break;
926:
1.1.1.5 root 927: case 'F':
1.1.1.4 root 928: currprefs.fastmem_size = atoi (arg) * 0x100000;
929: break;
930:
1.1.1.5 root 931: case 'b':
1.1.1.4 root 932: currprefs.bogomem_size = atoi (arg) * 0x40000;
933: break;
934:
1.1.1.5 root 935: case 'c':
1.1.1.4 root 936: currprefs.chipmem_size = atoi (arg) * 0x80000;
937: break;
938:
1.1.1.5 root 939: case 'l':
1.1.1.4 root 940: if (0 == strcasecmp(arg, "de"))
941: currprefs.keyboard_lang = KBD_LANG_DE;
1.1.1.9 root 942: else if (0 == strcasecmp(arg, "dk"))
943: currprefs.keyboard_lang = KBD_LANG_DK;
1.1.1.4 root 944: else if (0 == strcasecmp(arg, "us"))
945: currprefs.keyboard_lang = KBD_LANG_US;
946: else if (0 == strcasecmp(arg, "se"))
947: currprefs.keyboard_lang = KBD_LANG_SE;
948: else if (0 == strcasecmp(arg, "fr"))
949: currprefs.keyboard_lang = KBD_LANG_FR;
950: else if (0 == strcasecmp(arg, "it"))
951: currprefs.keyboard_lang = KBD_LANG_IT;
952: else if (0 == strcasecmp(arg, "es"))
953: currprefs.keyboard_lang = KBD_LANG_ES;
954: break;
955:
1.1.1.5 root 956: case 'O': parse_gfx_specs (arg); break;
957: case 'd':
1.1.1.4 root 958: if (strchr (arg, 'S') != NULL || strchr (arg, 's')) {
959: write_log (" Serial on demand.\n");
960: currprefs.serial_demand = 1;
961: }
962: if (strchr (arg, 'P') != NULL || strchr (arg, 'p')) {
963: write_log (" Parallel on demand.\n");
964: currprefs.parallel_demand = 1;
965: }
966:
967: break;
968:
1.1.1.5 root 969: case 'H':
1.1.1.4 root 970: currprefs.color_mode = atoi (arg);
971: if (currprefs.color_mode < 0) {
972: fprintf (stderr, "Bad color mode selected. Using default.\n");
973: currprefs.color_mode = 0;
974: }
975: break;
1.1.1.5 root 976: default:
1.1.1.4 root 977: fprintf (stderr, "Unknown option `-%c'!\n", c);
978: break;
979: }
980: return !! strchr (arg_required, c);
981: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.