diff --git a/src/config.c b/src/config.c index 20e9df4..ca2a184 100644 --- a/src/config.c +++ b/src/config.c @@ -13,7 +13,8 @@ typedef struct list_t struct list_t *next; } list_t; -static list_t config_head; +static list_t global_config_head; +static list_t machine_config_head; typedef struct section_t { @@ -43,13 +44,14 @@ typedef struct entry_t (new)->next = NULL; \ } -void config_dump() +void config_dump(int is_global) { section_t *current_section; - + list_t *head = is_global ? &global_config_head : &machine_config_head; + pclog("Config data :\n"); - current_section = (section_t *)config_head.next; + current_section = (section_t *)head->next; while (current_section) { @@ -70,10 +72,11 @@ void config_dump() } } -void config_free() +void config_free(int is_global) { section_t *current_section; - current_section = (section_t *)config_head.next; + list_t *head = is_global ? &global_config_head : &machine_config_head; + current_section = (section_t *)head->next; while (current_section) { @@ -95,16 +98,17 @@ void config_free() } } -void config_load(char *fn) +void config_load(int is_global, char *fn) { FILE *f = fopen(fn, "rt"); section_t *current_section; + list_t *head = is_global ? &global_config_head : &machine_config_head; - memset(&config_head, 0, sizeof(list_t)); + memset(head, 0, sizeof(list_t)); current_section = malloc(sizeof(section_t)); memset(current_section, 0, sizeof(section_t)); - list_add(¤t_section->list, &config_head); + list_add(¤t_section->list, head); if (!f) return; @@ -144,7 +148,7 @@ void config_load(char *fn) new_section = malloc(sizeof(section_t)); memset(new_section, 0, sizeof(section_t)); strncpy(new_section->name, name, 256); - list_add(&new_section->list, &config_head); + list_add(&new_section->list, head); current_section = new_section; @@ -187,7 +191,7 @@ void config_load(char *fn) fclose(f); - config_dump(); + config_dump(is_global); } @@ -198,12 +202,13 @@ void config_new() fclose(f); } -static section_t *find_section(char *name) +static section_t *find_section(char *name, int is_global) { section_t *current_section; char blank[] = ""; - - current_section = (section_t *)config_head.next; + list_t *head = is_global ? &global_config_head : &machine_config_head; + + current_section = (section_t *)head->next; if (!name) name = blank; @@ -233,13 +238,14 @@ static entry_t *find_entry(section_t *section, char *name) return NULL; } -static section_t *create_section(char *name) +static section_t *create_section(char *name, int is_global) { section_t *new_section = malloc(sizeof(section_t)); - + list_t *head = is_global ? &global_config_head : &machine_config_head; + memset(new_section, 0, sizeof(section_t)); strncpy(new_section->name, name, 256); - list_add(&new_section->list, &config_head); + list_add(&new_section->list, head); return new_section; } @@ -254,13 +260,13 @@ static entry_t *create_entry(section_t *section, char *name) return new_entry; } -int config_get_int(char *head, char *name, int def) +int config_get_int(int is_global, char *head, char *name, int def) { section_t *section; entry_t *entry; int value; - section = find_section(head); + section = find_section(head, is_global); if (!section) return def; @@ -275,12 +281,12 @@ int config_get_int(char *head, char *name, int def) return value; } -char *config_get_string(char *head, char *name, char *def) +char *config_get_string(int is_global, char *head, char *name, char *def) { section_t *section; entry_t *entry; - section = find_section(head); + section = find_section(head, is_global); if (!section) return def; @@ -293,15 +299,15 @@ char *config_get_string(char *head, char *name, char *def) return entry->data; } -void config_set_int(char *head, char *name, int val) +void config_set_int(int is_global, char *head, char *name, int val) { section_t *section; entry_t *entry; - section = find_section(head); + section = find_section(head, is_global); if (!section) - section = create_section(head); + section = create_section(head, is_global); entry = find_entry(section, name); @@ -311,15 +317,15 @@ void config_set_int(char *head, char *name, int val) sprintf(entry->data, "%i", val); } -void config_set_string(char *head, char *name, char *val) +void config_set_string(int is_global, char *head, char *name, char *val) { section_t *section; entry_t *entry; - section = find_section(head); + section = find_section(head, is_global); if (!section) - section = create_section(head); + section = create_section(head, is_global); entry = find_entry(section, name); @@ -370,12 +376,13 @@ char *get_extension(char *s) return &s[c+1]; } -void config_save(char *fn) +void config_save(int is_global, char *fn) { FILE *f = fopen(fn, "wt"); section_t *current_section; - - current_section = (section_t *)config_head.next; + list_t *head = is_global ? &global_config_head : &machine_config_head; + + current_section = (section_t *)head->next; while (current_section) { diff --git a/src/config.h b/src/config.h index d8710b0..23b0a48 100644 --- a/src/config.h +++ b/src/config.h @@ -1,16 +1,19 @@ -int config_get_int(char *head, char *name, int def); -char *config_get_string(char *head, char *name, char *def); -void config_set_int(char *head, char *name, int val); -void config_set_string(char *head, char *name, char *val); +int config_get_int(int is_global, char *head, char *name, int def); +char *config_get_string(int is_global, char *head, char *name, char *def); +void config_set_int(int is_global, char *head, char *name, int val); +void config_set_string(int is_global, char *head, char *name, char *val); char *get_filename(char *s); void append_filename(char *dest, char *s1, char *s2, int size); void put_backslash(char *s); char *get_extension(char *s); -void config_load(char *fn); -void config_save(char *fn); -void config_dump(); -void config_free(); +void config_load(int is_global, char *fn); +void config_save(int is_global, char *fn); +void config_dump(int is_global); +void config_free(int is_global); extern char config_file_default[256]; + +#define CFG_MACHINE 0 +#define CFG_GLOBAL 1 diff --git a/src/device.c b/src/device.c index 65526d5..c94b7b2 100644 --- a/src/device.c +++ b/src/device.c @@ -121,7 +121,7 @@ int device_get_config_int(char *s) while (config->type != -1) { if (!strcmp(s, config->name)) - return config_get_int(current_device->name, s, config->default_int); + return config_get_int(CFG_MACHINE, current_device->name, s, config->default_int); config++; } @@ -135,7 +135,7 @@ char *device_get_config_string(char *s) while (config->type != -1) { if (!strcmp(s, config->name)) - return config_get_string(current_device->name, s, config->default_string); + return config_get_string(CFG_MACHINE, current_device->name, s, config->default_string); config++; } @@ -155,7 +155,7 @@ int model_get_config_int(char *s) while (config->type != -1) { if (!strcmp(s, config->name)) - return config_get_int(device->name, s, config->default_int); + return config_get_int(CFG_MACHINE, device->name, s, config->default_int); config++; } @@ -175,7 +175,7 @@ char *model_get_config_string(char *s) while (config->type != -1) { if (!strcmp(s, config->name)) - return config_get_string(device->name, s, config->default_string); + return config_get_string(CFG_MACHINE, device->name, s, config->default_string); config++; } diff --git a/src/pc.c b/src/pc.c index 48a6767..29b0c05 100644 --- a/src/pc.c +++ b/src/pc.c @@ -579,19 +579,37 @@ void loadconfig(char *fn) { int c, d; char s[512]; + char global_config_file[512]; char *p; + + append_filename(global_config_file, pcempath, "pcem.cfg", 511); + + config_load(CFG_GLOBAL, global_config_file); if (!fn) - config_load(config_file_default); + config_load(CFG_MACHINE, config_file_default); else - config_load(fn); + config_load(CFG_MACHINE, fn); + + vid_resize = config_get_int(CFG_GLOBAL, NULL, "vid_resize", 0); + video_force_aspect_ration = config_get_int(CFG_GLOBAL, NULL, "vid_force_aspect_ratio", 0); + vid_disc_indicator = config_get_int(CFG_GLOBAL, NULL, "vid_disc_indicator", 1); + vid_api = config_get_int(CFG_GLOBAL, NULL, "vid_api", 0); + video_fullscreen_scale = config_get_int(CFG_GLOBAL, NULL, "video_fullscreen_scale", 0); + video_fullscreen_first = config_get_int(CFG_GLOBAL, NULL, "video_fullscreen_first", 1); + + window_w = config_get_int(CFG_GLOBAL, NULL, "window_w", 0); + window_h = config_get_int(CFG_GLOBAL, NULL, "window_h", 0); + window_x = config_get_int(CFG_GLOBAL, NULL, "window_x", 0); + window_y = config_get_int(CFG_GLOBAL, NULL, "window_y", 0); + window_remember = config_get_int(CFG_GLOBAL, NULL, "window_remember", 0); - GAMEBLASTER = config_get_int(NULL, "gameblaster", 0); - GUS = config_get_int(NULL, "gus", 0); - SSI2001 = config_get_int(NULL, "ssi2001", 0); - voodoo_enabled = config_get_int(NULL, "voodoo", 0); + GAMEBLASTER = config_get_int(CFG_MACHINE, NULL, "gameblaster", 0); + GUS = config_get_int(CFG_MACHINE, NULL, "gus", 0); + SSI2001 = config_get_int(CFG_MACHINE, NULL, "ssi2001", 0); + voodoo_enabled = config_get_int(CFG_MACHINE, NULL, "voodoo", 0); - p = (char *)config_get_string(NULL, "model", ""); + p = (char *)config_get_string(CFG_MACHINE, NULL, "model", ""); if (p) model = model_get_model_from_internal_name(p); else @@ -601,224 +619,217 @@ void loadconfig(char *fn) model = model_count() - 1; romset = model_getromset(); - cpu_manufacturer = config_get_int(NULL, "cpu_manufacturer", 0); - cpu = config_get_int(NULL, "cpu", 0); - cpu_use_dynarec = config_get_int(NULL, "cpu_use_dynarec", 0); - cpu_waitstates = config_get_int(NULL, "cpu_waitstates", 0); + cpu_manufacturer = config_get_int(CFG_MACHINE, NULL, "cpu_manufacturer", 0); + cpu = config_get_int(CFG_MACHINE, NULL, "cpu", 0); + cpu_use_dynarec = config_get_int(CFG_MACHINE, NULL, "cpu_use_dynarec", 0); + cpu_waitstates = config_get_int(CFG_MACHINE, NULL, "cpu_waitstates", 0); - p = (char *)config_get_string(NULL, "gfxcard", ""); + p = (char *)config_get_string(CFG_MACHINE, NULL, "gfxcard", ""); if (p) gfxcard = video_get_video_from_internal_name(p); else gfxcard = 0; - video_speed = config_get_int(NULL, "video_speed", 3); - p = (char *)config_get_string(NULL, "sndcard", ""); + video_speed = config_get_int(CFG_MACHINE, NULL, "video_speed", 3); + p = (char *)config_get_string(CFG_MACHINE, NULL, "sndcard", ""); if (p) sound_card_current = sound_card_get_from_internal_name(p); else sound_card_current = 0; - p = (char *)config_get_string(NULL, "disc_a", ""); + p = (char *)config_get_string(CFG_MACHINE, NULL, "disc_a", ""); if (p) strcpy(discfns[0], p); else strcpy(discfns[0], ""); - p = (char *)config_get_string(NULL, "disc_b", ""); + p = (char *)config_get_string(CFG_MACHINE, NULL, "disc_b", ""); if (p) strcpy(discfns[1], p); else strcpy(discfns[1], ""); - p = (char *)config_get_string(NULL, "hdd_controller", ""); + p = (char *)config_get_string(CFG_MACHINE, NULL, "hdd_controller", ""); if (p) strncpy(hdd_controller_name, p, sizeof(hdd_controller_name)-1); else strncpy(hdd_controller_name, "none", sizeof(hdd_controller_name)-1); - mem_size = config_get_int(NULL, "mem_size", 4096); + mem_size = config_get_int(CFG_MACHINE, NULL, "mem_size", 4096); if (mem_size < ((models[model].flags & MODEL_AT) ? models[model].min_ram*1024 : models[model].min_ram)) mem_size = ((models[model].flags & MODEL_AT) ? models[model].min_ram*1024 : models[model].min_ram); - cdrom_drive = config_get_int(NULL, "cdrom_drive", 0); - cdrom_enabled = config_get_int(NULL, "cdrom_enabled", 0); - cdrom_channel = config_get_int(NULL, "cdrom_channel", 2); + cdrom_drive = config_get_int(CFG_MACHINE, NULL, "cdrom_drive", 0); + cdrom_enabled = config_get_int(CFG_MACHINE, NULL, "cdrom_enabled", 0); + cdrom_channel = config_get_int(CFG_MACHINE, NULL, "cdrom_channel", 2); - p = (char *)config_get_string(NULL, "cdrom_path", ""); + p = (char *)config_get_string(CFG_MACHINE, NULL, "cdrom_path", ""); if (p) strcpy(iso_path, p); else strcpy(iso_path, ""); - vid_resize = config_get_int(NULL, "vid_resize", 0); - video_force_aspect_ration = config_get_int(NULL, "vid_force_aspect_ratio", 0); - vid_disc_indicator = config_get_int(NULL, "vid_disc_indicator", 1); - vid_api = config_get_int(NULL, "vid_api", 0); - video_fullscreen_scale = config_get_int(NULL, "video_fullscreen_scale", 0); - video_fullscreen_first = config_get_int(NULL, "video_fullscreen_first", 1); - - hdc[0].spt = config_get_int(NULL, "hdc_sectors", 0); - hdc[0].hpc = config_get_int(NULL, "hdc_heads", 0); - hdc[0].tracks = config_get_int(NULL, "hdc_cylinders", 0); - p = (char *)config_get_string(NULL, "hdc_fn", ""); + hdc[0].spt = config_get_int(CFG_MACHINE, NULL, "hdc_sectors", 0); + hdc[0].hpc = config_get_int(CFG_MACHINE, NULL, "hdc_heads", 0); + hdc[0].tracks = config_get_int(CFG_MACHINE, NULL, "hdc_cylinders", 0); + p = (char *)config_get_string(CFG_MACHINE, NULL, "hdc_fn", ""); if (p) strcpy(ide_fn[0], p); else strcpy(ide_fn[0], ""); - hdc[1].spt = config_get_int(NULL, "hdd_sectors", 0); - hdc[1].hpc = config_get_int(NULL, "hdd_heads", 0); - hdc[1].tracks = config_get_int(NULL, "hdd_cylinders", 0); - p = (char *)config_get_string(NULL, "hdd_fn", ""); + hdc[1].spt = config_get_int(CFG_MACHINE, NULL, "hdd_sectors", 0); + hdc[1].hpc = config_get_int(CFG_MACHINE, NULL, "hdd_heads", 0); + hdc[1].tracks = config_get_int(CFG_MACHINE, NULL, "hdd_cylinders", 0); + p = (char *)config_get_string(CFG_MACHINE, NULL, "hdd_fn", ""); if (p) strcpy(ide_fn[1], p); else strcpy(ide_fn[1], ""); - hdc[2].spt = config_get_int(NULL, "hde_sectors", 0); - hdc[2].hpc = config_get_int(NULL, "hde_heads", 0); - hdc[2].tracks = config_get_int(NULL, "hde_cylinders", 0); - p = (char *)config_get_string(NULL, "hde_fn", ""); + hdc[2].spt = config_get_int(CFG_MACHINE, NULL, "hde_sectors", 0); + hdc[2].hpc = config_get_int(CFG_MACHINE, NULL, "hde_heads", 0); + hdc[2].tracks = config_get_int(CFG_MACHINE, NULL, "hde_cylinders", 0); + p = (char *)config_get_string(CFG_MACHINE, NULL, "hde_fn", ""); if (p) strcpy(ide_fn[2], p); else strcpy(ide_fn[2], ""); - hdc[3].spt = config_get_int(NULL, "hdf_sectors", 0); - hdc[3].hpc = config_get_int(NULL, "hdf_heads", 0); - hdc[3].tracks = config_get_int(NULL, "hdf_cylinders", 0); - p = (char *)config_get_string(NULL, "hdf_fn", ""); + hdc[3].spt = config_get_int(CFG_MACHINE, NULL, "hdf_sectors", 0); + hdc[3].hpc = config_get_int(CFG_MACHINE, NULL, "hdf_heads", 0); + hdc[3].tracks = config_get_int(CFG_MACHINE, NULL, "hdf_cylinders", 0); + p = (char *)config_get_string(CFG_MACHINE, NULL, "hdf_fn", ""); if (p) strcpy(ide_fn[3], p); else strcpy(ide_fn[3], ""); - fdd_set_type(0, config_get_int(NULL, "drive_a_type", 7)); - fdd_set_type(1, config_get_int(NULL, "drive_b_type", 7)); - bpb_disable = config_get_int(NULL, "bpb_disable", 0); + fdd_set_type(0, config_get_int(CFG_MACHINE, NULL, "drive_a_type", 7)); + fdd_set_type(1, config_get_int(CFG_MACHINE, NULL, "drive_b_type", 7)); + bpb_disable = config_get_int(CFG_MACHINE, NULL, "bpb_disable", 0); - window_w = config_get_int(NULL, "window_w", 0); - window_h = config_get_int(NULL, "window_h", 0); - window_x = config_get_int(NULL, "window_x", 0); - window_y = config_get_int(NULL, "window_y", 0); - window_remember = config_get_int(NULL, "window_remember", 0); - - joystick_type = config_get_int(NULL, "joystick_type", 0); - mouse_type = config_get_int(NULL, "mouse_type", 0); + joystick_type = config_get_int(CFG_MACHINE, NULL, "joystick_type", 0); + mouse_type = config_get_int(CFG_MACHINE, NULL, "mouse_type", 0); for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { sprintf(s, "joystick_%i_nr", c); - joystick_state[c].plat_joystick_nr = config_get_int("Joysticks", s, 0); + joystick_state[c].plat_joystick_nr = config_get_int(CFG_MACHINE, "Joysticks", s, 0); if (joystick_state[c].plat_joystick_nr) { for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { sprintf(s, "joystick_%i_axis_%i", c, d); - joystick_state[c].axis_mapping[d] = config_get_int("Joysticks", s, d); + joystick_state[c].axis_mapping[d] = config_get_int(CFG_MACHINE, "Joysticks", s, d); } for (d = 0; d < joystick_get_button_count(joystick_type); d++) { sprintf(s, "joystick_%i_button_%i", c, d); - joystick_state[c].button_mapping[d] = config_get_int("Joysticks", s, d); + joystick_state[c].button_mapping[d] = config_get_int(CFG_MACHINE, "Joysticks", s, d); } for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { sprintf(s, "joystick_%i_pov_%i_x", c, d); - joystick_state[c].pov_mapping[d][0] = config_get_int("Joysticks", s, d); + joystick_state[c].pov_mapping[d][0] = config_get_int(CFG_MACHINE, "Joysticks", s, d); sprintf(s, "joystick_%i_pov_%i_y", c, d); - joystick_state[c].pov_mapping[d][1] = config_get_int("Joysticks", s, d); + joystick_state[c].pov_mapping[d][1] = config_get_int(CFG_MACHINE, "Joysticks", s, d); } } } - enable_sync = config_get_int(NULL, "enable_sync", 1); + enable_sync = config_get_int(CFG_MACHINE, NULL, "enable_sync", 1); } void saveconfig(char *fn) { int c, d; - - config_set_int(NULL, "gameblaster", GAMEBLASTER); - config_set_int(NULL, "gus", GUS); - config_set_int(NULL, "ssi2001", SSI2001); - config_set_int(NULL, "voodoo", voodoo_enabled); - - config_set_string(NULL, "model", model_get_internal_name()); - config_set_int(NULL, "cpu_manufacturer", cpu_manufacturer); - config_set_int(NULL, "cpu", cpu); - config_set_int(NULL, "cpu_use_dynarec", cpu_use_dynarec); - config_set_int(NULL, "cpu_waitstates", cpu_waitstates); - - config_set_string(NULL, "gfxcard", video_get_internal_name(video_old_to_new(gfxcard))); - config_set_int(NULL, "video_speed", video_speed); - config_set_string(NULL, "sndcard", sound_card_get_internal_name(sound_card_current)); - config_set_int(NULL, "cpu_speed", cpuspeed); - config_set_int(NULL, "has_fpu", hasfpu); - config_set_string(NULL, "disc_a", discfns[0]); - config_set_string(NULL, "disc_b", discfns[1]); - config_set_string(NULL, "hdd_controller", hdd_controller_name); + char global_config_file[512]; - config_set_int(NULL, "mem_size", mem_size); - config_set_int(NULL, "cdrom_drive", cdrom_drive); - config_set_int(NULL, "cdrom_enabled", cdrom_enabled); - config_set_int(NULL, "cdrom_channel", cdrom_channel); - config_set_string(NULL, "cdrom_path", iso_path); - config_set_int(NULL, "vid_resize", vid_resize); - config_set_int(NULL, "vid_force_aspect_ratio", video_force_aspect_ration); - config_set_int(NULL, "vid_disc_indicator", vid_disc_indicator); - config_set_int(NULL, "vid_api", vid_api); - config_set_int(NULL, "video_fullscreen_scale", video_fullscreen_scale); - config_set_int(NULL, "video_fullscreen_first", video_fullscreen_first); + append_filename(global_config_file, pcempath, "pcem.cfg", 511); + + config_set_int(CFG_GLOBAL, NULL, "vid_resize", vid_resize); + config_set_int(CFG_GLOBAL, NULL, "vid_force_aspect_ratio", video_force_aspect_ration); + config_set_int(CFG_GLOBAL, NULL, "vid_disc_indicator", vid_disc_indicator); + config_set_int(CFG_GLOBAL, NULL, "vid_api", vid_api); + config_set_int(CFG_GLOBAL, NULL, "video_fullscreen_scale", video_fullscreen_scale); + config_set_int(CFG_GLOBAL, NULL, "video_fullscreen_first", video_fullscreen_first); + + config_set_int(CFG_GLOBAL, NULL, "window_w", window_w); + config_set_int(CFG_GLOBAL, NULL, "window_h", window_h); + config_set_int(CFG_GLOBAL, NULL, "window_x", window_x); + config_set_int(CFG_GLOBAL, NULL, "window_y", window_y); + config_set_int(CFG_GLOBAL, NULL, "window_remember", window_remember); - config_set_int(NULL, "hdc_sectors", hdc[0].spt); - config_set_int(NULL, "hdc_heads", hdc[0].hpc); - config_set_int(NULL, "hdc_cylinders", hdc[0].tracks); - config_set_string(NULL, "hdc_fn", ide_fn[0]); - config_set_int(NULL, "hdd_sectors", hdc[1].spt); - config_set_int(NULL, "hdd_heads", hdc[1].hpc); - config_set_int(NULL, "hdd_cylinders", hdc[1].tracks); - config_set_string(NULL, "hdd_fn", ide_fn[1]); - config_set_int(NULL, "hde_sectors", hdc[2].spt); - config_set_int(NULL, "hde_heads", hdc[2].hpc); - config_set_int(NULL, "hde_cylinders", hdc[2].tracks); - config_set_string(NULL, "hde_fn", ide_fn[2]); - config_set_int(NULL, "hdf_sectors", hdc[3].spt); - config_set_int(NULL, "hdf_heads", hdc[3].hpc); - config_set_int(NULL, "hdf_cylinders", hdc[3].tracks); - config_set_string(NULL, "hdf_fn", ide_fn[3]); + config_set_int(CFG_MACHINE, NULL, "gameblaster", GAMEBLASTER); + config_set_int(CFG_MACHINE, NULL, "gus", GUS); + config_set_int(CFG_MACHINE, NULL, "ssi2001", SSI2001); + config_set_int(CFG_MACHINE, NULL, "voodoo", voodoo_enabled); + + config_set_string(CFG_MACHINE, NULL, "model", model_get_internal_name()); + config_set_int(CFG_MACHINE, NULL, "cpu_manufacturer", cpu_manufacturer); + config_set_int(CFG_MACHINE, NULL, "cpu", cpu); + config_set_int(CFG_MACHINE, NULL, "cpu_use_dynarec", cpu_use_dynarec); + config_set_int(CFG_MACHINE, NULL, "cpu_waitstates", cpu_waitstates); + + config_set_string(CFG_MACHINE, NULL, "gfxcard", video_get_internal_name(video_old_to_new(gfxcard))); + config_set_int(CFG_MACHINE, NULL, "video_speed", video_speed); + config_set_string(CFG_MACHINE, NULL, "sndcard", sound_card_get_internal_name(sound_card_current)); + config_set_int(CFG_MACHINE, NULL, "cpu_speed", cpuspeed); + config_set_int(CFG_MACHINE, NULL, "has_fpu", hasfpu); + config_set_string(CFG_MACHINE, NULL, "disc_a", discfns[0]); + config_set_string(CFG_MACHINE, NULL, "disc_b", discfns[1]); + config_set_string(CFG_MACHINE, NULL, "hdd_controller", hdd_controller_name); - config_set_int(NULL, "drive_a_type", fdd_get_type(0)); - config_set_int(NULL, "drive_b_type", fdd_get_type(1)); - config_set_int(NULL, "bpb_disable", bpb_disable); + config_set_int(CFG_MACHINE, NULL, "mem_size", mem_size); + config_set_int(CFG_MACHINE, NULL, "cdrom_drive", cdrom_drive); + config_set_int(CFG_MACHINE, NULL, "cdrom_enabled", cdrom_enabled); + config_set_int(CFG_MACHINE, NULL, "cdrom_channel", cdrom_channel); + config_set_string(CFG_MACHINE, NULL, "cdrom_path", iso_path); + + config_set_int(CFG_MACHINE, NULL, "hdc_sectors", hdc[0].spt); + config_set_int(CFG_MACHINE, NULL, "hdc_heads", hdc[0].hpc); + config_set_int(CFG_MACHINE, NULL, "hdc_cylinders", hdc[0].tracks); + config_set_string(CFG_MACHINE, NULL, "hdc_fn", ide_fn[0]); + config_set_int(CFG_MACHINE, NULL, "hdd_sectors", hdc[1].spt); + config_set_int(CFG_MACHINE, NULL, "hdd_heads", hdc[1].hpc); + config_set_int(CFG_MACHINE, NULL, "hdd_cylinders", hdc[1].tracks); + config_set_string(CFG_MACHINE, NULL, "hdd_fn", ide_fn[1]); + config_set_int(CFG_MACHINE, NULL, "hde_sectors", hdc[2].spt); + config_set_int(CFG_MACHINE, NULL, "hde_heads", hdc[2].hpc); + config_set_int(CFG_MACHINE, NULL, "hde_cylinders", hdc[2].tracks); + config_set_string(CFG_MACHINE, NULL, "hde_fn", ide_fn[2]); + config_set_int(CFG_MACHINE, NULL, "hdf_sectors", hdc[3].spt); + config_set_int(CFG_MACHINE, NULL, "hdf_heads", hdc[3].hpc); + config_set_int(CFG_MACHINE, NULL, "hdf_cylinders", hdc[3].tracks); + config_set_string(CFG_MACHINE, NULL, "hdf_fn", ide_fn[3]); - config_set_int(NULL, "window_w", window_w); - config_set_int(NULL, "window_h", window_h); - config_set_int(NULL, "window_x", window_x); - config_set_int(NULL, "window_y", window_y); - config_set_int(NULL, "window_remember", window_remember); + config_set_int(CFG_MACHINE, NULL, "drive_a_type", fdd_get_type(0)); + config_set_int(CFG_MACHINE, NULL, "drive_b_type", fdd_get_type(1)); + config_set_int(CFG_MACHINE, NULL, "bpb_disable", bpb_disable); - config_set_int(NULL, "joystick_type", joystick_type); - config_set_int(NULL, "mouse_type", mouse_type); + config_set_int(CFG_MACHINE, NULL, "joystick_type", joystick_type); + config_set_int(CFG_MACHINE, NULL, "mouse_type", mouse_type); for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { char s[80]; sprintf(s, "joystick_%i_nr", c); - config_set_int("Joysticks", s, joystick_state[c].plat_joystick_nr); + config_set_int(CFG_MACHINE, "Joysticks", s, joystick_state[c].plat_joystick_nr); if (joystick_state[c].plat_joystick_nr) { for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { sprintf(s, "joystick_%i_axis_%i", c, d); - config_set_int("Joysticks", s, joystick_state[c].axis_mapping[d]); + config_set_int(CFG_MACHINE, "Joysticks", s, joystick_state[c].axis_mapping[d]); } for (d = 0; d < joystick_get_button_count(joystick_type); d++) { sprintf(s, "joystick_%i_button_%i", c, d); - config_set_int("Joysticks", s, joystick_state[c].button_mapping[d]); + config_set_int(CFG_MACHINE, "Joysticks", s, joystick_state[c].button_mapping[d]); } for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { sprintf(s, "joystick_%i_pov_%i_x", c, d); - config_set_int("Joysticks", s, joystick_state[c].pov_mapping[d][0]); + config_set_int(CFG_MACHINE, "Joysticks", s, joystick_state[c].pov_mapping[d][0]); sprintf(s, "joystick_%i_pov_%i_y", c, d); - config_set_int("Joysticks", s, joystick_state[c].pov_mapping[d][1]); + config_set_int(CFG_MACHINE, "Joysticks", s, joystick_state[c].pov_mapping[d][1]); } } } - config_set_int(NULL, "enable_sync", enable_sync); + config_set_int(CFG_MACHINE, NULL, "enable_sync", enable_sync); pclog("config_save(%s)\n", config_file_default); if (fn) - config_save(fn); + config_save(CFG_MACHINE, fn); else - config_save(config_file_default); + config_save(CFG_MACHINE, config_file_default); + + config_save(CFG_GLOBAL, global_config_file); } diff --git a/src/win-config.c b/src/win-config.c index e03f0aa..0a4032f 100644 --- a/src/win-config.c +++ b/src/win-config.c @@ -27,7 +27,7 @@ static int settings_sound_to_list[20], settings_list_to_sound[20]; static int settings_mouse_to_list[20], settings_list_to_mouse[20]; static char *hdd_names[16]; -static int has_been_inited = 0; +int has_been_inited = 0; static int mouse_valid(int type, int model) { @@ -815,9 +815,7 @@ static BOOL CALLBACK config_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPAR return FALSE; } -void config_open(HWND hwnd, int inited) +void config_open(HWND hwnd) { - has_been_inited = inited; - DialogBox(hinstance, TEXT("ConfigureDlg"), hwnd, (DLGPROC)config_dlgproc); } diff --git a/src/win-config_sel.c b/src/win-config_sel.c index adeee10..5b4711e 100644 --- a/src/win-config_sel.c +++ b/src/win-config_sel.c @@ -10,8 +10,6 @@ #include "resources.h" #include "win.h" -static int has_been_inited = 0; - static void config_list_update(HWND hdlg) { char s[512]; @@ -106,7 +104,7 @@ static BOOL CALLBACK config_selection_dlgproc(HWND hdlg, UINT message, WPARAM wP if (!getsfile(hdlg, "Configuration (*.CFG)\0*.CFG\0All files (*.*)\0*.*\0", "", s)) { - config_open(hdlg, has_been_inited); + config_open(hdlg); saveconfig(openfilestring); } diff --git a/src/win-deviceconfig.c b/src/win-deviceconfig.c index 50fe626..4160523 100644 --- a/src/win-deviceconfig.c +++ b/src/win-deviceconfig.c @@ -33,7 +33,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam switch (config->type) { case CONFIG_BINARY: - val_int = config_get_int(config_device->name, config->name, config->default_int); + val_int = config_get_int(CFG_MACHINE, config_device->name, config->name, config->default_int); SendMessage(h, BM_SETCHECK, val_int, 0); @@ -41,7 +41,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam break; case CONFIG_SELECTION: - val_int = config_get_int(config_device->name, config->name, config->default_int); + val_int = config_get_int(CFG_MACHINE, config_device->name, config->name, config->default_int); c = 0; while (selection->description[0]) @@ -57,7 +57,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam break; case CONFIG_MIDI: - val_int = config_get_int(NULL, config->name, config->default_int); + val_int = config_get_int(CFG_MACHINE, NULL, config->name, config->default_int); num = midi_get_num_devs(); for (c = 0; c < num; c++) @@ -95,7 +95,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam switch (config->type) { case CONFIG_BINARY: - val_int = config_get_int(config_device->name, config->name, config->default_int); + val_int = config_get_int(CFG_MACHINE, config_device->name, config->name, config->default_int); if (val_int != SendMessage(h, BM_GETCHECK, 0, 0)) changed = 1; @@ -104,7 +104,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam break; case CONFIG_SELECTION: - val_int = config_get_int(config_device->name, config->name, config->default_int); + val_int = config_get_int(CFG_MACHINE, config_device->name, config->name, config->default_int); c = SendMessage(h, CB_GETCURSEL, 0, 0); @@ -118,7 +118,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam break; case CONFIG_MIDI: - val_int = config_get_int(NULL, config->name, config->default_int); + val_int = config_get_int(CFG_MACHINE, NULL, config->name, config->default_int); c = SendMessage(h, CB_GETCURSEL, 0, 0); @@ -137,7 +137,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam return TRUE; } - if (MessageBox(NULL, "This will reset PCem!\nOkay to continue?", "PCem", MB_OKCANCEL) != IDOK) + if (has_been_inited && MessageBox(NULL, "This will reset PCem!\nOkay to continue?", "PCem", MB_OKCANCEL) != IDOK) { EndDialog(hdlg, 0); return TRUE; @@ -154,7 +154,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam switch (config->type) { case CONFIG_BINARY: - config_set_int(config_device->name, config->name, SendMessage(h, BM_GETCHECK, 0, 0)); + config_set_int(CFG_MACHINE, config_device->name, config->name, SendMessage(h, BM_GETCHECK, 0, 0)); id++; break; @@ -163,14 +163,14 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam c = SendMessage(h, CB_GETCURSEL, 0, 0); for (; c > 0; c--) selection++; - config_set_int(config_device->name, config->name, selection->value); + config_set_int(CFG_MACHINE, config_device->name, config->name, selection->value); id += 2; break; case CONFIG_MIDI: c = SendMessage(h, CB_GETCURSEL, 0, 0); - config_set_int(NULL, config->name, c); + config_set_int(CFG_MACHINE, NULL, config->name, c); id += 2; break; @@ -180,7 +180,8 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam saveconfig(NULL); - resetpchard(); + if (has_been_inited) + resetpchard(); EndDialog(hdlg, 0); return TRUE; diff --git a/src/win-midi.c b/src/win-midi.c index 895df6a..3a94427 100644 --- a/src/win-midi.c +++ b/src/win-midi.c @@ -13,7 +13,7 @@ void midi_init() { MMRESULT hr; - midi_id = config_get_int(NULL, "midi", 0); + midi_id = config_get_int(CFG_MACHINE, NULL, "midi", 0); hr = midiOutOpen(&midi_out_device, midi_id, 0, 0, CALLBACK_NULL); diff --git a/src/win.c b/src/win.c index c6fecf8..b4b68d4 100644 --- a/src/win.c +++ b/src/win.c @@ -969,7 +969,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM hdconf_open(hwnd); break; case IDM_CONFIG: - config_open(hwnd, 1); + config_open(hwnd); break; case IDM_STATUS: status_open(hwnd); diff --git a/src/win.h b/src/win.h index c3f418f..ed12875 100644 --- a/src/win.h +++ b/src/win.h @@ -22,7 +22,7 @@ extern int status_is_open; void hdconf_open(HWND hwnd); -void config_open(HWND hwnd, int inited); +void config_open(HWND hwnd); int config_selection_open(HWND hwnd, int inited); @@ -37,3 +37,5 @@ int getfile(HWND hwnd, char *f, char *fn); int getsfile(HWND hwnd, char *f, char *fn, char *dir); extern int pause; + +extern int has_been_inited;