Diff for /np2/x11/ini.c between versions 1.10 and 1.26

version 1.10, 2004/03/25 15:10:33 version 1.26, 2012/01/23 04:20:24
Line 8 Line 8
 #include "strres.h"  #include "strres.h"
   
 #include "commng.h"  #include "commng.h"
   #include "joymng.h"
 #include "kbdmng.h"  #include "kbdmng.h"
 #include "soundmng.h"  #include "soundmng.h"
   
   
 typedef struct {  typedef struct {
         const char      *title;          const char      *title;
         const INITBL    *tbl;          INITBL          *tbl;
         const INITBL    *tblterm;          INITBL          *tblterm;
         UINT            count;          UINT            count;
 } _INIARG, *INIARG;  } _INIARG, *INIARG;
   
   
   static BOOL
   inigetbmp(const BYTE *ptr, UINT pos)
   {
   
           return ((ptr[pos >> 3] >> (pos & 7)) & 1);
   }
   
 static void  static void
 inirdargs16(const char *src, const INITBL *ini)  inisetbmp(BYTE *ptr, UINT pos, BOOL set)
   {
           UINT8 bit;
   
           ptr += (pos >> 3);
           bit = 1 << (pos & 7);
           if (set) {
                   *ptr |= bit;
           } else {
                   *ptr &= ~bit;
           }
   }
   
   static void
   inirdargs16(const char *src, INITBL *ini)
 {  {
         SINT16 *dst;          SINT16 *dst;
         int dsize;          int dsize;
Line 49  inirdargs16(const char *src, const INITB Line 71  inirdargs16(const char *src, const INITB
 }  }
   
 static void  static void
 inirdargh8(const char *src, const INITBL *ini)  inirdargh8(const char *src, INITBL *ini)
 {  {
         BYTE *dst;          BYTE *dst;
         int dsize;          int dsize;
Line 95  inirdargh8(const char *src, const INITBL Line 117  inirdargh8(const char *src, const INITBL
 }  }
   
 static void  static void
 iniwrsetargh8(char *work, int size, const INITBL *ini)  iniwrsetargh8(char *work, int size, INITBL *ini)
 {  {
         char tmp[8];          char tmp[8];
         const BYTE *ptr;          const BYTE *ptr;
Line 105  iniwrsetargh8(char *work, int size, cons Line 127  iniwrsetargh8(char *work, int size, cons
         ptr = (BYTE *)(ini->value);          ptr = (BYTE *)(ini->value);
         arg = ini->arg;          arg = ini->arg;
         if (arg > 0) {          if (arg > 0) {
                 SPRINTF(tmp, "%.2x ", ptr[0]);                  g_snprintf(tmp, sizeof(tmp), "%.2x ", ptr[0]);
                 milstr_ncpy(work, tmp, size);                  milstr_ncpy(work, tmp, size);
         }          }
         for (i = 1; i < arg; i++) {          for (i = 1; i < arg; i++) {
                 SPRINTF(tmp, "%.2x ", ptr[i]);                  g_snprintf(tmp, sizeof(tmp), "%.2x ", ptr[i]);
                 milstr_ncat(work, tmp, size);                  milstr_ncat(work, tmp, size);
         }          }
 }  }
Line 117  iniwrsetargh8(char *work, int size, cons Line 139  iniwrsetargh8(char *work, int size, cons
 /* ----- user */  /* ----- user */
   
 static void  static void
 inirdbyte3(const char *src, const INITBL *ini)  inirdbyte3(const char *src, INITBL *ini)
 {  {
         UINT i;          UINT i;
   
Line 133  inirdbyte3(const char *src, const INITBL Line 155  inirdbyte3(const char *src, const INITBL
 }  }
   
 static void  static void
 inirdkb(const char *src, const INITBL *ini)  inirdkb(const char *src, INITBL *ini)
 {  {
   
         if ((!milstr_extendcmp(src, "DOS"))          if ((!milstr_extendcmp(src, "DOS"))
Line 153  inirdkb(const char *src, const INITBL *i Line 175  inirdkb(const char *src, const INITBL *i
 }  }
   
 static void  static void
 inirdsnddrv(const char *src, const INITBL *ini)  inirdsnddrv(const char *src, INITBL *ini)
 {  {
   
         *(UINT8 *)ini->value = snddrv_drv2num(src);          *(UINT8 *)ini->value = snddrv_drv2num(src);
 }  }
   
   static void
   inirdinterp(const char *src, INITBL *ini)
   {
   
           if (!milstr_cmp(src, "NEAREST")) {
                   *(UINT8 *)ini->value = INTERP_NEAREST;
           } else if (!milstr_cmp(src, "TILES")) {
                   *(UINT8 *)ini->value = INTERP_TILES;
           } else if (!milstr_cmp(src, "HYPER")) {
                   *(UINT8 *)ini->value = INTERP_HYPER;
           } else {
                   *(UINT8 *)ini->value = INTERP_BILINEAR;
           }
   }
   
 static void update_iniread_flag(const INITBL *p);  static void update_iniread_flag(const INITBL *p);
   
 static BOOL  static BOOL
 inireadcb(void *arg, const char *para, const char *key, const char *data)  inireadcb(void *arg, const char *para, const char *key, const char *data)
 {  {
         char work[512];          char work[512];
         const INITBL *p;          INITBL *p;
         BOOL rv;          BOOL rv;
   
         if (arg == NULL) {          if (arg == NULL) {
Line 187  inireadcb(void *arg, const char *para, c Line 224  inireadcb(void *arg, const char *para, c
                                 *((BYTE *)p->value) = (!milstr_cmp(data, str_true))?1:0;                                  *((BYTE *)p->value) = (!milstr_cmp(data, str_true))?1:0;
                                 break;                                  break;
   
                           case INITYPE_BITMAP:
                                   inisetbmp((BYTE *)p->value, p->arg, milstr_cmp(data, str_true) == 0);
                                   break;
   
                         case INITYPE_ARGS16:                          case INITYPE_ARGS16:
                                 milstr_ncpy(work, data, 512);                                  milstr_ncpy(work, data, 512);
                                 inirdargs16(work, p);                                  inirdargs16(work, p);
Line 239  inireadcb(void *arg, const char *para, c Line 280  inireadcb(void *arg, const char *para, c
                                 inirdsnddrv(work, p);                                  inirdsnddrv(work, p);
                                 break;                                  break;
   
                           case INITYPE_INTERP:
                                   milstr_ncpy(work, data, 512);
                                   inirdinterp(work, p);
                                   break;
   
                         default:                          default:
                                 rv = FALSE;                                  rv = FALSE;
                                 break;                                  break;
Line 253  inireadcb(void *arg, const char *para, c Line 299  inireadcb(void *arg, const char *para, c
 }  }
   
 void  void
 ini_read(const char *path, const char *title, const INITBL *tbl, UINT count)  ini_read(const char *path, const char *title, INITBL *tbl, UINT count)
 {  {
         _INIARG iniarg;          _INIARG iniarg;
   
Line 313  iwss_extend: Line 359  iwss_extend:
         }          }
 }  }
   
   static const char *
   iniwrinterp(UINT8 interp)
   {
   
           if (interp == INTERP_NEAREST)
                   return "NEAREST";
           else if (interp == INTERP_TILES)
                   return "TILES";
           else if (interp == INTERP_HYPER)
                   return "HYPER";
           else
                   return "BILINEAR";
   }
   
 static BOOL read_iniread_flag(const INITBL *p);  static BOOL read_iniread_flag(const INITBL *p);
   
 void  void
 ini_write(const char *path, const char *title, const INITBL *tbl, UINT count, BOOL create)  ini_write(const char *path, const char *title, INITBL *tbl, UINT count, BOOL create)
 {  {
         char            work[512];          char    work[512];
         const INITBL    *p;          INITBL  *p;
         const INITBL    *pterm;          INITBL  *pterm;
         FILEH           fh;          FILEH   fh;
         BOOL            set;          BOOL    set;
   
         fh = FILEH_INVALID;          fh = FILEH_INVALID;
         if (!create) {          if (!create) {
Line 356  ini_write(const char *path, const char * Line 416  ini_write(const char *path, const char *
                                 milstr_ncpy(work, (*((BYTE *)p->value)) ? str_true : str_false, sizeof(work));                                  milstr_ncpy(work, (*((BYTE *)p->value)) ? str_true : str_false, sizeof(work));
                                 break;                                  break;
   
                           case INITYPE_BITMAP:
                                   milstr_ncpy(work, inigetbmp((BYTE *)p->value, p->arg) ? str_true : str_false, sizeof(work));
                                   break;
   
                         case INITYPE_ARGH8:                          case INITYPE_ARGH8:
                                 iniwrsetargh8(work, sizeof(work), p);                                  iniwrsetargh8(work, sizeof(work), p);
                                 break;                                  break;
   
                         case INITYPE_SINT8:                          case INITYPE_SINT8:
                                 SPRINTF(work, "%d", *((char *)p->value));                                  g_snprintf(work, sizeof(work), "%d", *((char *)p->value));
                                 break;                                  break;
   
                         case INITYPE_SINT16:                          case INITYPE_SINT16:
                                 SPRINTF(work, "%d", *((SINT16 *)p->value));                                  g_snprintf(work, sizeof(work), "%d", *((SINT16 *)p->value));
                                 break;                                  break;
   
                         case INITYPE_SINT32:                          case INITYPE_SINT32:
                                 SPRINTF(work, "%d", *((SINT32 *)p->value));                                  g_snprintf(work, sizeof(work), "%d", *((SINT32 *)p->value));
                                 break;                                  break;
   
                         case INITYPE_UINT8:                          case INITYPE_UINT8:
                                 SPRINTF(work, "%u", *((BYTE *)p->value));                                  g_snprintf(work, sizeof(work), "%u", *((BYTE *)p->value));
                                 break;                                  break;
   
                         case INITYPE_UINT16:                          case INITYPE_UINT16:
                                 SPRINTF(work, "%u", *((UINT16 *)p->value));                                  g_snprintf(work, sizeof(work), "%u", *((UINT16 *)p->value));
                                 break;                                  break;
   
                         case INITYPE_UINT32:                          case INITYPE_UINT32:
                                 SPRINTF(work, "%u", *((UINT32 *)p->value));                                  g_snprintf(work, sizeof(work), "%u", *((UINT32 *)p->value));
                                 break;                                  break;
   
                         case INITYPE_HEX8:                          case INITYPE_HEX8:
                                 SPRINTF(work, "%x", *((BYTE *)p->value));                                  g_snprintf(work, sizeof(work), "%x", *((BYTE *)p->value));
                                 break;                                  break;
   
                         case INITYPE_HEX16:                          case INITYPE_HEX16:
                                 SPRINTF(work, "%x", *((UINT16 *)p->value));                                  g_snprintf(work, sizeof(work), "%x", *((UINT16 *)p->value));
                                 break;                                  break;
   
                         case INITYPE_HEX32:                          case INITYPE_HEX32:
                                 SPRINTF(work, "%x", *((UINT32 *)p->value));                                  g_snprintf(work, sizeof(work), "%x", *((UINT32 *)p->value));
                                 break;                                  break;
   
                         case INITYPE_KB:                          case INITYPE_KB:
Line 404  ini_write(const char *path, const char * Line 468  ini_write(const char *path, const char *
                                 break;                                  break;
   
                         case INITYPE_SNDDRV:                          case INITYPE_SNDDRV:
                                 SPRINTF(work, "%s", snddrv_num2drv(*(UINT8 *)p->value));                                  g_snprintf(work, sizeof(work), "%s", snddrv_num2drv(*(UINT8 *)p->value));
                                   break;
   
                           case INITYPE_INTERP:
                                   g_snprintf(work, sizeof(work), "%s", iniwrinterp(*(UINT8 *)p->value));
                                 break;                                  break;
   
                         default:                          default:
Line 423  ini_write(const char *path, const char * Line 491  ini_write(const char *path, const char *
         file_close(fh);          file_close(fh);
 }  }
   
 extern char modulefile[];  static const char ini_title[] =
   #if !defined(CPUCORE_IA32)
 static const char ini_title[] = "NekoProjectII";          "NekoProjectII";
   #else
           "NekoProjectII_IA32";
   #endif
   
 enum {  enum {
         INIRO_STR       = INIFLAG_RO | INITYPE_STR,          INIRO_STR       = INIFLAG_RO | INITYPE_STR,
         INIRO_BOOL      = INIFLAG_RO | INITYPE_BOOL,          INIRO_BOOL      = INIFLAG_RO | INITYPE_BOOL,
           INIRO_BITMAP    = INIFLAG_RO | INITYPE_BITMAP,
         INIRO_UINT8     = INIFLAG_RO | INITYPE_UINT8,          INIRO_UINT8     = INIFLAG_RO | INITYPE_UINT8,
         INIMAX_UINT8    = INIFLAG_MAX | INITYPE_UINT8,          INIMAX_UINT8    = INIFLAG_MAX | INITYPE_UINT8,
         INIAND_UINT8    = INIFLAG_AND | INITYPE_UINT8,          INIAND_UINT8    = INIFLAG_AND | INITYPE_UINT8,
Line 440  enum { Line 512  enum {
         INIRO_KB        = INIFLAG_RO | INITYPE_KB          INIRO_KB        = INIFLAG_RO | INITYPE_KB
 };  };
   
 static const INITBL iniitem[] = {  static INITBL iniitem[] = {
         {"np2title", INIRO_STR,         np2oscfg.titles,        sizeof(np2oscfg.titles)},          {"np2title", INIRO_STR,         np2oscfg.titles,        sizeof(np2oscfg.titles)},
         {"paddingx", INIROMAX_SINT32,   &np2oscfg.paddingx,     32},          {"paddingx", INIROMAX_SINT32,   &np2oscfg.paddingx,     32},
         {"paddingy", INIROMAX_SINT32,   &np2oscfg.paddingy,     32},          {"paddingy", INIROMAX_SINT32,   &np2oscfg.paddingy,     32},
Line 449  static const INITBL iniitem[] = { Line 521  static const INITBL iniitem[] = {
         {"HDfolder", INITYPE_STR,       hddfolder,              MAX_PATH},          {"HDfolder", INITYPE_STR,       hddfolder,              MAX_PATH},
         {"bmap_Dir", INITYPE_STR,       bmpfilefolder,          MAX_PATH},          {"bmap_Dir", INITYPE_STR,       bmpfilefolder,          MAX_PATH},
         {"fontfile", INITYPE_STR,       np2cfg.fontfile,        MAX_PATH},          {"fontfile", INITYPE_STR,       np2cfg.fontfile,        MAX_PATH},
         {"biospath", INITYPE_STR,       np2cfg.biospath,        MAX_PATH},          {"biospath", INIRO_STR,         np2cfg.biospath,        MAX_PATH},
         {"hdrvroot", INIRO_STR,         np2cfg.hdrvroot,        MAX_PATH},          {"hdrvroot", INIRO_STR,         np2cfg.hdrvroot,        MAX_PATH},
         {"hdrv_acc", INIRO_UINT8,       &np2cfg.hdrvacc,        0},          {"hdrv_acc", INIRO_UINT8,       &np2cfg.hdrvacc,        0},
   
         {"pc_model", INITYPE_STR,       &np2cfg.model,          sizeof(np2cfg.model)},          {"pc_model", INITYPE_STR,       np2cfg.model,           sizeof(np2cfg.model)},
   
         {"clk_base", INITYPE_UINT32,    &np2cfg.baseclock,      0},          {"clk_base", INITYPE_UINT32,    &np2cfg.baseclock,      0},
         {"clk_mult", INITYPE_UINT32,    &np2cfg.multiple,       0},          {"clk_mult", INITYPE_UINT32,    &np2cfg.multiple,       0},
Line 518  static const INITBL iniitem[] = { Line 590  static const INITBL iniitem[] = {
   
         {"calendar", INITYPE_BOOL,      &np2cfg.calendar,       0},          {"calendar", INITYPE_BOOL,      &np2cfg.calendar,       0},
         {"USE144FD", INITYPE_BOOL,      &np2cfg.usefd144,       0},          {"USE144FD", INITYPE_BOOL,      &np2cfg.usefd144,       0},
           {"FDDRIVE1", INIRO_BITMAP,      &np2cfg.fddequip,       0},
           {"FDDRIVE2", INIRO_BITMAP,      &np2cfg.fddequip,       1},
           {"FDDRIVE3", INIRO_BITMAP,      &np2cfg.fddequip,       2},
           {"FDDRIVE4", INIRO_BITMAP,      &np2cfg.fddequip,       3},
   
         {"keyboard", INIRO_KB,          &np2oscfg.KEYBOARD,     0},          {"keyboard", INIRO_KB,          &np2oscfg.KEYBOARD,     0},
         {"F12_COPY", INITYPE_UINT8,     &np2oscfg.F12KEY,       0},          {"F12_COPY", INITYPE_UINT8,     &np2oscfg.F12KEY,       0},
         {"Joystick", INITYPE_BOOL,      &np2oscfg.JOYPAD1,      0},          {"Joystick", INITYPE_BOOL,      &np2oscfg.JOYPAD1,      0},
         {"Joy1_btn", INITYPE_ARGH8,     np2oscfg.JOY1BTN,       4},          {"Joy1_btn", INITYPE_ARGH8,     np2oscfg.JOY1BTN,       JOY_NBUTTON},
           {"Joy1_dev", INITYPE_STR,       &np2oscfg.JOYDEV[0],    MAX_PATH},
           {"Joy1amap", INITYPE_ARGH8,     np2oscfg.JOYAXISMAP[0], JOY_NAXIS},
           {"Joy1bmap", INITYPE_ARGH8,     np2oscfg.JOYBTNMAP[0],  JOY_NBUTTON},
   
         {"confirm_", INITYPE_BOOL,      &np2oscfg.confirm,      0},          {"confirm_", INITYPE_BOOL,      &np2oscfg.confirm,      0},
   
Line 552  static const INITBL iniitem[] = { Line 631  static const INITBL iniitem[] = {
         {"com3mmdl", INITYPE_STR,       np2oscfg.com[2].mdl,    64},          {"com3mmdl", INITYPE_STR,       np2oscfg.com[2].mdl,    64},
         {"com3mdef", INITYPE_STR,       np2oscfg.com[2].def,    MAX_PATH},          {"com3mdef", INITYPE_STR,       np2oscfg.com[2].def,    MAX_PATH},
   
   #if defined(SUPPORT_RESUME)
         {"e_resume", INITYPE_BOOL,      &np2oscfg.resume,       0},          {"e_resume", INITYPE_BOOL,      &np2oscfg.resume,       0},
   #endif
   #if defined(SUPPORT_STATSAVE)
         {"STATSAVE", INIRO_BOOL,        &np2oscfg.statsave,     0},          {"STATSAVE", INIRO_BOOL,        &np2oscfg.statsave,     0},
 #if defined(__GNUC__) && (defined(i386) || defined(__i386__))  #endif
   #if defined(GCC_CPU_ARCH_IA32)
         {"nousemmx", INITYPE_BOOL,      &np2oscfg.disablemmx,   0},          {"nousemmx", INITYPE_BOOL,      &np2oscfg.disablemmx,   0},
 #endif  #endif
         {"toolwind", INITYPE_BOOL,      &np2oscfg.toolwin,      0},          {"toolwind", INITYPE_BOOL,      &np2oscfg.toolwin,      0},
         {"keydispl", INITYPE_BOOL,      &np2oscfg.keydisp,      0},          {"keydispl", INITYPE_BOOL,      &np2oscfg.keydisp,      0},
           {"soft_kbd", INITYPE_BOOL,      &np2oscfg.softkbd,      0},
         {"jast_snd", INITYPE_BOOL,      &np2oscfg.jastsnd,      0},          {"jast_snd", INITYPE_BOOL,      &np2oscfg.jastsnd,      0},
   
         {"sounddrv", INITYPE_SNDDRV,    &np2oscfg.snddrv,       0},          {"sounddrv", INITYPE_SNDDRV,    &np2oscfg.snddrv,       0},
         {"audiodev", INITYPE_STR,       &np2oscfg.audiodev,     MAX_PATH},  
         {"MIDIOUTd", INITYPE_STR,       &np2oscfg.MIDIDEV[0],   MAX_PATH},          {"MIDIOUTd", INITYPE_STR,       &np2oscfg.MIDIDEV[0],   MAX_PATH},
         {"MIDIIN_d", INITYPE_STR,       &np2oscfg.MIDIDEV[1],   MAX_PATH},          {"MIDIIN_d", INITYPE_STR,       &np2oscfg.MIDIDEV[1],   MAX_PATH},
         {"MIDIWAIT", INITYPE_UINT32,    &np2oscfg.MIDIWAIT,     0},          {"MIDIWAIT", INITYPE_UINT32,    &np2oscfg.MIDIWAIT,     0},
   
         {"sharepix", INIRO_BOOL,        &np2oscfg.shared_pixmap,0},          {"dinterp_", INITYPE_INTERP,    &np2oscfg.drawinterp,   0},
           {"fullscrn", INITYPE_UINT32,    &ignore_fullscreen_mode,0},
         {"toolkit_", INIRO_STR,         &np2oscfg.toolkit,      sizeof(np2oscfg.toolkit)},          {"F11_KEY_", INITYPE_UINT8,     &np2oscfg.F11KEY,       0},
           {"READONLY", INIRO_BOOL,        &np2oscfg.cfgreadonly,  0},
   
         {"I286SAVE", INIRO_BOOL,        &np2oscfg.I286SAVE,     0}          {"I286SAVE", INIRO_BOOL,        &np2oscfg.I286SAVE,     0},
 };  };
 #define INIITEMS        (sizeof(iniitem) / sizeof(iniitem[0]))  #define INIITEMS        (sizeof(iniitem) / sizeof(iniitem[0]))
   
Line 585  calc_index(const INITBL *p) Line 669  calc_index(const INITBL *p)
         UINT idx;          UINT idx;
   
         if (p) {          if (p) {
                 offset = (char *)p - (char *)iniitem;                  offset = (const char *)p - (const char *)iniitem;
                 if ((offset % sizeof(iniitem[0])) == 0) {                  if ((offset % sizeof(iniitem[0])) == 0) {
                         idx = offset / sizeof(iniitem[0]);                          idx = offset / sizeof(iniitem[0]);
                         if (idx < INIITEMS) {                          if (idx < INIITEMS) {
Line 619  read_iniread_flag(const INITBL *p) Line 703  read_iniread_flag(const INITBL *p)
         return FALSE;          return FALSE;
 }  }
   
   NP2CFG np2cfg_default;
   NP2OSCFG np2oscfg_default;
   
 void  void
 initload(void)  initload(void)
 {  {
         char path[MAX_PATH];          char path[MAX_PATH];
   
           np2cfg_default = np2cfg;
           np2oscfg_default = np2oscfg;
   
         milstr_ncpy(path, modulefile, sizeof(path));          milstr_ncpy(path, modulefile, sizeof(path));
         ini_read(path, ini_title, iniitem, INIITEMS);          ini_read(path, ini_title, iniitem, INIITEMS);
 }  }

Removed from v.1.10  
changed lines
  Added in v.1.26


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