Diff for /np2/win9xc/ini.cpp between versions 1.6 and 1.11

version 1.6, 2003/12/27 02:29:44 version 1.11, 2005/05/16 06:08:22
Line 1 Line 1
 #include        "compiler.h"  #include        "compiler.h"
 #include        "strres.h"  #include        "strres.h"
 #include        "profile.h"  
 #include        "np2.h"  #include        "np2.h"
 #include        "dosio.h"  #include        "dosio.h"
 #include        "ini.h"  #include        "ini.h"
Line 8 Line 7
 #include        "pccore.h"  #include        "pccore.h"
   
   
 typedef struct {  void ini_read(const TCHAR *path, const TCHAR *title,
 const char              *title;                                                                                          const PFTBL *tbl, UINT count) {
 const INITBL    *tbl;  
 const INITBL    *tblterm;  
         UINT            count;  
 } _INIARG, *INIARG;  
   
 static void inirdarg8(BYTE *dst, int dsize, const char *src) {  
   
         int             i;  
         BYTE    val;  
         BOOL    set;  
         char    c;  
   
         for (i=0; i<dsize; i++) {  
                 val = 0;  
                 set = FALSE;  
                 while(*src == ' ') {  
                         src++;  
                 }  
                 while(1) {  
                         c = *src;  
                         if ((c == '\0') || (c == ' ')) {  
                                 break;  
                         }  
                         else if ((c >= '0') && (c <= '9')) {  
                                 val <<= 4;  
                                 val += c - '0';  
                                 set = TRUE;  
                         }  
                         else {  
                                 c |= 0x20;  
                                 if ((c >= 'a') && (c <= 'f')) {  
                                         val <<= 4;  
                                         val += c - 'a' + 10;  
                                         set = TRUE;  
                                 }  
                         }  
                         src++;  
                 }  
                 if (set == FALSE) {  
                         break;  
                 }  
                 dst[i] = val;  
         }  
 }  
   
 static BOOL inireadcb(void *arg, const char *para,  
                                                                                 const char *key, const char *data) {  
   
 const INITBL    *p;  
   
         if (arg == NULL) {  
                 return(FAILURE);  
         }  
         if (milstr_cmp(para, ((INIARG)arg)->title)) {  
                 return(SUCCESS);  
         }  
         p = ((INIARG)arg)->tbl;  
         while(p < ((INIARG)arg)->tblterm) {  
                 if (!milstr_cmp(key, p->item)) {  
                         switch(p->itemtype) {  
                                 case INITYPE_STR:  
                                         milstr_ncpy((char *)p->value, data, p->size);  
                                         break;  
   
                                 case INITYPE_BOOL:  
                                         *((BYTE *)p->value) = (!milstr_cmp(data, str_true))?1:0;  
                                         break;  
   
                                 case INITYPE_BYTEARG:  
                                         inirdarg8((BYTE *)p->value, p->size, data);  
                                         break;  
   
                                 case INITYPE_SINT8:  
                                 case INITYPE_UINT8:  
                                         *((BYTE *)p->value) = (BYTE)milstr_solveINT(data);  
                                         break;  
   
                                 case INITYPE_SINT16:  
                                 case INITYPE_UINT16:  
                                         *((UINT16 *)p->value) = (UINT16)milstr_solveINT(data);  
                                         break;  
   
                                 case INITYPE_SINT32:  
                                 case INITYPE_UINT32:  
                                         *((UINT32 *)p->value) = (UINT32)milstr_solveINT(data);  
                                         break;  
   
                                 case INITYPE_HEX8:  
                                         *((BYTE *)p->value) = (BYTE)milstr_solveHEX(data);  
                                         break;  
   
                                 case INITYPE_HEX16:  
                                         *((UINT16 *)p->value) = (UINT16)milstr_solveHEX(data);  
                                         break;  
   
                                 case INITYPE_HEX32:  
                                         *((UINT32 *)p->value) = (UINT32)milstr_solveHEX(data);  
                                         break;  
                         }  
                 }  
                 p++;  
         }  
         return(SUCCESS);  
 }  
   
 void ini_read(const char *path, const char *title,  
                                                                                         const INITBL *tbl, UINT count) {  
   
         _INIARG iniarg;  
   
         if (path == NULL) {  
                 return;  
         }  
         iniarg.title = title;  
         iniarg.tbl = tbl;  
         iniarg.tblterm = tbl + count;  
         profile_enum(path, &iniarg, inireadcb);  
 }  
   
   
 // ----          profile_iniread(path, title, tbl, count, NULL);
   
 static void iniwrsetstr(char *work, int size, const char *ptr) {  
   
         int             i;  
         char    c;  
   
         if (ptr[0] == ' ') {  
                 goto iwss_extend;  
                   
         }  
         i = strlen(ptr);  
         if ((i) && (ptr[i-1] == ' ')) {  
                 goto iwss_extend;  
         }  
         while(i > 0) {  
                 i--;  
                 if (ptr[i] == '\"') {  
                         goto iwss_extend;  
                 }  
         }  
         milstr_ncpy(work, ptr, size);  
         return;  
   
 iwss_extend:  
         if (size > 3) {  
                 size -= 3;  
                 *work++ = '\"';  
                 while(size > 0) {  
                         size--;  
                         c = *ptr++;  
                         if (c == '\"') {  
                                 if (size > 0) {  
                                         size--;  
                                         work[0] = c;  
                                         work[1] = c;  
                                         work += 2;  
                                 }  
                         }  
                         else {  
                                 *work++ = c;  
                         }  
                 }  
                 work[0] = '\"';  
                 work[1] = '\0';  
         }  
 }  
   
 static void iniwrsetarg8(char *work, int size, const BYTE *ptr, int arg) {  
   
         int             i;  
         char    tmp[8];  
   
         if (arg > 0) {  
                 SPRINTF(tmp, "%.2x", ptr[0]);  
                 milstr_ncpy(work, tmp, size);  
         }  
         for (i=1; i<arg; i++) {  
                 SPRINTF(tmp, " %.2x", ptr[i]);  
                 milstr_ncat(work, tmp, size);  
         }  
 }  }
   
 void ini_write(const char *path, const char *title,  void ini_write(const TCHAR *path, const TCHAR *title,
                                                                                         const INITBL *tbl, UINT count) {                                                                                          const PFTBL *tbl, UINT count) {
   
         FILEH           fh;          profile_iniwrite(path, title, tbl, count, NULL);
 const INITBL    *p;  
 const INITBL    *pterm;  
         BOOL            set;  
         char            work[512];  
   
         fh = file_create(path);  
         if (fh == FILEH_INVALID) {  
                 return;  
         }  
         milstr_ncpy(work, "[", sizeof(work));  
         milstr_ncat(work, title, sizeof(work));  
         milstr_ncat(work, "]\r\n", sizeof(work));  
         file_write(fh, work, strlen(work));  
   
         p = tbl;  
         pterm = tbl + count;  
         while(p < pterm) {  
                 work[0] = '\0';  
                 set = SUCCESS;  
                 switch(p->itemtype) {  
                         case INITYPE_STR:  
                                 iniwrsetstr(work, sizeof(work), (char *)p->value);  
                                 break;  
   
                         case INITYPE_BOOL:  
                                 milstr_ncpy(work, (*((BYTE *)p->value))?str_true:str_false,  
                                                                                                                                 sizeof(work));  
                                 break;  
   
                         case INITYPE_BYTEARG:  
                                 iniwrsetarg8(work, sizeof(work), (BYTE *)p->value, p->size);  
                                 break;  
   
                         case INITYPE_SINT8:  
                                 SPRINTF(work, "%d", *((char *)p->value));  
                                 break;  
   
                         case INITYPE_SINT16:  
                                 SPRINTF(work, "%d", *((SINT16 *)p->value));  
                                 break;  
   
                         case INITYPE_SINT32:  
                                 SPRINTF(work, "%d", *((SINT32 *)p->value));  
                                 break;  
   
                         case INITYPE_UINT8:  
                                 SPRINTF(work, "%u", *((BYTE *)p->value));  
                                 break;  
   
                         case INITYPE_UINT16:  
                                 SPRINTF(work, "%u", *((UINT16 *)p->value));  
                                 break;  
   
                         case INITYPE_UINT32:  
                                 SPRINTF(work, "%u", *((UINT32 *)p->value));  
                                 break;  
   
                         case INITYPE_HEX8:  
                                 SPRINTF(work, "%x", *((BYTE *)p->value));  
                                 break;  
   
                         case INITYPE_HEX16:  
                                 SPRINTF(work, "%x", *((UINT16 *)p->value));  
                                 break;  
   
                         case INITYPE_HEX32:  
                                 SPRINTF(work, "%x", *((UINT32 *)p->value));  
                                 break;  
   
                         default:  
                                 set = FAILURE;  
                                 break;  
                 }  
                 if (set == SUCCESS) {  
                         file_write(fh, p->item, strlen(p->item));  
                         file_write(fh, "=", 1);  
                         file_write(fh, work, strlen(work));  
                         file_write(fh, "\r\n", 2);  
                 }  
                 p++;  
         }  
         file_close(fh);  
 }  }
   
   
 // ----  // ----
   
 static const char ini_title[] = "NekoProjectII";  static const TCHAR ini_title[] = _T("NekoProjectII");
 static const char inifile[] = "np2.cfg";  #if defined(_UNICODE)
   static const TCHAR inifile[] = _T("np2u.cfg");
 static const INITBL iniitem[] = {  #else
         {"WindposX", INITYPE_SINT32,    &np2oscfg.winx,                 0},  static const TCHAR inifile[] = _T("np2.cfg");
         {"WindposY", INITYPE_SINT32,    &np2oscfg.winy,                 0},  #endif
   
         {"FDfolder", INITYPE_STR,               fddfolder,                              MAX_PATH},  enum {
         {"HDfolder", INITYPE_STR,               hddfolder,                              MAX_PATH},          PFRO_STR                = PFFLAG_RO + PFTYPE_STR,
         {"bmap_Dir", INITYPE_STR,               bmpfilefolder,                  MAX_PATH},          PFRO_BOOL               = PFFLAG_RO + PFTYPE_BOOL,
         {"fontfile", INITYPE_STR,               np2cfg.fontfile,                MAX_PATH},          PFRO_UINT8              = PFFLAG_RO + PFTYPE_UINT8,
         {"biospath", INITYPE_STR,               np2cfg.biospath,                MAX_PATH},          PFRO_HEX32              = PFFLAG_RO + PFTYPE_HEX32
   };
         {"pc_model", INITYPE_STR,               &np2cfg.model,  
                                                                                                         sizeof(np2cfg.model)},  static const PFTBL iniitem[] = {
         {"clk_base", INITYPE_SINT32,    &np2cfg.baseclock,              0},          PFVAL("WindposX", PFTYPE_SINT32,        &np2oscfg.winx),
         {"clk_mult", INITYPE_SINT32,    &np2cfg.multiple,               0},          PFVAL("WindposY", PFTYPE_SINT32,        &np2oscfg.winy),
   
         {"DIPswtch", INITYPE_BYTEARG,   np2cfg.dipsw,                   3},          PFSTR("FDfolder", PFTYPE_STR,           fddfolder),
         {"MEMswtch", INITYPE_BYTEARG,   np2cfg.memsw,                   8},          PFSTR("HDfolder", PFTYPE_STR,           hddfolder),
         {"ExMemory", INITYPE_UINT8,             &np2cfg.EXTMEM,                 0},          PFSTR("bmap_Dir", PFTYPE_STR,           bmpfilefolder),
         {"ITF_WORK", INITYPE_BOOL,              &np2cfg.ITF_WORK,               0},          PFSTR("fontfile", PFTYPE_STR,           np2cfg.fontfile),
           PFSTR("biospath", PFRO_STR,                     np2cfg.biospath),
         {"HDD1FILE", INITYPE_STR,               np2cfg.hddfile[0],              MAX_PATH},  
         {"HDD2FILE", INITYPE_STR,               np2cfg.hddfile[1],              MAX_PATH},  #if defined(SUPPORT_HOSTDRV)
           PFSTR("hdrvroot", PFRO_STR,                     np2cfg.hdrvroot),
         {"SampleHz", INITYPE_UINT16,    &np2cfg.samplingrate,   0},          PFVAL("hdrv_acc", PFRO_UINT8,           &np2cfg.hdrvacc),
         {"Latencys", INITYPE_UINT16,    &np2cfg.delayms,                0},  #endif
         {"SNDboard", INITYPE_HEX8,              &np2cfg.SOUND_SW,               0},  
         {"BEEP_vol", INITYPE_UINT8,             &np2cfg.BEEP_VOL,               0},          PFSTR("pc_model", PFTYPE_STR,           np2cfg.model),
         {"xspeaker", INITYPE_BOOL,              &np2cfg.snd_x,                  0},          PFVAL("clk_base", PFTYPE_UINT32,        &np2cfg.baseclock),
           PFVAL("clk_mult", PFTYPE_UINT32,        &np2cfg.multiple),
         {"SND14vol", INITYPE_BYTEARG,   np2cfg.vol14,                   6},  
 //      {"opt14BRD", INITYPE_BYTEARG,   np2cfg.snd14opt,                3},          PFEXT("DIPswtch", PFTYPE_BIN,           np2cfg.dipsw,                   3),
         {"opt26BRD", INITYPE_HEX8,              &np2cfg.snd26opt,               0},          PFEXT("MEMswtch", PFTYPE_BIN,           np2cfg.memsw,                   8),
         {"opt86BRD", INITYPE_HEX8,              &np2cfg.snd86opt,               0},          PFMAX("ExMemory", PFTYPE_UINT8,         &np2cfg.EXTMEM,                 63),
         {"optSPBRD", INITYPE_HEX8,              &np2cfg.spbopt,                 0},          PFVAL("ITF_WORK", PFRO_BOOL,            &np2cfg.ITF_WORK),
         {"optSPBVR", INITYPE_HEX8,              &np2cfg.spb_vrc,                0},  
         {"optSPBVL", INITYPE_UINT8,             &np2cfg.spb_vrl,                0},          PFSTR("HDD1FILE", PFTYPE_STR,           np2cfg.sasihdd[0]),
         {"optSPB_X", INITYPE_BOOL,              &np2cfg.spb_x,                  0},          PFSTR("HDD2FILE", PFTYPE_STR,           np2cfg.sasihdd[1]),
         {"optMPU98", INITYPE_HEX8,              &np2cfg.mpuopt,                 0},  
           PFVAL("SampleHz", PFTYPE_UINT16,        &np2cfg.samplingrate),
         {"volume_F", INITYPE_UINT8,             &np2cfg.vol_fm,                 0},          PFVAL("Latencys", PFTYPE_UINT16,        &np2cfg.delayms),
         {"volume_S", INITYPE_UINT8,             &np2cfg.vol_ssg,                0},          PFVAL("SNDboard", PFTYPE_HEX8,          &np2cfg.SOUND_SW),
         {"volume_A", INITYPE_UINT8,             &np2cfg.vol_adpcm,              0},          PFAND("BEEP_vol", PFTYPE_UINT8,         &np2cfg.BEEP_VOL,               3),
         {"volume_P", INITYPE_UINT8,             &np2cfg.vol_pcm,                0},          PFVAL("xspeaker", PFRO_BOOL,            &np2cfg.snd_x),
         {"volume_R", INITYPE_UINT8,             &np2cfg.vol_rhythm,             0},  
           PFEXT("SND14vol", PFTYPE_BIN,           np2cfg.vol14,                   6),
         {"Seek_Snd", INITYPE_BOOL,              &np2cfg.MOTOR,                  0},  //      PFEXT("opt14BRD", PFTYPE_BIN,           np2cfg.snd14opt,                3),
         {"Seek_Vol", INITYPE_UINT8,             &np2cfg.MOTORVOL,               0},          PFVAL("opt26BRD", PFTYPE_HEX8,          &np2cfg.snd26opt),
           PFVAL("opt86BRD", PFTYPE_HEX8,          &np2cfg.snd86opt),
         {"F12_COPY", INITYPE_UINT8,             &np2oscfg.F12COPY,              0},          PFVAL("optSPBRD", PFTYPE_HEX8,          &np2cfg.spbopt),
         {"Joystick", INITYPE_BOOL,              &np2oscfg.JOYPAD1,              0},          PFVAL("optSPBVR", PFTYPE_HEX8,          &np2cfg.spb_vrc),
         {"Joy1_btn", INITYPE_BYTEARG,   np2oscfg.JOY1BTN,               4},          PFMAX("optSPBVL", PFTYPE_UINT8,         &np2cfg.spb_vrl,                24),
         {"btnRAPID", INITYPE_BOOL,              &np2cfg.BTN_RAPID,              0},          PFVAL("optSPB_X", PFTYPE_BOOL,          &np2cfg.spb_x),
         {"btn_MODE", INITYPE_BOOL,              &np2cfg.BTN_MODE,               0},          PFVAL("optMPU98", PFTYPE_HEX8,          &np2cfg.mpuopt),
         {"Mouse_sw", INITYPE_BOOL,              &np2oscfg.MOUSE_SW,             0},  
         {"MS_RAPID", INITYPE_BOOL,              &np2cfg.MOUSERAPID,             0},          PFMAX("volume_F", PFTYPE_UINT8,         &np2cfg.vol_fm,                 128),
           PFMAX("volume_S", PFTYPE_UINT8,         &np2cfg.vol_ssg,                128),
         {"VRAMwait", INITYPE_BYTEARG,   np2cfg.wait,                    6},          PFMAX("volume_A", PFTYPE_UINT8,         &np2cfg.vol_adpcm,              128),
         {"DispSync", INITYPE_BOOL,              &np2cfg.DISPSYNC,               0},          PFMAX("volume_P", PFTYPE_UINT8,         &np2cfg.vol_pcm,                128),
         {"Real_Pal", INITYPE_BOOL,              &np2cfg.RASTER,                 0},          PFMAX("volume_R", PFTYPE_UINT8,         &np2cfg.vol_rhythm,             128),
         {"RPal_tim", INITYPE_UINT8,             &np2cfg.realpal,                0},  
         {"s_NOWAIT", INITYPE_BOOL,              &np2oscfg.NOWAIT,               0},          PFVAL("Seek_Snd", PFTYPE_BOOL,          &np2cfg.MOTOR),
         {"SkpFrame", INITYPE_UINT8,             &np2oscfg.DRAW_SKIP,    0},          PFMAX("Seek_Vol", PFTYPE_UINT8,         &np2cfg.MOTORVOL,               100),
         {"uPD72020", INITYPE_BOOL,              &np2cfg.uPD72020,               0},  
         {"GRCG_EGC", INITYPE_UINT8,             &np2cfg.grcg,                   0},          PFVAL("btnRAPID", PFTYPE_BOOL,          &np2cfg.BTN_RAPID),
         {"color16b", INITYPE_BOOL,              &np2cfg.color16,                0},          PFVAL("btn_MODE", PFTYPE_BOOL,          &np2cfg.BTN_MODE),
         {"skipline", INITYPE_BOOL,              &np2cfg.skipline,               0},          PFVAL("Mouse_sw", PFTYPE_BOOL,          &np2oscfg.MOUSE_SW),
         {"skplight", INITYPE_SINT16,    &np2cfg.skiplight,              0},          PFVAL("MS_RAPID", PFTYPE_BOOL,          &np2cfg.MOUSERAPID),
         {"LCD_MODE", INITYPE_UINT8,             &np2cfg.LCD_MODE,               0},  
         {"BG_COLOR", INITYPE_HEX32,             &np2cfg.BG_COLOR,               0},          PFEXT("VRAMwait", PFTYPE_BIN,           np2cfg.wait,                    6),
         {"FG_COLOR", INITYPE_HEX32,             &np2cfg.FG_COLOR,               0},          PFVAL("DispSync", PFTYPE_BOOL,          &np2cfg.DISPSYNC),
         {"pc9861_e", INITYPE_BOOL,              &np2cfg.pc9861enable,   0},          PFVAL("Real_Pal", PFTYPE_BOOL,          &np2cfg.RASTER),
         {"pc9861_s", INITYPE_BYTEARG,   np2cfg.pc9861sw,                3},          PFMAX("RPal_tim", PFTYPE_UINT8,         &np2cfg.realpal,                64),
         {"pc9861_j", INITYPE_BYTEARG,   np2cfg.pc9861jmp,               6},          PFVAL("s_NOWAIT", PFTYPE_BOOL,          &np2oscfg.NOWAIT),
         {"calendar", INITYPE_BOOL,              &np2cfg.calendar,               0},          PFVAL("SkpFrame", PFTYPE_UINT8,         &np2oscfg.DRAW_SKIP),
         {"USE144FD", INITYPE_BOOL,              &np2cfg.usefd144,               0},          PFVAL("uPD72020", PFTYPE_BOOL,          &np2cfg.uPD72020),
         {"jast_snd", INITYPE_BOOL,              &np2oscfg.jastsnd,              0},             // ver0.73          PFAND("GRCG_EGC", PFTYPE_UINT8,         &np2cfg.grcg,                   3),
         {"I286SAVE", INITYPE_BOOL,              &np2oscfg.I286SAVE,             0}};          PFVAL("color16b", PFTYPE_BOOL,          &np2cfg.color16),
           PFVAL("skipline", PFTYPE_BOOL,          &np2cfg.skipline),
 #define INIITEMS        (sizeof(iniitem) / sizeof(INITBL))          PFVAL("skplight", PFTYPE_UINT16,        &np2cfg.skiplight),
           PFAND("LCD_MODE", PFTYPE_UINT8,         &np2cfg.LCD_MODE,               0x03),
           PFAND("BG_COLOR", PFRO_HEX32,           &np2cfg.BG_COLOR,               0xffffff),
           PFAND("FG_COLOR", PFRO_HEX32,           &np2cfg.FG_COLOR,               0xffffff),
   
           PFVAL("pc9861_e", PFTYPE_BOOL,          &np2cfg.pc9861enable),
           PFEXT("pc9861_s", PFTYPE_BIN,           np2cfg.pc9861sw,                3),
           PFEXT("pc9861_j", PFTYPE_BIN,           np2cfg.pc9861jmp,               6),
   
           PFVAL("calendar", PFTYPE_BOOL,          &np2cfg.calendar),
           PFVAL("USE144FD", PFTYPE_BOOL,          &np2cfg.usefd144),
   
           PFVAL("F12_COPY", PFTYPE_UINT8,         &np2oscfg.F12COPY),
           PFVAL("Joystick", PFTYPE_BOOL,          &np2oscfg.JOYPAD1),
           PFEXT("Joy1_btn", PFTYPE_BIN,           np2oscfg.JOY1BTN,               4),
   
           PFVAL("e_resume", PFTYPE_BOOL,          &np2oscfg.resume),
           PFVAL("jast_snd", PFTYPE_BOOL,          &np2oscfg.jastsnd),
           PFVAL("I286SAVE", PFRO_BOOL,            &np2oscfg.I286SAVE)};
   
   
 void initload(void) {  void initload(void) {
   
         char    path[MAX_PATH];          TCHAR   path[MAX_PATH];
   
         milstr_ncpy(path, file_getcd(inifile), sizeof(path));          milstr_ncpy(path, file_getcd(inifile), NELEMENTS(path));
         ini_read(path, ini_title, iniitem, INIITEMS);          ini_read(path, ini_title, iniitem, NELEMENTS(iniitem));
 }  }
   
 void initsave(void) {  void initsave(void) {
   
         char    path[MAX_PATH];          TCHAR   path[MAX_PATH];
   
         milstr_ncpy(path, file_getcd(inifile), sizeof(path));          milstr_ncpy(path, file_getcd(inifile), NELEMENTS(path));
         ini_write(path, ini_title, iniitem, INIITEMS);          ini_write(path, ini_title, iniitem, NELEMENTS(iniitem));
 }  }
   

Removed from v.1.6  
changed lines
  Added in v.1.11


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