Diff for /np2/x11/main.c between versions 1.7 and 1.36

version 1.7, 2003/11/27 17:24:20 version 1.36, 2011/01/15 18:43:13
Line 10 Line 10
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. The name of the author may not be used to endorse or promote products  
  *    derived from this software without specific prior written permission.  
  *   *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Line 27 Line 25
   
 #include "compiler.h"  #include "compiler.h"
   
   #include <sys/stat.h>
 #include <getopt.h>  #include <getopt.h>
   #include <locale.h>
 #include <signal.h>  #include <signal.h>
   
   #if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER)
   #include <SDL.h>
   #endif
   
 #include "np2.h"  #include "np2.h"
 #include "diskdrv.h"  #include "diskdrv.h"
 #include "dosio.h"  #include "dosio.h"
Line 42 Line 46
 #include "timing.h"  #include "timing.h"
 #include "toolkit.h"  #include "toolkit.h"
   
 #include "keydisp.h"  #include "kdispwin.h"
 #include "toolwin.h"  #include "toolwin.h"
   #include "viewer.h"
   #include "debugwin.h"
   #include "skbdwin.h"
   
 #include "commng.h"  #include "commng.h"
   #include "fontmng.h"
 #include "joymng.h"  #include "joymng.h"
 #include "kbdmng.h"  #include "kbdmng.h"
 #include "mousemng.h"  #include "mousemng.h"
 #include "scrnmng.h"  #include "scrnmng.h"
 #include "soundmng.h"  #include "soundmng.h"
 #include "sysmng.h"  #include "sysmng.h"
   #include "taskmng.h"
   
 /*  
  * resume  
  */  
 static const char np2resumeext[] = "sav";  
   
   
 /*  /*
Line 82  static void Line 85  static void
 sighandler(int signo)  sighandler(int signo)
 {  {
   
         UNUSED(signo);  
   
         toolkit_widget_quit();          toolkit_widget_quit();
 }  }
   
Line 94  sighandler(int signo) Line 95  sighandler(int signo)
 static struct option longopts[] = {  static struct option longopts[] = {
         { "config",             required_argument,      0,      'c' },          { "config",             required_argument,      0,      'c' },
         { "timidity-config",    required_argument,      0,      'C' },          { "timidity-config",    required_argument,      0,      'C' },
         { "shared-pixmap",      no_argument,            0,      'p' },  
         { "help",               no_argument,            0,      'h' },          { "help",               no_argument,            0,      'h' },
         { 0,                    0,                      0,      0   },          { 0,                    0,                      0,      0   },
 };  };
Line 105  static void Line 105  static void
 usage(void)  usage(void)
 {  {
   
         printf("Usage: %s [options] [[FD1 image] [[FD2 image] [[FD3 image] [FD4 image]]]]\n", progname);          g_printerr("Usage: %s [options] [[FD1 image] [[FD2 image] [[FD3 image] [FD4 image]]]]\n\n", progname);
           g_printerr("options:\n");
           g_printerr("\t--help            [-h]        : print this message\n");
           g_printerr("\t--config          [-c] <file> : specify config file\n");
           g_printerr("\t--timidity-config [-C] <file> : specify timidity config file\n");
         exit(1);          exit(1);
 }  }
   
Line 121  main(int argc, char *argv[]) Line 125  main(int argc, char *argv[])
         int rv = 1;          int rv = 1;
         int ch;          int ch;
         int i, drvmax;          int i, drvmax;
         BOOL shared_pixmap_flag = FALSE;  
   
         progname = argv[0];          progname = argv[0];
   
           setlocale(LC_ALL, "");
           bindtextdomain(np2appname, NP2LOCALEDIR);
           bind_textdomain_codeset(np2appname, "UTF-8");
           textdomain(np2appname);
   
         toolkit_initialize();          toolkit_initialize();
         toolkit_arginit(&argc, &argv);          toolkit_arginit(&argc, &argv);
   
         while ((ch = getopt_long(argc, argv, "c:C:nh", longopts, NULL)) != -1) {          while ((ch = getopt_long(argc, argv, "c:C:t:vh", longopts, NULL)) != -1) {
                 switch (ch) {                  switch (ch) {
                 case 'c':                  case 'c':
                         if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) {                          if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) {
                                 fprintf(stderr, "Can't access %s.\n", optarg);                                  g_printerr("Can't access %s.\n", optarg);
                                 exit(1);                                  exit(1);
                         }                          }
                         milstr_ncpy(modulefile, optarg, sizeof(modulefile));                          milstr_ncpy(modulefile, optarg, sizeof(modulefile));
   
                         /* resume/statsave dir */  
                         file_cpyname(statpath, modulefile, sizeof(statpath));  
                         file_cutname(statpath);  
                         break;                          break;
   
                 case 'C':                  case 'C':
                         if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) {                          if (stat(optarg, &sb) < 0 || !S_ISREG(sb.st_mode)) {
                                 fprintf(stderr, "Can't access %s.\n", optarg);                                  g_printerr("Can't access %s.\n", optarg);
                                 exit(1);                                  exit(1);
                         }                          }
                         milstr_ncpy(timidity_cfgfile_path, optarg,                          milstr_ncpy(timidity_cfgfile_path, optarg,
                             sizeof(timidity_cfgfile_path));                              sizeof(timidity_cfgfile_path));
                         break;                          break;
   
                 case 'p':                  case 'v':
                         shared_pixmap_flag = TRUE;                          verbose = 1;
                         break;                          break;
   
                 case 'h':                  case 'h':
