/*
========================
idSWFBitStream::ReadColorRGB
========================
*/
void idSWFBitStream::ReadColorRGB( swfColorRGB_t& color )
{
	ResetBits();
	color.r = *readp++;
	color.g = *readp++;
	color.b = *readp++;
}
/*
========================
idSWFBitStream::Free
========================
*/
void idSWFBitStream::Free()
{
	if( free )
	{
		Mem_Free( ( void* )startp );
	}
	free = false;
	startp = NULL;
	endp = NULL;
	readp = NULL;
	ResetBits();
}
/*
========================
idSWFBitStream::ReadData
========================
*/
const byte* idSWFBitStream::ReadData( int size )
{
	assert( readp >= startp && readp <= endp );
	ResetBits();
	if( readp + size > endp )
	{
		// buffer overrun
		assert( false );
		readp = endp;
		return startp;
	}
	const byte* buffer = readp;
	readp += size;
	assert( readp >= startp && readp <= endp );
	return buffer;
}
/*
========================
idSWFBitStream::Load
========================
*/
void idSWFBitStream::Load( const byte* data, uint32 len, bool copy )
{
	Free();
	
	if( copy )
	{
		free = true;
		startp = ( const byte* )Mem_Alloc( len, TAG_SWF );
		memcpy( ( byte* )startp, data, len );
	}
	else
	{
		free = false;
		startp = data;
	}
	endp = startp + len;
	readp = startp;
	
	ResetBits();
}
void GPIO::SetValue(U32 pin, U32 value, U32 mask)
{
	SetBits((value<<pin) & mask);
	ResetBits((~value<<pin) & mask);
}