예제 #1
0
bool IniConfig::readAudio (ini_fd_t ini)
{
    bool ret = true;
    (void) ini_locateHeading (ini, "Audio");

    {
        int frequency = (int) audio_s.frequency;
        ret &= readInt (ini, "Frequency", frequency);
        audio_s.frequency = (unsigned long) frequency;
    }

    {
        int channels = 0;
        ret &= readInt (ini, "Channels",  channels);
        if (channels)
        {
            audio_s.playback = sid2_mono;
            if (channels != 1)
                audio_s.playback = sid2_stereo;
        }
    }

    ret &= readInt (ini, "BitsPerSample", audio_s.precision);
    return ret;
}
예제 #2
0
bool Rule::store ()
{
    char buff[10];
    char data[0x40006]; // Cater for worst possible case
    if (!m_matches)
        return false;
    sprintf (buff, "%d", m_player_id);
    ini_locateHeading (m_inifd, buff);

    {
        int   base  = m_addr[0] & 0xff00;
	    int   laddr = m_addr[0];
        int   group = 1;
        char *p     = data;

        sprintf (buff, "ID%d", group++);
        ini_locateKey (m_inifd, buff);
        p += sprintf (p, "$%04X", laddr - base);
        laddr--;
        for (int i = 0; i < m_ids; i++)
        {
            int addr = m_addr[i];
            if ((addr - 1) != laddr)
            {
                if ((addr - laddr) > (RULE_MAX_ERROR + 1))
                {
                    if (ini_writeString (m_inifd, data) < 0)
                        return false; // Error storing
                    p  = data;
                    // Move to next group
                    sprintf (buff, "ID%d", group++);
                    ini_locateKey (m_inifd, buff);
                    p  = data;
                    p += sprintf (p, "$%04X", addr - base);
                }
                else
                {
                    while (++laddr < addr)
                        p += sprintf (p, ":-");
                }
            }
            p += sprintf (p, ":$%02X", m_memory[addr]);
            laddr = addr;
        }
        if (ini_writeString (m_inifd, data) < 0)
            return false; // Error storing
    }
    return true;
}
예제 #3
0
bool IniConfig::readConsole (ini_fd_t ini)
{
    bool ret = true;
    (void) ini_locateHeading (ini, "Console");
    ret &= readBool (ini, "Ansi",                console_s.ansi);
    ret &= readChar (ini, "Char Top Left",       console_s.topLeft);
    ret &= readChar (ini, "Char Top Right",      console_s.topRight);
    ret &= readChar (ini, "Char Bottom Left",    console_s.bottomLeft);
    ret &= readChar (ini, "Char Bottom Right",   console_s.bottomRight);
    ret &= readChar (ini, "Char Vertical",       console_s.vertical);
    ret &= readChar (ini, "Char Horizontal",     console_s.horizontal);
    ret &= readChar (ini, "Char Junction Left",  console_s.junctionLeft);
    ret &= readChar (ini, "Char Junction Right", console_s.junctionRight);
    return ret;
}
예제 #4
0
int_least32_t SidDatabase::length (const char *md5, uint_least16_t song)
{
    int_least32_t  time = 0;

    if (!database)
    {
        errorString = ERR_NO_DATABASE_LOADED;
        return -1;
    }

    // Now set up array access
    if (ini_listDelims  (database, " ") == -1)
    {
        errorString = ERR_MEM_ALLOC;
        return -1;
    }

    // Read Time (and check times before hand)
    (void) ini_locateHeading (database, "Database");
    (void) ini_locateKey     (database, md5);
    // If length return is -1 then no entry found in database
    if (ini_dataLength (database) != -1)
    {
        char timeStamp[10];

        for (uint_least16_t i = 0; i < song; i++)
        {
            if (ini_readString (database, timeStamp, sizeof (timeStamp)) == -1)
            {   // No time found
                errorString = ERR_DATABASE_CORRUPT;
                return -1;
            }

            // Validate Time
            if (timesFound (timeStamp) != 1)
            {
                errorString = ERR_DATABASE_CORRUPT;
                return -1;
            }
        }

        // Parse timestamp
        time = parseTimeStamp (timeStamp);
    }

    return time;
}
예제 #5
0
bool IniConfig::readSidplay2 (ini_fd_t ini)
{
    bool ret = true;
    int  time, version = sidplay2_s.version;

    (void) ini_locateHeading (ini, "SIDPlay2");
    ret &= readInt (ini, "Version", version);
    if (version > 0)
        sidplay2_s.version = version;

    ret &= readString (ini, "Songlength Database", sidplay2_s.database);
    if (readTime (ini, "Default Play Length", time))
        sidplay2_s.playLength   = (uint_least32_t) time;
    if (readTime (ini, "Default Record Length", time))
        sidplay2_s.recordLength = (uint_least32_t) time;

    return ret;
}
예제 #6
0
void SidFilter::read (ini_fd_t ini, const char *heading)
{
    clear ();
    m_status = true;

    if (ini_locateHeading (ini, heading) < 0) {
        m_status = false;
        m_errorString = "SID Filter: Unable to locate filter section in input file";
        return;
    }

    struct parampair {
        const char* name;
        float*      address;
    };

    struct parampair sidparams[] = {
        { "DistortionRate",		&m_filter.rate                  },
        { "DistortionPoint",		&m_filter.point                 },
        { "DistortionCFThreshold",	&m_filter.cf_threshold          },
        { "VoiceNonlinearity",		&m_filter.voice_nonlinearity    },
        { "Type3BaseResistance",	&m_filter.baseresistance        },
        { "Type3Offset",		&m_filter.offset                },
        { "Type3Steepness",		&m_filter.steepness             },
        { "Type3MinimumFETResistance",	&m_filter.minimumfetresistance  },
        { "Type4K",			&m_filter.k                     },
        { "Type4B",			&m_filter.b                     },
        { NULL,				NULL                            }
    };

    for (int i = 0; sidparams[i].name != NULL; i ++) {
        /* Ensure that all parameters are zeroed, if missing. */
        double tmp = 0.;
        if (ini_locateKey(ini, sidparams[i].name) >= 0) {
            if (ini_readDouble(ini, &tmp) < 0) {
                std::string msg = "Invalid parameter: " + (std::string) sidparams[i].name + ": int expected";
                m_errorString = (char *) msg.c_str();
                m_status = false;
                return;
            }
        }
        *sidparams[i].address = (float) tmp;
    }
}
예제 #7
0
static int load_theme_config(void)
{
	char buffer[300], *p = buffer;
	int ret;

	if (!theme_config_fd) {
		/*Theme config is not loaded yet*/
		memset(theme_font_sizes_cache, 0, sizeof(theme_font_sizes_cache));
		/* Open config file */
		char *filename = cfg_findfile ("etc/nanowm.cfg");
		if (!filename)
			return -1;

		ini_fd_t fd = ini_open (filename, "r", "#;");
		free (filename);

		if (fd == NULL) {
			fprintf (stderr, "theme_get: Unable to open nanowm.cfg file\n");
			return -1;
		} else {
			ret = ini_locateHeading (fd, "Main");
			ret = ini_locateKey (fd, "Theme");
			ret = ini_readString (fd, p, sizeof (buffer));
		}
		ini_close(fd);
		if (ret < 0)
			p = "theme";
		/* open theme config file */
		char path[256] =  ACTIVETHEME_PATH;

		strncat(path, p, 255);
		strncat(path, ".cfg", 255);
		filename = cfg_findfile (path);
		theme_config_fd = ini_open (filename, "r", "#;");
		free (filename);
		if (theme_config_fd == NULL) {
			fprintf (stderr, "theme_get: Unable to open theme config file\n");
			return -1;
		}

	}
	return 0;
}
예제 #8
0
/**
 * Get font size from theme config
 */
