Diff for /xmil/wince/ini.cpp between versions 1.1 and 1.2

version 1.1, 2004/08/19 11:09:20 version 1.2, 2004/08/20 08:41:41
Line 1 Line 1
   
 #if 0  
 #include        "compiler.h"  #include        "compiler.h"
 #include        "strres.h"  #include        "strres.h"
 #include        "profile.h"  #include        "profile.h"
 #include        "np2.h"  
 #include        "dosio.h"  #include        "dosio.h"
   #include        "xmil.h"
 #include        "ini.h"  #include        "ini.h"
 #include        "pccore.h"  #include        "pccore.h"
   
   
 typedef struct {  static const char ini_title[] = "Xmillennium";
 const char              *title;  
 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);  
 }  
   
   
 // ----  
   
 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);  
         }  
 }  
   
   
 static const UINT8 utf8hdr[3] = {0xef, 0xbb, 0xbf};  enum {
           PFRO_BOOL                       = PFTYPE_BOOL + PFFLAG_RO,
           PFMAX_UINT8                     = PFTYPE_UINT8 + PFFLAG_MAX,
           PFAND_UINT8                     = PFTYPE_UINT8 + PFFLAG_AND,
           PFROAND_HEX32           = PFTYPE_HEX32 + PFFLAG_RO + PFFLAG_AND
   };
   
 void ini_write(const char *path, const char *title,  static const PFTBL iniitem[] = {
                                                                                         const INITBL *tbl, UINT count) {  
   
         FILEH           fh;          // OS°Í¸¡Á
 const INITBL    *p;  #if !defined(GX_DLL)
 const INITBL    *pterm;          {"WindposX", PFTYPE_SINT32,             &xmiloscfg.winx,                0},
         BOOL            set;          {"WindposY", PFTYPE_SINT32,             &xmiloscfg.winy,                0},
         char            work[512];  
   
         fh = file_create(path);  
         if (fh == FILEH_INVALID) {  
                 return;  
         }  
 #if defined(OSLANG_UTF8)  
         file_write(fh, utf8hdr, sizeof(utf8hdr));  
 #endif  #endif
         milstr_ncpy(work, "[", sizeof(work));          {"s_NOWAIT", PFTYPE_BOOL,               &xmiloscfg.NOWAIT,              0},
         milstr_ncat(work, title, sizeof(work));          {"SkpFrame", PFTYPE_UINT8,              &xmiloscfg.DRAW_SKIP,   0},
         milstr_ncat(work, "]\r\n", sizeof(work));  #if defined(WIN32_PLATFORM_PSPC)
         file_write(fh, work, strlen(work));          {"pbindcur", PFTYPE_UINT8,              &np2oscfg.bindcur,              0},
           {"pbindbtn", PFTYPE_UINT8,              &np2oscfg.bindbtn,              0},
         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, str_d, *((char *)p->value));  
                                 break;  
   
                         case INITYPE_SINT16:  
                                 SPRINTF(work, str_d, *((SINT16 *)p->value));  
                                 break;  
   
                         case INITYPE_SINT32:  
                                 SPRINTF(work, str_d, *((SINT32 *)p->value));  
                                 break;  
   
                         case INITYPE_UINT8:  
                                 SPRINTF(work, str_u, *((BYTE *)p->value));  
                                 break;  
   
                         case INITYPE_UINT16:  
                                 SPRINTF(work, str_u, *((UINT16 *)p->value));  
                                 break;  
   
                         case INITYPE_UINT32:  
                                 SPRINTF(work, str_u, *((UINT32 *)p->value));  
                                 break;  
   
                         case INITYPE_HEX8:  
                                 SPRINTF(work, str_x, *((BYTE *)p->value));  
                                 break;  
   
                         case INITYPE_HEX16:  
                                 SPRINTF(work, str_x, *((UINT16 *)p->value));  
                                 break;  
   
                         case INITYPE_HEX32:  
                                 SPRINTF(work, str_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);  
 }  
   
   
 // ----  
   
 #if defined(OSLANG_UTF8)  
 static const char ini_title[] = "NekoProjectIICE";  
 static const char inifile[] = "np2ce.cfg";  
 #else  
 static const char ini_title[] = "NekoProjectII";  
 static const char inifile[] = "np2.cfg";  
 #endif  #endif
   
 static const INITBL iniitem[] = {  
         {"pc_model", INITYPE_STR,               &np2cfg.model,  
                                                                                                         sizeof(np2cfg.model)},  
         {"clk_base", INITYPE_SINT32,    &np2cfg.baseclock,              0},  
         {"clk_mult", INITYPE_SINT32,    &np2cfg.multiple,               0},  
   
         {"DIPswtch", INITYPE_BYTEARG,   np2cfg.dipsw,                   3},  
         {"MEMswtch", INITYPE_BYTEARG,   np2cfg.memsw,                   8},  
         {"ExMemory", INITYPE_UINT8,             &np2cfg.EXTMEM,                 0},  
         {"ITF_WORK", INITYPE_BOOL,              &np2cfg.ITF_WORK,               0},  
   
         {"HDD1FILE", INITYPE_STR,               np2cfg.sasihdd[0],              MAX_PATH},  
         {"HDD2FILE", INITYPE_STR,               np2cfg.sasihdd[1],              MAX_PATH},  
 #if defined(SUPPORT_SCSI)  
         {"SCSIHDD0", INITYPE_STR,               np2cfg.scsihdd[0],              MAX_PATH},  
         {"SCSIHDD1", INITYPE_STR,               np2cfg.scsihdd[1],              MAX_PATH},  
         {"SCSIHDD2", INITYPE_STR,               np2cfg.scsihdd[2],              MAX_PATH},  
         {"SCSIHDD3", INITYPE_STR,               np2cfg.scsihdd[3],              MAX_PATH},  
 #endif  
         {"fontfile", INITYPE_STR,               np2cfg.fontfile,                MAX_PATH},  
         {"biospath", INITYPE_STR,               np2cfg.biospath,                MAX_PATH},  
   
         {"SampleHz", INITYPE_UINT16,    &np2cfg.samplingrate,   0},          // xmil
         {"Latencys", INITYPE_UINT16,    &np2cfg.delayms,                0},          {"IPL_TYPE", PFMAX_UINT8,               &xmilcfg.ROM_TYPE,              3},
         {"SNDboard", INITYPE_HEX8,              &np2cfg.SOUND_SW,               0},          {"Resolute", PFTYPE_HEX8,               &xmilcfg.DIP_SW,                0},
         {"BEEP_vol", INITYPE_UINT8,             &np2cfg.BEEP_VOL,               0},  
         {"xspeaker", INITYPE_BOOL,              &np2cfg.snd_x,                  0},  
   
         {"SND14vol", INITYPE_BYTEARG,   np2cfg.vol14,                   6},  
 //      {"opt14BRD", INITYPE_BYTEARG,   np2cfg.snd14opt,                3},  
         {"opt26BRD", INITYPE_HEX8,              &np2cfg.snd26opt,               0},  
         {"opt86BRD", INITYPE_HEX8,              &np2cfg.snd86opt,               0},  
         {"optSPBRD", INITYPE_HEX8,              &np2cfg.spbopt,                 0},  
         {"optSPBVR", INITYPE_HEX8,              &np2cfg.spb_vrc,                0},  
         {"optSPBVL", INITYPE_UINT8,             &np2cfg.spb_vrl,                0},  
         {"optSPB_X", INITYPE_BOOL,              &np2cfg.spb_x,                  0},  
         {"optMPU98", INITYPE_HEX8,              &np2cfg.mpuopt,                 0},  
   
         {"volume_F", INITYPE_UINT8,             &np2cfg.vol_fm,                 0},  
         {"volume_S", INITYPE_UINT8,             &np2cfg.vol_ssg,                0},  
         {"volume_A", INITYPE_UINT8,             &np2cfg.vol_adpcm,              0},  
         {"volume_P", INITYPE_UINT8,             &np2cfg.vol_pcm,                0},  
         {"volume_R", INITYPE_UINT8,             &np2cfg.vol_rhythm,             0},  
   
         {"Seek_Snd", INITYPE_BOOL,              &np2cfg.MOTOR,                  0},  
         {"Seek_Vol", INITYPE_UINT8,             &np2cfg.MOTORVOL,               0},  
   
         {"btnRAPID", INITYPE_BOOL,              &np2cfg.BTN_RAPID,              0},  
         {"btn_MODE", INITYPE_BOOL,              &np2cfg.BTN_MODE,               0},  
         {"MS_RAPID", INITYPE_BOOL,              &np2cfg.MOUSERAPID,             0},  
   
         {"VRAMwait", INITYPE_BYTEARG,   np2cfg.wait,                    6},  
         {"DispSync", INITYPE_BOOL,              &np2cfg.DISPSYNC,               0},  
         {"Real_Pal", INITYPE_BOOL,              &np2cfg.RASTER,                 0},  
         {"RPal_tim", INITYPE_UINT8,             &np2cfg.realpal,                0},  
         {"uPD72020", INITYPE_BOOL,              &np2cfg.uPD72020,               0},  
         {"GRCG_EGC", INITYPE_UINT8,             &np2cfg.grcg,                   0},  
         {"color16b", INITYPE_BOOL,              &np2cfg.color16,                0},  
         {"skipline", INITYPE_BOOL,              &np2cfg.skipline,               0},  
         {"skplight", INITYPE_SINT16,    &np2cfg.skiplight,              0},  
         {"LCD_MODE", INITYPE_UINT8,             &np2cfg.LCD_MODE,               0},  
         {"BG_COLOR", INITYPE_HEX32,             &np2cfg.BG_COLOR,               0},  
         {"FG_COLOR", INITYPE_HEX32,             &np2cfg.FG_COLOR,               0},  
         {"pc9861_e", INITYPE_BOOL,              &np2cfg.pc9861enable,   0},  
         {"pc9861_s", INITYPE_BYTEARG,   np2cfg.pc9861sw,                3},  
         {"pc9861_j", INITYPE_BYTEARG,   np2cfg.pc9861jmp,               6},  
         {"calendar", INITYPE_BOOL,              &np2cfg.calendar,               0},  
         {"USE144FD", INITYPE_BOOL,              &np2cfg.usefd144,               0},  
   
         // OS°Í¸¡Á          {"DispSync", PFTYPE_BOOL,               &xmilcfg.DISPSYNC,              0},
         {"s_NOWAIT", INITYPE_BOOL,              &np2oscfg.NOWAIT,               0},          {"Real_Pal", PFTYPE_BOOL,               &xmilcfg.RASTER,                0},
         {"SkpFrame", INITYPE_UINT8,             &np2oscfg.DRAW_SKIP,    0},          {"skipline", PFTYPE_BOOL,               &xmilcfg.skipline,              0},
         {"F12_bind", INITYPE_UINT8,             &np2oscfg.F12KEY,               0},          {"skplight", PFTYPE_UINT16,             &xmilcfg.skiplight,             0},
         {"e_resume", INITYPE_BOOL,              &np2oscfg.resume,               0},  
   
 #if !defined(GX_DLL)          {"SampleHz", PFTYPE_UINT16,             &xmilcfg.samplingrate,  0},
         {"WindposX", INITYPE_SINT32,    &np2oscfg.winx,                 0},          {"Latencys", PFTYPE_UINT16,             &xmilcfg.delayms,               0},
         {"WindposY", INITYPE_SINT32,    &np2oscfg.winy,                 0},          {"OPMsound", PFTYPE_BOOL,               &xmilcfg.SOUND_SW,              0},
 #endif          {"Seek_Snd", PFTYPE_BOOL,               &xmilcfg.MOTOR,                 0},
 #if defined(WIN32_PLATFORM_PSPC)          {"Seek_Vol", PFMAX_UINT8,               &xmilcfg.MOTORVOL,              100},
         {"pbindcur", INITYPE_UINT8,             &np2oscfg.bindcur,              0},  
         {"pbindbtn", INITYPE_UINT8,             &np2oscfg.bindbtn,              0},          {"MouseInt", PFTYPE_BOOL,               &xmilcfg.MOUSE_SW,              0},
 #endif          {"btnRAPID", PFTYPE_BOOL,               &xmilcfg.BTN_RAPID,             0},
         {"jast_snd", INITYPE_BOOL,              &np2oscfg.jastsnd,              0},             // ver0.73          {"btn_MODE", PFTYPE_BOOL,               &xmilcfg.BTN_MODE,              0}};
 };  
   
   
 #define INIITEMS        (sizeof(iniitem) / sizeof(INITBL))  void initgetfile(OEMCHAR *path, UINT size) {
   
           file_cpyname(path, modulefile, size);
           file_cutext(path);
           file_catname(path, OEMTEXT(".cfg"), size);
   }
   
 void initload(void) {  void initload(void) {
   
         char    path[MAX_PATH];          OEMCHAR path[MAX_PATH];
   
         milstr_ncpy(path, file_getcd(inifile), sizeof(path));          initgetfile(path, NELEMENTS(path));
         ini_read(path, ini_title, iniitem, INIITEMS);          profile_iniread(path, ini_title, iniitem, NELEMENTS(iniitem), NULL);
 }  }
   
 void initsave(void) {  void initsave(void) {
   
         char    path[MAX_PATH];          OEMCHAR path[MAX_PATH];
   
         milstr_ncpy(path, file_getcd(inifile), sizeof(path));          initgetfile(path, NELEMENTS(path));
         ini_write(path, ini_title, iniitem, INIITEMS);          profile_iniwrite(path, ini_title, iniitem, NELEMENTS(iniitem), NULL);
 }  }
 #endif  
   

Removed from v.1.1  
changed lines
  Added in v.1.2


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