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