PCem

changeset 151:55564c65aa15

Added configuration load/save options.
author TomW
date Sat Aug 23 21:32:36 2014 +0100
parents 871b132c6158
children f6069ee5e9d7
files src/config.c src/config.h src/ibm.h src/pc.c src/pc.rc src/resources.h src/win.c
diffstat 7 files changed, 54 insertions(+), 13 deletions(-) [+]
line diff
     1.1 --- a/src/config.c	Sat Aug 23 16:28:16 2014 +0100
     1.2 +++ b/src/config.c	Sat Aug 23 21:32:36 2014 +0100
     1.3 @@ -3,6 +3,8 @@
     1.4  #include <stdlib.h>
     1.5  #include "config.h"
     1.6  
     1.7 +char config_file_default[256];
     1.8 +
     1.9  static char config_file[256];
    1.10  
    1.11  typedef struct list_t
    1.12 @@ -92,9 +94,9 @@
    1.13          }
    1.14  }
    1.15  
    1.16 -void config_load()
    1.17 +void config_load(char *fn)
    1.18  {
    1.19 -        FILE *f = fopen(config_file, "rt");
    1.20 +        FILE *f = fopen(fn, "rt");
    1.21          section_t *current_section;
    1.22          
    1.23          memset(&config_head, 0, sizeof(list_t));
    1.24 @@ -357,9 +359,9 @@
    1.25             s[c] = '/';
    1.26  }
    1.27  
    1.28 -void config_save()
    1.29 +void config_save(char *fn)
    1.30  {
    1.31 -        FILE *f = fopen(config_file, "wt");
    1.32 +        FILE *f = fopen(fn, "wt");
    1.33          section_t *current_section;
    1.34          
    1.35          current_section = (section_t *)config_head.next;
     2.1 --- a/src/config.h	Sat Aug 23 16:28:16 2014 +0100
     2.2 +++ b/src/config.h	Sat Aug 23 21:32:36 2014 +0100
     2.3 @@ -8,7 +8,9 @@
     2.4  void append_filename(char *dest, char *s1, char *s2, int size);
     2.5  void put_backslash(char *s);
     2.6  
     2.7 -void config_load();
     2.8 -void config_save();
     2.9 +void config_load(char *fn);
    2.10 +void config_save(char *fn);
    2.11  void config_dump();
    2.12  void config_free();
    2.13 +
    2.14 +extern char config_file_default[256];
     3.1 --- a/src/ibm.h	Sat Aug 23 16:28:16 2014 +0100
     3.2 +++ b/src/ibm.h	Sat Aug 23 21:32:36 2014 +0100
     3.3 @@ -470,3 +470,6 @@
     3.4  
     3.5  uint64_t timer_read();
     3.6  extern uint64_t timer_freq;
     3.7 +
     3.8 +
     3.9 +void loadconfig(char *fn);
     4.1 --- a/src/pc.c	Sat Aug 23 16:28:16 2014 +0100
     4.2 +++ b/src/pc.c	Sat Aug 23 21:32:36 2014 +0100
     4.3 @@ -52,7 +52,7 @@
     4.4  
     4.5  int output;
     4.6  int atfullspeed;
     4.7 -void loadconfig();
     4.8 +
     4.9  void saveconfig();
    4.10  int infocus;
    4.11  int mousecapture;
    4.12 @@ -198,7 +198,7 @@
    4.13          mouse_init();
    4.14          joystick_init();
    4.15          
    4.16 -        loadconfig();
    4.17 +        loadconfig(NULL);
    4.18          pclog("Config loaded\n");
    4.19          
    4.20          cpuspeed2=(AT)?2:1;
    4.21 @@ -424,14 +424,19 @@
    4.22  
    4.23  int cga_comp=0;
    4.24  
    4.25 -void loadconfig()
    4.26 +void loadconfig(char *fn)
    4.27  {
    4.28          char s[512];
    4.29          char *p;
    4.30 -        append_filename(s, pcempath, "pcem.cfg", 511);
    4.31 -        set_config_file(s);
    4.32          
    4.33 -        config_load();
    4.34 +        if (!fn)
    4.35 +        {
    4.36 +                append_filename(config_file_default, pcempath, "pcem.cfg", 511);
    4.37 +        
    4.38 +                config_load(config_file_default);
    4.39 +        }
    4.40 +        else
    4.41 +                config_load(fn);
    4.42          
    4.43          GAMEBLASTER = get_config_int(NULL, "gameblaster", 0);
    4.44          GUS = get_config_int(NULL, "gus", 0);
    4.45 @@ -522,5 +527,5 @@
    4.46          set_config_int(NULL, "hdd_cylinders", hdc[1].tracks);
    4.47          set_config_string(NULL, "hdd_fn", ide_fn[1]);
    4.48          
    4.49 -        config_save();
    4.50 +        config_save(config_file_default);
    4.51  }
     5.1 --- a/src/pc.rc	Sat Aug 23 16:28:16 2014 +0100
     5.2 +++ b/src/pc.rc	Sat Aug 23 21:32:36 2014 +0100
     5.3 @@ -40,6 +40,9 @@
     5.4                                  MENUITEM "&Integer scale", IDM_VID_FS_INT
     5.5                          END
     5.6                  END
     5.7 +                MENUITEM SEPARATOR
     5.8 +                MENUITEM "&Load configuration...", IDM_CONFIG_LOAD
     5.9 +                MENUITEM "&Save configuration...", IDM_CONFIG_SAVE
    5.10          END
    5.11          POPUP "&Misc"
    5.12          BEGIN
     6.1 --- a/src/resources.h	Sat Aug 23 16:28:16 2014 +0100
     6.2 +++ b/src/resources.h	Sat Aug 23 21:32:36 2014 +0100
     6.3 @@ -7,6 +7,8 @@
     6.4  #define IDM_EJECT_B        40013
     6.5  #define IDM_HDCONF         40014
     6.6  #define IDM_CONFIG         40020
     6.7 +#define IDM_CONFIG_LOAD    40021
     6.8 +#define IDM_CONFIG_SAVE    40022
     6.9  #define IDM_STATUS         40030
    6.10  #define IDM_VID_RESIZE     40050
    6.11  #define IDM_VID_DDRAW      40060
     7.1 --- a/src/win.c	Sat Aug 23 16:28:16 2014 +0100
     7.2 +++ b/src/win.c	Sat Aug 23 21:32:36 2014 +0100
     7.3 @@ -14,6 +14,7 @@
     7.4  #include <stdarg.h>
     7.5  #include <stdlib.h>
     7.6  #include "ibm.h"
     7.7 +#include "config.h"
     7.8  #include "video.h"
     7.9  #include "resources.h"
    7.10  #include "cpu.h"
    7.11 @@ -840,6 +841,29 @@
    7.12                          CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED);
    7.13                          saveconfig();
    7.14                          break;
    7.15 +
    7.16 +                        case IDM_CONFIG_LOAD:
    7.17 +                        pause = 1;
    7.18 +                        if (!getfile(hwnd, "Configuration (*.CFG)\0*.CFG\0All files (*.*)\0*.*\0", ""))
    7.19 +                        {
    7.20 +                                if (MessageBox(NULL, "This will reset PCem!\nOkay to continue?", "PCem", MB_OKCANCEL) == IDOK)
    7.21 +                                {
    7.22 +                                        loadconfig(openfilestring);
    7.23 +                                        config_save(config_file_default);
    7.24 +                                        mem_resize();
    7.25 +                                        loadbios();
    7.26 +                                        resetpchard();
    7.27 +                                }
    7.28 +                        }
    7.29 +                        pause = 0;
    7.30 +                        break;                        
    7.31 +                        
    7.32 +                        case IDM_CONFIG_SAVE:
    7.33 +                        pause = 1;
    7.34 +                        if (!getsfile(hwnd, "Configuration (*.CFG)\0*.CFG\0All files (*.*)\0*.*\0", ""))
    7.35 +                                config_save(openfilestring);
    7.36 +                        pause = 0;
    7.37 +                        break;
    7.38                          
    7.39                          case IDM_CDROM_DISABLED:
    7.40                          if (cdrom_enabled)