diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 33fb3644d..8a2f10928 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -8,7 +8,7 @@ # # Modified Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.45 2017/09/12 +# Version: @(#)Makefile.mingw 1.0.46 2017/09/19 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -34,6 +34,7 @@ STUFF = # -DENABLE_CDROM_LOG enables extra logging. # -DENABLE_D86F_LOG enables extra logging. # -DENABLE_FDC_LOG enables extra logging. +# -DENABLE_HDD_IMAGE_LOG enables extra logging. # -DENABLE_IDE_LOG enables extra logging. # -DENABLE_SERIAL_LOG enables extra logging. # -DENABLE_NIC_LOG enables extra logging. @@ -464,8 +465,8 @@ x87.o: ibm.h pic.h cpu/x86.h cpu/x86_flags.h cpu/x86_ops.h cpu/x87.h cpu/386_co bugger.o: ibm.h io.h bugger.h -cdrom.o: 86box.h cdrom.h ibm.h hdd/hdd_ide_at.h piix.h scsi/scsi.h timer.h \ - win/plat_iodev.h +cdrom.o: 86box.h cdrom.h ibm.h hdd/hdd_ide_at.h piix.h scsi/scsi.h \ + timer.h nvr.h win/plat_iodev.h cdrom_dosbox.o: cdrom_dosbox.h @@ -492,7 +493,7 @@ floppy.o: ibm.h config.h floppy.h floppy_fdi.h fdc.h fdd.h timer.h \ floppy_common.o: ibm.h floppy.h floppy_common.h fdc.h fdd.h floppy_86f.o: lzf/lzf.h config.h dma.h random.h floppy.h floppy_86f.h \ - fdc.h fdd.h ibm.h + fdc.h fdd.h ibm.h nvr.h floppy_fdi.o: ibm.h floppy.h floppy_img.h floppy_fdi.h fdc.h fdd.h fdi2raw.h \ floppy.h floppy_imd.h fdc.h fdd.h config.h floppy_img.h @@ -535,7 +536,7 @@ hdd_mfm_xebec.o: ibm.h device.h dma.h hdd/hdd_image.h io.h mem.h pic.h rom.h \ intel.o: ibm.h cpu/cpu.h io.h mem.h pit.h timer.h intel.h -intel_flash.o: ibm.h cpu/cpu.h device.h mem.h machine/machine.h rom.h +intel_flash.o: ibm.h cpu/cpu.h device.h mem.h machine/machine.h nvr.h intel_sio.o: ibm.h dma.h mem.h pci.h intel_sio.h @@ -629,7 +630,7 @@ machine_at_wd76c10.o: ibm.h floppy.h fdc.h io.h mem.h serial.h machine/machine_ machine_common.o: ibm.h dma.h floppy.h fdd.h fdc.h lpt.h pic.h pit.h serial.h machine/machine_common.h -machine_europc.o: ibm.h cpu/cpu.h io.h device.h gameport.h keyboard_xt.h lpt.h mem.h nmi.h rom.h machine/machine_common.h \ +machine_europc.o: ibm.h cpu/cpu.h io.h device.h gameport.h keyboard_xt.h lpt.h mem.h nmi.h rom.h nvr.h machine/machine_common.h \ machine/machine_europc.h europc_hdd.o: ibm.h io.h dma.h pic.h device.h timer.h hdd/hdd_image.h europc.h @@ -684,10 +685,10 @@ net_slirp.o: network/slirp/slirp.h network/slirp/queue.h ibm.h config.h device.h net_ne2000.o: ibm.h io.h mem.h rom.h pci.h pic.h device.h config.h random.h network/network.h network/net_ne2000.h network/bswap.h -nvr.o: ibm.h cpu/cpu.h device.h io.h mem.h machine/machine.h \ +nvr.o: ibm.h cpu/cpu.h device.h io.h mem.h nvr.h machine/machine.h \ machine/machine_europc.h nvr.h pic.h rom.h timer.h rtc.h -nvr_ps2.o: ibm.h device.h io.h mem.h rom.h nvr_ps2.h +nvr_ps2.o: ibm.h device.h io.h mem.h nvr.h nvr_ps2.h pc.o: 86box.h config.h random.h ibm.h mem.h \ cpu/cpu.h cpu/x86_ops.h cpu/codegen.h \ @@ -770,7 +771,7 @@ snd_ad1848.o: ibm.h dma.h pic.h timer.h sound/sound.h sound/snd_ad1848.h snd_adlib.o: ibm.h io.h mca.h device.h sound/sound.h sound/snd_adlib.h sound/snd_opl.h -snd_adlibgold.o: ibm.h io.h dma.h pic.h pit.h mem.h rom.h timer.h device.h sound/sound.h sound/filters.h sound/snd_opl.h sound/snd_ym7128.h +snd_adlibgold.o: ibm.h io.h dma.h pic.h pit.h mem.h rom.h nvr.h timer.h device.h sound/sound.h sound/filters.h sound/snd_opl.h sound/snd_ym7128.h snd_cms.o: ibm.h io.h device.h sound/sound.h sound/snd_cms.h @@ -815,7 +816,7 @@ snd_ym7128.o: ibm.h sound/snd_ym7128.h sound.o: ibm.h device.h timer.h cdrom.h win/plat_thread.h sound/midi.h sound/sound.h sound/snd_opl.h sound/snd_adlib.h \ sound/snd_pas16.h sound/snd_sb.h sound/snd_sb_dsp.h sound/snd_wss.h sound/filters.h -tandy_eeprom.o: ibm.h device.h mem.h io.h rom.h tandy_eeprom.h +tandy_eeprom.o: ibm.h device.h mem.h io.h nvr.h tandy_eeprom.h tandy_rom.o: ibm.h device.h io.h mem.h rom.h tandy_rom.h @@ -823,7 +824,7 @@ timer.o: ibm.h timer.h usb.o: ibm.h io.h mem.h usb.h -vid_ati_eeprom.o: ibm.h mem.h rom.h video/vid_ati_eeprom.h +vid_ati_eeprom.o: ibm.h mem.h nvr.h video/vid_ati_eeprom.h vid_ati_mach64.o: ibm.h device.h io.h mem.h pci.h rom.h win/plat_thread.h video/video.h video/vid_svga.h video/vid_svga_render.h \ video/vid_ati68860_ramdac.h video/vid_ati_eeprom.h video/vid_ics2595.h @@ -904,7 +905,7 @@ vid_sdac_ramdac.o: ibm.h mem.h video/video.h video/vid_svga.h video/vid_sdac_ram vid_stg_ramdac.o: ibm.h mem.h video/video.h video/vid_svga.h video/vid_stg_ramdac.h -vid_svga.o: ibm.h io.h mem.h rom.h timer.h video/video.h video/vid_svga.h video/vid_svga_render.h +vid_svga.o: ibm.h io.h mem.h nvr.h timer.h video/video.h video/vid_svga.h video/vid_svga_render.h vid_svga_render.o: ibm.h mem.h video/video.h video/vid_svga.h video/vid_svga_render.h diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 3986b1591..625297b40 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)cdrom.c 1.0.4 2017/09/03 + * Version: @(#)cdrom.c 1.0.5 2017/09/19 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -24,6 +24,7 @@ #include "../piix.h" #include "../scsi/scsi.h" #include "../timer.h" +#include "../nvr.h" #include "../hdd/hdd_ide_at.h" #include "../win/plat_iodev.h" #include "cdrom.h" diff --git a/src/config.c b/src/config.c index 89b84d199..396fb7d37 100644 --- a/src/config.c +++ b/src/config.c @@ -8,7 +8,7 @@ * * Configuration file handler. * - * Version: @(#)config.c 1.0.4 2017/09/03 + * Version: @(#)config.c 1.0.5 2017/09/22 * * Authors: Sarah Walker, * Miran Grca, @@ -18,9 +18,9 @@ * Copyright 2016,2017 Miran Grca. * Copyright 2017 Fred N. van Kempen. * - * NOTE: Forcing config files to be in Unicode encoding breaks it on - * Windows XP, and possibly also Vista. Use -DANSI_CFG for use - * on these systems. + * NOTE: Forcing config files to be in Unicode encoding breaks + * it on Windows XP, and possibly also Vista. Use the + * -DANSI_CFG for use on these systems. */ #include #include @@ -58,123 +58,199 @@ #include "win/win_language.h" -wchar_t config_file_default[256]; - -static wchar_t config_file[256]; - - -typedef struct list_t +typedef struct _list_ { - struct list_t *next; + struct _list_ *next; } list_t; -static list_t config_head; - -typedef struct section_t +typedef struct { - struct list_t list; + list_t list; char name[256]; - struct list_t entry_head; + list_t entry_head; } section_t; -typedef struct entry_t +typedef struct { - struct list_t list; + list_t list; char name[256]; char data[256]; wchar_t wdata[256]; } entry_t; -#define list_add(new, head) \ - { \ - struct list_t *next = head; \ - \ - while (next->next) \ - next = next->next; \ - \ - (next)->next = new; \ - (new)->next = NULL; \ - } +#define list_add(new, head) \ +{ \ + list_t *next = head; \ + \ + while (next->next != NULL) \ + next = next->next; \ + \ + (next)->next = new; \ + (new)->next = NULL; \ +} -#define list_delete(old, head) \ - { \ - struct list_t *next = head; \ - \ - while ((next)->next != old) \ - { \ - next = (next)->next; \ - } \ - \ - (next)->next = (old)->next; \ - } +#define list_delete(old, head) \ +{ \ + list_t *next = head; \ + \ + while ((next)->next != old) \ + { \ + next = (next)->next; \ + } \ + \ + (next)->next = (old)->next; \ +} -void config_dump(void) +wchar_t config_file_default[256]; + +static list_t config_head; + + +static section_t * +find_section(char *name) { - section_t *current_section; + section_t *sec; + char blank[] = ""; - pclog("Config data :\n"); - - current_section = (section_t *)config_head.next; - - while (current_section) + sec = (section_t *)config_head.next; + if (name == NULL) + name = blank; + + while (sec != NULL) { - entry_t *current_entry; + if (! strncmp(sec->name, name, 256)) + return(sec); - pclog("[%s]\n", current_section->name); - - current_entry = (entry_t *)current_section->entry_head.next; - - while (current_entry) - { - pclog("%s = %s\n", current_entry->name, current_entry->data); - - current_entry = (entry_t *)current_entry->list.next; - } - - current_section = (section_t *)current_section->list.next; + sec = (section_t *)sec->list.next; } + + return(NULL); +} + + +static entry_t * +find_entry(section_t *section, char *name) +{ + entry_t *ent; + + ent = (entry_t *)section->entry_head.next; + + while (ent != NULL) + { + if (! strncmp(ent->name, name, 256)) + return(ent); + + ent = (entry_t *)ent->list.next; + } + + return(NULL); +} + + +static int +entries_num(section_t *section) +{ + entry_t *ent; + int i = 0; + + ent = (entry_t *)section->entry_head.next; + + while (ent != NULL) + { + if (strlen(ent->name) > 0) + { + i++; + } + + ent = (entry_t *)ent->list.next; + } + + return(i); +} + + +static void +delete_section_if_empty(char *head) +{ + section_t *section; + + section = find_section(head); + if (section == NULL) return; + + if (entries_num(section) == 0) + { + list_delete(§ion->list, &config_head); + free(section); + } +} + + +static section_t * +create_section(char *name) +{ + section_t *ns = malloc(sizeof(section_t)); + + memset(ns, 0x00, sizeof(section_t)); + strncpy(ns->name, name, 256); + list_add(&ns->list, &config_head); + + return(ns); +} + + +static entry_t * +create_entry(section_t *section, char *name) +{ + entry_t *ne = malloc(sizeof(entry_t)); + + memset(ne, 0x00, sizeof(entry_t)); + strncpy(ne->name, name, 256); + list_add(&ne->list, §ion->entry_head); + + return(ne); } #if 0 -static void config_free(void) +static void +config_free(void) { - section_t *current_section; - current_section = (section_t *)config_head.next; - - while (current_section) + section_t *sec; + + sec = (section_t *)config_head.next; + while (sec != NULL) { - section_t *next_section = (section_t *)current_section->list.next; - entry_t *current_entry; - - current_entry = (entry_t *)current_section->entry_head.next; - - while (current_entry) + section_t *ns = (section_t *)sec->list.next; + entry_t *ent; + + ent = (entry_t *)sec->entry_head.next; + + while (ent != NULL) { - entry_t *next_entry = (entry_t *)current_entry->list.next; - - free(current_entry); - current_entry = next_entry; + entry_t *nent = (entry_t *)ent->list.next; + + free(ent); + ent = nent; } - free(current_section); - current_section = next_section; + free(sec); + sec = ns; } } #endif -static wchar_t cfgbuffer[1024]; -static char sname[256]; -static char ename[256]; - -int config_load(wchar_t *fn) +/* Read and parse the configuration file into memory. */ +static int +config_read(wchar_t *fn) { section_t *current_section; + char sname[256], ename[256]; + wchar_t cfgbuffer[1024]; section_t *new_section; entry_t *new_entry; FILE *f; @@ -196,7 +272,7 @@ int config_load(wchar_t *fn) while (1) { - memset(cfgbuffer, 0, 2048); + memset(cfgbuffer, 0, sizeof(cfgbuffer)); fgetws(cfgbuffer, 255, f); if (feof(f)) break; @@ -207,8 +283,10 @@ int config_load(wchar_t *fn) if (cfgbuffer[c] == L'\0') continue; - if (cfgbuffer[c] == L'#') /*Comment*/ + if ((cfgbuffer[c] == L'#') || (cfgbuffer[c] == L';')) { + /*Comment*/ continue; + } if (cfgbuffer[c] == L'[') /*Section*/ { @@ -222,7 +300,7 @@ int config_load(wchar_t *fn) sname[sd] = 0; new_section = malloc(sizeof(section_t)); - memset(new_section, 0, sizeof(section_t)); + memset(new_section, 0x00, sizeof(section_t)); strncpy(new_section->name, sname, 256); list_add(&new_section->list, &config_head); @@ -261,7 +339,7 @@ int config_load(wchar_t *fn) } } - fclose(f); + (void)fclose(f); config_dump(); @@ -269,477 +347,17 @@ int config_load(wchar_t *fn) } -void config_new(void) +/* + * Write the in-memory configuration to disk. + * This is a public function, because the Settings UI + * want to directly write the configuration after it + * has changed it. + */ +void +config_write(wchar_t *fn) { -#ifdef ANSI_CFG - FILE *f = _wfopen(config_file, L"wt"); -#else - FILE *f = _wfopen(config_file, L"wt, ccs=UNICODE"); -#endif - fclose(f); -} - - -static section_t *find_section(char *name) -{ - section_t *current_section; - char blank[] = ""; - - current_section = (section_t *)config_head.next; - if (!name) - name = blank; - - while (current_section) - { - if (!strncmp(current_section->name, name, 256)) - return current_section; - - current_section = (section_t *)current_section->list.next; - } - return NULL; -} - - -static entry_t *find_entry(section_t *section, char *name) -{ - entry_t *current_entry; - - current_entry = (entry_t *)section->entry_head.next; - - while (current_entry) - { - if (!strncmp(current_entry->name, name, 256)) - return current_entry; - - current_entry = (entry_t *)current_entry->list.next; - } - return NULL; -} - - -static int entries_num(section_t *section) -{ - entry_t *current_entry; - int i = 0; - - current_entry = (entry_t *)section->entry_head.next; - - while (current_entry) - { - if (strlen(current_entry->name) > 0) - { - i++; - } - - current_entry = (entry_t *)current_entry->list.next; - } - return i; -} - - -static section_t *create_section(char *name) -{ - section_t *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); - - return new_section; -} - - -static entry_t *create_entry(section_t *section, char *name) -{ - entry_t *new_entry = malloc(sizeof(entry_t)); - memset(new_entry, 0, sizeof(entry_t)); - strncpy(new_entry->name, name, 256); - list_add(&new_entry->list, §ion->entry_head); - - return new_entry; -} - - -int config_get_int(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - int value; - - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); - - if (!entry) - return def; - - sscanf(entry->data, "%i", &value); - - return value; -} - - -int config_get_hex16(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - int value; - - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); - - if (!entry) - return def; - - sscanf(entry->data, "%04X", &value); - - return value; -} - - -int config_get_hex20(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - int value; - - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); - - if (!entry) - return def; - - sscanf(entry->data, "%05X", &value); - - return value; -} - - -int config_get_mac(char *head, char *name, int def) -{ - section_t *section; - entry_t *entry; - int val0 = 0, val1 = 0, val2 = 0; - - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); - - if (!entry) - return def; - - sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); - - return (val0 << 16) + (val1 << 8) + val2; -} - - -char *config_get_string(char *head, char *name, char *def) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); - - if (!entry) - return def; - - return entry->data; -} - - -wchar_t *config_get_wstring(char *head, char *name, wchar_t *def) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - return def; - - entry = find_entry(section, name); - - if (!entry) - return def; - - return entry->wdata; -} - - -void config_delete_var(char *head, char *name) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - return; - - entry = find_entry(section, name); - - if (!entry) - return; - - list_delete(&entry->list, §ion->entry_head); - free(entry); - - return; -} - - -void config_delete_section_if_empty(char *head) -{ - section_t *section; - - section = find_section(head); - - if (!section) - return; - - if (entries_num(section) == 0) - { - list_delete(§ion->list, &config_head); - free(section); - } - - return; -} - - -void config_set_int(char *head, char *name, int val) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); - - if (!entry) - entry = create_entry(section, name); - - sprintf(entry->data, "%i", val); - mbstowcs(entry->wdata, entry->data, 512); -} - - -void config_set_hex16(char *head, char *name, int val) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); - - if (!entry) - entry = create_entry(section, name); - - sprintf(entry->data, "%04X", val); - mbstowcs(entry->wdata, entry->data, 512); -} - - -void config_set_hex20(char *head, char *name, int val) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); - - if (!entry) - entry = create_entry(section, name); - - sprintf(entry->data, "%05X", val); - mbstowcs(entry->wdata, entry->data, 512); -} - - -void config_set_mac(char *head, char *name, int val) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); - - if (!entry) - entry = create_entry(section, name); - - sprintf(entry->data, "%02x:%02x:%02x", (val >> 16) & 0xff, (val >> 8) & 0xff, val & 0xff); - mbstowcs(entry->wdata, entry->data, 512); -} - - -void config_set_string(char *head, char *name, char *val) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); - - if (!entry) - entry = create_entry(section, name); - - strncpy(entry->data, val, 256); - mbstowcs(entry->wdata, entry->data, 256); -} - - -void config_set_wstring(char *head, char *name, wchar_t *val) -{ - section_t *section; - entry_t *entry; - - section = find_section(head); - - if (!section) - section = create_section(head); - - entry = find_entry(section, name); - - if (!entry) - entry = create_entry(section, name); - - memcpy(entry->wdata, val, 512); -} - - -char *get_filename(char *s) -{ - int c = strlen(s) - 1; - while (c > 0) - { - if (s[c] == '/' || s[c] == '\\') - return &s[c+1]; - c--; - } - return s; -} - - -wchar_t *get_filename_w(wchar_t *s) -{ - int c = wcslen(s) - 1; - while (c > 0) - { - if (s[c] == L'/' || s[c] == L'\\') - return &s[c+1]; - c--; - } - return s; -} - - -void append_filename(char *dest, char *s1, char *s2, int size) -{ - sprintf(dest, "%s%s", s1, s2); -} - - -void append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) -{ - _swprintf(dest, L"%s%s", s1, s2); -} - - -void put_backslash(char *s) -{ - int c = strlen(s) - 1; - if (s[c] != '/' && s[c] != '\\') - s[c] = '/'; -} - - -void put_backslash_w(wchar_t *s) -{ - int c = wcslen(s) - 1; - if (s[c] != L'/' && s[c] != L'\\') - s[c] = L'/'; -} - - -char *get_extension(char *s) -{ - int c = strlen(s) - 1; - - if (c <= 0) - return s; - - while (c && s[c] != '.') - c--; - - if (!c) - return &s[strlen(s)]; - - return &s[c+1]; -} - - -wchar_t *get_extension_w(wchar_t *s) -{ - int c = wcslen(s) - 1; - - if (c <= 0) - return s; - - while (c && s[c] != L'.') - c--; - - if (!c) - return &s[wcslen(s)]; - - return &s[c+1]; -} - - -static wchar_t wname[512]; - - -void config_save(wchar_t *fn) -{ - section_t *current_section; + wchar_t wname[512]; + section_t *sec; FILE *f; int fl = 0; @@ -748,73 +366,77 @@ void config_save(wchar_t *fn) #else f = _wfopen(fn, L"wt, ccs=UNICODE"); #endif - if (f == NULL) - return; + if (f == NULL) return; - current_section = (section_t *)config_head.next; - while (current_section) + sec = (section_t *)config_head.next; + while (sec != NULL) { - entry_t *current_entry; + entry_t *ent; - if (current_section->name[0]) + if (sec->name[0]) { - mbstowcs(wname, current_section->name, strlen(current_section->name) + 1); + mbstowcs(wname, sec->name, strlen(sec->name)+1); if (fl) - { fwprintf(f, L"\n[%ws]\n", wname); - } - else - { + else fwprintf(f, L"[%ws]\n", wname); - } fl++; } - current_entry = (entry_t *)current_section->entry_head.next; - - while (current_entry) + ent = (entry_t *)sec->entry_head.next; + while (ent != NULL) { - if(current_entry->name[0]) + if (ent->name[0]) { - mbstowcs(wname, current_entry->name, strlen(current_entry->name) + 1); - if (current_entry->wdata[0] == L'\0') - { + mbstowcs(wname, ent->name, strlen(ent->name)+1); + if (ent->wdata[0] == L'\0') fwprintf(f, L"%ws = \n", wname); - } - else - { - fwprintf(f, L"%ws = %ws\n", wname, current_entry->wdata); - } - + else + fwprintf(f, L"%ws = %ws\n", wname, ent->wdata); fl++; } - current_entry = (entry_t *)current_entry->list.next; + ent = (entry_t *)ent->list.next; } - current_section = (section_t *)current_section->list.next; + sec = (section_t *)sec->list.next; } - fclose(f); + (void)fclose(f); } -/* General */ -static void loadconfig_general(void) +#if NOT_USED +static void +config_new(void) +{ +#ifdef ANSI_CFG + FILE *f = _wfopen(config_file, L"wt"); +#else + FILE *f = _wfopen(config_file, L"wt, ccs=UNICODE"); +#endif + (void)fclose(f); +} +#endif + + +/* Load "General" section. */ +static void +load_general(void) { char *cat = "General"; - char temps[512]; + char temp[512]; char *p; vid_resize = !!config_get_int(cat, "vid_resize", 0); - memset(temps, '\0', sizeof(temps)); + memset(temp, '\0', sizeof(temp)); p = config_get_string(cat, "vid_renderer", "d3d9"); if (p != NULL) { - strcpy(temps, p); + strcpy(temp, p); } - if (!strcmp(temps, "ddraw")) + if (!strcmp(temp, "ddraw")) { vid_api = 0; } @@ -856,19 +478,22 @@ static void loadconfig_general(void) } #ifndef __unix - /* Currently, 86Box is English (US) only, but in the future (version 1.30 at the earliest) other languages will be added, - therefore it is better to future-proof the code. */ + /* + * Currently, 86Box is English (US) only, but in the future + * (version 1.30 at the earliest) other languages will be + * added, therefore it is better to future-proof the code. + */ dwLanguage = config_get_hex16(cat, "language", 0x0409); #endif } -/* Machine */ -static void loadconfig_machine(void) +/* Load "Machine" section. */ +static void +load_machine(void) { char *cat = "Machine"; wchar_t *wp; - wchar_t last; char *p; p = config_get_string(cat, "machine", NULL); @@ -917,35 +542,31 @@ static void loadconfig_machine(void) if (wp != NULL) { if (wcslen(wp) && (wcslen(wp) <= 992)) { +#if 1 + /* + * NOTE: + * Temporary hack to remove the absolute + * path currently saved in most config + * files. We should remove this before + * finalizing this release! --FvK + */ + if (! wcsnicmp(wp, exe_path, wcslen(exe_path))) { + /* + * Yep, its absolute and prefixed + * with the EXE path. Just strip + * that off for now... + */ + wcscpy(nvr_path, &wp[wcslen(exe_path)]); + } else +#endif wcscpy(nvr_path, wp); } else { - append_filename_w(nvr_path, pcempath, L"nvr\\", 511); + wcscpy(nvr_path, L"nvr\\"); } } - else append_filename_w(nvr_path, pcempath, L"nvr\\", 511); - - if (nvr_path[wcslen(nvr_path) - 1] != L'/') - { - if (nvr_path[wcslen(nvr_path) - 1] != L'\\') - { - nvr_path[wcslen(nvr_path)] = L'\\'; - nvr_path[wcslen(nvr_path) + 1] = L'\0'; - } - } - - path_len = wcslen(nvr_path); - -#ifndef __unix - last = nvr_path[wcslen(nvr_path) - 1]; - nvr_path[wcslen(nvr_path) - 1] = 0; - if (!DirectoryExists(nvr_path)) - { - CreateDirectory(nvr_path, NULL); - } - nvr_path[wcslen(nvr_path)] = last; -#endif + else wcscpy(nvr_path, L"nvr\\"); cpu_use_dynarec = !!config_get_int(cat, "cpu_use_dynarec", 0); @@ -955,8 +576,9 @@ static void loadconfig_machine(void) } -/* Video */ -static void loadconfig_video(void) +/* Load "Video" section. */ +static void +load_video(void) { char *cat = "Video"; char *p; @@ -973,11 +595,12 @@ static void loadconfig_video(void) } -/* Input devices */ -static void loadconfig_input_devices(void) +/* Load "Input Devices" section. */ +static void +load_input_devices(void) { char *cat = "Input devices"; - char temps[512]; + char temp[512]; int c, d; char *p; @@ -991,25 +614,25 @@ static void loadconfig_input_devices(void) for (c = 0; c < joystick_get_max_joysticks(joystick_type); c++) { - sprintf(temps, "joystick_%i_nr", c); - joystick_state[c].plat_joystick_nr = config_get_int(cat, temps, 0); + sprintf(temp, "joystick_%i_nr", c); + joystick_state[c].plat_joystick_nr = config_get_int(cat, temp, 0); if (joystick_state[c].plat_joystick_nr) { for (d = 0; d < joystick_get_axis_count(joystick_type); d++) { - sprintf(temps, "joystick_%i_axis_%i", c, d); - joystick_state[c].axis_mapping[d] = config_get_int(cat, temps, d); + sprintf(temp, "joystick_%i_axis_%i", c, d); + joystick_state[c].axis_mapping[d] = config_get_int(cat, temp, d); } for (d = 0; d < joystick_get_button_count(joystick_type); d++) { - sprintf(temps, "joystick_%i_button_%i", c, d); - joystick_state[c].button_mapping[d] = config_get_int(cat, temps, d); + sprintf(temp, "joystick_%i_button_%i", c, d); + joystick_state[c].button_mapping[d] = config_get_int(cat, temp, d); } for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { - sprintf(temps, "joystick_%i_pov_%i", c, d); - p = config_get_string(cat, temps, "0, 0"); + sprintf(temp, "joystick_%i_pov_%i", c, d); + p = config_get_string(cat, temp, "0, 0"); joystick_state[c].pov_mapping[d][0] = joystick_state[c].pov_mapping[d][1] = 0; sscanf(p, "%i, %i", &joystick_state[c].pov_mapping[d][0], &joystick_state[c].pov_mapping[d][1]); } @@ -1018,11 +641,12 @@ static void loadconfig_input_devices(void) } -/* Sound */ -static void loadconfig_sound(void) +/* Load "Sound" section. */ +static void +load_sound(void) { char *cat = "Sound"; - char temps[512]; + char temp[512]; char *p; p = config_get_string(cat, "sndcard", NULL); @@ -1043,13 +667,13 @@ static void loadconfig_sound(void) GAMEBLASTER = !!config_get_int(cat, "gameblaster", 0); GUS = !!config_get_int(cat, "gus", 0); - memset(temps, '\0', sizeof(temps)); + memset(temp, '\0', sizeof(temp)); p = config_get_string(cat, "opl3_type", "dbopl"); if (p != NULL) { - strcpy(temps, p); + strcpy(temp, p); } - if (!strcmp(temps, "nukedopl") || !strcmp(temps, "1")) + if (!strcmp(temp, "nukedopl") || !strcmp(temp, "1")) { opl3_type = 1; } @@ -1058,13 +682,13 @@ static void loadconfig_sound(void) opl3_type = 0; } - memset(temps, '\0', sizeof(temps)); + memset(temp, '\0', sizeof(temp)); p = config_get_string(cat, "sound_type", "float"); if (p != NULL) { - strcpy(temps, p); + strcpy(temp, p); } - if (!strcmp(temps, "float") || !strcmp(temps, "1")) + if (!strcmp(temp, "float") || !strcmp(temp, "1")) { sound_is_float = 1; } @@ -1076,24 +700,25 @@ static void loadconfig_sound(void) #ifdef USE_NETWORK -/* Network */ -static void loadconfig_network(void) +/* Load "Network" section. */ +static void +load_network(void) { char *cat = "Network"; - char temps[512]; + char temp[512]; char *p; - memset(temps, '\0', sizeof(temps)); + memset(temp, '\0', sizeof(temp)); p = config_get_string(cat, "net_type", "none"); if (p != NULL) { - strcpy(temps, p); + strcpy(temp, p); } - if (!strcmp(temps, "slirp") || !strcmp(temps, "2")) + if (!strcmp(temp, "slirp") || !strcmp(temp, "2")) { network_type = NET_TYPE_SLIRP; } - else if (!strcmp(temps, "pcap") || !strcmp(temps, "1")) + else if (!strcmp(temp, "pcap") || !strcmp(temp, "1")) { network_type = NET_TYPE_PCAP; } @@ -1133,8 +758,9 @@ static void loadconfig_network(void) #endif -/* Ports (COM & LPT) */ -static void loadconfig_ports(void) +/* Load "Ports" section. */ +static void +load_ports(void) { char *cat = "Ports (COM & LPT)"; char *p; @@ -1151,11 +777,12 @@ static void loadconfig_ports(void) } -/* Other peripherals */ -static void loadconfig_other_peripherals(void) +/* Load "Other Peripherals" section. */ +static void +load_other_peripherals(void) { char *cat = "Other peripherals"; - char temps[512]; + char temp[512]; char *p; int c; @@ -1172,11 +799,11 @@ static void loadconfig_other_peripherals(void) else strcpy(hdd_controller_name, "none"); - memset(temps, '\0', sizeof(temps)); + memset(temp, '\0', sizeof(temp)); for (c = 2; c < 4; c++) { - sprintf(temps, "ide_%02i", c + 1); - p = config_get_string(cat, temps, NULL); + sprintf(temp, "ide_%02i", c + 1); + p = config_get_string(cat, temp, NULL); if (p == NULL) p = "0, 00"; sscanf(p, "%i, %02i", &ide_enable[c], &ide_irq[c]); @@ -1192,14 +819,16 @@ static void loadconfig_other_peripherals(void) } -static int config_string_to_bus(char *str, int cdrom) +/* FIXME: this should be in HDD somewhere. --FvK */ +static int +string_to_bus(char *str, int cdrom) { - if (!strcmp(str, "none")) + if (! strcmp(str, "none")) { return HDD_BUS_DISABLED; } - if (!strcmp(str, "mfm")) + if (! strcmp(str, "mfm")) { if (cdrom) goto no_mfm_cdrom; @@ -1214,78 +843,78 @@ static int config_string_to_bus(char *str, int cdrom) return HDD_BUS_ESDI; } - if (!strcmp(str, "ide_pio_only")) + if (! strcmp(str, "ide_pio_only")) { return HDD_BUS_IDE_PIO_ONLY; } - if (!strcmp(str, "ide")) + if (! strcmp(str, "ide")) { return HDD_BUS_IDE_PIO_ONLY; } - if (!strcmp(str, "atapi_pio_only")) + if (! strcmp(str, "atapi_pio_only")) { return HDD_BUS_IDE_PIO_ONLY; } - if (!strcmp(str, "atapi")) + if (! strcmp(str, "atapi")) { return HDD_BUS_IDE_PIO_ONLY; } - if (!strcmp(str, "eide")) + if (! strcmp(str, "eide")) { return HDD_BUS_IDE_PIO_ONLY; } - if (!strcmp(str, "xtide")) + if (! strcmp(str, "xtide")) { return HDD_BUS_XTIDE; } - if (!strcmp(str, "atide")) + if (! strcmp(str, "atide")) { return HDD_BUS_IDE_PIO_ONLY; } - if (!strcmp(str, "ide_pio_and_dma")) + if (! strcmp(str, "ide_pio_and_dma")) { return HDD_BUS_IDE_PIO_AND_DMA; } - if (!strcmp(str, "atapi_pio_and_dma")) + if (! strcmp(str, "atapi_pio_and_dma")) { return HDD_BUS_IDE_PIO_AND_DMA; } - if (!strcmp(str, "scsi")) + if (! strcmp(str, "scsi")) { return HDD_BUS_SCSI; } - if (!strcmp(str, "removable")) + if (! strcmp(str, "removable")) { if (cdrom) goto no_mfm_cdrom; return HDD_BUS_SCSI_REMOVABLE; } - if (!strcmp(str, "scsi_removable")) + if (! strcmp(str, "scsi_removable")) { if (cdrom) goto no_mfm_cdrom; return HDD_BUS_SCSI_REMOVABLE; } - if (!strcmp(str, "removable_scsi")) + if (! strcmp(str, "removable_scsi")) { if (cdrom) goto no_mfm_cdrom; return HDD_BUS_SCSI_REMOVABLE; } - if (!strcmp(str, "usb")) + if (! strcmp(str, "usb")) { msgbox_error(ghwnd, IDS_4110); return 0; @@ -1299,7 +928,9 @@ no_mfm_cdrom: } -static int hard_disk_is_valid(int c) +/* FIXME: this should be in HDD. --FvK */ +static int +hard_disk_is_valid(int c) { if (hdc[c].bus == HDD_BUS_DISABLED) { @@ -1320,7 +951,8 @@ static int hard_disk_is_valid(int c) } -static int tally_char(char *string, char c) +static int +tally_char(char *string, char c) { int i = 0; int tally = 0; @@ -1347,8 +979,9 @@ static int tally_char(char *string, char c) } -/* Hard disks */ -static void loadconfig_hard_disks(void) +/* Load "Hard Disks" section. */ +static void +load_hard_disks(void) { char *cat = "Hard disks"; char temps[512]; @@ -1377,7 +1010,7 @@ static void loadconfig_hard_disks(void) sscanf(p, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %i, %s", &hdc[c].spt, &hdc[c].hpc, &hdc[c].tracks, &hdc[c].wp, s); } - hdc[c].bus = config_string_to_bus(s, 0); + hdc[c].bus = string_to_bus(s, 0); switch(hdc[c].bus) { @@ -1423,7 +1056,7 @@ static void loadconfig_hard_disks(void) hdc[c].tracks = max_tracks; } - /* MFM */ + /* MFM/RLL */ sprintf(temps, "hdd_%02i_mfm_channel", c + 1); if (hdc[c].bus == HDD_BUS_MFM) { @@ -1510,10 +1143,27 @@ static void loadconfig_hard_disks(void) config_delete_var(cat, temps); } - memset(hdc[c].fn, 0, sizeof(hdc[c].fn)); - memset(hdc[c].prev_fn, 0, sizeof(hdc[c].prev_fn)); + memset(hdc[c].fn, 0x00, sizeof(hdc[c].fn)); + memset(hdc[c].prev_fn, 0x00, sizeof(hdc[c].prev_fn)); sprintf(temps, "hdd_%02i_fn", c + 1); wp = config_get_wstring(cat, temps, L""); +#if 1 + /* + * NOTE: + * Temporary hack to remove the absolute + * path currently saved in most config + * files. We should remove this before + * finalizing this release! --FvK + */ + if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { + /* + * Yep, its absolute and prefixed + * with the CFG path. Just strip + * that off for now... + */ + wcscpy((wchar_t *)hdc[c].fn, &wp[wcslen(cfg_path)]); + } else +#endif memcpy(hdc[c].fn, wp, (wcslen(wp) << 1) + 2); /* If the hard disk is in any way empty or invalid, mark the relevant variables for deletion. */ @@ -1544,8 +1194,9 @@ static void loadconfig_hard_disks(void) } -/* Removable devices */ -static void loadconfig_removable_devices(void) +/* Load "Removable Devices" section. */ +static void +load_removable_devices(void) { char *cat = "Removable devices"; char temps[512]; @@ -1568,6 +1219,23 @@ static void loadconfig_removable_devices(void) sprintf(temps, "fdd_%02i_fn", c + 1); wp = config_get_wstring(cat, temps, L""); +#if 0 + /* + * NOTE: + * Temporary hack to remove the absolute + * path currently saved in most config + * files. We should remove this before + * finalizing this release! --FvK + */ + if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { + /* + * Yep, its absolute and prefixed + * with the EXE path. Just strip + * that off for now... + */ + wcscpy((wchar_t *)floppyfns[c], &wp[wcslen(cfg_path)]); + } else +#endif memcpy(floppyfns[c], wp, (wcslen(wp) << 1) + 2); printf("Floppy: %ws\n", floppyfns[c]); sprintf(temps, "fdd_%02i_writeprot", c + 1); @@ -1627,7 +1295,7 @@ static void loadconfig_removable_devices(void) sscanf("0, none", "%u, %s", &cdrom_drives[c].sound_on, s); } - cdrom_drives[c].bus_type = config_string_to_bus(s, 1); + cdrom_drives[c].bus_type = string_to_bus(s, 1); sprintf(temps, "cdrom_%02i_ide_channel", c + 1); if ((cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) || (cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_AND_DMA)) @@ -1682,6 +1350,23 @@ static void loadconfig_removable_devices(void) sprintf(temps, "cdrom_%02i_image_path", c + 1); wp = config_get_wstring(cat, temps, L""); +#if 0 + /* + * NOTE: + * Temporary hack to remove the absolute + * path currently saved in most config + * files. We should remove this before + * finalizing this release! --FvK + */ + if (! wcsnicmp(wp, cfg_path, wcslen(cfg_path))) { + /* + * Yep, its absolute and prefixed + * with the EXE path. Just strip + * that off for now... + */ + wcscpy((wchar_t *)cdrom_image[c].image_path, &wp[wcslen(cfg_path)]); + } else +#endif memcpy(cdrom_image[c].image_path, wp, (wcslen(wp) << 1) + 2); wcscpy(cdrom_image[c].prev_image_path, cdrom_image[c].image_path); @@ -1720,13 +1405,16 @@ static void loadconfig_removable_devices(void) } -void loadconfig(wchar_t *fn) +/* Load the specified or a default configuration file. */ +void +config_load(wchar_t *fn) { int i = 0; if (fn == NULL) fn = config_file_default; - i = config_load(fn); + pclog("Loading config file '%S'..\n", fn); + i = config_read(fn); if (i == 0) { @@ -1746,66 +1434,52 @@ void loadconfig(wchar_t *fn) fdd_set_type(1, 2); mem_size = 640; + pclog("Config file not present or invalid!\n"); return; } /* General */ - loadconfig_general(); + load_general(); /* Machine */ - loadconfig_machine(); + load_machine(); /* Video */ - loadconfig_video(); + load_video(); /* Input devices */ - loadconfig_input_devices(); + load_input_devices(); /* Sound */ - loadconfig_sound(); + load_sound(); #ifdef USE_NETWORK /* Network */ - loadconfig_network(); + load_network(); #endif /* Ports (COM & LPT) */ - loadconfig_ports(); + load_ports(); /* Other peripherals */ - loadconfig_other_peripherals(); + load_other_peripherals(); /* Hard disks */ - loadconfig_hard_disks(); + load_hard_disks(); /* Removable devices */ - loadconfig_removable_devices(); + load_removable_devices(); + pclog("Config loaded.\n"); } -wchar_t *nvr_concat(wchar_t *to_concat) -{ - static wchar_t temp_nvr_path[1024]; - char *p; - wchar_t *wp; - - memset(temp_nvr_path, 0, 2048); - wcscpy(temp_nvr_path, nvr_path); - - p = (char *) temp_nvr_path; - p += (path_len * 2); - wp = (wchar_t *) p; - - wcscpy(wp, to_concat); - return temp_nvr_path; -} - - -static void saveconfig_general(void) +/* Save "General" section. */ +static void +save_general(void) { char *cat = "General"; - char temps[512]; + char temp[512]; config_set_int(cat, "vid_resize", vid_resize); if (vid_resize == 0) @@ -1907,8 +1581,8 @@ static void saveconfig_general(void) { config_set_int(cat, "window_remember", window_remember); - sprintf(temps, "%i, %i, %i, %i", window_w, window_h, window_x, window_y); - config_set_string(cat, "window_coordinates", temps); + sprintf(temp, "%i, %i, %i, %i", window_w, window_h, window_x, window_y); + config_set_string(cat, "window_coordinates", temp); } else { @@ -1927,12 +1601,13 @@ static void saveconfig_general(void) } #endif - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -/* Machine */ -static void saveconfig_machine(void) +/* Save "Machine" section. */ +static void +save_machine(void) { char *cat = "Machine"; @@ -1996,12 +1671,13 @@ static void saveconfig_machine(void) config_set_int(cat, "enable_sync", enable_sync); } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -/* Video */ -static void saveconfig_video(void) +/* Save "Video" section. */ +static void +save_video(void) { char *cat = "Video"; @@ -2025,15 +1701,16 @@ static void saveconfig_video(void) config_set_int(cat, "voodoo", voodoo_enabled); } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -/* Input devices */ -static void saveconfig_input_devices(void) +/* Save "Input Devices" section. */ +static void +save_input_devices(void) { char *cat = "Input devices"; - char temps[512]; + char temp[512]; char s[512]; int c, d; @@ -2096,19 +1773,20 @@ static void saveconfig_input_devices(void) for (d = 0; d < joystick_get_pov_count(joystick_type); d++) { sprintf(s, "joystick_%i_pov_%i", c, d); - sprintf(temps, "%i, %i", joystick_state[c].pov_mapping[d][0], joystick_state[c].pov_mapping[d][1]); - config_set_string(cat, s, temps); + sprintf(temp, "%i, %i", joystick_state[c].pov_mapping[d][0], joystick_state[c].pov_mapping[d][1]); + config_set_string(cat, s, temp); } } } } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -/* Sound */ -static void saveconfig_sound(void) +/* Save "Sound" section. */ +static void +save_sound(void) { char *cat = "Sound"; @@ -2185,13 +1863,14 @@ static void saveconfig_sound(void) config_set_string(cat, "sound_type", (sound_is_float == 1) ? "float" : "int16"); } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } #ifdef USE_NETWORK -/* Network */ -static void saveconfig_network(void) +/* Save "Network" section. */ +static void +save_network(void) { char *cat = "Network"; @@ -2230,13 +1909,14 @@ static void saveconfig_network(void) config_set_string(cat, "net_card", network_card_get_internal_name(network_card)); } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } #endif -/* Ports (COM & LPT) */ -static void saveconfig_ports(void) +/* Save "Ports" section. */ +static void +save_ports(void) { char *cat = "Ports (COM & LPT)"; @@ -2276,12 +1956,13 @@ static void saveconfig_ports(void) config_set_string(cat, "lpt1_device", lpt1_device_name); } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -/* Other peripherals */ -static void saveconfig_other_peripherals(void) +/* Save "Other Peripherals" section. */ +static void +save_other_peripherals(void) { char *cat = "Other peripherals"; char temps[512]; @@ -2331,11 +2012,12 @@ static void saveconfig_other_peripherals(void) config_set_int(cat, "bugger_enabled", bugger_enabled); } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -static char *config_bus_to_string(int bus, int cdrom) +static char * +bus_to_string(int bus, int cdrom) { switch (bus) { @@ -2368,8 +2050,9 @@ static char *config_bus_to_string(int bus, int cdrom) } -/* Hard disks */ -static void saveconfig_hard_disks(void) +/* Save "Hard Disks" section. */ +static void +save_hard_disks(void) { char *cat = "Hard disks"; char temps[24]; @@ -2389,7 +2072,7 @@ static void saveconfig_hard_disks(void) } else { - p = config_bus_to_string(hdc[c].bus, 0); + p = bus_to_string(hdc[c].bus, 0); sprintf(temps2, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %i, %s", hdc[c].spt, hdc[c].hpc, hdc[c].tracks, hdc[c].wp, p); config_set_string(cat, temps, temps2); } @@ -2457,12 +2140,13 @@ static void saveconfig_hard_disks(void) } } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -/* Removable devices */ -static void saveconfig_removable_devices(void) +/* Save "Removable Devices" section. */ +static void +save_removable_devices(void) { char *cat = "Removable devices"; char temps[512]; @@ -2548,7 +2232,7 @@ static void saveconfig_removable_devices(void) } else { - sprintf(temps2, "%u, %s", cdrom_drives[c].sound_on, config_bus_to_string(cdrom_drives[c].bus_type, 1)); + sprintf(temps2, "%u, %s", cdrom_drives[c].sound_on, bus_to_string(cdrom_drives[c].bus_type, 1)); config_set_string(cat, temps, temps2); } @@ -2585,43 +2269,451 @@ static void saveconfig_removable_devices(void) } } - config_delete_section_if_empty(cat); + delete_section_if_empty(cat); } -void saveconfig(void) +void +config_save(void) { /* General */ - saveconfig_general(); + save_general(); /* Machine */ - saveconfig_machine(); + save_machine(); /* Video */ - saveconfig_video(); + save_video(); /* Input devices */ - saveconfig_input_devices(); + save_input_devices(); /* Sound */ - saveconfig_sound(); + save_sound(); #ifdef USE_NETWORK /* Network */ - saveconfig_network(); + save_network(); #endif /* Ports (COM & LPT) */ - saveconfig_ports(); + save_ports(); /* Other peripherals */ - saveconfig_other_peripherals(); + save_other_peripherals(); /* Hard disks */ - saveconfig_hard_disks(); + save_hard_disks(); /* Removable devices */ - saveconfig_removable_devices(); + save_removable_devices(); - config_save(config_file_default); + config_write(config_file_default); } + + +void +config_dump(void) +{ + section_t *sec; + + pclog("Config data :\n"); + + sec = (section_t *)config_head.next; + while (sec != NULL) + { + entry_t *ent; + + pclog("[%s]\n", sec->name); + + ent = (entry_t *)sec->entry_head.next; + + while (ent != NULL) + { + pclog("%s = %s\n", ent->name, ent->data); + + ent = (entry_t *)ent->list.next; + } + + sec = (section_t *)sec->list.next; + } +} + + +void +config_delete_var(char *head, char *name) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + if (section == NULL) return; + + entry = find_entry(section, name); + if (entry == NULL) return; + + list_delete(&entry->list, §ion->entry_head); + free(entry); +} + + +int +config_get_int(char *head, char *name, int def) +{ + section_t *section; + entry_t *entry; + int value; + + section = find_section(head); + + if (!section) + return def; + + entry = find_entry(section, name); + + if (!entry) + return def; + + sscanf(entry->data, "%i", &value); + + return value; +} + + +int +config_get_hex16(char *head, char *name, int def) +{ + section_t *section; + entry_t *entry; + int value; + + section = find_section(head); + + if (!section) + return def; + + entry = find_entry(section, name); + + if (!entry) + return def; + + sscanf(entry->data, "%04X", &value); + + return value; +} + + +int +config_get_hex20(char *head, char *name, int def) +{ + section_t *section; + entry_t *entry; + int value; + + section = find_section(head); + + if (!section) + return def; + + entry = find_entry(section, name); + + if (!entry) + return def; + + sscanf(entry->data, "%05X", &value); + + return value; +} + + +int +config_get_mac(char *head, char *name, int def) +{ + section_t *section; + entry_t *entry; + int val0 = 0, val1 = 0, val2 = 0; + + section = find_section(head); + + if (!section) + return def; + + entry = find_entry(section, name); + + if (!entry) + return def; + + sscanf(entry->data, "%02x:%02x:%02x", &val0, &val1, &val2); + + return (val0 << 16) + (val1 << 8) + val2; +} + + +char * +config_get_string(char *head, char *name, char *def) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + return def; + + entry = find_entry(section, name); + + if (!entry) + return def; + + return entry->data; +} + + +wchar_t * +config_get_wstring(char *head, char *name, wchar_t *def) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + return def; + + entry = find_entry(section, name); + + if (!entry) + return def; + + return entry->wdata; +} + + +void +config_set_int(char *head, char *name, int val) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + section = create_section(head); + + entry = find_entry(section, name); + + if (!entry) + entry = create_entry(section, name); + + sprintf(entry->data, "%i", val); + mbstowcs(entry->wdata, entry->data, 512); +} + + +void +config_set_hex16(char *head, char *name, int val) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + section = create_section(head); + + entry = find_entry(section, name); + + if (!entry) + entry = create_entry(section, name); + + sprintf(entry->data, "%04X", val); + mbstowcs(entry->wdata, entry->data, 512); +} + + +void +config_set_hex20(char *head, char *name, int val) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + section = create_section(head); + + entry = find_entry(section, name); + + if (!entry) + entry = create_entry(section, name); + + sprintf(entry->data, "%05X", val); + mbstowcs(entry->wdata, entry->data, 512); +} + + +void +config_set_mac(char *head, char *name, int val) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + section = create_section(head); + + entry = find_entry(section, name); + + if (!entry) + entry = create_entry(section, name); + + sprintf(entry->data, "%02x:%02x:%02x", + (val>>16)&0xff, (val>>8)&0xff, val&0xff); + mbstowcs(entry->wdata, entry->data, 512); +} + + +void +config_set_string(char *head, char *name, char *val) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + section = create_section(head); + + entry = find_entry(section, name); + + if (!entry) + entry = create_entry(section, name); + + strncpy(entry->data, val, 256); + mbstowcs(entry->wdata, entry->data, 256); +} + + +void +config_set_wstring(char *head, char *name, wchar_t *val) +{ + section_t *section; + entry_t *entry; + + section = find_section(head); + + if (!section) + section = create_section(head); + + entry = find_entry(section, name); + + if (!entry) + entry = create_entry(section, name); + + memcpy(entry->wdata, val, 512); +} + + +/* FIXME: should be moved elsewhere. --FvK */ +char * +get_filename(char *s) +{ + int c = strlen(s) - 1; + while (c > 0) + { + if (s[c] == '/' || s[c] == '\\') + return &s[c+1]; + c--; + } + return s; +} + + +/* FIXME: should be moved elsewhere. --FvK */ +wchar_t * +get_filename_w(wchar_t *s) +{ + int c = wcslen(s) - 1; + while (c > 0) + { + if (s[c] == L'/' || s[c] == L'\\') + return &s[c+1]; + c--; + } + return s; +} + + +/* FIXME: should be moved elsewhere. --FvK */ +void +append_filename(char *dest, char *s1, char *s2, int size) +{ + sprintf(dest, "%s%s", s1, s2); +} + + +/* FIXME: should be moved elsewhere. --FvK */ +void +append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) +{ + _swprintf(dest, L"%s%s", s1, s2); +} + + +/* FIXME: should be moved elsewhere. --FvK */ +void +put_backslash(char *s) +{ + int c = strlen(s) - 1; + if (s[c] != '/' && s[c] != '\\') + s[c] = '/'; +} + + +/* FIXME: should be moved elsewhere. --FvK */ +void +put_backslash_w(wchar_t *s) +{ + int c = wcslen(s) - 1; + if (s[c] != L'/' && s[c] != L'\\') + s[c] = L'/'; +} + + +/* FIXME: should be moved elsewhere. --FvK */ +char * +get_extension(char *s) +{ + int c = strlen(s) - 1; + + if (c <= 0) + return s; + + while (c && s[c] != '.') + c--; + + if (!c) + return &s[strlen(s)]; + + return &s[c+1]; +} + + +/* FIXME: should be moved elsewhere. --FvK */ +wchar_t +*get_extension_w(wchar_t *s) +{ + int c = wcslen(s) - 1; + + if (c <= 0) + return s; + + while (c && s[c] != L'.') + c--; + + if (!c) + return &s[wcslen(s)]; + + return &s[c+1]; +} diff --git a/src/config.h b/src/config.h index 352d19faa..84bccc1e9 100644 --- a/src/config.h +++ b/src/config.h @@ -8,7 +8,7 @@ * * Configuration file handler header. * - * Version: @(#)config.h 1.0.1 2017/08/23 + * Version: @(#)config.h 1.0.2 2017/09/19 * * Authors: Sarah Walker, * Miran Grca, @@ -29,13 +29,18 @@ extern wchar_t config_file_default[256]; extern "C" { #endif +extern void config_load(wchar_t *fn); +extern void config_save(void); +extern void config_write(wchar_t *fn); +extern void config_dump(void); + +extern void config_delete_var(char *head, char *name); extern int config_get_int(char *head, char *name, int def); extern int config_get_hex16(char *head, char *name, int def); extern int config_get_hex20(char *head, char *name, int def); extern int config_get_mac(char *head, char *name, int def); extern char *config_get_string(char *head, char *name, char *def); extern wchar_t *config_get_wstring(char *head, char *name, wchar_t *def); -extern void config_delete_var(char *head, char *name); extern void config_set_int(char *head, char *name, int val); extern void config_set_hex16(char *head, char *name, int val); extern void config_set_hex20(char *head, char *name, int val); @@ -50,15 +55,8 @@ extern void append_filename_w(wchar_t *dest, wchar_t *s1, wchar_t *s2, int size) extern void put_backslash(char *s); extern void put_backslash_w(wchar_t *s); extern char *get_extension(char *s); - extern wchar_t *get_extension_w(wchar_t *s); -extern int config_load(wchar_t *fn); -extern void config_save(wchar_t *fn); -extern void config_dump(void); - -extern void loadconfig(wchar_t *fn); -extern void saveconfig(void); #ifdef __cplusplus } diff --git a/src/cpu/808x.c b/src/cpu/808x.c index d948031ba..0a56f7499 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -8,12 +8,12 @@ * * 808x CPU emulation. * - * Version: @(#)808x.c 1.0.0 2017/05/30 + * Version: @(#)808x.c 1.0.1 2017/09/19 * - * Author: Sarah Walker, + * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ /*SHR AX,1 @@ -503,7 +503,7 @@ void dumpregs(int force) #ifndef RELEASE_BUILD indump = 1; output=0; - _wchdir(pcempath); + _wchdir(cfg_path); nopageerrors=1; f=fopen("ram.dmp","wb"); fwrite(ram,mem_size*1024,1,f); diff --git a/src/floppy/floppy_86f.c b/src/floppy/floppy_86f.c index 842945435..08bdfc0ac 100644 --- a/src/floppy/floppy_86f.c +++ b/src/floppy/floppy_86f.c @@ -10,7 +10,7 @@ * data in the form of FM/MFM-encoded transitions) which also * forms the core of the emulator's floppy disk emulation. * - * Version: @(#)floppy_86f.c 1.0.2 2017/09/03 + * Version: @(#)floppy_86f.c 1.0.3 2017/09/19 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -26,6 +26,7 @@ #include "../ibm.h" #include "../config.h" #include "../dma.h" +#include "../nvr.h" #include "../random.h" #include "floppy.h" #include "fdc.h" diff --git a/src/ibm.h b/src/ibm.h index b6f9b54d5..a5ca95b68 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -8,7 +8,7 @@ * * General include file. * - * Version: @(#)ibm.h 1.0.3 2017/09/03 + * Version: @(#)ibm.h 1.0.4 2017/09/19 * * Authors: Sarah Walker, * Miran Grca, @@ -585,7 +585,9 @@ extern int gated,speakval,speakon; #define SND_WSS 9 /*Windows Sound System*/ #define SND_PAS16 10 /*Pro Audio Spectrum 16*/ -extern wchar_t pcempath[512]; +extern wchar_t exe_path[1024]; +extern wchar_t cfg_path[1024]; +extern wchar_t nvr_path[1024]; /*Hard disk*/ @@ -704,10 +706,6 @@ extern uint64_t star; #define FPU_CW_Reserved_Bits (0xe0c0) -extern wchar_t nvr_path[1024]; -extern int path_len; - -wchar_t *nvr_concat(wchar_t *to_concat); extern int mem_a20_state; @@ -781,7 +779,6 @@ extern void resetpchard(void); extern void resetreadlookup(void); extern void resetx86(void); extern void runpc(void); -extern void saveconfig(void); extern void softresetx86(void); extern void speedchanged(void); extern void x86_int_sw(int num); diff --git a/src/intel_flash.c b/src/intel_flash.c index 990c603ee..59955a0ca 100644 --- a/src/intel_flash.c +++ b/src/intel_flash.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 2 Mbit 8-bit flash devices. * - * Version: @(#)intel_flash.c 1.0.1 2017/08/23 + * Version: @(#)intel_flash.c 1.0.2 2017/09/19 * * Authors: Sarah Walker, * Miran Grca, @@ -22,7 +22,7 @@ #include "device.h" #include "mem.h" #include "machine/machine.h" -#include "rom.h" +#include "nvr.h" #define FLASH_IS_BXB 2 #define FLASH_INVERT 1 diff --git a/src/nvr.c b/src/nvr.c index c888f8358..d83a56ab4 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -8,7 +8,7 @@ * * CMOS NVRAM emulation. * - * Version: @(#)nvr.c 1.0.2 2017/09/03 + * Version: @(#)nvr.c 1.0.3 2017/09/19 * * Authors: Sarah Walker, * Miran Grca, @@ -22,6 +22,7 @@ #include #include #include "ibm.h" +#include "config.h" #include "cpu/cpu.h" #include "device.h" #include "io.h" @@ -34,6 +35,7 @@ #include "rom.h" #include "timer.h" #include "rtc.h" +#include "win/win.h" int oldmachine; @@ -317,7 +319,9 @@ void savenvr(void) free(machine_name); } -void nvr_init(void) + +void +nvr_init(void) { io_sethandler(0x0070, 0x0002, readnvr, NULL, NULL, writenvr, NULL, NULL, NULL); timer_add(nvr_rtc, &rtctime, TIMER_ALWAYS_ENABLED, NULL); @@ -325,3 +329,52 @@ void nvr_init(void) timer_add(nvr_update_end, &nvr_update_end_count, &nvr_update_end_count, NULL); } + + +wchar_t * +nvr_concat(wchar_t *str) +{ + static wchar_t temp[1024]; + wchar_t last; + + /* Get the full prefix in place. */ + memset(temp, 0x00, sizeof(temp)); + append_filename_w(temp, cfg_path, nvr_path, sizeof(temp)-1); + + /* Make sure we have a trailing backslash. */ + if (temp[wcslen(temp) - 1] != L'/') { + if (temp[wcslen(temp) - 1] != L'\\') { + temp[wcslen(temp)] = L'\\'; + temp[wcslen(temp) + 1] = L'\0'; + } + } + +#ifndef __unix + /* Save the backslash and zap it. */ + last = temp[wcslen(temp) - 1]; + temp[wcslen(temp) - 1] = 0; + + /* Create the directory if needed. */ + if (! DirectoryExists(temp)) + CreateDirectory(temp, NULL); + + /* Restore the backslash. */ + temp[wcslen(temp)] = last; +#endif + + /* Now append the actual filename. */ + wcscat(temp, str); + + return(temp); +} + + +FILE * +nvrfopen(wchar_t *fn, wchar_t *mode) +{ + wchar_t *p; + + p = nvr_concat(fn); + + return(_wfopen(p, mode)); +} diff --git a/src/nvr.h b/src/nvr.h index 0c7780240..a0c6ef4a6 100644 --- a/src/nvr.h +++ b/src/nvr.h @@ -8,7 +8,7 @@ * * CMOS NVRAM emulation. * - * Version: @(#)nvr.h 1.0.1 2017/06/03 + * Version: @(#)nvr.h 1.0.2 2017/06/19 * * Authors: Sarah Walker, * Miran Grca, @@ -25,11 +25,13 @@ extern int enable_sync; extern int nvr_dosave; -extern void nvr_init(void); -extern void time_get(char *nvrram); -extern void nvr_recalc(void); -extern void loadnvr(void); -extern void savenvr(void); +extern wchar_t *nvr_concat(wchar_t *to_concat); +extern void nvr_init(void); +extern FILE *nvrfopen(wchar_t *fn, wchar_t *mode); +extern void time_get(char *nvrram); +extern void nvr_recalc(void); +extern void loadnvr(void); +extern void savenvr(void); #endif /*EMU_NVR_H*/ diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index 75ba968e4..c56e0f5df 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -3,7 +3,7 @@ #include "device.h" #include "io.h" #include "mem.h" -#include "rom.h" +#include "nvr.h" #include "nvr_ps2.h" diff --git a/src/pc.c b/src/pc.c index bc7f6bf65..e6e948d85 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Emulation core dispatcher. * - * Version: @(#)pc.c 1.0.8 2017/09/03 + * Version: @(#)pc.c 1.0.10 2017/09/22 * * Authors: Sarah Walker, * Miran Grca, @@ -18,6 +18,7 @@ #include #include #include +#include #include "86box.h" #include "config.h" #include "ibm.h" @@ -81,9 +82,9 @@ #include "cpu/x86_ops.h" -wchar_t pcempath[512]; - -wchar_t nvr_path[1024]; +wchar_t exe_path[1024]; +wchar_t cfg_path[1024]; +wchar_t nvr_path[1024]; int path_len; int window_w, window_h, window_x, window_y, window_remember; @@ -108,7 +109,6 @@ int framecount,fps; int output; int atfullspeed; -void saveconfig(); int infocus; int mousecapture; @@ -181,7 +181,7 @@ void fatal(const char *format, ...) va_end(ap); fflush(stdout); savenvr(); - saveconfig(); + config_save(); #ifndef __unix newline = memmem(msg, strlen(msg), "\n", strlen("\n")); if (newline != NULL) @@ -286,41 +286,56 @@ void pc_reset(void) #undef printf void initpc(int argc, wchar_t *argv[]) { - wchar_t *p; wchar_t *config_file = NULL; - int c; - get_executable_name(pcempath, 511); - pclog("executable_name = %S\n", pcempath); - p=get_filename_w(pcempath); - *p=L'\0'; - pclog("path = %S\n", pcempath); + wchar_t *p; #ifdef WALTJE - DIR *dir; struct direct *dp; + DIR *dir; #endif + int c; + + /* Grab the executable's full path. */ + get_executable_name(exe_path, sizeof(exe_path)-1); + p = get_filename_w(exe_path); + *p = L'\0'; + pclog("exe_path=%S\n", exe_path); + + /* + * Get the current working directory. + * This is normally the directory from where the + * program was run. If we have been started via + * a shortcut (desktop icon), however, the CWD + * could have been set to something else. + */ + _wgetcwd(cfg_path, sizeof(cfg_path)-1); for (c = 1; c < argc; c++) { if (!_wcsicmp(argv[c], L"--help")) { +usage: printf("Command line options :\n\n"); printf("--config file.cfg - use given config file as initial configuration\n"); printf("--dump - always dump memory on exit\n"); printf("--fullscreen - start in fullscreen mode\n"); + printf("--vmpath pathname - set 'path' to be root for vm\n"); exit(-1); } - else if (!_wcsicmp(argv[c], L"--config")) + else if (!_wcsicmp(argv[c], L"--config") || + !_wcsicmp(argv[c], L"-C")) { if ((c+1) == argc) break; config_file = argv[c+1]; c++; } - else if (!_wcsicmp(argv[c], L"--dump")) + else if (!_wcsicmp(argv[c], L"--dump") || + !_wcsicmp(argv[c], L"-D")) { dump_on_exit = 1; } - else if (!_wcsicmp(argv[c], L"--fullscreen")) + else if (!_wcsicmp(argv[c], L"--fullscreen") || + !_wcsicmp(argv[c], L"-F")) { start_in_fullscreen = 1; } @@ -328,9 +343,9 @@ void initpc(int argc, wchar_t *argv[]) { /* some (undocumented) test function here.. */ #ifdef WALTJE - dir = opendirw(pcempath); + dir = opendirw(exe_path); if (dir != NULL) { - printf("Directory '%S':\n", pcempath); + printf("Directory '%S':\n", exe_path); for (;;) { dp = readdir(dir); if (dp == NULL) break; @@ -338,26 +353,56 @@ void initpc(int argc, wchar_t *argv[]) } closedir(dir); } else { - printf("Could not open '%S'..\n", pcempath); + printf("Could not open '%S'..\n", exe_path); } #endif /* .. and then exit. */ exit(0); } + else if (!_wcsicmp(argv[c], L"--vmpath") || + !_wcsicmp(argv[c], L"-P")) + { + if ((c+1) == argc) + break; + wcscpy(cfg_path, argv[c+1]); + c++; + } + + /* Uhm... out of options here.. */ + else goto usage; } - if (config_file == NULL) - { - append_filename_w(config_file_default, pcempath, CONFIG_FILE_W, 511); + /* Make sure cfg_path has a trailing backslash. */ + if ((cfg_path[wcslen(cfg_path)-1] != L'\\') && + (cfg_path[wcslen(cfg_path)-1] != L'/')) { + wcscat(cfg_path, L"\\"); } - else - { - append_filename_w(config_file_default, pcempath, config_file, 511); + pclog("cwd_path=%S\n", cfg_path); + + if (config_file != NULL) { + /* + * The user specified a configuration file. + * + * If this is an absolute path, keep it, as + * they probably have a reason to do that. + * Otherwise, assume the pathname given is + * relative to whatever the cfg_path is. + */ + if ((config_file[1] == L':') || /* drive letter present */ + (config_file[0] == L'\\')) /* backslash, root dir */ + append_filename_w(config_file_default, + NULL, /* empty */ + config_file, 511); + else + append_filename_w(config_file_default, + cfg_path, + config_file, 511); + } else { + append_filename_w(config_file_default, cfg_path, CONFIG_FILE_W, 511); } - loadconfig(config_file); - pclog("Config loaded\n"); + config_load(config_file); } void initmodules(void) diff --git a/src/rom.c b/src/rom.c index 4114ee243..7ab364dd8 100644 --- a/src/rom.c +++ b/src/rom.c @@ -11,25 +11,22 @@ FILE *romfopen(wchar_t *fn, wchar_t *mode) { - wchar_t s[512]; - wcscpy(s, pcempath); + wchar_t s[1024]; + + wcscpy(s, exe_path); put_backslash_w(s); wcscat(s, fn); + return _wfopen(s, mode); } -FILE *nvrfopen(wchar_t *fn, wchar_t *mode) -{ - return _wfopen(nvr_concat(fn), mode); -} - int rom_getfile(wchar_t *fn, wchar_t *s, int size) { FILE *f; - wcscpy(s, pcempath); + wcscpy(s, exe_path); put_backslash_w(s); wcscat(s, fn); f = _wfopen(s, L"rb"); @@ -46,7 +43,7 @@ int rom_present(wchar_t *fn) FILE *f; wchar_t s[512]; - wcscpy(s, pcempath); + wcscpy(s, exe_path); put_backslash_w(s); wcscat(s, fn); f = _wfopen(s, L"rb"); diff --git a/src/rom.h b/src/rom.h index a2f85d01f..455a98bd1 100644 --- a/src/rom.h +++ b/src/rom.h @@ -2,7 +2,6 @@ see COPYING for more details */ extern FILE *romfopen(wchar_t *fn, wchar_t *mode); -extern FILE *nvrfopen(wchar_t *fn, wchar_t *mode); extern int rom_getfile(wchar_t *fn, wchar_t *s, int size); extern int rom_present(wchar_t *fn); diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index 782ed3450..18f078d3f 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -12,7 +12,7 @@ * * NOTE: THIS IS CURRENTLY A MESS, but will be cleaned up as I go. * - * Version: @(#)scsi_aha154x.c 1.0.16 2017/09/05 + * Version: @(#)scsi_aha154x.c 1.0.17 2017/09/19 * * Authors: Fred N. van Kempen, * Original Buslogic version by SA1988 and Miran Grca. @@ -29,6 +29,7 @@ #include "../mem.h" #include "../mca.h" #include "../rom.h" +#include "../nvr.h" #include "../dma.h" #include "../pic.h" #include "../timer.h" diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index f6d0ee901..a07ee5908 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -10,7 +10,7 @@ * 0 - BT-545C ISA; * 1 - BT-958D PCI (but BT-545C ISA on non-PCI machines) * - * Version: @(#)scsi_buslogic.c 1.0.12 2017/09/05 + * Version: @(#)scsi_buslogic.c 1.0.13 2017/09/19 * * Authors: TheCollector1995, * Miran Grca, @@ -27,6 +27,7 @@ #include "../io.h" #include "../mem.h" #include "../rom.h" +#include "../nvr.h" #include "../dma.h" #include "../pic.h" #include "../pci.h" diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index 2d16bfd7b..e99f299f9 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -7,6 +7,7 @@ #include "../pit.h" #include "../mem.h" #include "../rom.h" +#include "../nvr.h" #include "../timer.h" #include "../device.h" #include "sound.h" diff --git a/src/tandy_eeprom.c b/src/tandy_eeprom.c index 8e9e9fc27..593790afa 100644 --- a/src/tandy_eeprom.c +++ b/src/tandy_eeprom.c @@ -6,7 +6,7 @@ #include "device.h" #include "mem.h" #include "io.h" -#include "rom.h" +#include "nvr.h" #include "tandy_eeprom.h" diff --git a/src/video/vid_ati_eeprom.c b/src/video/vid_ati_eeprom.c index 198575a60..e824708cb 100644 --- a/src/video/vid_ati_eeprom.c +++ b/src/video/vid_ati_eeprom.c @@ -3,7 +3,7 @@ */ #include "../ibm.h" #include "../mem.h" -#include "../rom.h" +#include "../nvr.h" #include "vid_ati_eeprom.h" diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index 7df65bea6..9131aa48b 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -8,22 +8,23 @@ * * Generic SVGA handling. * - * Version: @(#)vid_svga.c 1.0.0 2017/05/30 + * This is intended to be used by another SVGA driver, + * and not as a card in it's own right. * - * Author: Sarah Walker, + * Version: @(#)vid_svga.c 1.0.1 2017/09/19 + * + * Authors: Sarah Walker, * Miran Grca, * Copyright 2008-2017 Sarah Walker. - * Copyright 2016-2017 Miran Grca. + * Copyright 2016,2017 Miran Grca. */ - -/*This is intended to be used by another SVGA driver, and not as a card in it's own right*/ #include #include #include "../ibm.h" #include "../io.h" #include "../mem.h" #ifdef ENABLE_VRAM_DUMP -#include "../rom.h" +# include "../nvr.h" #endif #include "../timer.h" #include "video.h" diff --git a/src/video/video.c b/src/video/video.c index 463d898ea..f5cf8ea47 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -718,7 +718,7 @@ BOOL DirectoryExists(LPCTSTR szPath) (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); } -void take_screenshot() +void take_screenshot(void) { if ((vid_api < 0) || (vid_api > 1)) return; time(&now); @@ -727,7 +727,7 @@ void take_screenshot() memset(screenshot_fn_partial, 0, 4096); memset(screenshot_path, 0, 8192); pclog("Video API is: %i\n", vid_api); - append_filename_w(screenshot_path, pcempath, L"screenshots", 4095); + append_filename_w(screenshot_path, cfg_path, L"screenshots", 4095); if (!DirectoryExists(screenshot_path)) { CreateDirectory(screenshot_path, NULL); @@ -735,7 +735,7 @@ void take_screenshot() if (vid_api == 1) { wcsftime(screenshot_fn_partial, 2048, L"screenshots\\%Y%m%d_%H%M%S.png", info); - append_filename_w(screenshot_fn, pcempath, screenshot_fn_partial, 4095); + append_filename_w(screenshot_fn, cfg_path, screenshot_fn_partial, 4095); if (video_fullscreen) { d3d_fs_take_screenshot(screenshot_fn); @@ -749,7 +749,7 @@ void take_screenshot() else if (vid_api == 0) { wcsftime(screenshot_fn_partial, 2048, L"screenshots\\%Y%m%d_%H%M%S.bmp", info); - append_filename_w(screenshot_fn, pcempath, screenshot_fn_partial, 4095); + append_filename_w(screenshot_fn, cfg_path, screenshot_fn_partial, 4095); if (video_fullscreen) { ddraw_fs_take_screenshot(screenshot_fn); diff --git a/src/win/win.c b/src/win/win.c index c8efeef12..63065d2e9 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -8,7 +8,7 @@ * * The Emulator's Windows core. * - * Version: @(#)win.c 1.0.8 2017/09/03 + * Version: @(#)win.c 1.0.9 2017/09/19 * * Authors: Sarah Walker, * Miran Grca, @@ -1783,7 +1783,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpsz { romset = c; machine = machine_getmachine(romset); - saveconfig(); + config_save(); resetpchard(); break; } @@ -1806,7 +1806,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpsz if (gfx_present[c]) { gfxcard = c; - saveconfig(); + config_save(); resetpchard(); break; } @@ -1899,7 +1899,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpsz Sleep(200); TerminateThread(mainthreadh,0); savenvr(); - saveconfig(); + config_save(); closepc(); vid_apis[video_fullscreen][vid_api].close(); @@ -1996,7 +1996,7 @@ static void win_pc_reset(int hard) pause=1; Sleep(100); savenvr(); - saveconfig(); + config_save(); if (hard) { resetpchard(); @@ -2015,7 +2015,7 @@ void video_toggle_option(HMENU hmenu, int *val, int id) *val ^= 1; CheckMenuItem(hmenu, id, *val ? MF_CHECKED : MF_UNCHECKED); endblit(); - saveconfig(); + config_save(); device_force_redraw(); } @@ -2089,7 +2089,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM EnableMenuItem(hmenu, IDM_VID_SCALE_3X, vid_resize ? MF_GRAYED : MF_ENABLED); EnableMenuItem(hmenu, IDM_VID_SCALE_4X, vid_resize ? MF_GRAYED : MF_ENABLED); win_doresize = 1; - saveconfig(); + config_save(); break; case IDM_VID_REMEMBER: @@ -2103,7 +2103,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM window_w = rect.right - rect.left; window_h = rect.bottom - rect.top; } - saveconfig(); + config_save(); break; case IDM_VID_DDRAW: @@ -2116,7 +2116,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_CHECKED); vid_apis[0][vid_api].init(hwndRender); endblit(); - saveconfig(); + config_save(); device_force_redraw(); cgapal_rebuild(); break; @@ -2139,7 +2139,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM mouse_init(); leave_fullscreen_flag = 0; endblit(); - saveconfig(); + config_save(); device_force_redraw(); cgapal_rebuild(); } @@ -2152,7 +2152,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_UNCHECKED); video_fullscreen_scale = LOWORD(wParam) - IDM_VID_FS_FULL; CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED); - saveconfig(); + config_save(); device_force_redraw(); break; @@ -2163,7 +2163,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED); scale = LOWORD(wParam) - IDM_VID_SCALE_1X; CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_CHECKED); - saveconfig(); + config_save(); device_force_redraw(); break; @@ -2184,7 +2184,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM vid_cga_contrast ^= 1; CheckMenuItem(hmenu, IDM_VID_CGACON, vid_cga_contrast ? MF_CHECKED : MF_UNCHECKED); cgapal_rebuild(); - saveconfig(); + config_save(); break; case IDM_VID_GRAYCT_601: @@ -2193,7 +2193,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_UNCHECKED); video_graytype = LOWORD(wParam) - IDM_VID_GRAYCT_601; CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_CHECKED); - saveconfig(); + config_save(); device_force_redraw(); break; @@ -2205,7 +2205,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_UNCHECKED); video_grayscale = LOWORD(wParam) - IDM_VID_GRAY_RGB; CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED); - saveconfig(); + config_save(); device_force_redraw(); break; @@ -2281,7 +2281,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM { if (msgbox_reset_yn(ghwnd) == IDYES) { - config_save(config_file_default); + config_write(config_file_default); for (i = 0; i < FDD_NUM; i++) { floppy_close(i); @@ -2303,7 +2303,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM } } resetpchard_close(); - loadconfig(wopenfilestring); + config_load(wopenfilestring); for (i = 0; i < CDROM_NUM; i++) { if (cdrom_drives[i].bus_type) @@ -2348,7 +2348,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM pause = 1; if (!file_dlg_st(hwnd, IDS_2160, "", 1)) { - config_save(wopenfilestring); + config_write(wopenfilestring); } pause = 0; break; @@ -2454,7 +2454,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM save_window_pos = 1; } - saveconfig(); + config_save(); break; case WM_MOVE: @@ -2494,7 +2494,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM mouse_close(); vid_apis[1][vid_api].close(); video_fullscreen = 0; - saveconfig(); + config_save(); vid_apis[0][vid_api].init(hwndRender); mouse_init(); endblit(); @@ -2589,7 +2589,7 @@ LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPAR update_status_bar_icon_state(SB_FLOPPY | id, wcslen(floppyfns[id]) ? 0 : 1); EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EJECT | id, MF_BYCOMMAND | (wcslen(floppyfns[id]) ? MF_ENABLED : MF_GRAYED)); update_tip(SB_FLOPPY | id); - saveconfig(); + config_save(); } break; @@ -2605,7 +2605,7 @@ LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPAR update_status_bar_icon_state(SB_FLOPPY | id, 1); EnableMenuItem(sb_menu_handles[part], IDM_FLOPPY_EJECT | id, MF_BYCOMMAND | MF_GRAYED); update_tip(SB_FLOPPY | id); - saveconfig(); + config_save(); break; case IDM_CDROM_MUTE: @@ -2618,7 +2618,7 @@ LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPAR cdrom_drives[id].sound_on ^= 1; CheckMenuItem(sb_menu_handles[part], IDM_CDROM_MUTE | id, cdrom_drives[id].sound_on ? MF_UNCHECKED : MF_CHECKED); - saveconfig(); + config_save(); sound_cd_thread_reset(); break; @@ -2674,7 +2674,7 @@ LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPAR } EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); update_tip(SB_CDROM | id); - saveconfig(); + config_save(); } break; @@ -2710,7 +2710,7 @@ LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPAR EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); update_status_bar_icon_state(SB_CDROM | id, 0); update_tip(SB_CDROM | id); - saveconfig(); + config_save(); break; case IDM_RDISK_EJECT: @@ -2755,7 +2755,7 @@ LRESULT CALLBACK StatusBarProcedure(HWND hwnd, UINT message, WPARAM wParam, LPAR EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_GRAYED); } update_tip(SB_RDISK | id); - saveconfig(); + config_save(); } break; diff --git a/src/win/win_deviceconfig.c b/src/win/win_deviceconfig.c index 21517727d..7de0bdb9c 100644 --- a/src/win/win_deviceconfig.c +++ b/src/win/win_deviceconfig.c @@ -8,7 +8,7 @@ * * Windows device configuration dialog implementation. * - * Version: @(#)win_deviceconfig.c 1.0.1 2017/06/19 + * Version: @(#)win_deviceconfig.c 1.0.2 2017/09/19 * * Authors: Sarah Walker, * Miran Grca, @@ -352,7 +352,7 @@ static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam config++; } - saveconfig(); + config_save(); resetpchard(); diff --git a/src/win/win_iodev.c b/src/win/win_iodev.c index 30ecbe5b2..25f6af567 100644 --- a/src/win/win_iodev.c +++ b/src/win/win_iodev.c @@ -8,7 +8,7 @@ * * Windows IO device menu handler. * - * Version: @(#)win_iodev.c 1.0.1 2017/09/03 + * Version: @(#)win_iodev.c 1.0.2 2017/09/19 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -29,6 +29,7 @@ #include #include #include "../ibm.h" +#include "../config.h" #include "../device.h" #include "../cdrom/cdrom.h" #include "../cdrom/cdrom_image.h" @@ -78,7 +79,7 @@ void cdrom_eject(uint8_t id) update_status_bar_icon_state(SB_CDROM | id, 1); EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); update_tip(SB_CDROM | id); - saveconfig(); + config_save(); } void cdrom_reload(uint8_t id) @@ -139,7 +140,7 @@ void cdrom_reload(uint8_t id) } EnableMenuItem(sb_menu_handles[part], IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); update_tip(SB_CDROM | id); - saveconfig(); + config_save(); } void removable_disk_unload(uint8_t id) @@ -170,7 +171,7 @@ void removable_disk_eject(uint8_t id) EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | MF_GRAYED); update_tip(SB_RDISK | id); - saveconfig(); + config_save(); } void removable_disk_reload(uint8_t id) @@ -196,6 +197,6 @@ void removable_disk_reload(uint8_t id) EnableMenuItem(sb_menu_handles[part], IDM_RDISK_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(sb_menu_handles[part], IDM_RDISK_SEND_CHANGE | id, MF_BYCOMMAND | (wcslen(hdc[id].fn) ? MF_ENABLED : MF_GRAYED)); update_tip(SB_RDISK | id); - saveconfig(); + config_save(); } diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 32ca41369..ba4e367c3 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -8,7 +8,7 @@ * * Windows 86Box Settings dialog handler. * - * Version: @(#)win_settings.c 1.0.10 2017/09/03 + * Version: @(#)win_settings.c 1.0.11 2017/09/19 * * Author: Miran Grca, * Copyright 2016,2017 Miran Grca. @@ -22,6 +22,7 @@ #include #include #include "../ibm.h" +#include "../config.h" #include "../cpu/cpu.h" #include "../mem.h" #include "../device.h" @@ -372,7 +373,7 @@ static void win_settings_save(void) cpu_update_waitstates(); - saveconfig(); + config_save(); speedchanged();