Example #1
0
uint32_t hsStream::WriteSafeWStringLong(const plString &string)
{
    plStringBuffer<uint16_t> wbuff = string.ToUtf16();
    uint32_t len = wbuff.GetSize();
    WriteLE32(len);
    if (len > 0)
    {
        const uint16_t *buffp = wbuff.GetData();
        for (uint32_t i=0; i<len; i++)
        {
            WriteLE16(~buffp[i]);
        }
        WriteLE16(static_cast<uint16_t>(0));
    }
    return 0;
}
Example #2
0
uint32_t hsStream::WriteSafeWString(const plString &string)
{
    plStringBuffer<uint16_t> wbuff = string.ToUtf16();
    uint32_t len = wbuff.GetSize();
    hsAssert(len<0xf000, plString::Format("string len of %d is too long for WriteSafeWString, use WriteSafeWStringLong",
        len).c_str() );

    WriteLE16(len | 0xf000);
    if (len > 0)
    {
        const uint16_t *buffp = wbuff.GetData();
        for (uint32_t i=0; i<len; i++)
        {
            WriteLE16(~buffp[i]);
        }
        WriteLE16(static_cast<uint16_t>(0));
    }
    return 0;
}
Example #3
0
bool i82557eeprom::initWithAddress(volatile eeprom_control_t * p)
{
    int 	i;
    UInt16	sum;

    if (!super::init())
		return false;

    ee_p = p;

    /*
     * Find out the number of bits in the address by issuing a read to address
     * 0 ie. keep feeding eeprom address bits with value 0, until the eeprom
     * says that the address is complete.  It tells us by setting EEDO to 0 
     * after a write cycle.
     */
    EEPROMEnable(ee_p);
    EEPROMWriteBit(ee_p, 1); /* read */
    EEPROMWriteBit(ee_p, 1);
    EEPROMWriteBit(ee_p, 0);
    nbits = 1;

    do {
		EEPROMWriteBit(ee_p, 0);
		if ((ReadLE16(ee_p) & EEPROM_CONTROL_EEDO) == 0)
	    	break;
		nbits++;
    } while (nbits <= 32);

	// IOLog("nbits: %d\n", nbits);

    EEPROMDisable(ee_p);

    // Read NUM_EEPROM_WORDS words into memory.
    // Also compute a sum of the entire EEPROM.

    for (sum = 0, i = 0; i < (1 << nbits); i++) {
		UInt16 w = readWord(i);
		sum += w;
        if (i < NUM_EEPROM_WORDS)
            WriteLE16(&image.words[i], w);
    }
    if (sum != EEPROM_CHECKSUM_VALUE) {
		IOLog("i82557eeprom: checksum %x incorrect\n", sum);
        return false;
    }

    return true;
}
Example #4
0
uint32_t hsStream::WriteSafeString(const plString &string)
{
    int len = string.GetSize();
    hsAssert(len<0xf000, plString::Format("string len of %d is too long for WriteSafeString %s, use WriteSafeStringLong",
        len, string.c_str()).c_str() );

    WriteLE16(len | 0xf000);
    if (len > 0)
    {
        uint32_t i;
        const char *buffp = string.c_str();
        for (i = 0; i < len; i++)
        {
            WriteByte(~buffp[i]);
        }
        return i;
    }
    else
        return 0;
}
Example #5
0
/* load 82M object to AGG::Cache in Audio::CVT */
void AGG::Cache::LoadWAV(const M82::m82_t m82)
{
    std::vector<u8> & v = wav_cache[m82];

    if(v.size() || !Mixer::isValid()) return;

#ifdef WITH_MIXER
    const Settings & conf = Settings::Get();

    if(conf.UseAltResource())
    {
       std::string name(M82::GetString(m82));
       String::Lower(name);
       // ogg
       String::Replace(name, ".82m", ".ogg");
       std::string sound = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "sounds" + SEPARATOR + name;

       if(StoreFileToMem(v, sound))
       {
           DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadWAV: " << sound);
           return;
       }

       // mp3
       String::Replace(name, ".82m", ".mp3");
       sound = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "sounds" + SEPARATOR + name;

       if(StoreFileToMem(v, sound))
       {
           DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadWAV: " << sound);
           return;
       }
    }
#endif

    DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadWAV: " << M82::GetString(m82));
    std::vector<u8> body;

#ifdef WITH_MIXER
    if(ReadChunk(M82::GetString(m82), body))
    {
	// create WAV format
	v.resize(body.size() + 44);

	WriteLE32(&v[0], 0x46464952);		// RIFF
	WriteLE32(&v[4], body.size() + 0x24);	// size
	WriteLE32(&v[8], 0x45564157);		// WAVE
	WriteLE32(&v[12], 0x20746D66);		// FMT
	WriteLE32(&v[16], 0x10);		// size_t
	WriteLE16(&v[20], 0x01);		// format
	WriteLE16(&v[22], 0x01);		// channels
	WriteLE32(&v[24], 22050);		// samples
	WriteLE32(&v[28], 22050);		// byteper
	WriteLE16(&v[32], 0x01);		// align
	WriteLE16(&v[34], 0x08);		// bitsper
	WriteLE32(&v[36], 0x61746164);		// DATA
	WriteLE32(&v[40], body.size());		// size

	std::copy(body.begin(), body.end(), &v[44]);
    }
#else
    Audio::Spec wav_spec;
    wav_spec.format = AUDIO_U8;
    wav_spec.channels = 1;
    wav_spec.freq = 22050;

    const Audio::Spec & hardware = Audio::GetHardwareSpec();

    Audio::CVT cvt;

    if(cvt.Build(wav_spec, hardware) &&
       ReadChunk(M82::GetString(m82), body))
    {
	const u32 size = cvt.len_mult * body.size();

	cvt.buf = new u8[size];
	cvt.len = body.size();

	memcpy(cvt.buf, &body[0], body.size());

	cvt.Convert();

	v.assign(cvt.buf, cvt.buf + size - 1);

	delete [] cvt.buf;
	cvt.buf = NULL;
    }
#endif
}