示例#1
0
void osd_init(int width, int height)
{
    const char *fontpath;

    fontpath = ConfigGetSharedDataFilepath(FONT_FILENAME);

    l_font = new OGLFT::Monochrome(fontpath, (float) height / 35.0f);  // make font size proportional to screen height

    if(!l_font || !l_font->isValid())
    {
        DebugMessage(M64MSG_ERROR, "Could not construct face from %s", fontpath);
        return;
    }

    // clear statics
    for (int i = 0; i < OSD_NUM_CORNERS; i++)
        fCornerScroll[i] = 0.0;

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
#if defined(GL_RASTER_POSITION_UNCLIPPED_IBM)
    glEnable(GL_RASTER_POSITION_UNCLIPPED_IBM);
#endif

    pglActiveTexture = (PTRGLACTIVETEXTURE) VidExt_GL_GetProcAddress("glActiveTexture");
    if (pglActiveTexture == NULL)
    {
        DebugMessage(M64MSG_WARNING, "OpenGL function glActiveTexture() not supported.  OSD deactivated.");
        return;
    }

    // set initialized flag
    l_OsdInitialized = 1;
}
示例#2
0
void Config_LoadConfig(void)
{
   FILE *f;
   char line[4096];

   // default configuration
   Config_SetDefault();

   // __LIBRETRO__: Get screen size
   config.screen.width = screen_width;
   config.screen.height = screen_height;


   // read configuration
   const char *filename = ConfigGetSharedDataFilepath("gles2n64.conf");
   f = fopen(filename, "r");
   if (!f)
   {
      if (log_cb)
      {
         log_cb(RETRO_LOG_WARN, "[gles2N64]: Couldn't open config file '%s' for reading: %s\n", filename, strerror( errno ) );
         log_cb(RETRO_LOG_WARN, "[gles2N64]: Attempting to write new Config \n");
      }
      Config_WriteConfig(filename);
   }
   else
   {
      if (log_cb)
         log_cb(RETRO_LOG_INFO, "[gles2n64]: Loading Config from %s \n", filename);

      while (!feof( f ))
      {
         char *val;
         fgets( line, 4096, f );

         if (line[0] == '#' || line[0] == '\n')
            continue;

         val = strchr( line, '=' );
         if (!val) continue;

         *val++ = '\0';

         Config_SetOption(line,val);
      }

      if (config.version < CONFIG_VERSION)
      {
         if (log_cb)
            log_cb(RETRO_LOG_WARN, "[gles2N64]: Wrong config version, rewriting config with defaults\n");
         Config_SetDefault();
         Config_WriteConfig(filename);
      }

      fclose(f);
   }
}
示例#3
0
void Config_LoadConfig()
{
    FILE *f;
    char line[4096];

    // default configuration
    Config_SetDefault();

    // read configuration
    const char *filename = ConfigGetSharedDataFilepath("gles2n64.conf");
    f = fopen(filename, "r");
    if (!f)
    {
        LOG(LOG_MINIMAL, "[gles2N64]: Couldn't open config file '%s' for reading: %s\n", filename, strerror( errno ) );
        LOG(LOG_MINIMAL, "[gles2N64]: Attempting to write new Config \n");
        Config_WriteConfig(filename);
    }
    else
    {
        LOG(LOG_MINIMAL, "[gles2n64]: Loading Config from %s \n", filename);

        while (!feof( f ))
        {
            char *val;
            fgets( line, 4096, f );

            if (line[0] == '#' || line[0] == '\n')
                continue;

            val = strchr( line, '=' );
            if (!val) continue;

            *val++ = '\0';

             Config_SetOption(line,val);
        }

        if (config.version < CONFIG_VERSION)
        {
            LOG(LOG_WARNING, "[gles2N64]: Wrong config version, rewriting config with defaults\n");
            Config_SetDefault();
            Config_WriteConfig(filename);
        }

        fclose(f);
    }
}
示例#4
0
void romdatabase_open(void)
{
    FILE *fPtr;
    char buffer[256];
    romdatabase_search* search = NULL;
    romdatabase_search** next_search;

    int counter, value, lineno;
    unsigned char index;
    const char *pathname = ConfigGetSharedDataFilepath("mupen64plus.ini");

    if(g_romdatabase.have_database)
        return;

    /* Open romdatabase. */
    if (pathname == NULL || (fPtr = fopen(pathname, "rb")) == NULL)
    {
        DebugMessage(M64MSG_ERROR, "Unable to open rom database file '%s'.", pathname);
        return;
    }

    g_romdatabase.have_database = 1;

    /* Clear premade indices. */
    for(counter = 0; counter < 255; ++counter)
        g_romdatabase.crc_lists[counter] = NULL;
    for(counter = 0; counter < 255; ++counter)
        g_romdatabase.md5_lists[counter] = NULL;
    g_romdatabase.list = NULL;

    next_search = &g_romdatabase.list;

    /* Parse ROM database file */
    for (lineno = 1; fgets(buffer, 255, fPtr) != NULL; lineno++)
    {
        char *line = buffer;
        ini_line l = ini_parse_line(&line);
        switch (l.type)
        {
        case INI_SECTION:
        {
            md5_byte_t md5[16];
            if (!parse_hex(l.name, md5, 16))
            {
                DebugMessage(M64MSG_WARNING, "ROM Database: Invalid MD5 on line %i", lineno);
                search = NULL;
                continue;
            }

            *next_search = (romdatabase_search*) malloc(sizeof(romdatabase_search));
            search = *next_search;
            next_search = &search->next_entry;
            
            memset(search, 0, sizeof(romdatabase_search));

            search->entry.goodname = NULL;
            memcpy(search->entry.md5, md5, 16);
            search->entry.refmd5 = NULL;
            search->entry.crc1 = 0;
            search->entry.crc2 = 0;
            search->entry.status = 0; /* Set default to 0 stars. */
            search->entry.savetype = DEFAULT;
            search->entry.players = DEFAULT;
            search->entry.rumble = DEFAULT; 
            search->entry.countperop = COUNT_PER_OP_DEFAULT;
            search->entry.alternate_vi_timing = ALTERNATE_VI_TIMING_DEFAULT;
            search->entry.count_per_scanline = DEFAULT_COUNT_PER_SCANLINE;
            search->entry.cheats = NULL;
            search->entry.set_flags = ROMDATABASE_ENTRY_NONE;

            search->next_entry = NULL;
            search->next_crc = NULL;
            /* Index MD5s by first 8 bits. */
            index = search->entry.md5[0];
            search->next_md5 = g_romdatabase.md5_lists[index];
            g_romdatabase.md5_lists[index] = search;

            break;
        }
        case INI_PROPERTY:
            // This happens if there's stray properties before any section,
            // or if some error happened on INI_SECTION (e.g. parsing).
            if (search == NULL)
            {
                DebugMessage(M64MSG_WARNING, "ROM Database: Ignoring property on line %i", lineno);
                continue;
            }
            if(!strcmp(l.name, "GoodName"))
            {
                search->entry.goodname = strdup(l.value);
                search->entry.set_flags |= ROMDATABASE_ENTRY_GOODNAME;
            }
            else if(!strcmp(l.name, "CRC"))
            {
                char garbage_sweeper;
                if (sscanf(l.value, "%X %X%c", &search->entry.crc1,
                    &search->entry.crc2, &garbage_sweeper) == 2)
                {
                    /* Index CRCs by first 8 bits. */
                    index = search->entry.crc1 >> 24;
                    search->next_crc = g_romdatabase.crc_lists[index];
                    g_romdatabase.crc_lists[index] = search;
                    search->entry.set_flags |= ROMDATABASE_ENTRY_CRC;
                }
                else
                {
                    search->entry.crc1 = search->entry.crc2 = 0;
                    DebugMessage(M64MSG_WARNING, "ROM Database: Invalid CRC on line %i", lineno);
                }
            }
示例#5
0
void ReadCheats(char *RomSection)
{
    sCheatInfo *curr_code;
    const char *romdbpath = ConfigGetSharedDataFilepath(CHEAT_FILE);
    if (romdbpath == NULL)
    {
        printf("UI-Console: cheat code database file '%s' not found.\n", CHEAT_FILE);
        return;
    }

    /* read the INI file into a new buffer */
    FILE *fPtr = NULL;
    fPtr = fopen(romdbpath, "rb");
    if (fPtr == NULL)
    {
        printf("UI-Console: Couldn't open cheat code database file '%s'.\n", romdbpath);
        return;
    }
    fseek(fPtr, 0L, SEEK_END);
    long IniLength = ftell(fPtr);
    fseek(fPtr, 0L, SEEK_SET);
    l_IniText = (char *) malloc(IniLength + 1);
    if (l_IniText == NULL)
    {
        printf("UI-Console: Couldn't allocate %li bytes of memory to read cheat file.\n", IniLength);
        fclose(fPtr);
        return;
    }
    if (fread(l_IniText, 1, IniLength, fPtr) != IniLength)
    {
        printf("UI-Console: Couldn't read %li bytes from cheat file.\n", IniLength);
        free(l_IniText);
        l_IniText = NULL;
        fclose(fPtr);
        return;
    }
    fclose(fPtr);
    l_IniText[IniLength] = 0; /* null-terminate the text data */

    /* parse lines from cheat database */
    char *curline = NULL;
    char *nextline = l_IniText;
    int NumCheats = 0;

    while(nextline != NULL && *nextline != 0)
    {
        curline = nextline;
        /* get pointer to next line and NULL-terminate the current line */
        nextline = strchr(curline, '\n');
        if (nextline != NULL)
        {
            *nextline = 0;
            nextline++;
        }

        /* remove leading and trailing white space */
        while(isSpace(*curline)) curline++;
        char *endptr = curline + strlen(curline) - 1;
        while(isSpace(*endptr)) *endptr-- = 0;

        /* ignore line if comment or empty */
        if (*curline == '#' || strncmp(curline, "//", 2) == 0 || *curline == 0)
            continue;

        /* handle beginning of new rom section */
        if (strncmp(curline, "crc ", 4) == 0)
        {
            /* if we have already found cheats for the given ROM file, then exit upon encountering a new ROM section */
            if (l_RomFound && (l_CheatGameName != NULL || l_CheatList != NULL))
                return;
            /* else see if this Rom Section matches */
            if (strcmp(curline+4, RomSection) == 0)
                l_RomFound = 1;
            continue;
        }

        /* if we haven't found the specified ROM section, then continue looking */
        if (!l_RomFound)
            continue;

        /* Game name */
        if (strncmp(curline, "gn ", 3) == 0)
        {
            l_CheatGameName = curline+3;
            continue;
        }

        /* code name */
        if (strncmp(curline, "cn ", 3) == 0)
        {
            curr_code = NewCode(curline + 3, l_CheatCodesFound);
            if (curr_code == NULL)
                printf("UI-Console error: error getting new code (%s)\n", curline+3);
            continue;
        }

        /* if curr_code is NULL, don't do these checks */
        if (curr_code == NULL)
            continue;

        /* code description */
        if (strncmp(curline, "cd ", 3) == 0)
        {
            curr_code->Description = curline+3;
            continue;
        }

        /* code line */
        int address;
        if (sscanf(curline, "%8X %*s", &address) == 1)
        {
            curr_code->Codes = (cheat_code*) realloc(curr_code->Codes, sizeof(cheat_code) * (curr_code->Count + 1));
            if (strncmp(curline+9, "????", 4) == 0)
            {
                curr_code->Codes[curr_code->Count].var_count = 0;
                CheatAddVariables(&curr_code->Codes[curr_code->Count], curline+14);
                curr_code->VariableLine = curr_code->Count;
            }
            else
            {
                int var;
                curr_code->Codes[curr_code->Count].var_count = 1;
                curr_code->Codes[curr_code->Count].variables = (int*) malloc(sizeof(int));
                if(curr_code->Codes[curr_code->Count].variables == NULL)
                {
                    printf("UI-Console Error: error allocating memory; ignoring line: '%s'\n", curline);
                    continue;
                }
                if (sscanf(curline+9, "%04X", &var) != 1)
                    var = 0;
                curr_code->Codes[curr_code->Count].variables[0] = var;
                curr_code->Codes[curr_code->Count].variable_names = NULL;
            }
            curr_code->Codes[curr_code->Count].var_to_use = 0;
            curr_code->Codes[curr_code->Count].address = address;
            curr_code->Count++;
            continue;
        }

        /* otherwise we don't know what this line is */
        printf("UI-Console Warning: unrecognized line in cheat file: '%s'\n", curline);
    }

}
示例#6
0
void Config_LoadRomConfig(unsigned char* header)
{
   char line[4096];
   int i;

   // get the name of the ROM
   for (i = 0; i < 20; i++)
      config.romName[i] = header[0x20+i];
   config.romName[20] = '\0';
   while (config.romName[strlen(config.romName)-1] == ' ')
   {
      config.romName[strlen(config.romName)-1] = '\0';
   }

   switch(header[0x3e])
   {
      // PAL codes
      case 0x44:
      case 0x46:
      case 0x49:
      case 0x50:
      case 0x53:
      case 0x55:
      case 0x58:
      case 0x59:
         config.romPAL = true;
         break;

         // NTSC codes
      case 0x37:
      case 0x41:
      case 0x45:
      case 0x4a:
         config.romPAL = false;
         break;

         // Fallback for unknown codes
      default:
         config.romPAL = false;
   }

   if (log_cb)
      log_cb(RETRO_LOG_INFO, "Rom is %s\n", config.romPAL ? "PAL" : "NTSC");

   const char *filename = ConfigGetSharedDataFilepath("gles2n64rom.conf");
   FILE *f = fopen(filename,"r");
   if (!f)
   {
      if (log_cb)
         log_cb(RETRO_LOG_INFO, "Could not find %s Rom settings file, using global.\n", filename);
      return;
   }
   else
   {
      if (log_cb)
         log_cb(RETRO_LOG_INFO, "[gles2N64]: Searching %s Database for \"%s\" ROM\n", filename, config.romName);
      bool isRom = false;
      while (!feof(f))
      {
         fgets(line, 4096, f);
         if (line[0] == '\n') continue;

         if (strncmp(line,"rom name=", 9) == 0)
         {
            //Depending on the editor, end lines could be terminated by "LF" or "CRLF"
            char* lf = strchr(line, '\n'); //Line Feed
            char* cr = strchr(line, '\r'); //Carriage Return
            if (lf) *lf='\0';
            if (cr) *cr='\0';
            isRom = (strcasecmp(config.romName, line+9) == 0);
         }
         else
         {
            if (isRom)
            {
               char* val = strchr(line, '=');
               if (!val) continue;
               *val++ = '\0';
               Config_SetOption(line,val);
               if (log_cb)
                  log_cb(RETRO_LOG_INFO, "%s = %s", line, val);
            }
         }
      }
   }

   fclose(f);
}
示例#7
0
/* global functions */
int auto_set_defaults(int iDeviceIdx, const char *joySDLName)
{
    FILE *pfIn;
    m64p_handle pConfig = NULL;
    const char *CfgFilePath = ConfigGetSharedDataFilepath(INI_FILE_NAME);
    enum { E_NAME_SEARCH, E_NAME_FOUND, E_PARAM_READ } eParseState;
    char *pchIni, *pchNextLine, *pchCurLine;
    long iniLength;
    int ControllersFound = 0;

    /* if we couldn't get a name (no joystick plugged in to given port), then return with a failure */
    if (joySDLName == NULL)
        return 0;
    /* if we couldn't find the shared data file, dump an error and return */
    if (CfgFilePath == NULL || strlen(CfgFilePath) < 1)
    {
        DebugMessage(M64MSG_ERROR, "Couldn't find config file '%s'", INI_FILE_NAME);
        return 0;
    }

    /* read the input auto-config .ini file */
    pfIn = fopen(CfgFilePath, "rb");
    if (pfIn == NULL)
    {
        DebugMessage(M64MSG_ERROR, "Couldn't open config file '%s'", CfgFilePath);
        return 0;
    }
    fseek(pfIn, 0L, SEEK_END);
    iniLength = ftell(pfIn);
    fseek(pfIn, 0L, SEEK_SET);
    pchIni = (char *) malloc(iniLength + 1);
    if (pchIni == NULL)
    {
        DebugMessage(M64MSG_ERROR, "Couldn't allocate %li bytes for config file '%s'", iniLength, CfgFilePath);
        fclose(pfIn);
        return 0;
    }
    if (fread(pchIni, 1, iniLength, pfIn) != iniLength)
    {
        DebugMessage(M64MSG_ERROR, "File read failed for %li bytes of config file '%s'", iniLength, CfgFilePath);
        free(pchIni);
        fclose(pfIn);
        return 0;
    }
    fclose(pfIn);
    pchIni[iniLength] = 0;

    /* parse the INI file, line by line */
    pchNextLine = pchIni;
    eParseState = E_NAME_SEARCH;
    while (pchNextLine != NULL && *pchNextLine != 0)
    {
        char *pivot = NULL;
        /* set up character pointers */
        pchCurLine = pchNextLine;
        pchNextLine = strchr(pchNextLine, '\n');
        if (pchNextLine != NULL)
            *pchNextLine++ = 0;
        pchCurLine = StripSpace(pchCurLine);

        /* handle blank/comment lines */
        if (strlen(pchCurLine) < 1 || *pchCurLine == ';' || *pchCurLine == '#')
            continue;

        /* handle section (joystick name in ini file) */
        if (*pchCurLine == '[' && pchCurLine[strlen(pchCurLine)-1] == ']')
        {
            char Word[64];
            char *wordPtr;
            int  joyFound = 1;

            if (eParseState == E_PARAM_READ)
            {
                /* we've finished parsing all parameters for the discovered input device */
                free(pchIni);
                return ControllersFound;
            }
            else if (eParseState == E_NAME_FOUND)
            {
                /* this is an equivalent device name to the one we're looking for (and found); keep looking for parameters */
                continue;
            }
            /* we need to look through the device name word by word to see if it matches the joySDLName that we're looking for */ 
            pchCurLine[strlen(pchCurLine)-1] = 0;
            wordPtr = StripSpace(pchCurLine + 1);
            /* first, if there is a preceding system name in this .ini device name, and the system matches, then strip out */
#if defined(__unix__)
            if (strncmp(wordPtr, "Unix:", 5) == 0)
                wordPtr = StripSpace(wordPtr + 5);
#endif
#if defined(__linux__)
            if (strncmp(wordPtr, "Linux:", 6) == 0)
                wordPtr = StripSpace(wordPtr + 6);
#endif
#if defined(__APPLE__)
            if (strncmp(wordPtr, "OSX:", 4) == 0)
                wordPtr = StripSpace(wordPtr + 4);
#endif
#if defined(WIN32)
            if (strncmp(wordPtr, "Win32:", 6) == 0)
                wordPtr = StripSpace(wordPtr + 6);
#endif
            /* search in the .ini device name for all the words in the joystick name.  If any are missing, then this is not the right joystick model */
            while (wordPtr != NULL && strlen(wordPtr) > 0)
            {
                char *nextSpace = strchr(wordPtr, ' ');
                if (nextSpace == NULL)
                {
                    strncpy(Word, wordPtr, 63);
                    Word[63] = 0;
                    wordPtr = NULL;
                }
                else
                {
                    int length = (int) (nextSpace - wordPtr);
                    if (length > 63) length = 63;
                    strncpy(Word, wordPtr, length);
                    Word[length] = 0;
                    wordPtr = nextSpace + 1;
                }
                printf("Word1: %s, Word2: %s\n", joySDLName, Word);fflush(stdout);
                if (strstr(joySDLName, Word) == NULL)
                    joyFound = 0;
            }
            /* if we found the right joystick, then open up the core config section to store parameters and set the 'device' param */
            if (joyFound)
            {
                char SectionName[32];
                sprintf(SectionName, "AutoConfig%i", ControllersFound);
                if (ConfigOpenSection(SectionName, &pConfig) != M64ERR_SUCCESS)
                {
                    DebugMessage(M64MSG_ERROR, "auto_set_defaults(): Couldn't open config section '%s'", SectionName);
                    free(pchIni);
                    return 0;
                }
                eParseState = E_NAME_FOUND;
                ControllersFound++;
                DebugMessage(M64MSG_INFO, "Using auto-configuration for device '%s'", joySDLName);
                ConfigSetParameter(pConfig, "device", M64TYPE_INT, &iDeviceIdx);
            }
            continue;
        }

        /* handle parameters */
        pivot = strchr(pchCurLine, '=');
        if (pivot != NULL)
        {
            /* if we haven't found the correct section yet, just skip this */
            if (eParseState == E_NAME_SEARCH)
                continue;
            eParseState = E_PARAM_READ;
            /* otherwise, store this parameter in the current active joystick config */
            *pivot++ = 0;
            pchCurLine = StripSpace(pchCurLine);
            pivot = StripSpace(pivot);
            if (strcasecmp(pchCurLine, "plugin") == 0 || strcasecmp(pchCurLine, "device") == 0)
            {
                int iVal = atoi(pivot);
                ConfigSetParameter(pConfig, pchCurLine, M64TYPE_INT, &iVal);
            }
            else if (strcasecmp(pchCurLine, "plugged") == 0 || strcasecmp(pchCurLine, "mouse") == 0)
            {
                int bVal = (strcasecmp(pivot, "true") == 0);
                ConfigSetParameter(pConfig, pchCurLine, M64TYPE_BOOL, &bVal);
            }
            else
            {
                ConfigSetParameter(pConfig, pchCurLine, M64TYPE_STRING, pivot);
            }
            continue;
        }

        /* handle keywords */
        if (pchCurLine[strlen(pchCurLine)-1] == ':')
        {
            /* if we haven't found the correct section yet, just skip this */
            if (eParseState == E_NAME_SEARCH)
                continue;
            /* otherwise parse the keyword */
            if (strcmp(pchCurLine, "__NextController:") == 0)
            {
                char SectionName[32];
                /* if there are no more N64 controller spaces left, then exit */
                if (ControllersFound == 4)
                {
                    free(pchIni);
                    return ControllersFound;
                }
                /* otherwise go to the next N64 controller */
                sprintf(SectionName, "AutoConfig%i", ControllersFound);
                if (ConfigOpenSection(SectionName, &pConfig) != M64ERR_SUCCESS)
                {
                    DebugMessage(M64MSG_ERROR, "auto_set_defaults(): Couldn't open config section '%s'", SectionName);
                    free(pchIni);
                    return ControllersFound;
                }
                ControllersFound++;
                DebugMessage(M64MSG_INFO, "Using auto-configuration for device '%s': %i controllers for this device", joySDLName, ControllersFound);
                ConfigSetParameter(pConfig, "device", M64TYPE_INT, &iDeviceIdx);
            }
            else
            {
                DebugMessage(M64MSG_ERROR, "Unknown keyword '%s' in %s", pchCurLine, INI_FILE_NAME);
            }
            continue;
        }

        /* unhandled line in .ini file */
        DebugMessage(M64MSG_ERROR, "Invalid line in %s: '%s'", INI_FILE_NAME, pchCurLine);
    }

    if (eParseState == E_PARAM_READ)
    {
        /* we've finished parsing all parameters for the discovered input device, which is the last in the .ini file */
        free(pchIni);
        return ControllersFound;
    }

    DebugMessage(M64MSG_INFO, "No auto-configuration found for device '%s'", joySDLName);
    free(pchIni);
    return 0;
}
int auto_set_defaults(int iDeviceIdx, const char *joySDLName)
{
    FILE *pfIn;
    m64p_handle pConfig = NULL;
    const char *CfgFilePath = ConfigGetSharedDataFilepath(INI_FILE_NAME);
    enum { E_NAME_SEARCH, E_NAME_FOUND, E_PARAM_READ } eParseState;
    char *pchIni, *pchNextLine, *pchCurLine;
    long iniLength;
    int ControllersFound = 0;
    int joyFoundScore = -1;

    /* if we couldn't get a name (no joystick plugged in to given port), then return with a failure */
    if (joySDLName == NULL)
        return 0;
    /* if we couldn't find the shared data file, dump an error and return */
    if (CfgFilePath == NULL || strlen(CfgFilePath) < 1)
    {
        DebugMessage(M64MSG_ERROR, "Couldn't find config file '%s'", INI_FILE_NAME);
        return 0;
    }

    /* read the input auto-config .ini file */
    pfIn = fopen(CfgFilePath, "rb");
    if (pfIn == NULL)
    {
        DebugMessage(M64MSG_ERROR, "Couldn't open config file '%s'", CfgFilePath);
        return 0;
    }
    fseek(pfIn, 0L, SEEK_END);
    iniLength = ftell(pfIn);
    fseek(pfIn, 0L, SEEK_SET);
    if (iniLength < 0) {
        DebugMessage(M64MSG_ERROR, "Couldn't get size of config file '%s'", CfgFilePath);
        fclose(pfIn);
        return 0;
    }

    pchIni = (char *) malloc(iniLength + 1);
    if (pchIni == NULL)
    {
        DebugMessage(M64MSG_ERROR, "Couldn't allocate %li bytes for config file '%s'", iniLength, CfgFilePath);
        fclose(pfIn);
        return 0;
    }
    if (fread(pchIni, 1, iniLength, pfIn) != iniLength)
    {
        DebugMessage(M64MSG_ERROR, "File read failed for %li bytes of config file '%s'", iniLength, CfgFilePath);
        free(pchIni);
        fclose(pfIn);
        return 0;
    }
    fclose(pfIn);
    pchIni[iniLength] = 0;

    /* parse the INI file, line by line */
    DebugMessage(M64MSG_INFO, "Using auto-config file at: '%s'", CfgFilePath);
    pchNextLine = pchIni;
    eParseState = E_NAME_SEARCH;
    while (pchNextLine != NULL && *pchNextLine != 0)
    {
        char *pivot = NULL;
        int  joyFound = 0;
        /* set up character pointers */
        pchCurLine = pchNextLine;
        pchNextLine = strchr(pchNextLine, '\n');
        if (pchNextLine != NULL)
            *pchNextLine++ = 0;
        pchCurLine = StripSpace(pchCurLine);

        /* handle blank/comment lines */
        if (strlen(pchCurLine) < 1 || *pchCurLine == ';' || *pchCurLine == '#')
            continue;

        /* handle section (joystick name in ini file) */
        if (*pchCurLine == '[' && pchCurLine[strlen(pchCurLine)-1] == ']')
        {
            /* only switch to name search when some section body was identified since last header */
            if (eParseState == E_PARAM_READ)
                eParseState = E_NAME_SEARCH;

            /* we need to look through the device name word by word to see if it matches the joySDLName that we're looking for */ 
            pchCurLine[strlen(pchCurLine)-1] = 0;
            joyFound = auto_compare_name(joySDLName, StripSpace(pchCurLine + 1));
            /* if we found the right joystick, then open up the core config section to store parameters and set the 'device' param */
            if (joyFound > joyFoundScore)
            {
                char SectionName[32];
                ControllersFound = 0;
                sprintf(SectionName, "AutoConfig%i", ControllersFound);
                if (ConfigOpenSection(SectionName, &pConfig) != M64ERR_SUCCESS)
                {
                    DebugMessage(M64MSG_ERROR, "auto_set_defaults(): Couldn't open config section '%s'", SectionName);
                    free(pchIni);
                    return 0;
                }
                eParseState = E_NAME_FOUND;
                ControllersFound++;
                ConfigSetParameter(pConfig, "device", M64TYPE_INT, &iDeviceIdx);
                joyFoundScore = joyFound;
            }
            continue;
        }

        /* handle parameters */
        pivot = strchr(pchCurLine, '=');
        if (pivot != NULL)
        {
            /* if we haven't found the correct section yet, just skip this */
            if (eParseState == E_NAME_SEARCH)
                continue;
            eParseState = E_PARAM_READ;
            /* otherwise, store this parameter in the current active joystick config */
            *pivot++ = 0;
            pchCurLine = StripSpace(pchCurLine);
            pivot = StripSpace(pivot);
            if (strcasecmp(pchCurLine, "device") == 0)
            {
                int iVal = atoi(pivot);
                ConfigSetParameter(pConfig, pchCurLine, M64TYPE_INT, &iVal);
            }
            else if (strcasecmp(pchCurLine, "plugged") == 0 || strcasecmp(pchCurLine, "mouse") == 0)
            {
                int bVal = (strcasecmp(pivot, "true") == 0);
                ConfigSetParameter(pConfig, pchCurLine, M64TYPE_BOOL, &bVal);
            }
            else
            {
                ConfigSetParameter(pConfig, pchCurLine, M64TYPE_STRING, pivot);
            }
            continue;
        }

        /* handle keywords */
        if (pchCurLine[strlen(pchCurLine)-1] == ':')
        {
            /* if we haven't found the correct section yet, just skip this */
            if (eParseState == E_NAME_SEARCH)
                continue;
            eParseState = E_PARAM_READ;
            /* otherwise parse the keyword */
            if (strcmp(pchCurLine, "__NextController:") == 0)
            {
                char SectionName[32];
                /* if there are no more N64 controller spaces left, then exit */
                if (ControllersFound == 4)
                {
                    free(pchIni);
                    return ControllersFound;
                }
                /* otherwise go to the next N64 controller */
                sprintf(SectionName, "AutoConfig%i", ControllersFound);
                if (ConfigOpenSection(SectionName, &pConfig) != M64ERR_SUCCESS)
                {
                    DebugMessage(M64MSG_ERROR, "auto_set_defaults(): Couldn't open config section '%s'", SectionName);
                    free(pchIni);
                    return ControllersFound;
                }
                ControllersFound++;
                ConfigSetParameter(pConfig, "device", M64TYPE_INT, &iDeviceIdx);
            }
            else
            {
                DebugMessage(M64MSG_ERROR, "Unknown keyword '%s' in %s", pchCurLine, INI_FILE_NAME);
            }
            continue;
        }

        /* unhandled line in .ini file */
        DebugMessage(M64MSG_ERROR, "Invalid line in %s: '%s'", INI_FILE_NAME, pchCurLine);
    }

    if (joyFoundScore != -1)
    {
        /* we've finished parsing all parameters for the discovered input device, which is the last in the .ini file */
        free(pchIni);
        return ControllersFound;
    }

    free(pchIni);
    return 0;
}
示例#9
0
BOOL INI_Open ()
{
#ifdef __LIBRETRO__ //use ConfigGetSharedDataFilepath
    const char *path = ConfigGetSharedDataFilepath("Glide64mk2.ini");
#else
	//TODO: use ConfigGetSharedDataFilepath
	
    // Get the path of the dll, ex: C:\Games\Project64\Plugin\Glide64.dll
    char path[PATH_MAX];
    if(strlen(configdir) > 0)
    {
        strncpy(path, configdir, PATH_MAX);
        // make sure there's a trailing '/'
        //if(path[strlen(path)-1] != '/')
        //    strncat(path, "/", PATH_MAX - strlen(path));
    }
    else
    {
#ifdef _WIN32
    GetModuleFileName (NULL, path, PATH_MAX);
#else // _WIN32
# ifdef __FreeBSD__
   int n = readlink("/proc/curproc/files", path, PATH_MAX);
#else
   int n = readlink("/proc/self/exe", path, PATH_MAX);
#endif
   if (n == -1) strcpy(path, "./");
   else
     {
    char path2[PATH_MAX];
    int i;
    
    path[n] = '\0';
    strcpy(path2, path);
    for (i=strlen(path2)-1; i>0; i--)
      {
         if(path2[i] == '/') break;
      }
    if(i == 0) strcpy(path, "./");
    else
      {
         DIR *dir;
         struct dirent *entry;
         int gooddir = 0;
         
         path2[i+1] = '\0';
         dir = opendir(path2);
         while((entry = readdir(dir)) != NULL)
           {
          if(!strcmp(entry->d_name, "plugins"))
            gooddir = 1;
           }
         closedir(dir);
         if(!gooddir) strcpy(path, "./");
      }
     }

#endif // _WIN32

    // Find the previous backslash
    int i;
    for (i=strlen(path)-1; i>0; i--)
    {
#ifdef _WIN32
        if (path[i] == '\\')
#else // _WIN32
            if (path[i] == '/')
#endif // _WIN32
            break;
    }
    if (path == 0) return FALSE;
    path[i+1] = 0;

#ifndef _WIN32
   strcat(path, "plugins/");
#endif // _WIN32
    }
#endif   

    //strncat (path, "Glide64mk2.ini", PATH_MAX - strlen(path));
    LOG("opening %s\n", path);
    // Open the file
    ini = fopen (path, "rb");
    if (ini == NULL)
    {
        ERRLOG("Could not find Glide64mk2.ini!");
        return FALSE;
        /*
        ini = fopen (path, "w+b");
        if (ini == NULL)
        {
            return FALSE;
        }
        */
    }

    sectionstart = 0;
    last_line = 0;
    last_line_ret = 1;

    return TRUE;
}
示例#10
0
void Config_LoadRomConfig(unsigned char* header)
{
    char line[4096];

    // get the name of the ROM
    for (int i=0; i<20; i++) config.romName[i] = header[0x20+i];
    config.romName[20] = '\0';
    while (config.romName[strlen(config.romName)-1] == ' ')
    {
        config.romName[strlen(config.romName)-1] = '\0';
    }

    switch(header[0x3e])
    {
        // PAL codes
        case 0x44:
        case 0x46:
        case 0x49:
        case 0x50:
        case 0x53:
        case 0x55:
        case 0x58:
        case 0x59:
            config.romPAL = true;
            break;

        // NTSC codes
        case 0x37:
        case 0x41:
        case 0x45:
        case 0x4a:
            config.romPAL = false;
            break;

        // Fallback for unknown codes
        default:
            config.romPAL = false;
    }

    LOG(LOG_MINIMAL, "Rom is %s\n", config.romPAL ? "PAL" : "NTSC");

    const char *filename = ConfigGetSharedDataFilepath("gles2n64rom.conf");
    FILE *f = fopen(filename,"r");
    if (!f)
    {
        LOG(LOG_MINIMAL, "Could not find %s Rom settings file, using global.\n", filename);
        return;
    }
    else
    {
        LOG(LOG_MINIMAL, "[gles2N64]: Searching %s Database for \"%s\" ROM\n", filename, config.romName);
        bool isRom = false;
        while (!feof(f))
        {
            fgets(line, 4096, f);
            if (line[0] == '\n') continue;

            if (strncmp(line,"rom name=", 9) == 0)
            {
                char* v = strchr(line, '\n');
                if (v) *v='\0';
                isRom = (strcasecmp(config.romName, line+9) == 0);
            }
            else
            {
                if (isRom)
                {
                    char* val = strchr(line, '=');
                    if (!val) continue;
                    *val++ = '\0';
                    Config_SetOption(line,val);
                }
            }
        }
    }
	
    fclose(f);
}
void LoadCustomSettings(bool internal)
{
	std::string myString = replaceChars(RSP.romname);
	bool found = false;
	char buffer[256];
	char* line;
	FILE* fPtr;
	std::transform(myString.begin(), myString.end(), myString.begin(), ::toupper);
	if (internal) {
		line = strtok(customini, "\n");
	} else {
		const char *pathname = ConfigGetSharedDataFilepath("GLideN64.custom.ini");
		if (pathname == NULL || (fPtr = fopen(pathname, "rb")) == NULL)
			return;
	}
	while (true)
	{
		if (!internal) {
			if (fgets(buffer, 255, fPtr) == NULL)
				break;
			else
				line = buffer;
		}
		ini_line l = ini_parse_line(&line);
		switch (l.type)
		{
			case INI_SECTION:
			{
				if (myString == replaceChars(l.name))
					found = true;
				else
					found = false;
			}
			case INI_PROPERTY:
			{
				if (found) {
					if (!strcmp(l.name, "video\\cropMode"))
						config.video.cropMode = atoi(l.value);
					else if (!strcmp(l.name, "video\\cropWidth"))
						config.video.cropWidth = atoi(l.value);
					else if (!strcmp(l.name, "video\\cropHeight"))
						config.video.cropHeight = atoi(l.value);
					else if (!strcmp(l.name, "video\\multisampling"))
						config.video.multisampling = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\aspect"))
						config.frameBufferEmulation.aspect = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\nativeResFactor"))
						config.frameBufferEmulation.nativeResFactor = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\copyToRDRAM"))
						config.frameBufferEmulation.copyToRDRAM = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\copyFromRDRAM"))
						config.frameBufferEmulation.copyFromRDRAM = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\copyDepthToRDRAM"))
						config.frameBufferEmulation.copyDepthToRDRAM = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\copyAuxToRDRAM"))
						config.frameBufferEmulation.copyAuxToRDRAM = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\N64DepthCompare"))
						config.frameBufferEmulation.N64DepthCompare = atoi(l.value);
					else if (!strcmp(l.name, "frameBufferEmulation\\bufferSwapMode"))
						config.frameBufferEmulation.bufferSwapMode = atoi(l.value);
					else if (!strcmp(l.name, "texture\\bilinearMode"))
						config.texture.bilinearMode = atoi(l.value);
					else if (!strcmp(l.name, "texture\\maxAnisotropy"))
						config.texture.maxAnisotropy = atoi(l.value);
					else if (!strcmp(l.name, "generalEmulation\\enableNativeResTexrects"))
						config.generalEmulation.enableNativeResTexrects = atoi(l.value);
					else if (!strcmp(l.name, "generalEmulation\\correctTexrectCoords"))
						config.generalEmulation.correctTexrectCoords = atoi(l.value);
					else if (!strcmp(l.name, "generalEmulation\\enableLegacyBlending"))
						config.generalEmulation.enableLegacyBlending = atoi(l.value);
					else if (!strcmp(l.name, "generalEmulation\\enableFragmentDepthWrite"))
						config.generalEmulation.enableFragmentDepthWrite = atoi(l.value);
				}
			}
		}
		if (internal) {
			line = strtok(NULL, "\n");
			if (line == NULL)
				break;
		}
	}
}