More cleanups, and a bugfix in config.c (harddisk id and lun were not saved.)

This commit is contained in:
waltje
2017-10-13 18:26:25 -04:00
parent c95c2d5534
commit ae3d0d8b22
3 changed files with 196 additions and 173 deletions

View File

@@ -8,7 +8,7 @@
* *
* Configuration file handler. * Configuration file handler.
* *
* Version: @(#)config.c 1.0.19 2017/10/12 * Version: @(#)config.c 1.0.20 2017/10/13
* *
* Authors: Sarah Walker, * Authors: Sarah Walker,
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -66,7 +66,7 @@ typedef struct _list_ {
typedef struct { typedef struct {
list_t list; list_t list;
char name[256]; char name[128];
list_t entry_head; list_t entry_head;
} section_t; } section_t;
@@ -74,9 +74,9 @@ typedef struct {
typedef struct { typedef struct {
list_t list; list_t list;
char name[256]; char name[128];
char data[256]; char data[256];
wchar_t wdata[256]; wchar_t wdata[512];
} entry_t; } entry_t;
#define list_add(new, head) { \ #define list_add(new, head) { \
@@ -116,7 +116,7 @@ find_section(char *name)
name = blank; name = blank;
while (sec != NULL) { while (sec != NULL) {
if (! strncmp(sec->name, name, 256)) if (! strncmp(sec->name, name, sizeof(sec->name)))
return(sec); return(sec);
sec = (section_t *)sec->list.next; sec = (section_t *)sec->list.next;
@@ -134,7 +134,7 @@ find_entry(section_t *section, char *name)
ent = (entry_t *)section->entry_head.next; ent = (entry_t *)section->entry_head.next;
while (ent != NULL) { while (ent != NULL) {
if (! strncmp(ent->name, name, 256)) if (! strncmp(ent->name, name, sizeof(ent->name)))
return(ent); return(ent);
ent = (entry_t *)ent->list.next; ent = (entry_t *)ent->list.next;
@@ -183,7 +183,7 @@ create_section(char *name)
section_t *ns = malloc(sizeof(section_t)); section_t *ns = malloc(sizeof(section_t));
memset(ns, 0x00, sizeof(section_t)); memset(ns, 0x00, sizeof(section_t));
strncpy(ns->name, name, 256); strncpy(ns->name, name, sizeof(ns->name));
list_add(&ns->list, &config_head); list_add(&ns->list, &config_head);
return(ns); return(ns);
@@ -196,7 +196,7 @@ create_entry(section_t *section, char *name)
entry_t *ne = malloc(sizeof(entry_t)); entry_t *ne = malloc(sizeof(entry_t));
memset(ne, 0x00, sizeof(entry_t)); memset(ne, 0x00, sizeof(entry_t));
strncpy(ne->name, name, 256); strncpy(ne->name, name, sizeof(ne->name));
list_add(&ne->list, &section->entry_head); list_add(&ne->list, &section->entry_head);
return(ne); return(ne);
@@ -233,15 +233,14 @@ config_free(void)
static int static int
config_read(wchar_t *fn) config_read(wchar_t *fn)
{ {
char sname[256], ename[256]; char sname[128], ename[128];
wchar_t buff[1024]; wchar_t buff[1024];
section_t *sec, *ns; section_t *sec, *ns;
int sd = 0, ed = 0;
int c, data_pos;
entry_t *ne; entry_t *ne;
int c, d;
FILE *f; FILE *f;
#ifdef ANSI_CFG #if defined(ANSI_CFG) || !defined(WIN32)
f = plat_fopen(fn, L"rt"); f = plat_fopen(fn, L"rt");
#else #else
f = plat_fopen(fn, L"rt, ccs=UNICODE"); f = plat_fopen(fn, L"rt, ccs=UNICODE");
@@ -255,73 +254,76 @@ config_read(wchar_t *fn)
while (1) { while (1) {
memset(buff, 0x00, sizeof(buff)); memset(buff, 0x00, sizeof(buff));
fgetws(buff, sizeof(buff)-1, f); fgetws(buff, sizeof_w(buff), f);
if (feof(f)) break; if (feof(f)) break;
#if 0
/* Make sure there are no stray newlines or hard-returns in there. */ /* Make sure there are no stray newlines or hard-returns in there. */
if (buff[wcslen(buff)-1] == L'\n') buff[wcslen(buff)-1] = L'\0'; if (buff[wcslen(buff)-1] == L'\n') buff[wcslen(buff)-1] = L'\0';
if (buff[wcslen(buff)-1] == L'\r') buff[wcslen(buff)-1] = L'\0'; if (buff[wcslen(buff)-1] == L'\r') buff[wcslen(buff)-1] = L'\0';
#endif
/* Skip any leading whitespace. */
c = 0; c = 0;
while (buff[c] == L' ') while ((buff[c] == L' ') || (buff[c] == L'\t'))
c++; c++;
/* Skip empty lines. */
if (buff[c] == L'\0') continue; if (buff[c] == L'\0') continue;
if ((buff[c] == L'#') || (buff[c] == L';')) { /* Skip lines that (only) have a comment. */
/*Comment*/ if ((buff[c] == L'#') || (buff[c] == L';')) continue;
continue;
}
if (buff[c] == L'[') { /*Section*/ if (buff[c] == L'[') { /*Section*/
sd = 0;
c++; c++;
d = 0;
while (buff[c] != L']' && buff[c]) while (buff[c] != L']' && buff[c])
wctomb(&(sname[sd++]), buff[c++]); wctomb(&(sname[d++]), buff[c++]);
sname[d] = L'\0';
/* Is the section name properly terminated? */
if (buff[c] != L']') continue; if (buff[c] != L']') continue;
sname[sd] = 0; /* Create a new section and insert it. */
ns = malloc(sizeof(section_t)); ns = malloc(sizeof(section_t));
memset(ns, 0x00, sizeof(section_t)); memset(ns, 0x00, sizeof(section_t));
strncpy(ns->name, sname, sizeof(ns->name)); strncpy(ns->name, sname, sizeof(ns->name));
list_add(&ns->list, &config_head); list_add(&ns->list, &config_head);
/* New section is now the current one. */
sec = ns; sec = ns;
} else { continue;
ed = 0; }
while (buff[c] != L'=' && buff[c] != L' ' && buff[c])
wctomb(&(ename[ed++]), buff[c++]);
/* Get the variable name. */
d = 0;
while ((buff[c] != L'=') && (buff[c] != L' ') && buff[c])
wctomb(&(ename[d++]), buff[c++]);
ename[d] = L'\0';
/* Skip incomplete lines. */
if (buff[c] == L'\0') continue; if (buff[c] == L'\0') continue;
ename[ed] = 0; /* Look for =, skip whitespace. */
while ((buff[c] == L'=' || buff[c] == L' ') && buff[c]) while ((buff[c] == L'=' || buff[c] == L' ') && buff[c])
c++; c++;
if (! buff[c]) continue; /* Skip incomplete lines. */
if (buff[c] == L'\0') continue;
data_pos = c; /* This is where the value part starts. */
while (buff[c]) { d = c;
if (buff[c] == L'\n')
buff[c] = L'\0';
c++;
}
/* Allocate a new variable entry.. */
ne = malloc(sizeof(entry_t)); ne = malloc(sizeof(entry_t));
memset(ne, 0x00, sizeof(entry_t)); memset(ne, 0x00, sizeof(entry_t));
strncpy(ne->name, ename, 256); strncpy(ne->name, ename, sizeof(ne->name));
memcpy(ne->wdata, &buff[data_pos], 512); wcsncpy(ne->wdata, &buff[d], sizeof_w(ne->wdata)-1);
ne->wdata[255] = L'\0'; ne->wdata[sizeof_w(ne->wdata)-1] = L'\0';
wcstombs(ne->data, ne->wdata, sizeof(ne->data)); wcstombs(ne->data, ne->wdata, sizeof(ne->data));
ne->data[255] = '\0'; ne->data[sizeof(ne->data)-1] = '\0';
/* .. and insert it. */
list_add(&ne->list, &sec->entry_head); list_add(&ne->list, &sec->entry_head);
} }
}
(void)fclose(f); (void)fclose(f);
@@ -340,12 +342,12 @@ config_read(wchar_t *fn)
void void
config_write(wchar_t *fn) config_write(wchar_t *fn)
{ {
wchar_t wname[512]; wchar_t wtemp[512];
section_t *sec; section_t *sec;
FILE *f; FILE *f;
int fl = 0; int fl = 0;
#ifdef ANSI_CFG #if defined(ANSI_CFG) || !defined(WIN32)
f = plat_fopen(fn, L"wt"); f = plat_fopen(fn, L"wt");
#else #else
f = plat_fopen(fn, L"wt, ccs=UNICODE"); f = plat_fopen(fn, L"wt, ccs=UNICODE");
@@ -357,22 +359,22 @@ config_write(wchar_t *fn)
entry_t *ent; entry_t *ent;
if (sec->name[0]) { if (sec->name[0]) {
mbstowcs(wname, sec->name, strlen(sec->name)+1); mbstowcs(wtemp, sec->name, strlen(sec->name)+1);
if (fl) if (fl)
fwprintf(f, L"\n[%ls]\n", wname); fwprintf(f, L"\n[%ls]\n", wtemp);
else else
fwprintf(f, L"[%ls]\n", wname); fwprintf(f, L"[%ls]\n", wtemp);
fl++; fl++;
} }
ent = (entry_t *)sec->entry_head.next; ent = (entry_t *)sec->entry_head.next;
while (ent != NULL) { while (ent != NULL) {
if (ent->name[0]) { if (ent->name[0] != '\0') {
mbstowcs(wname, ent->name, strlen(ent->name)+1); mbstowcs(wtemp, ent->name, sizeof_w(wtemp));
if (ent->wdata[0] == L'\0') if (ent->wdata[0] == L'\0')
fwprintf(f, L"%ls = \n", wname); fwprintf(f, L"%ls = \n", wtemp);
else else
fwprintf(f, L"%ls = %ls\n", wname, ent->wdata); fwprintf(f, L"%ls = %ls\n", wtemp, ent->wdata);
fl++; fl++;
} }
@@ -390,7 +392,7 @@ config_write(wchar_t *fn)
static void static void
config_new(void) config_new(void)
{ {
#ifdef ANSI_CFG #if defined(ANSI_CFG) || !defined(WIN32)
FILE *f = _wfopen(config_file, L"wt"); FILE *f = _wfopen(config_file, L"wt");
#else #else
FILE *f = _wfopen(config_file, L"wt, ccs=UNICODE"); FILE *f = _wfopen(config_file, L"wt, ccs=UNICODE");
@@ -418,8 +420,16 @@ load_general(void)
strcpy(temp, p); strcpy(temp, p);
if (! strcmp(temp, "ddraw")) if (! strcmp(temp, "ddraw"))
vid_api = 0; vid_api = 0;
else else if (! strcmp(temp, "d3d9"))
vid_api = 1; vid_api = 1;
else if (! strcmp(temp, "vnc"))
vid_api = 2;
#if 0
else if (! strcmp(temp, "rdp"))
vid_api = 3;
#endif
else
vid_api = 1; /* default to d3d9 on invalid values */
config_delete_var(cat, "vid_api"); config_delete_var(cat, "vid_api");
video_fullscreen_scale = config_get_int(cat, "video_fullscreen_scale", 0); video_fullscreen_scale = config_get_int(cat, "video_fullscreen_scale", 0);
@@ -455,7 +465,7 @@ load_general(void)
* (version 1.30 at the earliest) other languages will be * (version 1.30 at the earliest) other languages will be
* added, therefore it is better to future-proof the code. * added, therefore it is better to future-proof the code.
*/ */
plat_language = config_get_hex16(cat, "language", 0x0409); plat_langid = config_get_hex16(cat, "language", 0x0409);
#endif #endif
} }
@@ -750,8 +760,7 @@ static void
load_hard_disks(void) load_hard_disks(void)
{ {
char *cat = "Hard disks"; char *cat = "Hard disks";
char temp[512]; char temp[512], tmp2[512];
char temp2[512];
char s[512]; char s[512];
int c; int c;
char *p; char *p;
@@ -761,10 +770,8 @@ load_hard_disks(void)
memset(temp, '\0', sizeof(temp)); memset(temp, '\0', sizeof(temp));
for (c=0; c<HDD_NUM; c++) { for (c=0; c<HDD_NUM; c++) {
sprintf(temp, "hdd_%02i_parameters", c + 1); sprintf(temp, "hdd_%02i_parameters", c+1);
p = config_get_string(cat, temp, NULL); p = config_get_string(cat, temp, "0, 0, 0, 0, none");
if (p == NULL)
p = "0, 0, 0, 0, none";
if (tally_char(p, ',') == 3) { if (tally_char(p, ',') == 3) {
sscanf(p, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %s", sscanf(p, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %s",
&hdd[c].spt, &hdd[c].hpc, &hdd[c].tracks, s); &hdd[c].spt, &hdd[c].hpc, &hdd[c].tracks, s);
@@ -841,8 +848,8 @@ load_hard_disks(void)
sprintf(temp, "hdd_%02i_ide_channel", c+1); sprintf(temp, "hdd_%02i_ide_channel", c+1);
if ((hdd[c].bus == HDD_BUS_IDE_PIO_ONLY) || if ((hdd[c].bus == HDD_BUS_IDE_PIO_ONLY) ||
(hdd[c].bus == HDD_BUS_IDE_PIO_AND_DMA)) { (hdd[c].bus == HDD_BUS_IDE_PIO_AND_DMA)) {
sprintf(temp2, "%01u:%01u", c>>1, c&1); sprintf(tmp2, "%01u:%01u", c>>1, c&1);
p = config_get_string(cat, temp, temp2); p = config_get_string(cat, temp, tmp2);
if (! strstr(p, ":")) { if (! strstr(p, ":")) {
sscanf(p, "%i", (int *)&hdd[c].ide_channel); sscanf(p, "%i", (int *)&hdd[c].ide_channel);
hdd[c].ide_channel &= 7; hdd[c].ide_channel &= 7;
@@ -861,11 +868,11 @@ load_hard_disks(void)
} }
/* SCSI */ /* SCSI */
sprintf(temp, "hdd_%02i_scsi_location", c + 1); sprintf(temp, "hdd_%02i_scsi_location", c+1);
if ((hdd[c].bus == HDD_BUS_SCSI) || if ((hdd[c].bus == HDD_BUS_SCSI) ||
(hdd[c].bus == HDD_BUS_SCSI_REMOVABLE)) { (hdd[c].bus == HDD_BUS_SCSI_REMOVABLE)) {
sprintf(temp, "%02u:%02u", c, 0); sprintf(tmp2, "%02u:%02u", c, 0);
p = config_get_string(cat, temp, temp2); p = config_get_string(cat, temp, tmp2);
sscanf(p, "%02u:%02u", sscanf(p, "%02u:%02u",
(int *)&hdd[c].scsi_id, (int *)&hdd[c].scsi_lun); (int *)&hdd[c].scsi_id, (int *)&hdd[c].scsi_lun);
@@ -880,7 +887,7 @@ load_hard_disks(void)
memset(hdd[c].fn, 0x00, sizeof(hdd[c].fn)); memset(hdd[c].fn, 0x00, sizeof(hdd[c].fn));
memset(hdd[c].prev_fn, 0x00, sizeof(hdd[c].prev_fn)); memset(hdd[c].prev_fn, 0x00, sizeof(hdd[c].prev_fn));
sprintf(temp, "hdd_%02i_fn", c + 1); sprintf(temp, "hdd_%02i_fn", c+1);
wp = config_get_wstring(cat, temp, L""); wp = config_get_wstring(cat, temp, L"");
#if 0 #if 0
@@ -897,10 +904,10 @@ load_hard_disks(void)
* with the CFG path. Just strip * with the CFG path. Just strip
* that off for now... * that off for now...
*/ */
wcscpy((wchar_t *)hdd[c].fn, &wp[wcslen(cfg_path)]); wcsncpy(hdd[c].fn, &wp[wcslen(cfg_path)], sizeof_w(hdd[c].fn));
} else } else
#endif #endif
memcpy(hdd[c].fn, wp, (wcslen(wp) << 1) + 2); wcsncpy(hdd[c].fn, wp, sizeof_w(hdd[c].fn));
/* If disk is empty or invalid, mark it for deletion. */ /* If disk is empty or invalid, mark it for deletion. */
if (! hdd_is_valid(c)) { if (! hdd_is_valid(c)) {
@@ -934,7 +941,7 @@ static void
load_removable_devices(void) load_removable_devices(void)
{ {
char *cat = "Removable devices"; char *cat = "Removable devices";
char temp[512], temp2[512], *p; char temp[512], tmp2[512], *p;
char s[512]; char s[512];
unsigned int board = 0, dev = 0; unsigned int board = 0, dev = 0;
wchar_t *wp; wchar_t *wp;
@@ -964,10 +971,10 @@ load_removable_devices(void)
* with the EXE path. Just strip * with the EXE path. Just strip
* that off for now... * that off for now...
*/ */
wcscpy((wchar_t *)floppyfns[c], &wp[wcslen(cfg_path)]); wcsncpy(floppyfns[c], &wp[wcslen(cfg_path)], sizeof_w(floppyfns[c]));
} else } else
#endif #endif
memcpy(floppyfns[c], wp, (wcslen(wp) << 1) + 2); wcsncpy(floppyfns[c], wp, sizeof_w(floppyfns[c]));
if (*wp != L'\0') if (*wp != L'\0')
printf("Floppy%d: %ls\n", c, floppyfns[c]); printf("Floppy%d: %ls\n", c, floppyfns[c]);
@@ -978,7 +985,7 @@ load_removable_devices(void)
sprintf(temp, "fdd_%02i_check_bpb", c+1); sprintf(temp, "fdd_%02i_check_bpb", c+1);
fdd_set_check_bpb(c, !!config_get_int(cat, temp, 1)); fdd_set_check_bpb(c, !!config_get_int(cat, temp, 1));
/* Check, whether each value is default, if yes, delete it so that only non-default values will later be saved. */ /* Check whether each value is default, if yes, delete it so that only non-default values will later be saved. */
if (fdd_get_type(c) == ((c < 2) ? 2 : 0)) { if (fdd_get_type(c) == ((c < 2) ? 2 : 0)) {
sprintf(temp, "fdd_%02i_type", c+1); sprintf(temp, "fdd_%02i_type", c+1);
config_delete_var(cat, temp); config_delete_var(cat, temp);
@@ -1018,8 +1025,8 @@ load_removable_devices(void)
sprintf(temp, "cdrom_%02i_ide_channel", c+1); sprintf(temp, "cdrom_%02i_ide_channel", c+1);
if ((cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) || if ((cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_ONLY) ||
(cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_AND_DMA)) { (cdrom_drives[c].bus_type == CDROM_BUS_ATAPI_PIO_AND_DMA)) {
sprintf(temp2, "%01u:%01u", (c+2)>>1, (c+2)&1); sprintf(tmp2, "%01u:%01u", (c+2)>>1, (c+2)&1);
p = config_get_string(cat, temp, temp2); p = config_get_string(cat, temp, tmp2);
if (! strstr(p, ":")) { if (! strstr(p, ":")) {
sscanf(p, "%i", (int *)&hdd[c].ide_channel); sscanf(p, "%i", (int *)&hdd[c].ide_channel);
cdrom_drives[c].ide_channel &= 7; cdrom_drives[c].ide_channel &= 7;
@@ -1038,8 +1045,8 @@ load_removable_devices(void)
} else { } else {
sprintf(temp, "cdrom_%02i_scsi_location", c+1); sprintf(temp, "cdrom_%02i_scsi_location", c+1);
if (cdrom_drives[c].bus_type == CDROM_BUS_SCSI) { if (cdrom_drives[c].bus_type == CDROM_BUS_SCSI) {
sprintf(temp2, "%02u:%02u", c+2, 0); sprintf(tmp2, "%02u:%02u", c+2, 0);
p = config_get_string(cat, temp, temp2); p = config_get_string(cat, temp, tmp2);
sscanf(p, "%02u:%02u", sscanf(p, "%02u:%02u",
&cdrom_drives[c].scsi_device_id, &cdrom_drives[c].scsi_device_id,
&cdrom_drives[c].scsi_device_lun); &cdrom_drives[c].scsi_device_lun);
@@ -1070,10 +1077,10 @@ load_removable_devices(void)
* with the EXE path. Just strip * with the EXE path. Just strip
* that off for now... * that off for now...
*/ */
wcscpy(cdrom_image[c].image_path,&wp[wcslen(cfg_path)]); wcsncpy(cdrom_image[c].image_path, &wp[wcslen(cfg_path)], sizeof_w(cdrom_image[c].image_path));
} else } else
#endif #endif
memcpy(cdrom_image[c].image_path, wp, (wcslen(wp) << 1) + 2); wcsncpy(cdrom_image[c].image_path, wp, sizeof_w(cdrom_image[c].image_path));
wcscpy(cdrom_image[c].prev_image_path, cdrom_image[c].image_path); wcscpy(cdrom_image[c].prev_image_path, cdrom_image[c].image_path);
if (cdrom_drives[c].host_drive < 'A') if (cdrom_drives[c].host_drive < 'A')
@@ -1118,7 +1125,7 @@ config_load(wchar_t *fn)
if (! config_read(fn)) { if (! config_read(fn)) {
cpu = 0; cpu = 0;
#ifdef USE_LANGUAGE #ifdef USE_LANGUAGE
plat_language = 0x0409; plat_langid = 0x0409;
#endif #endif
scale = 1; scale = 1;
vid_api = 1; vid_api = 1;
@@ -1147,7 +1154,7 @@ config_load(wchar_t *fn)
load_hard_disks(); /* Hard disks */ load_hard_disks(); /* Hard disks */
load_removable_devices(); /* Removable devices */ load_removable_devices(); /* Removable devices */
pclog("Config loaded.\n"); pclog("Config loaded.\n\n");
} }
@@ -1173,6 +1180,16 @@ save_general(void)
default: default:
config_set_string(cat, "vid_renderer", "d3d9"); config_set_string(cat, "vid_renderer", "d3d9");
break; break;
case 2:
config_set_string(cat, "vid_renderer", "vnc");
break;
#if 0
case 3:
config_set_string(cat, "vid_renderer", "rdp");
break;
#endif
} }
if (video_fullscreen_scale == 0) if (video_fullscreen_scale == 0)
@@ -1226,10 +1243,10 @@ save_general(void)
} }
#ifdef USE_LANGUAGE #ifdef USE_LANGUAGE
if (plat_language == 0x0409) if (plat_langid == 0x0409)
config_delete_var(cat, "language"); config_delete_var(cat, "language");
else else
config_set_hex16(cat, "language", plat_language); config_set_hex16(cat, "language", plat_langid);
#endif #endif
delete_section_if_empty(cat); delete_section_if_empty(cat);
@@ -1308,7 +1325,7 @@ static void
save_input_devices(void) save_input_devices(void)
{ {
char *cat = "Input devices"; char *cat = "Input devices";
char temp[512], temp2[512]; char temp[512], tmp2[512];
int c, d; int c, d;
config_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type)); config_set_string(cat, "mouse_type", mouse_get_internal_name(mouse_type));
@@ -1320,42 +1337,42 @@ save_input_devices(void)
config_set_int(cat, "joystick_type", joystick_type); config_set_int(cat, "joystick_type", joystick_type);
for (c=0; c<16; c++) { for (c=0; c<16; c++) {
sprintf(temp2, "joystick_%i_nr", c); sprintf(tmp2, "joystick_%i_nr", c);
config_delete_var(cat, temp2); config_delete_var(cat, tmp2);
for (d=0; d<16; d++) { for (d=0; d<16; d++) {
sprintf(temp2, "joystick_%i_axis_%i", c, d); sprintf(tmp2, "joystick_%i_axis_%i", c, d);
config_delete_var(cat, temp2); config_delete_var(cat, tmp2);
} }
for (d=0; d<16; d++) { for (d=0; d<16; d++) {
sprintf(temp2, "joystick_%i_button_%i", c, d); sprintf(tmp2, "joystick_%i_button_%i", c, d);
config_delete_var(cat, temp2); config_delete_var(cat, tmp2);
} }
for (d=0; d<16; d++) { for (d=0; d<16; d++) {
sprintf(temp2, "joystick_%i_pov_%i", c, d); sprintf(tmp2, "joystick_%i_pov_%i", c, d);
config_delete_var(cat, temp2); config_delete_var(cat, tmp2);
} }
} }
} else { } else {
config_set_int(cat, "joystick_type", joystick_type); config_set_int(cat, "joystick_type", joystick_type);
for (c=0; c<joystick_get_max_joysticks(joystick_type); c++) { for (c=0; c<joystick_get_max_joysticks(joystick_type); c++) {
sprintf(temp2, "joystick_%i_nr", c); sprintf(tmp2, "joystick_%i_nr", c);
config_set_int(cat, temp2, joystick_state[c].plat_joystick_nr); config_set_int(cat, tmp2, joystick_state[c].plat_joystick_nr);
if (joystick_state[c].plat_joystick_nr) { if (joystick_state[c].plat_joystick_nr) {
for (d=0; d<joystick_get_axis_count(joystick_type); d++) { for (d=0; d<joystick_get_axis_count(joystick_type); d++) {
sprintf(temp2, "joystick_%i_axis_%i", c, d); sprintf(tmp2, "joystick_%i_axis_%i", c, d);
config_set_int(cat, temp2, joystick_state[c].axis_mapping[d]); config_set_int(cat, tmp2, joystick_state[c].axis_mapping[d]);
} }
for (d=0; d<joystick_get_button_count(joystick_type); d++) { for (d=0; d<joystick_get_button_count(joystick_type); d++) {
sprintf(temp2, "joystick_%i_button_%i", c, d); sprintf(tmp2, "joystick_%i_button_%i", c, d);
config_set_int(cat, temp2, joystick_state[c].button_mapping[d]); config_set_int(cat, tmp2, joystick_state[c].button_mapping[d]);
} }
for (d=0; d<joystick_get_pov_count(joystick_type); d++) { for (d=0; d<joystick_get_pov_count(joystick_type); d++) {
sprintf(temp2, "joystick_%i_pov_%i", c, d); sprintf(tmp2, "joystick_%i_pov_%i", c, d);
sprintf(temp, "%i, %i", joystick_state[c].pov_mapping[d][0], joystick_state[c].pov_mapping[d][1]); sprintf(temp, "%i, %i", joystick_state[c].pov_mapping[d][0], joystick_state[c].pov_mapping[d][1]);
config_set_string(cat, temp2, temp); config_set_string(cat, tmp2, temp);
} }
} }
} }
@@ -1482,7 +1499,7 @@ static void
save_other_peripherals(void) save_other_peripherals(void)
{ {
char *cat = "Other peripherals"; char *cat = "Other peripherals";
char temp[512], temp2[512]; char temp[512], tmp2[512];
int c; int c;
if (scsi_card_current == 0) if (scsi_card_current == 0)
@@ -1496,11 +1513,11 @@ save_other_peripherals(void)
memset(temp, '\0', sizeof(temp)); memset(temp, '\0', sizeof(temp));
for (c=2; c<4; c++) { for (c=2; c<4; c++) {
sprintf(temp, "ide_%02i", c + 1); sprintf(temp, "ide_%02i", c + 1);
sprintf(temp2, "%i, %02i", !!ide_enable[c], ide_irq[c]); sprintf(tmp2, "%i, %02i", !!ide_enable[c], ide_irq[c]);
if (ide_enable[c] == 0) if (ide_enable[c] == 0)
config_delete_var(cat, temp); config_delete_var(cat, temp);
else else
config_set_string(cat, temp, temp2); config_set_string(cat, temp, tmp2);
} }
if (bugger_enabled == 0) if (bugger_enabled == 0)
@@ -1517,7 +1534,7 @@ static void
save_hard_disks(void) save_hard_disks(void)
{ {
char *cat = "Hard disks"; char *cat = "Hard disks";
char temp[24], temp2[64]; char temp[24], tmp2[64];
char *p; char *p;
int c; int c;
@@ -1526,9 +1543,9 @@ save_hard_disks(void)
sprintf(temp, "hdd_%02i_parameters", c+1); sprintf(temp, "hdd_%02i_parameters", c+1);
if (hdd_is_valid(c)) { if (hdd_is_valid(c)) {
p = hdd_bus_to_string(hdd[c].bus, 0); p = hdd_bus_to_string(hdd[c].bus, 0);
sprintf(temp2, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %i, %s", sprintf(tmp2, "%" PRIu64 ", %" PRIu64", %" PRIu64 ", %i, %s",
hdd[c].spt, hdd[c].hpc, hdd[c].tracks, hdd[c].wp, p); hdd[c].spt, hdd[c].hpc, hdd[c].tracks, hdd[c].wp, p);
config_set_string(cat, temp, temp2); config_set_string(cat, temp, tmp2);
} else { } else {
config_delete_var(cat, temp); config_delete_var(cat, temp);
} }
@@ -1555,16 +1572,16 @@ save_hard_disks(void)
if (! hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_IDE_PIO_ONLY) && (hdd[c].bus != HDD_BUS_IDE_PIO_AND_DMA))) { if (! hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_IDE_PIO_ONLY) && (hdd[c].bus != HDD_BUS_IDE_PIO_AND_DMA))) {
config_delete_var(cat, temp); config_delete_var(cat, temp);
} else { } else {
sprintf(temp2, "%01u:%01u", hdd[c].ide_channel >> 1, hdd[c].ide_channel & 1); sprintf(tmp2, "%01u:%01u", hdd[c].ide_channel >> 1, hdd[c].ide_channel & 1);
config_set_string(cat, temp, temp2); config_set_string(cat, temp, tmp2);
} }
sprintf(temp, "hdd_%02i_scsi_location", c+1); sprintf(temp, "hdd_%02i_scsi_location", c+1);
if (! hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_SCSI) && (hdd[c].bus != HDD_BUS_SCSI_REMOVABLE))) { if (! hdd_is_valid(c) || ((hdd[c].bus != HDD_BUS_SCSI) && (hdd[c].bus != HDD_BUS_SCSI_REMOVABLE))) {
config_delete_var(cat, temp); config_delete_var(cat, temp);
} else { } else {
sprintf(temp2, "%02u:%02u", hdd[c].scsi_id, hdd[c].scsi_lun); sprintf(tmp2, "%02u:%02u", hdd[c].scsi_id, hdd[c].scsi_lun);
config_set_string(cat, temp, temp2); config_set_string(cat, temp, tmp2);
} }
sprintf(temp, "hdd_%02i_fn", c+1); sprintf(temp, "hdd_%02i_fn", c+1);
@@ -1583,7 +1600,7 @@ static void
save_removable_devices(void) save_removable_devices(void)
{ {
char *cat = "Removable devices"; char *cat = "Removable devices";
char temp[512], temp2[512]; char temp[512], tmp2[512];
int c; int c;
for (c=0; c<FDD_NUM; c++) { for (c=0; c<FDD_NUM; c++) {
@@ -1638,9 +1655,9 @@ save_removable_devices(void)
if (cdrom_drives[c].bus_type == 0) { if (cdrom_drives[c].bus_type == 0) {
config_delete_var(cat, temp); config_delete_var(cat, temp);
} else { } else {
sprintf(temp2, "%u, %s", cdrom_drives[c].sound_on, sprintf(tmp2, "%u, %s", cdrom_drives[c].sound_on,
hdd_bus_to_string(cdrom_drives[c].bus_type, 1)); hdd_bus_to_string(cdrom_drives[c].bus_type, 1));
config_set_string(cat, temp, temp2); config_set_string(cat, temp, tmp2);
} }
sprintf(temp, "cdrom_%02i_ide_channel", c+1); sprintf(temp, "cdrom_%02i_ide_channel", c+1);
@@ -1648,18 +1665,18 @@ save_removable_devices(void)
(cdrom_drives[c].bus_type != CDROM_BUS_ATAPI_PIO_AND_DMA)) { (cdrom_drives[c].bus_type != CDROM_BUS_ATAPI_PIO_AND_DMA)) {
config_delete_var(cat, temp); config_delete_var(cat, temp);
} else { } else {
sprintf(temp2, "%01u:%01u", cdrom_drives[c].ide_channel>>1, sprintf(tmp2, "%01u:%01u", cdrom_drives[c].ide_channel>>1,
cdrom_drives[c].ide_channel & 1); cdrom_drives[c].ide_channel & 1);
config_set_string(cat, temp, temp2); config_set_string(cat, temp, tmp2);
} }
sprintf(temp, "cdrom_%02i_scsi_location", c + 1); sprintf(temp, "cdrom_%02i_scsi_location", c + 1);
if (cdrom_drives[c].bus_type != CDROM_BUS_SCSI) { if (cdrom_drives[c].bus_type != CDROM_BUS_SCSI) {
config_delete_var(cat, temp); config_delete_var(cat, temp);
} else { } else {
sprintf(temp2, "%02u:%02u", cdrom_drives[c].scsi_device_id, sprintf(tmp2, "%02u:%02u", cdrom_drives[c].scsi_device_id,
cdrom_drives[c].scsi_device_lun); cdrom_drives[c].scsi_device_lun);
config_set_string(cat, temp, temp2); config_set_string(cat, temp, tmp2);
} }
sprintf(temp, "cdrom_%02i_image_path", c + 1); sprintf(temp, "cdrom_%02i_image_path", c + 1);
@@ -1707,7 +1724,7 @@ config_dump(void)
ent = (entry_t *)sec->entry_head.next; ent = (entry_t *)sec->entry_head.next;
while (ent != NULL) { while (ent != NULL) {
pclog("%s = %s\n", ent->name, ent->data); pclog("%s = %ls\n", ent->name, ent->wdata);
ent = (entry_t *)ent->list.next; ent = (entry_t *)ent->list.next;
} }
@@ -1858,18 +1875,18 @@ void
config_set_int(char *head, char *name, int val) config_set_int(char *head, char *name, int val)
{ {
section_t *section; section_t *section;
entry_t *entry; entry_t *ent;
section = find_section(head); section = find_section(head);
if (section == NULL) if (section == NULL)
section = create_section(head); section = create_section(head);
entry = find_entry(section, name); ent = find_entry(section, name);
if (entry == NULL) if (ent == NULL)
entry = create_entry(section, name); ent = create_entry(section, name);
sprintf(entry->data, "%i", val); sprintf(ent->data, "%i", val);
mbstowcs(entry->wdata, entry->data, 512); mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata));
} }
@@ -1877,18 +1894,18 @@ void
config_set_hex16(char *head, char *name, int val) config_set_hex16(char *head, char *name, int val)
{ {
section_t *section; section_t *section;
entry_t *entry; entry_t *ent;
section = find_section(head); section = find_section(head);
if (section == NULL) if (section == NULL)
section = create_section(head); section = create_section(head);
entry = find_entry(section, name); ent = find_entry(section, name);
if (entry == NULL) if (ent == NULL)
entry = create_entry(section, name); ent = create_entry(section, name);
sprintf(entry->data, "%04X", val); sprintf(ent->data, "%04X", val);
mbstowcs(entry->wdata, entry->data, 512); mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata));
} }
@@ -1896,18 +1913,18 @@ void
config_set_hex20(char *head, char *name, int val) config_set_hex20(char *head, char *name, int val)
{ {
section_t *section; section_t *section;
entry_t *entry; entry_t *ent;
section = find_section(head); section = find_section(head);
if (section == NULL) if (section == NULL)
section = create_section(head); section = create_section(head);
entry = find_entry(section, name); ent = find_entry(section, name);
if (entry == NULL) if (ent == NULL)
entry = create_entry(section, name); ent = create_entry(section, name);
sprintf(entry->data, "%05X", val); sprintf(ent->data, "%05X", val);
mbstowcs(entry->wdata, entry->data, 512); mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata));
} }
@@ -1915,19 +1932,19 @@ void
config_set_mac(char *head, char *name, int val) config_set_mac(char *head, char *name, int val)
{ {
section_t *section; section_t *section;
entry_t *entry; entry_t *ent;
section = find_section(head); section = find_section(head);
if (section == NULL) if (section == NULL)
section = create_section(head); section = create_section(head);
entry = find_entry(section, name); ent = find_entry(section, name);
if (entry == NULL) if (ent == NULL)
entry = create_entry(section, name); ent = create_entry(section, name);
sprintf(entry->data, "%02x:%02x:%02x", sprintf(ent->data, "%02x:%02x:%02x",
(val>>16)&0xff, (val>>8)&0xff, val&0xff); (val>>16)&0xff, (val>>8)&0xff, val&0xff);
mbstowcs(entry->wdata, entry->data, 512); mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata));
} }
@@ -1935,18 +1952,18 @@ void
config_set_string(char *head, char *name, char *val) config_set_string(char *head, char *name, char *val)
{ {
section_t *section; section_t *section;
entry_t *entry; entry_t *ent;
section = find_section(head); section = find_section(head);
if (section == NULL) if (section == NULL)
section = create_section(head); section = create_section(head);
entry = find_entry(section, name); ent = find_entry(section, name);
if (entry == NULL) if (ent == NULL)
entry = create_entry(section, name); ent = create_entry(section, name);
strncpy(entry->data, val, 256); strncpy(ent->data, val, sizeof(ent->data));
mbstowcs(entry->wdata, entry->data, 256); mbstowcs(ent->wdata, ent->data, sizeof_w(ent->wdata));
} }
@@ -1954,18 +1971,18 @@ void
config_set_wstring(char *head, char *name, wchar_t *val) config_set_wstring(char *head, char *name, wchar_t *val)
{ {
section_t *section; section_t *section;
entry_t *entry; entry_t *ent;
section = find_section(head); section = find_section(head);
if (section == NULL) if (section == NULL)
section = create_section(head); section = create_section(head);
entry = find_entry(section, name); ent = find_entry(section, name);
if (entry == NULL) if (ent == NULL)
entry = create_entry(section, name); ent = create_entry(section, name);
memcpy(entry->wdata, val, 512); memcpy(ent->wdata, val, sizeof_w(ent->wdata));
wcstombs(entry->data, entry->wdata, 256); wcstombs(ent->data, ent->wdata, sizeof(ent->data));
} }
@@ -2046,6 +2063,7 @@ put_backslash_w(wchar_t *s)
} }
#if 0
/* FIXME: should be moved elsewhere. --FvK */ /* FIXME: should be moved elsewhere. --FvK */
char * char *
get_extension(char *s) get_extension(char *s)
@@ -2063,6 +2081,7 @@ get_extension(char *s)
return(&s[c+1]); return(&s[c+1]);
} }
#endif
/* FIXME: should be moved elsewhere. --FvK */ /* FIXME: should be moved elsewhere. --FvK */

View File

@@ -8,7 +8,7 @@
* *
* Handling of hard disk image files. * Handling of hard disk image files.
* *
* Version: @(#)hdd_image.c 1.0.4 2017/11/12 * Version: @(#)hdd_image.c 1.0.5 2017/11/13
* *
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/> * Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>

View File

@@ -8,7 +8,7 @@
* *
* Define the various platform support functions. * Define the various platform support functions.
* *
* Version: @(#)plat.h 1.0.5 2017/10/12 * Version: @(#)plat.h 1.0.6 2017/10/13
* *
* Authors: Miran Grca, <mgrca8@gmail.com> * Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com> * Fred N. van Kempen, <decwiz@yahoo.com>
@@ -38,6 +38,10 @@ extern int dir_check_exist(wchar_t *path);
extern int dir_create(wchar_t *path); extern int dir_create(wchar_t *path);
extern void leave_fullscreen(void); extern void leave_fullscreen(void);
/* Return the size (in wchar's) of a wchar_t array. */
#define sizeof_w(x) (sizeof((x)) / sizeof(wchar_t))
/* The Win32 API uses _wcsicmp. */
#ifdef WIN32 #ifdef WIN32
# define wcscasecmp _wcsicmp # define wcscasecmp _wcsicmp
#endif #endif