Line 169  main(int argc, char *argv[]) Line 173  main(int argc, char *argv[])
                 char *env = getenv("HOME");                  char *env = getenv("HOME");
                 if (env) {                  if (env) {
                         /* base dir */                          /* base dir */
                         snprintf(modulefile, sizeof(modulefile),                          g_snprintf(modulefile, sizeof(modulefile),
                             "%s/.np2", env);                              "%s/.%s", env, np2appname);
                         if (stat(modulefile, &sb) < 0) {                          if (stat(modulefile, &sb) < 0) {
                                 if (mkdir(modulefile, 0700) < 0) {                                  if (mkdir(modulefile, 0700) < 0) {
                                         perror(modulefile);                                          perror(modulefile);
                                         exit(1);                                          exit(1);
                                 }                                  }
                         } else if (!S_ISDIR(sb.st_mode)) {                          } else if (!S_ISDIR(sb.st_mode)) {
                                 fprintf(stderr, "%s isn't directory.\n",                                  g_printerr("%s isn't directory.\n",
                                     modulefile);                                      modulefile);
                                 exit(1);                                  exit(1);
                         }                          }
   
                         /* font file */  
                         snprintf(np2cfg.fontfile, sizeof(np2cfg.fontfile),  
                             "%s/font.bmp", modulefile);  
   
                         /* resume/statsave dir */  
                         file_cpyname(statpath, modulefile, sizeof(statpath));  
                         file_catname(statpath, "/sav/", sizeof(statpath));  
                         if (stat(statpath, &sb) < 0) {  
                                 if (mkdir(statpath, 0700) < 0) {  
                                         perror(statpath);  
                                         exit(1);  
                                 }  
                         } else if (!S_ISDIR(sb.st_mode)) {  
                                 fprintf(stderr, "%s isn't directory.\n",  
                                     statpath);  
                                 exit(1);  
                         }  
   
                         /* config file */                          /* config file */
                         milstr_ncat(modulefile, "/np2rc", sizeof(modulefile));                          milstr_ncat(modulefile, "/np2rc", sizeof(modulefile));
                         if ((stat(modulefile, &sb) >= 0)                          if ((stat(modulefile, &sb) >= 0)
                          && !S_ISREG(sb.st_mode)) {                           && !S_ISREG(sb.st_mode)) {
                                 fprintf(stderr, "%s isn't regular file.\n",                                  g_printerr("%s isn't regular file.\n",
                                     modulefile);                                      modulefile);
                         }                          }
                 }                  }
         }          }
           if (modulefile[0] != '\0') {
                   /* font file */
                   file_cpyname(np2cfg.fontfile, modulefile,
                       sizeof(np2cfg.fontfile));
                   file_cutname(np2cfg.fontfile);
                   file_setseparator(np2cfg.fontfile, sizeof(np2cfg.fontfile));
                   file_catname(np2cfg.fontfile, "font.bmp",
                       sizeof(np2cfg.fontfile));
   
                   /* resume/statsave dir */
                   file_cpyname(statpath, modulefile, sizeof(statpath));
                   file_cutname(statpath);
                   file_catname(statpath, "/sav/", sizeof(statpath));
                   if (stat(statpath, &sb) < 0) {
                           if (mkdir(statpath, 0700) < 0) {
                                   perror(statpath);
                                   exit(1);
                           }
                   } else if (!S_ISDIR(sb.st_mode)) {
                           g_printerr("%s isn't directory.\n",
                               statpath);
                           exit(1);
                   }
                   file_catname(statpath, np2appname, sizeof(statpath));
           }
         if (timidity_cfgfile_path[0] == '\0') {          if (timidity_cfgfile_path[0] == '\0') {
                 file_cpyname(timidity_cfgfile_path, modulefile,                  file_cpyname(timidity_cfgfile_path, modulefile,
                     sizeof(timidity_cfgfile_path));                      sizeof(timidity_cfgfile_path));
Line 221  main(int argc, char *argv[]) Line 232  main(int argc, char *argv[])
         file_setcd(modulefile);          file_setcd(modulefile);
         initload();          initload();
         toolwin_readini();          toolwin_readini();
         keydisp_readini();          kdispwin_readini();
           skbdwin_readini();
   
         rand_setseed((SINT32)time(NULL));          rand_setseed((SINT32)time(NULL));
   
 #if defined(__GNUC__) && (defined(i386) || defined(__i386__))  
         mmxflag = havemmx() ? 0 : MMXFLAG_NOTSUPPORT;          mmxflag = havemmx() ? 0 : MMXFLAG_NOTSUPPORT;
         mmxflag += np2oscfg.disablemmx ? MMXFLAG_DISABLE : 0;          mmxflag += np2oscfg.disablemmx ? MMXFLAG_DISABLE : 0;
 #endif  
   
         use_shared_pixmap = np2oscfg.shared_pixmap && shared_pixmap_flag;  
   
         TRACEINIT();          TRACEINIT();
   
         keystat_reset();  #if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER)
           SDL_Init(0);
   #endif
   
           if (fontmng_init() != SUCCESS)
                   goto fontmng_failure;
   
           kdispwin_initialize();
           viewer_init();
           skbdwin_initialize();
   
         toolkit_widget_create();          toolkit_widget_create();
         scrnmng_initialize();          scrnmng_initialize();
         kbdmng_init();          kbdmng_init();
           keystat_initialize();
   
         scrnmode = 0;          scrnmode = 0;
         if (np2cfg.RASTER) {          if (np2cfg.RASTER) {
                 scrnmode |= SCRNMODE_HIGHCOLOR;                  scrnmode |= SCRNMODE_HIGHCOLOR;
         }          }
         if (scrnmng_create(scrnmode) != SUCCESS)          if (scrnmng_create(scrnmode) != SUCCESS)
                 goto resource_cleanup;                  goto scrnmng_failure;
   
         if (soundmng_initialize() == SUCCESS) {          if (soundmng_initialize() == SUCCESS) {
                 result = soundmng_pcmload(SOUND_PCMSEEK, file_getcd("fddseek.wav"));                  result = soundmng_pcmload(SOUND_PCMSEEK, file_getcd("fddseek.wav"));
                 if (!result) {                  if (!result) {
                         result = soundmng_pcmload(SOUND_PCMSEEK, SYSRESPATH "/wav/fddseek.wav");                          result = soundmng_pcmload(SOUND_PCMSEEK, SYSRESPATH "/fddseek.wav");
                 }                  }
                 if (result) {                  if (result) {
                         soundmng_pcmvolume(SOUND_PCMSEEK, np2cfg.MOTORVOL);                          soundmng_pcmvolume(SOUND_PCMSEEK, np2cfg.MOTORVOL);
Line 258  main(int argc, char *argv[]) Line 276  main(int argc, char *argv[])
   
                 result = soundmng_pcmload(SOUND_PCMSEEK1, file_getcd("fddseek1.wav"));                  result = soundmng_pcmload(SOUND_PCMSEEK1, file_getcd("fddseek1.wav"));
                 if (!result) {                  if (!result) {
                         result = soundmng_pcmload(SOUND_PCMSEEK1, SYSRESPATH "/wav/fddseek1.wav");                          result = soundmng_pcmload(SOUND_PCMSEEK1, SYSRESPATH "/fddseek1.wav");
                 }                  }
                 if (result) {                  if (result) {
                         soundmng_pcmvolume(SOUND_PCMSEEK1, np2cfg.MOTORVOL);                          soundmng_pcmvolume(SOUND_PCMSEEK1, np2cfg.MOTORVOL);
                 }                  }
         }          }
   
           joymng_initialize();
         mousemng_initialize();          mousemng_initialize();
         if (np2oscfg.MOUSE_SW) {          if (np2oscfg.MOUSE_SW) {
                 mouse_running(MOUSE_ON);                  mouse_running(MOUSE_ON);
Line 272  main(int argc, char *argv[]) Line 291  main(int argc, char *argv[])
   
         commng_initialize();          commng_initialize();
         sysmng_initialize();          sysmng_initialize();
           taskmng_initialize();
   
         joy_init();  
         pccore_init();          pccore_init();
         S98_init();          S98_init();
   
Line 287  main(int argc, char *argv[]) Line 306  main(int argc, char *argv[])
                         toolwin_create();                          toolwin_create();
                 }                  }
                 if (np2oscfg.keydisp) {                  if (np2oscfg.keydisp) {
                         keydisp_create();                          kdispwin_create();
                   }
                   if (np2oscfg.softkbd) {
                           skbdwin_create();
                 }                  }
         }          }
   
   #if defined(SUPPORT_RESUME)
         if (np2oscfg.resume) {          if (np2oscfg.resume) {
                 flagload(np2resumeext, "Resume", FALSE);                  flagload(np2resumeext, "Resume", FALSE);
         }          }
   #endif
         sysmng_workclockreset();          sysmng_workclockreset();
   
         drvmax = (argc < 4) ? argc : 4;          drvmax = (argc < 4) ? argc : 4;
         for (i = 0; i < drvmax; i++) {          for (i = 0; i < drvmax; i++) {
                 milstr_ncpy(diskdrv_fname[i],argv[i],sizeof(diskdrv_fname[0]));                  diskdrv_readyfdd(i, argv[i], 0);
                 diskdrv_delay[i] = 1;  
         }          }
   
         setup_signal(SIGINT, sighandler);          setup_signal(SIGINT, sighandler);
         setup_signal(SIGTERM, sighandler);          setup_signal(SIGTERM, sighandler);
   
         np2running = TRUE;  
         toolkit_widget_mainloop();          toolkit_widget_mainloop();
         np2running = FALSE;  
         rv = 0;          rv = 0;
   
         keydisp_destroy();          kdispwin_destroy();
         toolwin_destroy();          toolwin_destroy();
           skbdwin_destroy();
   
         pccore_cfgupdate();          pccore_cfgupdate();
   
         mouse_running(MOUSE_OFF);          mouse_running(MOUSE_OFF);
           joymng_deinitialize();
         S98_trash();          S98_trash();
   
   #if !defined(CPUCORE_IA32)
         if (np2oscfg.resume) {          if (np2oscfg.resume) {
                 flagsave(np2resumeext);                  flagsave(np2resumeext);
         } else {          } else {
                 flagdelete(np2resumeext);                  flagdelete(np2resumeext);
         }          }
   #endif
   
         pccore_term();          pccore_term();
           debugwin_destroy();
   
         soundmng_deinitialize();          soundmng_deinitialize();
         scrnmng_destroy();          scrnmng_destroy();
   
 resource_cleanup:  scrnmng_failure:
         if (sys_updates & (SYS_UPDATECFG|SYS_UPDATEOSCFG)) {          fontmng_terminate();
   
   fontmng_failure:
           if (!np2oscfg.cfgreadonly
            && (sys_updates & (SYS_UPDATECFG|SYS_UPDATEOSCFG))) {
                 initsave();                  initsave();
                 toolwin_writeini();                  toolwin_writeini();
                 keydisp_writeini();                  kdispwin_writeini();
                   skbdwin_writeini();
         }          }
   
           skbdwin_deinitialize();
   
   #if defined(USE_SDLAUDIO) || defined(USE_SDLMIXER)
           SDL_Quit();
   #endif
   
         TRACETERM();          TRACETERM();
         dosio_term();          dosio_term();
   
           viewer_term();
         toolkit_terminate();          toolkit_terminate();
   
         return rv;          return rv;

Removed from v.1.7  
changed lines
  Added in v.1.36


RetroPC.NET-CVS <cvs@retropc.net>