示例#1
0
BigInt::BigInt(std::string number)
{
    _sign = SIGN_POSITIVE;
    std::string character;
    for (unsigned int i = 0; i < number.size(); i++){
        character = number.substr(i, 1);
        if (_isDigit(character)){
            _number.push_back(std::stoi(character));
        } else if (i == 0 && character == std::string("-")){
            _sign = SIGN_NEGATIVE;
        }
    }
}
示例#2
0
UInt32
IOUSBIUnknown::_versionNumberFromString(CFStringRef versStr)
{
    // Parse version number from a string that has XXXX.Y.ZZZ
    // String can end at any point, but elements within the string cannot be skipped.
    
    UInt32      major1 = 0, minor1 = 0,  stage = RELEASE_STAGE, build = 0;
    UniChar     versChars[MAX_VERS_LEN];
    UniChar *   chars = NULL;
    CFIndex     len;
    UInt32      theVers;
    CFIndex     majorCount = 0;
    UInt32      firstTuple = 0;
    
    if (!versStr)
        return 0;
    
    len = CFStringGetLength(versStr);
    if (len <= 0 || len > MAX_VERS_LEN)
        return 0;
    
    CFStringGetCharacters(versStr, CFRangeMake(0, len), versChars);
    chars = versChars;
    
    // Get first tuple
    if (_isDigit(*chars))
    {
        // Count how many digits in the tuple
        while (*chars != (UniChar)'.')
        {
            majorCount++;
            chars++;
        }
        
        majorCount--;
        chars = versChars;
        while (*chars != (UniChar)'.')
        {
            major1 = *chars - (UniChar)'0';
            firstTuple += major1 * pow(10, majorCount);
            majorCount--;
            chars++;
            len--;
            if (len == 0)
                break;
        }
        
        // Now we have the first tuple, create the Major and Minor versions from it.  Minor will be the 10's + 1's.
        // Major will be the rest.
        major1 = firstTuple / 100;
        minor1 = firstTuple - (major1*100);
        chars++;
        len--;
    }
    
    // Now either len is 0 or chars points at the build stage letter.
    // Get the build stage
    if (len > 0)
    {
        if (*chars == (UniChar)'1')
        {
            stage = DEVELOPMENT_STAGE;
        }
        else if (*chars == (UniChar)'2')
        {
            stage = ALPHA_STAGE;
        }
        else if (*chars == (UniChar)'3')
        {
            stage = BETA_STAGE;
        }
        else if (*chars == (UniChar)'4')
        {
            stage = RELEASE_STAGE;
        }
        else
        {
            stage = 0;
        }
        
        // Skip over the "." and point to the release
        chars++;
        chars++;
        len--;
        len--;
    }
    
    // Now stage contains the release stage.
    // Now either len is 0 or chars points at the build number.
    // Get the first digit of the build number.
    if (len > 0)
    {
        if (_isDigit(*chars))
        {
            build = *chars - (UniChar)'0';
            chars++;
            len--;
        }
    }
    
    // Get the second digit of the build number.
    if (len > 0)
    {
        if (_isDigit(*chars))
        {
            build *= 10;
            build += *chars - (UniChar)'0';
            chars++;
            len--;
        }
    }
    
    // Get the third digit of the build number.
    if (len > 0)
    {
        if (_isDigit(*chars))
        {
            build *= 10;
            build += *chars - (UniChar)'0';
            chars++;
            len--;
        }
    }
    
    // Range check
    if (build > 0xFF)
        build = 0xFF;
    
    // Build the number
    theVers = major1 << 24;
    theVers += minor1 << 16;
    theVers += stage << 8;
    theVers += build;
    
    return theVers;
}
示例#3
0
void GBIInfo::loadMicrocode(u32 uc_start, u32 uc_dstart, u16 uc_dsize)
{
	for (Microcodes::iterator iter = m_list.begin(); iter != m_list.end(); ++iter) {
		if (iter->address == uc_start && iter->dataAddress == uc_dstart && iter->dataSize == uc_dsize) {
			_makeCurrent(&(*iter));
			return;
		}
	}

	m_list.emplace_front();
	MicrocodeInfo & current = m_list.front();
	current.address = uc_start;
	current.dataAddress = uc_dstart;
	current.dataSize = uc_dsize;
	current.NoN = false;
	current.textureGen = true;
	current.branchLessZ = true;
	current.type = NONE;

	// See if we can identify it by CRC
	const u32 uc_crc = CRC_Calculate( 0xFFFFFFFF, &RDRAM[uc_start & 0x1FFFFFFF], 4096 );
	const u32 numSpecialMicrocodes = sizeof(specialMicrocodes) / sizeof(SpecialMicrocodeInfo);
	for (u32 i = 0; i < numSpecialMicrocodes; ++i) {
		if (uc_crc == specialMicrocodes[i].crc) {
			current.type = specialMicrocodes[i].type;
			current.NoN = specialMicrocodes[i].NoN;
			_makeCurrent(&current);
			return;
		}
	}

	// See if we can identify it by text
	char uc_data[2048];
	UnswapCopyWrap(RDRAM, uc_dstart & 0x1FFFFFFF, (u8*)uc_data, 0, 0x7FF, 2048);
	char uc_str[256];
	strcpy(uc_str, "Not Found");

	for (u32 i = 0; i < 2048; ++i) {
		if ((uc_data[i] == 'R') && (uc_data[i+1] == 'S') && (uc_data[i+2] == 'P')) {
			u32 j = 0;
			while (uc_data[i+j] > 0x0A) {
				uc_str[j] = uc_data[i+j];
				j++;
			}

			uc_str[j] = 0x00;

			int type = NONE;

			if (strncmp( &uc_str[4], "SW", 2 ) == 0)
				type = F3D;
			else if (strncmp( &uc_str[4], "Gfx", 3 ) == 0) {
				current.NoN = (strstr( uc_str + 4, ".NoN") != NULL);

				if (strncmp( &uc_str[14], "F3D", 3 ) == 0) {
					if (uc_str[28] == '1' || strncmp(&uc_str[28], "0.95", 4) == 0 || strncmp(&uc_str[28], "0.96", 4) == 0)
						type = F3DEX;
					else if (uc_str[31] == '2')
						type = F3DEX2;
					if (strncmp(&uc_str[14], "F3DF", 4) == 0)
						current.textureGen = false;
					else if (strncmp(&uc_str[14], "F3DZ", 4) == 0)
						current.branchLessZ = false;
				}
				else if (strncmp( &uc_str[14], "L3D", 3 ) == 0) {
					u32 t = 22;
					while (!_isDigit(uc_str[t]) && t++ < j);
					if (uc_str[t] == '1')
						type = L3DEX;
					else if (uc_str[t] == '2')
						type = L3DEX2;
				}
				else if (strncmp( &uc_str[14], "S2D", 3 ) == 0) {
					u32 t = 20;
					while (!_isDigit(uc_str[t]) && t++ < j);
					if (uc_str[t] == '1')
						type = S2DEX;
					else if (uc_str[t] == '2')
						type = S2DEX2;
				}
				else if (strncmp(&uc_str[14], "ZSortp", 6) == 0) {
					type = ZSortp;
				}
			}

			if (type != NONE) {
				current.type = type;
				_makeCurrent(&current);
				return;
			}

			break;
		}
	}

	assert(false && "unknown ucode!!!'n");
	_makeCurrent(&current);
}