int theme_fontsize(int index)
{
	int ret, fontsize;

	if (index < 0 || index > 3)
		return -1;
	if (load_theme_config() < 0)
		return -1;

	if (theme_font_sizes_cache[index])
		return theme_font_sizes_cache[index];

	ret = ini_locateHeading (theme_config_fd, "FontSize");
	ret |= ini_locateKey (theme_config_fd, theme_font_sizes[index]);
	ret |= ini_readInt(theme_config_fd, &fontsize);
	if (ret < 0)
		return -1;
	else {
		theme_font_sizes_cache[index] = fontsize;
		return fontsize;
	}
}
예제 #9
0
bool IniConfig::readEmulation (ini_fd_t ini)
{
    bool ret = true;
    (void) ini_locateHeading (ini, "Emulation");

    {
        int clockSpeed = -1;
        ret &= readInt (ini, "ClockSpeed", clockSpeed);
        if (clockSpeed != -1)
        {
            if (clockSpeed < 0 || clockSpeed > 1)
                ret = false;
            emulation_s.clockSpeed = SID2_CLOCK_PAL;
            if (clockSpeed)
                emulation_s.clockSpeed = SID2_CLOCK_NTSC;
        }
    }

    ret &= readBool (ini, "ForceSongSpeed", emulation_s.clockForced);

    {
        int mos8580 = -1;
        ret &= readInt (ini, "MOS8580", mos8580);
        if (mos8580 != -1)
        {
            if (mos8580 < 0 || mos8580 > 1)
                ret = false;
            emulation_s.sidModel = SID2_MOS6581;
            if (mos8580)
                emulation_s.sidModel = SID2_MOS8580;
        }
    }

    ret &= readBool (ini, "UseFilter", emulation_s.filter);

    ret &= readString (ini, "Filter6581", emulation_s.filter6581);
    ret &= readString (ini, "Filter8580", emulation_s.filter8580);
    ret &= readBool   (ini, "SidSamples", emulation_s.sidSamples);

    // These next two change the ini section!
    if (emulation_s.filter6581)
    {   // Try to load the filter
        filter6581.read (ini, emulation_s.filter6581);
        if (!filter6581)
        {
            filter6581.read (emulation_s.filter6581);
            if (!filter6581)
                ret = false;
        }
    }

    if (emulation_s.filter8580)
    {   // Try to load the filter
        filter8580.read (ini, emulation_s.filter8580);
        if (!filter8580)
        {
            filter8580.read (emulation_s.filter8580);
            if (!filter8580)
                ret = false;
        }
    }

    return ret;
}
예제 #10
0
bool Rule::recall (int player_id)
{
    char buff[10];
    char data[0x40006]; // Cater for worst possible case
    sprintf (buff, "%d", m_player_id);
    if (ini_locateHeading (m_inifd, buff) < 0)
        return false;

    {
        int   addr  = 0;
        int   count = 0;
        int   group = 1;
        char *p     = data;

        memset (m_memory, 0, sizeof (m_memory));

        for (;;)
        {
            int ret, val;
            sprintf (buff, "ID%d", group++);
            if (ini_locateKey (m_inifd, buff) < 0)
            {
                if (group == 1)
                    return false;
                break;
            }
            if (ini_readString (m_inifd, data, sizeof (data)) < 0)
                return false;

            p   = data;
            ret = 0;
            sscanf (p, "$%x%n", &val, &ret);
            if (ret != 5)
                return false;
            addr = val;
            p   += ret;
            while (*p != '\0')
            {
                int val;

                // Seperator
                if (*p++ != ':')
                    return false;

                // Place holder
                if (*p == '-')
                {
                    addr++;
                    p++;
                    continue;
                }

                // value
                ret = 0;
                sscanf (p, "$%x%n", &val, &ret);
                if (ret != 3)
                    return false;
                p += ret;
                m_memory[addr]  = val;
                m_flags[addr]   = UNKNOWN;
                m_addr[count++] = addr++;
            }
        }
        m_ids = count;
    }

    // Reset
    m_base        = m_addr[0];
    m_status      = true;
    m_filename[0] = '\0';
    m_matches     = 0;
    m_player_id   = player_id;

    // Double check input values are ok
    _eval ();
    return true;
}
예제 #11
0
/**
 * Get specified image from the active theme
 *
*/
int theme_get_image(int group_index, int image_index, int * xcoord, int * ycoord, GR_IMAGE_ID * pict_id)
{
	char buffer[300], *p = buffer;

	if (load_theme_config() < 0)
		return -1;
	/* load needed image */
	const char * theme_group; /*  group name */
	const char ** theme_images;	/* pointer to the theme_*_images array */
	switch(group_index) {
		case THEME_GROUP_TITLE:
			theme_group 	= theme_title;
			theme_images	= theme_title_images;
			break;
		case THEME_GROUP_MAINSCREEN:
			theme_group 	= theme_mainscreen;
			theme_images	= theme_mainscreen_images;
			break;
		default:
			return -1;
	}
	if (ini_locateHeading (theme_config_fd, theme_group) ) {
		fprintf (stderr, "theme_get: Unable to find group %s\n",theme_group);
		return -1;
	}
	if (ini_locateKey (theme_config_fd, theme_images[image_index] ) < 0 ) {
		fprintf (stderr, "theme_get: Unable to find key %s\n",theme_images[image_index]);
		return -1;
	}
	if (ini_readString (theme_config_fd, p, sizeof (buffer))  < 0 ) {
		fprintf (stderr, "theme_get: Unable to get string from key %s\n",theme_images[image_index]);
		return -1;
	}
	/* now parse key value */
	char * token;
	token = strtok(p, ", ");
	/*token = xcoord */
	*xcoord = atoi(token);

	token = strtok(NULL, ", ");
	/*token = ycoord */
	*ycoord = atoi(token);

	token = strtok(NULL, ", ");
	/*token = imagename */

	if (token) {
		/* we have found image name, now load it */
		char path[256] =  ACTIVETHEME_PATH;
		strncat(path, token, 255);
		char *filename = cfg_findfile (path);
		if(!filename) {
			fprintf (stderr, "theme_get: Unable to find image %s\n",path);
		} else {
	//		*wid = theme_load_image(filename);
			*pict_id = GrLoadImageFromFile(filename, 0);
			if (*pict_id == 0)
				fprintf(stderr, "theme_get: Failed to load image %s\n", filename);
			free(filename);
		}
	} else {
		*pict_id = 0;
	}
	return (*pict_id == 0)?-2:0;
}